FreeNOS
lseek.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <FileDescriptor.h>
19 #include "errno.h"
20 #include "unistd.h"
21 
22 off_t lseek(int fildes, off_t offset, int whence)
23 {
24  // Do we have this file descriptor?
26  if (!fd || !fd->open)
27  {
28  errno = ENOENT;
29  return -1;
30  }
31 
32  // Update the file position pointer
33  fd->position = offset;
34 
35  // Done
36  return 0;
37 }
FileDescriptor::Entry::position
Size position
< Process identifier of the filesystem
Definition: FileDescriptor.h:50
off_t
sint off_t
Used for file sizes.
Definition: types.h:59
StrictSingleton< FileDescriptor >::instance
static FileDescriptor * instance()
Retrieve the instance.
Definition: Singleton.h:53
errno
C int errno
The lvalue errno is used by many functions to return error values.
FileDescriptor::Entry::open
bool open
< Current position indicator.
Definition: FileDescriptor.h:51
FileDescriptor.h
FileDescriptor::getEntry
Entry * getEntry(const Size index)
Retrieve a file descriptor Entry.
Definition: FileDescriptor.cpp:58
FileDescriptor::Entry
Describes a single file opened by a user process.
Definition: FileDescriptor.h:46
lseek
off_t lseek(int fildes, off_t offset, int whence)
Move the read/write file offset.
Definition: lseek.cpp:22
unistd.h
ENOENT
#define ENOENT
No such file or directory.
Definition: errno.h:178
errno.h