home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / LIBSRC.ZOO / libsrc / local / readdir.c < prev    next >
Text File  |  1992-04-06  |  1KB  |  56 lines

  1. #define INCL_DOSFILEMGR
  2. #include <os2.h>
  3.  
  4. #define __DIRENT_PRIVATE__
  5. #include <dirent.h>
  6.  
  7. #ifdef DEBUG
  8. #include <stdio.h>
  9. #endif
  10.  
  11. ULONG Dos32FindFirst() asm ("Dos32FindFirst");
  12. ULONG Dos32FindNext() asm ("Dos32FindNext");
  13.  
  14. struct dirent *readdir(dir)
  15.    DIR *dir;
  16. {
  17.      ULONG ret;
  18.      FILEFINDBUF3 buf;
  19.      ULONG cnt;
  20.  
  21.      cnt = 1;
  22.      
  23.      if (dir->reset) {
  24.       /* opendir() also calls DosFindFirst, so this is sometimes */
  25.       /* unnecessary */
  26. #ifdef DEBUG
  27.       fprintf(stderr, "readdir: calling findfirst\n");
  28. #endif 
  29.       dir->reset = 0;
  30.       ret = Dos32FindFirst(dir->searchname, &dir->dirhandle,
  31.                  DIRENT_ALLFILES, &buf, sizeof(buf), &cnt,
  32.                  1);
  33.      } else {
  34. #ifdef DEBUG
  35.       fprintf(stderr, "readdir: calling findnext\n");
  36. #endif 
  37.       ret = Dos32FindNext(dir->dirhandle, &buf, sizeof(buf), &cnt);
  38.      }
  39.      
  40.      if (ret != 0 || cnt != 1)
  41.     return NULL;
  42.      else {
  43.       strcpy(dir->ent.d_name, buf.achName);
  44.       dir->ent.d_namelen = strlen(dir->ent.d_name);
  45.       dir->ent.d_reclen = dir->ent.d_namelen;
  46.       dir->ent.d_fileno = 0;
  47.       return &dir->ent;
  48.      }
  49. }
  50.  
  51.      
  52.      
  53.       
  54.  
  55.      
  56.