home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 5.ddi / CLIBSRC2.ZIP / LSEEK.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  2.6 KB  |  84 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - lseek.cas
  3.  *
  4.  * function(s)
  5.  *        lseek - moves read/write file pointer
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #pragma inline
  18. #include <asmrules.h>
  19. #include <io.h>
  20. #include <fcntl.h>
  21. #include <_io.h>
  22. #include <RtlData.h>
  23.  
  24. /*-----------------------------------------------------------------------*
  25.  
  26. Name            lseek - moves read/write file pointer
  27.  
  28. Usage           #include <io.h>
  29.                 long lseek(int handle, long ofs, int fromwhere);
  30.  
  31. Related
  32. functions usage long tell(int handle);
  33.  
  34. Prototype in    io.h
  35.  
  36. Description     lseek sets the file pointer associated with handle
  37.                 to a new position that is offset bytes beyond the file
  38.                 location given by fromwhere. fromwhere must be one of the
  39.                 values 0, 1 or 2, which represent three symbolic constants
  40.                 (defined in stdio.h) as follows:
  41.  
  42.                 fromwhere       File Location
  43.                 SEEK_SET (0)    file beginning
  44.                 SEEK_CUR (1)    current file pointer position
  45.                 SEEK_END (2)    end-of-file
  46.  
  47.                 tell gets the current position of the file pointer associated
  48.                 with handle and expresses it as the number of bytes from the
  49.                 beginning of the file.
  50.  
  51. Return value    lseek returns the offset of the pointer's new
  52.                 position, measured in bytes from the file beginning. lseek
  53.                 returns -1L on error, and errno is set to one of the following:
  54.  
  55.                         EBADF   Bad file number
  56.                         EINVAL  Invalid argument
  57.  
  58.                 On devices incapable of seeking (such as terminals and
  59.                 printers), the return value is undefined.
  60.  
  61.                 tell returns the current file pointer position. A return of -1
  62.                 (long) indicates an error, and errno is set to:
  63.  
  64.                         EBADF   Bad file number
  65.  
  66. *------------------------------------------------------------------------*/
  67. long _CType lseek(int fd, long ofs, int kind)
  68. {
  69.         _RTLInstanceData(_openfd) [fd] &= ~_O_EOF;      /* forget about ^Z      */
  70.  
  71. asm     mov     ah, 42h
  72. asm     mov     al, kind
  73. asm     mov     bx, fd
  74. asm     mov     cx, ofs+2
  75. asm     mov     dx, ofs
  76. asm     int     21h
  77. asm     jc      lseekFailed
  78.  
  79.         return( MK_LONG );
  80.  
  81. lseekFailed:
  82.         return  __IOerror (_AX);
  83. }
  84.