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

  1. /*---------------------------------------------------------------------------
  2.  * filename - dosfind.cas
  3.  *
  4.  * function(s)
  5.  *        _dos_findfirst - searches disk directory
  6.  *        _dos_findnext  - fetches files which match _dos_findfirst
  7.  *--------------------------------------------------------------------------*/
  8.  
  9. /*
  10.  *      C/C++ Run Time Library - Version 5.0
  11.  *
  12.  *      Copyright (c) 1991, 1992 by Borland International
  13.  *      All Rights Reserved.
  14.  *
  15.  */
  16.  
  17.  
  18. #pragma  inline
  19. #include <asmrules.h>
  20. #include <_io.h>
  21. #include <dos.h>
  22.  
  23. /*--------------------------------------------------------------------------*
  24.  
  25. Name            _dos_findfirst - searches disk directory
  26.  
  27. Usage           unsigned _dos_findfirst(const char *pathname, unsigned attrib,
  28.                               struct find_t *fileinfo);
  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 fileinfo 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.                         _A_RDONLY  Read only
  45.                         _A_HIDDEN  Hidden file
  46.                         _A_SYSTEM  System file
  47.                         _A_VOLID   Volume label
  48.                         _A_SUBDIR  Directory
  49.                         _A_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. unsigned _dos_findfirst(const char *pathname, unsigned attrib,
  62.                                 struct find_t *fileinfo )
  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, fileinfo
  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. asm     xchg    ax, bx          /* save return code */
  83.  
  84. asm     mov     ah, 01Ah        /* restore DTA */
  85. asm     pop     dx
  86. asm     pop     ds
  87. asm     int     21h
  88.  
  89. asm     push    cx
  90. asm     popf
  91. asm     pop     ds
  92.  
  93. asm     jc      findfirstFailed
  94.         return(0);
  95.  
  96. findfirstFailed:
  97.         return (__DOSerror(_BX));
  98. }
  99.  
  100.  
  101. /*--------------------------------------------------------------------------*
  102.  
  103. Name            _dos_findnext - fetches files which match _dos_findfirst
  104.  
  105. Usage           unsigned _dos_findnext(struct find_t *fileinfo);
  106.  
  107. Prototype in    dir.h
  108.  
  109. Description     _dos_findnext is used to fetch subsequent files which
  110.                 match the pathname given in _dos_findfirst.  fileinfo is the
  111.                 same block filled in by the _dos_findfirst call.  This
  112.                 block contains necessary information for continuing
  113.                 the search.  One file name for each call to _dos_findnext will
  114.                 be returned until no more files are found in the directory
  115.                 matching the pathname.
  116.  
  117. Return value    success : 0
  118.                 else : -1 and errno is set to
  119.                         ENOENT  Path or file name not found
  120.                         ENMFILE No more files
  121.  
  122. *---------------------------------------------------------------------------*/
  123. unsigned _dos_findnext(struct find_t *fileinfo)
  124. {
  125. asm     push    ds
  126.  
  127. asm     mov     ah,2fh          /* get (and save) DTA */
  128. asm     int     21h
  129. asm     push    es
  130. asm     push    bx
  131.  
  132. asm     mov     ah, 01Ah
  133. asm     LDS_    dx, fileinfo
  134. asm     int     021h            /* Set the disk transfer address */
  135.  
  136. asm     mov     ah, 04Fh
  137. asm     int     021h            /* Find next matching file */
  138.  
  139. asm     pushf                   /* save state of carry flag */
  140. asm     pop     cx
  141. asm     xchg    ax, bx          /* save return code */
  142.  
  143. asm     mov     ah, 01Ah        /* restore DTA */
  144. asm     pop     dx
  145. asm     pop     ds
  146. asm     int     21h
  147.  
  148. asm     push    cx
  149. asm     popf
  150. asm     pop     ds
  151.  
  152. asm     jc      findnextFailed
  153.         return(0);
  154.  
  155. findnextFailed:
  156.         return (__DOSerror(_BX));
  157. }
  158.