home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / LIBSRC.ZOO / libsrc / local / lseek.c < prev    next >
Text File  |  1992-02-16  |  847b  |  43 lines

  1. #define INCL_DOSFILEMGR
  2. #define INCL_DOSERRORS
  3. #include <os2.h>
  4. #include <sys/file.h>
  5. #include <errno.h>
  6.  
  7. ULONG Dos32SetFilePtr() asm ("Dos32SetFilePtr");
  8.  
  9. int lseek (int fd, long offset, int whence)
  10. {
  11.    ULONG rc;
  12.    ULONG NewPos;
  13.  
  14.    if (whence == L_SET)
  15.       rc = Dos32SetFilePtr (fd, offset, FILE_BEGIN, &NewPos);
  16.    else
  17.       if (whence == L_INCR)
  18.          rc = Dos32SetFilePtr (fd, offset, FILE_CURRENT, &NewPos);
  19.       else
  20.          if (whence == L_XTND)
  21.             rc = Dos32SetFilePtr (fd, offset, FILE_END, &NewPos);
  22.          else
  23.          {
  24.             errno = EINVAL;
  25.             return (-1);
  26.          }
  27.  
  28.    if (rc)
  29.    {
  30.       if (rc == ERROR_INVALID_HANDLE)
  31.       {
  32.          errno = EBADF;
  33.          return (-1);
  34.       }
  35.  
  36.       errno = EIO;
  37.       return (-1);
  38.    }
  39.  
  40.    return (NewPos);
  41. }
  42.  
  43.