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

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