home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / os2 / insp110p.zip / DUTILSRC.ZIP / dosdir.h next >
C/C++ Source or Header  |  1993-04-23  |  4KB  |  194 lines

  1. /*
  2.  * DOS & OS/2 compiler portability module
  3.  * Provides "portability"" for 'findfirst' calls between
  4.  * DOS/OS2 compilers compilers.
  5.  *
  6.  * $Id$
  7.  *
  8.  * $Log$
  9.  */
  10.  
  11. #if !defined(_DOSDIR_H)
  12. #define _DOSDIR_H 1
  13.  
  14. #if defined(_cplusplus)
  15. extern "C"
  16. {
  17. #endif
  18.  
  19. # if defined(OS2)
  20. #  include <os2.h>
  21. /* Note: this section needs to be updated for 32-bit */
  22.  
  23. #      if defined(_MSC_VER)
  24. #       include <direct.h>
  25. #      define GETCWD getcwd
  26. #      endif
  27.  
  28. #  if defined(__cplusplus)
  29. #   define INLINE        inline
  30. #  else
  31. #   if defined(_MSC_VER) && !defined(__STDC__)
  32. #    define INLINE        __inline
  33. #   else
  34. #    define INLINE        static
  35. #   endif
  36. #  endif
  37.  
  38. #  define ALLFILES "*"
  39.  
  40. struct FFIND
  41. {
  42.     HDIR                dh;
  43.     struct _FILEFINDBUF    f;
  44. };
  45.  
  46. INLINE int
  47. FINDFIRST (char *spec, USHORT attr, struct FFIND *ff)
  48. {
  49.     USHORT cnt = 1;
  50.     ff->dh = (HDIR) -1;
  51.     return (int) DosFindFirst ((PSZ)spec, &ff->dh, attr, &ff->f, (USHORT)sizeof(struct _FILEFINDBUF), &cnt, 0L);
  52. }
  53.  
  54. INLINE int
  55. FINDNEXT (struct FFIND *ff)
  56. {
  57.     USHORT cnt = 1;
  58.     return (int) DosFindNext (ff->dh, &ff->f, sizeof(struct _FILEFINDBUF), &cnt);
  59. }
  60.  
  61. INLINE int
  62. FINDCLOSE (struct FFIND *ff)
  63. {
  64.     return (int) DosFindClose (ff->dh);
  65. }
  66.  
  67. #  if !defined(_A_NORMAL)
  68. #     define _A_NORMAL         FILE_NORMAL
  69. #     define _A_SUBDIR         FILE_DIRECTORY
  70. #     define _A_HIDDEN         FILE_HIDDEN
  71. #     define _A_RDONLY         FILE_READONLY
  72. #     define _A_SYSTEM         FILE_SYSTEM
  73. #  endif
  74.  
  75. #     define f_name(x)         (x)->f.achName
  76. #     define f_size(x)         (x)->f.cbFile
  77. #     define f_attr(x)         (x)->f.attrFile
  78. #     define f_wrdate(x)      (x)->f.fdateLastWrite
  79. #     define f_wrtime(x)      (x)->f.ftimeLastWrite
  80. #     define f_crdate(x)      (x)->f.fdateCreation
  81. #     define f_crtime(x)      (x)->f.ftimeCreation
  82. #     define f_acdate(x)      (x)->f.fdateAccess
  83. #     define f_actime(x)      (x)->f.ftimeAccess
  84.  
  85. # else
  86.  
  87. #  define ALLFILES "*.*"
  88.  
  89. #  if defined(MSDOS)
  90. #    include <dos.h>
  91.  
  92. #    if defined(__TURBOC__) || defined(__GO32__) || defined(__BORLANDC__)
  93. /* Turbo/Borland C / djgpp */
  94. #     include <dir.h>
  95. #    define GETCWD getcwd
  96.  
  97. #     if defined(__GO32__)
  98. #      include <std.h>
  99. #     endif
  100.  
  101. /* djgpp/go32 uses turboc compatible calls */
  102.  
  103. #     define FINDFIRST(n,a,f) findfirst(n,f,a)
  104. #     define FINDNEXT(f)      findnext(f)
  105. #     define FINDCLOSE(f)
  106.  
  107. #     define FFIND            ffblk
  108.  
  109. #     define _A_NORMAL        0
  110. #     define _A_SUBDIR        FA_DIREC
  111. #     define _A_HIDDEN        FA_HIDDEN
  112. #     define _A_RDONLY        FA_RDONLY
  113. #     define _A_SYSTEM        FA_SYSTEM
  114.  
  115. #     define f_name(x)        (x)->ff_name
  116. #     define f_size(x)        (x)->ff_fsize
  117. #     define f_attr(x)        (x)->ff_attrib
  118. #     define f_wrdate(x)     (x)->ff_fdate
  119. #     define f_wrtime(x)     (x)->ff_ftime
  120. #     define f_crdate(x)        0
  121. #     define f_crtime(x)        0
  122. #     define f_acdate(x)        0
  123. #     define f_actime(x)        0
  124.  
  125. #    else
  126.  
  127. #     if defined(__ZTC__) || defined(_MSC_VER)
  128.  
  129. #      if defined(_MSC_VER)
  130. #       include <direct.h>
  131. #     define GETCWD getcwd
  132. #      endif
  133.  
  134. /* Zortech can use MSC compatible calls */
  135.  
  136. #      define FFIND              _find_t
  137.  
  138. #      define FINDFIRST(n,a,f) _dos_findfirst(n,a,f)
  139. #      define FINDNEXT(f)      _dos_findnext(f)
  140. #      define FINDCLOSE(f)
  141.  
  142. #      define f_name(x)         (x)->name
  143. #      define f_size(x)         (x)->size
  144. #      define f_attr(x)         (x)->attrib
  145. #      define f_wrdate(x)     (x)->wr_date
  146. #      define f_wrtime(x)     (x)->wr_time
  147. #      define f_crdate(x)     0
  148. #      define f_crtime(x)     0
  149. #      define f_acdate(x)     0
  150. #      define f_actime(x)     0
  151.  
  152. #     else
  153.  
  154. #      error ("MSDOS compiler type cannot be determined in "__FILE__)
  155.  
  156. #     endif
  157.  
  158. #    endif
  159.  
  160. #    define d_PERMS            (_A_SUBDIR|_A_HIDDEN|_A_RDONLY|_A_SYSTEM)
  161. #    define a_PERMS            (_A_SUBDIR|_A_HIDDEN|_A_RDONLY|_A_SYSTEM)
  162.  
  163. #    define ISDIR(x)         (f_attr(x) & _A_SUBDIR)
  164. #    define f_acdate(x)        0
  165. #    define f_actime(x)        0
  166. #    define f_crdate(x)        0
  167. #    define f_crtime(x)        0
  168.  
  169.  
  170. #  else                            /* Not MSDOS */
  171.  
  172. #    include <dirent.h>
  173. #    include <sys/types.h>
  174. #    include <sys/stat.h>
  175.  
  176. #    define FFIND             DIR
  177. #    define d_PERMS             07777
  178. #    define a_PERMS             07777
  179. #    define ISDIR()             (S_ISDIR(st.st_mode))
  180. #    define f_name()          fe->d_name
  181. #    define f_size()          st.st_size
  182. #    define f_attr()          st.st_mode
  183.  
  184. #  endif
  185.  
  186. # endif
  187.  
  188. #if defined(_cplusplus)
  189. }
  190. #endif
  191.  
  192. #endif
  193.  
  194.