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

  1. /*---------------------------------------------------------------------------
  2.  * filename - eof.cas
  3.  *
  4.  * function(s)
  5.  *        eof - detects end-of-file
  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 <io.h>
  19. #include <fcntl.h>
  20. #include <_io.h>
  21. #include <RtlData.h>
  22.  
  23. /*--------------------------------------------------------------------------*
  24.  
  25. Name            eof - detects end-of-file
  26.  
  27. Usage           int eof(int handle);
  28.  
  29. Prototype in    io.h
  30.  
  31. Description     determines whether the file associated with handle has
  32.                 reached end-of-file
  33.  
  34. Return value    1 on end of file; otherwise 0.  A return value of -1
  35.                 indicates an error; and errno is set to:
  36.  
  37.                         EBADF  Bad file number
  38.  
  39. *---------------------------------------------------------------------------*/
  40. int     _FARFUNC eof(int handle)
  41. {
  42.         long    endPosn;
  43.  
  44.         if ((unsigned)handle >= _nfile)
  45.                 return __IOerror(e_badHandle);
  46.  
  47.         if (_O_EOF & _RTLInstanceData(_openfd )[handle])
  48.            return 1;      /* ^Z has been seen */
  49.  
  50. asm     mov     ax,4400h
  51. asm     mov     bx,handle
  52. asm     int     21h
  53. asm     jc      eofFailed
  54. asm     test    dl,080h
  55. asm     jnz     NotEof          /* Never EOF for devices */
  56.  
  57. asm     mov     ax,04201h
  58. asm     xor     cx,cx
  59. asm     mov     dx,cx
  60. asm     int     21h             /* Get current endPosn */
  61. asm     jc      eofFailed
  62.  
  63. asm     push    dx
  64. asm     push    ax
  65. asm     mov     ax,04202h
  66. asm     xor     cx,cx
  67. asm     mov     dx,cx
  68. asm     int     21h             /* Get end-of-file endPosn */
  69. asm     mov     word ptr endPosn, ax
  70. asm     mov     word ptr endPosn+2, dx
  71. asm     pop     dx
  72. asm     pop     cx
  73. asm     jc      eofFailed
  74.  
  75. asm     mov     ax,04200h
  76. asm     int     21h             /* Restore current endPosn */
  77. asm     jc      eofFailed
  78.  
  79. asm     cmp     dx, endPosn + 2
  80. asm     jb      NotEof
  81. asm     ja      IsEof
  82. asm     cmp     ax, endPosn
  83. asm     jb      NotEof
  84.  
  85. IsEof:
  86.     return  1;
  87.  
  88. NotEof:
  89.     return  0;
  90.  
  91. eofFailed:
  92.     return __IOerror (_AX);
  93. }
  94.  
  95.