Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1.  
  2. #include <errno.h>
  3. #include <stdlib.h>
  4. #include <sys/unistd.h>
  5. #include <sys/kos_io.h>
  6. #include "glue.h"
  7. #include "io.h"
  8.  
  9.  
  10. _off_t
  11. _DEFUN (lseek, (fd, pos, whence),
  12.      int fd _AND
  13.      _off_t pos _AND
  14.      int whence)
  15.  
  16. {
  17.     fileinfo_t  info;
  18.     __io_handle *ioh;
  19.     _off_t ret;
  20.  
  21.     if( (fd < 0) || (fd >=64) )
  22.     {
  23.         errno = EBADF;
  24.         return (-1);
  25.     };
  26.  
  27.     ioh = &__io_tab[fd];
  28.  
  29.     switch(whence)
  30.     {
  31.         case SEEK_SET:
  32.             ret = pos;
  33.             break;
  34.         case SEEK_CUR:
  35.             ret = ioh->offset + pos;
  36.             break;
  37.         case SEEK_END:
  38.         {
  39.             get_fileinfo(ioh->name, &info);
  40.             ret = pos + info.size;
  41.             break;
  42.         }
  43.         default:
  44.             errno = EINVAL;
  45.             return (-1);
  46.     };
  47.  
  48.     ioh->offset = ret;
  49.  
  50.     return( ret );
  51. };
  52.