home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / dos / dir / findnext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-31  |  2.4 KB  |  103 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <libc/stubs.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <errno.h>
  6. #include <go32.h>
  7. #include <dpmi.h>
  8. #include <dir.h>
  9. #include <fcntl.h>
  10. #include <libc/dosio.h>
  11.  
  12. int
  13. findnext(struct ffblk *ffblk)
  14. {
  15.   __dpmi_regs r;
  16.  
  17.   if (ffblk == 0)
  18.   {
  19.     errno = EACCES;
  20.     return -1;
  21.   }
  22.  
  23.   if(_USE_LFN)
  24.   {
  25.     /* si = 1 indicates DOS style dates, 0 means Win32 type dates.
  26.        DOS style dates are broken in some Win95 betas, build for either.
  27.        Release works with DOS date, it's faster, so use it. */
  28.     #define USEDOSDATE 1
  29.     #if USEDOSDATE == 1
  30.       #define _Win32_to_DOS (long)
  31.     #else
  32.       extern long _Win32_to_DOS(long long WinTime);
  33.     #endif
  34.  
  35.     r.x.ax = 0x714f;
  36.     r.x.bx = ffblk->lfn_handle;
  37.     if(!r.x.bx)
  38.     {
  39.       errno = ENMFILE;
  40.       return 1;
  41.     }
  42.     r.x.di = __tb_offset;
  43.     r.x.es = __tb_segment;
  44.     r.x.si = USEDOSDATE;
  45.  
  46.     __dpmi_int(0x21, &r);
  47.     if (!(r.x.flags & 1))
  48.     {
  49.       struct ffblklfn ffblk32;
  50.       /* Recover results */
  51.       dosmemget(__tb, sizeof(struct ffblklfn), &ffblk32);
  52.  
  53.       ffblk->ff_attrib = (char)ffblk32.fd_attrib;
  54.       *(long *)&ffblk->ff_ftime = _Win32_to_DOS(ffblk32.fd_mtime);
  55.       ffblk->ff_fsize = ffblk32.fd_size;
  56.       strcpy(ffblk->ff_name, ffblk32.fd_longname);
  57.       *(long *)&ffblk->lfn_ctime = _Win32_to_DOS(ffblk32.fd_ctime);
  58.       *(long *)&ffblk->lfn_atime = _Win32_to_DOS(ffblk32.fd_atime);
  59.  
  60.       return 0;
  61.     }
  62.     errno = __doserr_to_errno(r.x.ax);
  63.     if (errno == ENMFILE)         /* call FindClose */
  64.     {
  65.       ffblk->lfn_handle = 0;
  66.       r.x.ax = 0x71a1;
  67.       __dpmi_int(0x21, &r);
  68.       if(r.x.flags & 1)
  69.       {
  70.         errno = __doserr_to_errno(r.x.ax);
  71.         return -1;
  72.       }
  73.       return 1;
  74.     }
  75.     return -1;
  76.   }
  77.   else
  78.   {
  79.     #define _sizeof_dos_ffblk 44
  80.     /* The 43 character ff block must be put to the DTA, make the call, then
  81.        recover the ff block. */
  82.  
  83.     r.x.dx = __tb_offset;
  84.     r.x.ds = __tb_segment;
  85.     r.h.ah = 0x1a;
  86.     __dpmi_int(0x21, &r);
  87.  
  88.     dosmemput(ffblk, sizeof(struct ffblk), __tb);
  89.  
  90.     r.h.ah = 0x4f;
  91.     __dpmi_int(0x21, &r);
  92.     if(r.x.flags & 1)
  93.     {
  94.       errno = __doserr_to_errno(r.x.ax);
  95.       return -1;
  96.     }
  97.  
  98.     /* Recover results */
  99.     dosmemget(__tb, _sizeof_dos_ffblk, ffblk);
  100.     return 0;
  101.   }
  102. }
  103.