home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / MN325SRC.ZIP / makenl-3.2.5 / src / osgnufnd.c < prev    next >
C/C++ Source or Header  |  2005-02-06  |  1KB  |  60 lines

  1. /* $Id: osgnufnd.c,v 1.2 2004/07/11 09:29:14 ozzmosis Exp $ */
  2.  
  3. #define _GNU_SOURCE
  4. #include <dirent.h>
  5. #include <stdlib.h>
  6. #include <fnmatch.h>
  7. char *os_findfirst(struct _filefind *pff, const char *path,
  8.                    const char *mask)
  9. {
  10.     strcpy(pff->path, path);
  11.     os_remove_slash(pff->path);
  12.     strcpy(pff->mask, mask);
  13.     pff->flags = FNM_NOESCAPE;
  14.  
  15. #ifdef __EMX__
  16.     pff->flags |= (_osmode == OS2_MODE) ? _FNM_OS2 : _FNM_DOS;
  17.     pff->flags |= _FNM_IGNORECASE;
  18. #endif
  19.  
  20. #if defined(__unix__) || defined(__MSDOS__)
  21.     pff->flags |= FNM_CASEFOLD;
  22. #endif
  23.  
  24.     if ((pff->dirp = opendir(pff->path)) != NULL)
  25.     {
  26.         char *p;
  27.  
  28.         if ((p = os_findnext(pff)) != NULL)
  29.             return p;
  30.     }
  31.  
  32.     closedir(pff->dirp);
  33.     pff->dirp = NULL;
  34.     return NULL;
  35. }
  36.  
  37.  
  38. char *os_findnext(struct _filefind *pff)
  39. {
  40.     int matchresult;
  41.  
  42.     for (;;)
  43.     {
  44.         if ((pff->pentry = readdir(pff->dirp)) == NULL)
  45.             return NULL;
  46.  
  47.         matchresult = fnmatch(pff->mask, pff->pentry->d_name, pff->flags);
  48.         if (matchresult == 0)
  49.             return pff->pentry->d_name;
  50.     }
  51. }
  52.  
  53.  
  54. void os_findclose(struct _filefind *pff)
  55. {
  56.     if (pff->dirp)
  57.         closedir(pff->dirp);
  58.     pff->dirp = NULL;
  59. }
  60.