home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / SYS / FILEFIND.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  1.4 KB  |  61 lines

  1. /* sys/filefind.c (emx+gcc) -- Copyright (c) 1992-1993 by Eberhard Mattes */
  2.  
  3. #include <sys/emx.h>
  4. #include <string.h>
  5. #include <errno.h>
  6. #include <os2emx.h>
  7. #include "syscalls.h"
  8.  
  9. static HDIR find_handle;
  10. static ULONG find_count;
  11. static FILEFINDBUF3 find_buf;
  12.  
  13. static int find_conv (struct _find *fp)
  14. {
  15.   if (find_count != 1)
  16.     {
  17.       errno = ENOENT;
  18.       return (-1);
  19.     }
  20.   fp->attr = (unsigned char)find_buf.attrFile;
  21.   fp->time = *(unsigned short *)&find_buf.ftimeLastWrite;
  22.   fp->date = *(unsigned short *)&find_buf.fdateLastWrite;
  23.   fp->size_lo = (unsigned short)(find_buf.cbFile & 0xffff);
  24.   fp->size_hi = (unsigned short)(find_buf.cbFile >> 16);
  25.   strcpy (fp->name, find_buf.achName);
  26.   return (0);
  27. }
  28.  
  29.  
  30. int __findfirst (const char *name, int attr, struct _find *fp)
  31. {
  32.   ULONG rc;
  33.  
  34.   find_handle = HDIR_SYSTEM;
  35.   find_count = 1;
  36.   rc = DosFindFirst (name, &find_handle, attr & 0x37,
  37.                      &find_buf, sizeof (find_buf),
  38.                      &find_count, 1);
  39.   if (rc != 0)
  40.     {
  41.       _sys_set_errno (rc);
  42.       return (-1);
  43.     }
  44.   return (find_conv (fp));
  45. }
  46.  
  47.  
  48. int __findnext (struct _find *fp)
  49. {
  50.   ULONG rc;
  51.  
  52.   find_count = 1;
  53.   rc = DosFindNext (find_handle, &find_buf, sizeof (find_buf), &find_count);
  54.   if (rc != 0)
  55.     {
  56.       _sys_set_errno (rc);
  57.       return (-1);
  58.     }
  59.   return (find_conv (fp));
  60. }
  61.