home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / EOF.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  2.6 KB  |  91 lines

  1. /*---------------------------------------------------------------------------
  2.  * filename - eof.cas
  3.  *
  4.  * function(s)
  5.  *        eof - detects end-of-file
  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 <io.h>
  20. #include <fcntl.h>
  21. #include <_io.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     eof(int handle)
  41. {
  42.         long    endPosn;
  43.  
  44.         if (_O_EOF & _openfd [handle])  return 1;      /* ^Z has been seen */
  45.  
  46. asm     mov     ax,4400h
  47. asm     mov     bx,handle
  48. asm     int     21h
  49. asm     jc      eofFailed
  50. asm     test    dl,080h
  51. asm     jnz     NotEof          /* Never EOF for devices */
  52.  
  53. asm     mov     ax,04201h
  54. asm     xor     cx,cx
  55. asm     mov     dx,cx
  56. asm     int     21h             /* Get current endPosn */
  57. asm     jc      eofFailed
  58.  
  59. asm     push    dx
  60. asm     push    ax
  61. asm     mov     ax,04202h
  62. asm     xor     cx,cx
  63. asm     mov     dx,cx
  64. asm     int     21h             /* Get end-of-file endPosn */
  65. asm     mov     word ptr endPosn, ax
  66. asm     mov     word ptr endPosn+2, dx
  67. asm     pop     dx
  68. asm     pop     cx
  69. asm     jc      eofFailed
  70.  
  71. asm     mov     ax,04200h
  72. asm     int     21h             /* Restore current endPosn */
  73. asm     jc      eofFailed
  74.  
  75. asm     cmp     dx, endPosn + 2
  76. asm     jb      NotEof
  77. asm     ja      IsEof
  78. asm     cmp     ax, endPosn
  79. asm     jb      NotEof
  80.  
  81. IsEof:
  82.     return  1;
  83.  
  84. NotEof:
  85.     return  0;
  86.  
  87. eofFailed:
  88.     return __IOerror (_AX);
  89. }
  90.  
  91.