home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / VP2SRC.ZIP / DIRFIND.C < prev    next >
Text File  |  1990-05-12  |  4KB  |  124 lines

  1. /*--------------------------------------------------------------------------*/
  2. /* Include files                                                            */
  3. /*--------------------------------------------------------------------------*/
  4.  
  5. #include    <errno.h>
  6.  
  7. #    include <dos.h>
  8. #    include <stdlib.h>
  9. #    include <sys\types.h>
  10.  
  11. #define INCL_DOSPROCESS
  12. #    include <os2.h>
  13.  
  14. #include    <sys\stat.h>
  15. #include    <ctype.h>
  16. #include    <string.h>
  17. #include    <io.h>
  18. #include    <fcntl.h>
  19. #include    <time.h>
  20.  
  21. /*--------------------------------------------------------------------------*/
  22. /* Static function declarations                                             */
  23. /*--------------------------------------------------------------------------*/
  24.  
  25. /*    ... NONE ...  */
  26.  
  27. /*--------------------------------------------------------------------------*/
  28. /* Static variable definitions                                                */
  29. /*--------------------------------------------------------------------------*/
  30.  
  31. static struct _FILEFINDBUF InfoBuf;
  32. static struct find_t dta;
  33.  
  34. /*--------------------------------------------------------------------------*/
  35. /* External variable declarations                                            */
  36. /*--------------------------------------------------------------------------*/
  37.  
  38. /*    ... NONE ...  */
  39.  
  40. /*--------------------------------------------------------------------------*/
  41. /* Locally defined globals                                                    */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. HDIR                    hDir;
  45. USHORT                    cSearch;
  46. USHORT                    usAttrib;
  47.  
  48. /*--------------------------------------------------------------------------*/
  49. /* Local constants                                                            */
  50. /*--------------------------------------------------------------------------*/
  51.  
  52. #    define    FILENAMELEN 13
  53.  
  54. /****************************************************************************/
  55.  
  56.  
  57. /*--------------------------------------------------------------------------*/
  58. /* DIR_FINDFIRST                                     FOR PORTABILITY        */
  59. /*--------------------------------------------------------------------------*/
  60.  
  61. int dir_findfirst(char * filename, int attribute, struct find_t * dta)
  62. {
  63.     hDir     = 0x0001;
  64.     usAttrib = attribute;
  65.     cSearch  = 1;
  66.  
  67. #ifdef DEBUG
  68.     printf("\nDIR_FINDFIRST Inputs: '%s' %d.\n", filename, attribute);
  69. #endif
  70.     if (DosFindFirst( filename
  71.                     , &hDir
  72.                     , usAttrib
  73.                     , &InfoBuf
  74.                     , (USHORT)( sizeof(InfoBuf) * cSearch )
  75.                     , &cSearch
  76.                     , (ULONG)NULL ) != 0 )
  77.     {
  78. #ifdef DEBUG
  79.     printf("DIR_FINDFIRST:  DosFindFirst returned <>0.\n");
  80. #endif
  81.         DosFindClose( hDir );
  82.         errno = ENOENT;
  83.         return (-1);
  84.     } else {
  85. #ifdef DEBUG
  86.     printf("DIR_FINDFIRST:  DosFindFirst returned 0.\n");
  87.     printf("DIR_FINDFIRST:  attrFile = %d.\n", InfoBuf.attrFile);
  88. #endif
  89.         dta->attrib    = (unsigned char) InfoBuf.attrFile;
  90.         dta->size       = InfoBuf.cbFile;
  91.         strcpy( dta->name, InfoBuf.achName);
  92.         errno = 0;
  93.         return (0);
  94.     }
  95. }
  96.  
  97. /*--------------------------------------------------------------------------*/
  98. /* DIR_FINDNEXT                                      FOR PORTABILITY        */
  99. /*--------------------------------------------------------------------------*/
  100.  
  101. int dir_findnext(struct find_t * dta)
  102. {
  103.  
  104.     if ((DosFindNext( hDir
  105.                     , &InfoBuf
  106.                     , (USHORT)(FILENAMELEN + 23)
  107.                     , &cSearch)
  108.                     ) || (cSearch != 1))
  109.     {
  110.         DosFindClose( hDir );
  111.         errno = ENOENT;
  112.         return (-1);
  113.     } else {
  114.         dta->size       = InfoBuf.cbFile;
  115.         strcpy(  dta->name, InfoBuf.achName);
  116.         errno = 0;
  117.         return (0);
  118.     }
  119. }
  120.  
  121. /*--------------------------------------------------------------------------*/
  122. /*                                  END OF FILE                                */
  123. /*--------------------------------------------------------------------------*/
  124.