home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / LSEEK.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  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. /*|                                                              |*/
  10. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  11. /*|                                                              |*/
  12. /*|                                                              |*/
  13. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  14. /*|     All Rights Reserved.                                     |*/
  15. /*|                                                              |*/
  16. /*[]------------------------------------------------------------[]*/
  17.  
  18. #pragma inline
  19. #include <asmrules.h>
  20. #include <io.h>
  21. #include <fcntl.h>
  22. #include <_io.h>
  23.  
  24. /*-----------------------------------------------------------------------*
  25.  
  26. Name        lseek - moves read/write file pointer
  27.  
  28. Usage        #include <io.h>
  29.         long lseek(int handle, long offset, 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 offset, int kind)
  68. {
  69.     _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, offset+2
  75. asm    mov    dx, offset
  76. asm    int    21h
  77. asm    jc    lseekFailed
  78.  
  79.         return( MK_LONG );
  80.  
  81. lseekFailed:
  82.     return    __IOerror (_AX);
  83. }
  84.