home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / CLIBSRC2.ZIP / DOSSEEK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.4 KB  |  71 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - dosseek.c
  3.  *
  4.  * function(s)
  5.  *        _dos_seek - moves read/write file pointer
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1991, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #include <_io.h>
  18. #include <dos.h>
  19.  
  20. /*-----------------------------------------------------------------------*
  21.  
  22. Name            _dos_seek - moves read/write file pointer
  23.  
  24. Usage           #include <io.h>
  25.                 unsigned _dos_seek(int handle, long offset, int fromwhere,
  26.                                    long *newoffset);
  27.  
  28. Prototype in    none
  29.  
  30. Description     _dos_seek sets the file pointer associated with handle
  31.                 to a new position that is offset bytes beyond the file
  32.                 location given by fromwhere. fromwhere must be one of the
  33.                 values 0, 1 or 2, which represent three symbolic constants
  34.                 (defined in stdio.h and io.h) as follows:
  35.  
  36.                 fromwhere       File Location
  37.                 SEEK_SET (0)    file beginning
  38.                 SEEK_CUR (1)    current file pointer position
  39.                 SEEK_END (2)    end-of-file
  40.  
  41.                 The new file position, measured in bytes from the start
  42.                 of the file, is stored at *newoffset if the seek is
  43.                 successful.
  44.  
  45. Return value    On success, _dos_seek returns 0.  Otherwise, it returns
  46.                 the DOS error code, and errno is set to one of the following:
  47.  
  48.                         EBADF   Bad file number
  49.                         EINVAL  Invalid argument
  50.  
  51.                 On devices incapable of seeking (such as terminals and
  52.                 printers), the return value is undefined.
  53.  
  54. *------------------------------------------------------------------------*/
  55. unsigned _dos_seek(int fd, long offset, int kind, long *newoffset)
  56. {
  57.     _BX = fd;
  58.     _CX = FP_SEG(offset);
  59.     _DX = FP_OFF(offset);
  60.     _AH = 0x42;
  61.     _AL = kind;
  62.     geninterrupt(0x21);
  63.     if (_FLAGS & 1)                     /* if carry set, error */
  64.         return (__DOSerror(_AX));       /* set errno */
  65.     else
  66.     {
  67.         *newoffset = (long)((void _seg *)(_DX) + (void near *)(_AX));
  68.         return (0);
  69.     }
  70. }
  71.