2024-01-04 23:20:35 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) KolibriOS team 2004-2024. All rights reserved.
|
|
|
|
* Distributed under terms of the GNU General Public License
|
|
|
|
*/
|
2014-05-11 00:12:19 +02:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/unistd.h>
|
2024-01-04 23:20:35 +01:00
|
|
|
#include <sys/ksys.h>
|
2014-05-11 00:12:19 +02:00
|
|
|
#include "glue.h"
|
|
|
|
#include "io.h"
|
|
|
|
|
|
|
|
_off_t
|
|
|
|
_DEFUN (lseek, (fd, pos, whence),
|
|
|
|
int fd _AND
|
|
|
|
_off_t pos _AND
|
|
|
|
int whence)
|
|
|
|
{
|
2024-01-04 23:20:35 +01:00
|
|
|
ksys_file_info_t info;
|
2014-05-11 00:12:19 +02:00
|
|
|
__io_handle *ioh;
|
|
|
|
_off_t ret;
|
|
|
|
|
2024-01-04 23:20:35 +01:00
|
|
|
if ((fd < 0) || (fd >=64))
|
2014-05-11 00:12:19 +02:00
|
|
|
{
|
|
|
|
errno = EBADF;
|
|
|
|
return (-1);
|
2024-01-04 23:20:35 +01:00
|
|
|
}
|
2014-05-11 00:12:19 +02:00
|
|
|
|
|
|
|
ioh = &__io_tab[fd];
|
|
|
|
|
|
|
|
switch(whence)
|
|
|
|
{
|
|
|
|
case SEEK_SET:
|
|
|
|
ret = pos;
|
|
|
|
break;
|
|
|
|
case SEEK_CUR:
|
|
|
|
ret = ioh->offset + pos;
|
|
|
|
break;
|
|
|
|
case SEEK_END:
|
|
|
|
{
|
2024-01-04 23:20:35 +01:00
|
|
|
_ksys_file_info(ioh->name, &info);
|
2014-05-11 00:12:19 +02:00
|
|
|
ret = pos + info.size;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
errno = EINVAL;
|
2024-01-04 23:20:35 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2014-05-11 00:12:19 +02:00
|
|
|
|
|
|
|
ioh->offset = ret;
|
|
|
|
|
2024-01-04 23:20:35 +01:00
|
|
|
return ret;
|
|
|
|
}
|