home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / CLIBSRC1.ZIP / FLENGTH.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  1.6 KB  |  67 lines

  1. /*---------------------------------------------------------------------------
  2.  * filename - flength.cas
  3.  *
  4.  * function(s)
  5.  *        filelength - gets file size in bytes
  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 <_io.h>
  20.  
  21. /*--------------------------------------------------------------------------*
  22.  
  23. Name            filelength - gets file size in bytes
  24.  
  25. Usage           long filelength(int handle);
  26.  
  27. Prototype in    io.h
  28.  
  29. Description     returns the length (in bytes) of the file associated
  30.                 with handle
  31.  
  32. Return value    success : length of the file
  33.                 failure : -1L and errno is set to
  34.  
  35.                         EBADF  Bad file number
  36.  
  37. *---------------------------------------------------------------------------*/
  38. long _FARFUNC filelength (int handle)
  39. {
  40.         long    Position;
  41.  
  42. asm     mov     ax,4201h
  43. asm     mov     bx,handle
  44. asm     xor     cx,cx
  45. asm     xor     dx,dx
  46. asm     int     21h
  47. asm     jc      filelengthFailed
  48. asm     push    dx
  49. asm     push    ax
  50. asm     mov     ax,4202h
  51. asm     xor     cx,cx
  52. asm     xor     dx,dx
  53. asm     int     21h
  54. asm     mov     word ptr Position, ax
  55. asm     mov     word ptr Position+2, dx
  56. asm     pop     dx
  57. asm     pop     cx
  58. asm     jc      filelengthFailed
  59. asm     mov     ax,4200h
  60. asm     int     21h
  61. asm     jc      filelengthFailed
  62.         return (Position);
  63.  
  64. filelengthFailed:
  65.         return __IOerror (_AX);
  66. }
  67.