home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 2.ddi / CLIBSRC3.ZIP / FINDFIRS.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  4.7 KB  |  157 lines

  1. /*---------------------------------------------------------------------------
  2.  * filename - findfirs.cas
  3.  *
  4.  * function(s)
  5.  *        findfirst - searches disk directory
  6.  *        findnext  - fetches files which match findfirst
  7.  *--------------------------------------------------------------------------*/
  8.  
  9. /*
  10.  *      C/C++ Run Time Library - Version 5.0
  11.  *
  12.  *      Copyright (c) 1987, 1992 by Borland International
  13.  *      All Rights Reserved.
  14.  *
  15.  */
  16.  
  17.  
  18. #pragma  inline
  19. #include <asmrules.h>
  20. #include <dir.h>
  21. #include <_io.h>
  22.  
  23. /*--------------------------------------------------------------------------*
  24.  
  25. Name            findfirst - searches disk directory
  26.  
  27. Usage           int findfirst(const char *pathname, struct ffblk *ffblk,
  28.                               int attrib);
  29.  
  30. Prototype in    dir.h
  31.  
  32. Description     begins a search of a disk directory by using the
  33.                 MS-DOS system call 0x4E.
  34.  
  35.                 pathname is a string with an optional drive specifier,
  36.                 path and file name of the file to be found.   If a
  37.                 matching file is found, the ffblk structure is filled
  38.                 with the file-directory information.
  39.  
  40.                 attrib is an MS-DOS file-attribute byte used in selecting
  41.                 eligible files for the search.  attrib can be one of the
  42.                 following constants defined in dos.h
  43.  
  44.                         FA_RDONLY  Read only
  45.                         FA_HIDDEN  Hidden file
  46.                         FA_SYSTEM  System file
  47.                         FA_LABEL   Volume label
  48.                         FA_DIREC   Directory
  49.                         FA_ARCH    Archive
  50.  
  51.                 For more detailed information about these attributes, refer
  52.                 to the MS-DOS Programmer's Reference Manual.
  53.  
  54. Return value    success : 0
  55.                 else : -1 and errno is set to
  56.                         ENOENT  Path or file name not found
  57.                         ENMFILE No more files
  58.  
  59. *---------------------------------------------------------------------------*/
  60.  
  61. int _CType _FARFUNC findfirst(const char *pathname, struct ffblk *ffblk, int attrib)
  62. {
  63. asm     push    ds
  64.  
  65. asm     mov     ah,2fh          /* get (and save) DTA */
  66. asm     int     21h
  67. asm     push    es
  68. asm     push    bx
  69.  
  70. asm     mov     ah, 01Ah
  71. asm     LDS_    dx, ffblk
  72. asm     int     021h            /* Set the disk transfer address */
  73.  
  74. asm     mov     ah, 04Eh
  75. asm     mov     cx, attrib
  76. asm     LDS_    dx, pathname
  77. asm     int     021h            /* Find first matching file */
  78.  
  79. asm     pushf                   /* save state of carry flag */
  80. asm     pop     cx
  81. asm     xchg    ax, bx          /* save return code */
  82.  
  83. asm     mov     ah, 01Ah        /* restore DTA */
  84. asm     pop     dx
  85. asm     pop     ds
  86. asm     int     21h
  87.  
  88. asm     push    cx
  89. asm     popf
  90. asm     pop     ds
  91.  
  92. asm     jc      findfirstFailed
  93.         return(0);
  94.  
  95. findfirstFailed:
  96.         return __IOerror(_BX);
  97. }
  98.  
  99.  
  100. /*--------------------------------------------------------------------------*
  101.  
  102. Name            findnext - fetches files which match findfirst
  103.  
  104. Usage           int findnext(struct ffblk *ffblk);
  105.  
  106. Prototype in    dir.h
  107.  
  108. Description     findnext is used to fetch subsequent files which
  109.                 match the pathname given in findfirst.  ffblk is the
  110.                 same block filled in by the findfirst call.  This
  111.                 block contains necessary information for continuing
  112.                 the search.  One file name for each call to findnext will
  113.                 be returned until no more files are found in the directory
  114.                 matching the pathname.
  115.  
  116. Return value    success : 0
  117.                 else : -1 and errno is set to
  118.                         ENOENT  Path or file name not found
  119.                         ENMFILE No more files
  120.  
  121. *---------------------------------------------------------------------------*/
  122. int _CType _FARFUNC findnext(struct ffblk *ffblk)
  123. {
  124. asm     push    ds
  125.  
  126. asm     mov     ah,2fh          /* get (and save) DTA */
  127. asm     int     21h
  128. asm     push    es
  129. asm     push    bx
  130.  
  131. asm     mov     ah, 01Ah
  132. asm     LDS_    dx, ffblk
  133. asm     int     021h            /* Set the disk transfer address */
  134.  
  135. asm     mov     ah, 04Fh
  136. asm     int     021h            /* Find next matching file */
  137.  
  138. asm     pushf                   /* save state of carry flag */
  139. asm     pop     cx
  140. asm     xchg    ax, bx          /* save return code */
  141.  
  142. asm     mov     ah, 01Ah        /* restore DTA */
  143. asm     pop     dx
  144. asm     pop     ds
  145. asm     int     21h
  146.  
  147. asm     push    cx
  148. asm     popf
  149. asm     pop     ds
  150.  
  151. asm     jc      findnextFailed
  152.         return(0);
  153.  
  154. findnextFailed:
  155.         return __IOerror(_BX);
  156. }
  157.