home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / FINDFIRS.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  5.0 KB  |  156 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. /*|                                                              |*/
  11. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  12. /*|                                                              |*/
  13. /*|                                                              |*/
  14. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  15. /*|     All Rights Reserved.                                     |*/
  16. /*|                                                              |*/
  17. /*[]------------------------------------------------------------[]*/
  18.  
  19. #pragma  inline
  20. #include <asmrules.h>
  21. #include <dir.h>
  22. #include <_io.h>
  23.  
  24. /*--------------------------------------------------------------------------*
  25.  
  26. Name            findfirst - searches disk directory
  27.  
  28. Usage           int findfirst(const char *pathname, struct ffblk *ffblk,
  29.                               int attrib);
  30.  
  31. Prototype in    dir.h
  32.  
  33. Description     begins a search of a disk directory by using the
  34.                 MS-DOS system call 0x4E.
  35.  
  36.                 pathname is a string with an optional drive specifier,
  37.                 path and file name of the file to be found.   If a
  38.                 matching file is found, the ffblk structure is filled
  39.                 with the file-directory information.
  40.  
  41.                 attrib is an MS-DOS file-attribute byte used in selecting
  42.                 eligible files for the search.  attrib can be one of the
  43.                 following constants defined in dos.h
  44.  
  45.                         FA_RDONLY  Read only
  46.                         FA_HIDDEN  Hidden file
  47.                         FA_SYSTEM  System file
  48.                         FA_LABEL   Volume label
  49.                         FA_DIREC   Directory
  50.                         FA_ARCH    Archive
  51.  
  52.                 For more detailed information about these attributes, refer
  53.                 to the MS-DOS Programmer's Reference Manual.
  54.  
  55. Return value    success : 0
  56.                 else : -1 and errno is set to
  57.                         ENOENT  Path or file name not found
  58.                         ENMFILE No more files
  59.  
  60. *---------------------------------------------------------------------------*/
  61.  
  62. int _CType findfirst(const char *pathname, struct ffblk *ffblk, int attrib)
  63. {
  64. asm     push    ds
  65.  
  66. asm     mov     ah,2fh          /* get (and save) DTA */
  67. asm     int     21h
  68. asm     push    es
  69. asm     push    bx
  70.  
  71. asm     mov     ah, 01Ah
  72. asm     LDS_    dx, ffblk
  73. asm     int     021h            /* Set the disk transfer address */
  74.  
  75. asm     mov     ah, 04Eh
  76. asm     mov     cx, attrib
  77. asm     LDS_    dx, pathname
  78. asm     int     021h            /* Find first matching file */
  79.  
  80. asm     pushf                   /* save state of carry flag */
  81. asm     pop     cx
  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(_AX);
  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 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.  
  141. asm     mov     ah, 01Ah        /* restore DTA */
  142. asm     pop     dx
  143. asm     pop     ds
  144. asm     int     21h
  145.  
  146. asm     push    cx
  147. asm     popf
  148. asm     pop     ds
  149.  
  150. asm     jc      findnextFailed
  151.         return(0);
  152.  
  153. findnextFailed:
  154.         return __IOerror(_AX);
  155. }
  156.