Subversion Repositories Kolibri OS

Rev

Rev 4921 | Blame | Compare with Previous | Last modification | View Log | RSS feed

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