home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / PPL4C11.ZIP / DIR_IO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-09  |  2.0 KB  |  101 lines

  1. /* dir_io.c */
  2.  
  3. #include <stdio.h>
  4. #include <dos.h>
  5. #include <string.h>
  6.  
  7. #include "dir_io.h"
  8.  
  9. #define FALSE 0
  10. #define TRUE !FALSE
  11.  
  12. #define BYTE unsigned char
  13. #define WORD unsigned int
  14.  
  15. typedef struct DTAbufferType
  16. {BYTE Reserved[21];
  17.  BYTE Attribute;
  18.  WORD Time;
  19.  WORD Date;
  20.  long Size;
  21.  BYTE Name[13];
  22.  BYTE Junk[85];
  23. } DTAbufferType;
  24.  
  25. static DTAbufferType DTA1buffer;
  26. static DTAbufferType DTA2buffer;
  27.  
  28. static DTAbufferType far *Ptr1 = &DTA1buffer;
  29. static DTAbufferType far *Ptr2 = &DTA2buffer;
  30.  
  31. static void dosSetDTA(int which)
  32. {union REGS reg;
  33.  struct SREGS sreg;
  34.  switch(which)
  35.    {case 1:
  36.       reg.x.dx = (WORD) FP_OFF(Ptr1);
  37.       sreg.ds  = (WORD) FP_SEG(Ptr1);
  38.       break;
  39.     case 2:
  40.       reg.x.dx = (WORD) FP_OFF(Ptr2);
  41.       sreg.ds  = (WORD) FP_SEG(Ptr2);
  42.       break;
  43.    }
  44.  reg.h.ah = 0x1A;
  45.  int86x(0x21, ®, ®, &sreg);
  46. }
  47.  
  48. static int dosFindFirst(char *FileSpec)
  49. {union  REGS  reg;
  50.  struct SREGS sreg;
  51.  char far *Ptr;
  52.  Ptr = (char far *)FileSpec;
  53.  reg.x.dx = (WORD) FP_OFF(Ptr);
  54.  sreg.ds  = (WORD) FP_SEG(Ptr);
  55.  reg.h.ah = 0x4e;
  56.  reg.x.cx = 0;
  57.  int86x(0x21, ®, ®, &sreg);
  58.  if(reg.x.cflag) return FALSE;
  59.  return TRUE;
  60. }
  61.  
  62. static int dosFindNext(void)
  63. {union REGS reg;
  64.  reg.h.ah = 0x4f;
  65.  int86(0x21, ®, ®);
  66.  if(reg.x.cflag) return FALSE;
  67.  return TRUE;
  68. }
  69.  
  70.  
  71. int FindFirst(char *Specifier,char *Name,long *Size)
  72. {dosSetDTA(1);
  73.  if(dosFindFirst(Specifier))
  74.    {if(Name) strncpy(Name,DTA1buffer.Name,13);
  75.     if(Size) *Size = DTA1buffer.Size;
  76.     return TRUE;
  77.    }
  78.  return FALSE;
  79. }
  80.  
  81. int FindNext(char *Name,long *Size)
  82. {dosSetDTA(1);
  83.  if(dosFindNext())
  84.    {strncpy(Name,DTA1buffer.Name,13);
  85.     if(Size) *Size = DTA1buffer.Size;
  86.     return TRUE;
  87.    }
  88.  return FALSE;
  89. }
  90.  
  91. int FileSDT(char *Name,long *Size,WORD *Date,WORD *Time)
  92. {dosSetDTA(2);
  93.  if(dosFindFirst(Name))
  94.    {*Size = DTA2buffer.Size;
  95.     *Date = DTA2buffer.Date;
  96.     *Time = DTA2buffer.Time;
  97.     return TRUE;
  98.    }
  99.  return FALSE;
  100. }
  101.