akaros/tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/lseek.c
<<
>>
Prefs
   1#include <unistd.h>
   2#include <sys/types.h>
   3#include <errno.h>
   4#include <assert.h>
   5#include <ros/syscall.h>
   6
   7/* potentially a 32 bit seek (off_t is a long) */
   8off_t __libc_lseek (int fd, off_t offset, int whence)
   9{
  10        loff_t retoff = 0;
  11        off_t hi = 0;
  12        off_t lo = 0;
  13        off_t ret;
  14
  15        if (fd < 0) {
  16                __set_errno (EBADF);
  17                return -1;
  18        }
  19        switch (whence) {
  20                case SEEK_SET:
  21                case SEEK_CUR:
  22                case SEEK_END:
  23                        break;
  24                default:
  25                        __set_errno (EINVAL);
  26                        return -1;
  27        }
  28        /* get the high and low part, regardless of whether offset was already
  29         * 64 bits or not (casting to avoid warnings) */
  30        hi = (loff_t)offset >> 32;
  31        lo = offset & 0xffffffff;
  32        ret = ros_syscall(SYS_llseek, fd, hi, lo, &retoff, whence, 0);
  33        if (ret) {
  34                assert(ret == -1);      /* catch odd bugs */
  35                return ret;
  36        }
  37        /* Get the lower 32 or 64 bits, depending on the length of long */
  38        ret = retoff & (unsigned long)(-1);
  39        return ret;
  40}
  41weak_alias (__libc_lseek, __lseek)
  42libc_hidden_def (__lseek)
  43weak_alias (__libc_lseek, lseek)
  44