Added pipe() syscall; Fixed some memleaks;
[ZeXOS.git] / kernel / lib / unistd / lseek.c
blobad414eddc229ccabb6f066e9ed89396c051623d1
1 /*
2 * ZeX/OS
3 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <fd.h>
21 #include <file.h>
22 #include <stdio.h>
23 #include <system.h>
25 long lseek (int fd, long offset, int whence)
27 fd_t *d = fd_get (fd);
29 if (!d)
30 return offset-1;
32 unsigned l = d->p + d->e;
34 switch (whence) {
35 case SEEK_SET:
36 d->p = offset;
37 d->e = l;
38 break;
39 case SEEK_CUR:
40 d->p += offset;
41 break;
42 case SEEK_END:
43 d->p = (l + offset);
44 d->e = 0;
45 break;
48 return d->p;