/src/core/sys/posix/dirent.d

http://github.com/AlexeyProkhin/druntime · D · 254 lines · 185 code · 21 blank · 48 comment · 13 complexity · 8bb6c843a09fcb94b5f07d9433c7a42d MD5 · raw file

  1. /**
  2. * D header file for POSIX.
  3. *
  4. * Copyright: Copyright Sean Kelly 2005 - 2009.
  5. * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
  6. * Authors: Sean Kelly,
  7. Alex Rønne Petersn
  8. * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
  9. */
  10. /* Copyright Sean Kelly 2005 - 2009.
  11. * Distributed under the Boost Software License, Version 1.0.
  12. * (See accompanying file LICENSE or copy at
  13. * http://www.boost.org/LICENSE_1_0.txt)
  14. */
  15. module core.sys.posix.dirent;
  16. private import core.sys.posix.config;
  17. public import core.sys.posix.sys.types; // for ino_t
  18. version (Posix):
  19. extern (C):
  20. //
  21. // Required
  22. //
  23. /*
  24. DIR
  25. struct dirent
  26. {
  27. char[] d_name;
  28. }
  29. int closedir(DIR*);
  30. DIR* opendir(in char*);
  31. dirent* readdir(DIR*);
  32. void rewinddir(DIR*);
  33. */
  34. version( linux )
  35. {
  36. // NOTE: The following constants are non-standard Linux definitions
  37. // for dirent.d_type.
  38. enum
  39. {
  40. DT_UNKNOWN = 0,
  41. DT_FIFO = 1,
  42. DT_CHR = 2,
  43. DT_DIR = 4,
  44. DT_BLK = 6,
  45. DT_REG = 8,
  46. DT_LNK = 10,
  47. DT_SOCK = 12,
  48. DT_WHT = 14
  49. }
  50. struct dirent
  51. {
  52. ino_t d_ino;
  53. off_t d_off;
  54. ushort d_reclen;
  55. ubyte d_type;
  56. char[256] d_name;
  57. }
  58. struct DIR
  59. {
  60. // Managed by OS
  61. }
  62. static if( __USE_FILE_OFFSET64 )
  63. {
  64. dirent* readdir64(DIR*);
  65. alias readdir64 readdir;
  66. }
  67. else
  68. {
  69. dirent* readdir(DIR*);
  70. }
  71. }
  72. else version( OSX )
  73. {
  74. enum
  75. {
  76. DT_UNKNOWN = 0,
  77. DT_FIFO = 1,
  78. DT_CHR = 2,
  79. DT_DIR = 4,
  80. DT_BLK = 6,
  81. DT_REG = 8,
  82. DT_LNK = 10,
  83. DT_SOCK = 12,
  84. DT_WHT = 14
  85. }
  86. align(4)
  87. struct dirent
  88. {
  89. ino_t d_ino;
  90. ushort d_reclen;
  91. ubyte d_type;
  92. ubyte d_namlen;
  93. char[256] d_name;
  94. }
  95. struct DIR
  96. {
  97. // Managed by OS
  98. }
  99. dirent* readdir(DIR*);
  100. }
  101. else version( FreeBSD )
  102. {
  103. enum
  104. {
  105. DT_UNKNOWN = 0,
  106. DT_FIFO = 1,
  107. DT_CHR = 2,
  108. DT_DIR = 4,
  109. DT_BLK = 6,
  110. DT_REG = 8,
  111. DT_LNK = 10,
  112. DT_SOCK = 12,
  113. DT_WHT = 14
  114. }
  115. align(4)
  116. struct dirent
  117. {
  118. uint d_fileno;
  119. ushort d_reclen;
  120. ubyte d_type;
  121. ubyte d_namlen;
  122. char[256] d_name;
  123. }
  124. alias void* DIR;
  125. dirent* readdir(DIR*);
  126. }
  127. else version (Solaris)
  128. {
  129. struct dirent
  130. {
  131. ino_t d_ino;
  132. off_t d_off;
  133. ushort d_reclen;
  134. char[1] d_name;
  135. }
  136. struct DIR
  137. {
  138. int dd_fd;
  139. int dd_loc;
  140. int dd_size;
  141. char* dd_buf;
  142. }
  143. static if (__USE_LARGEFILE64)
  144. {
  145. dirent* readdir64(DIR*);
  146. alias readdir64 readdir;
  147. }
  148. else
  149. {
  150. dirent* readdir(DIR*);
  151. }
  152. }
  153. else
  154. {
  155. static assert(false, "Unsupported platform");
  156. }
  157. int closedir(DIR*);
  158. DIR* opendir(in char*);
  159. //dirent* readdir(DIR*);
  160. void rewinddir(DIR*);
  161. //
  162. // Thread-Safe Functions (TSF)
  163. //
  164. /*
  165. int readdir_r(DIR*, dirent*, dirent**);
  166. */
  167. version( linux )
  168. {
  169. static if( __USE_LARGEFILE64 )
  170. {
  171. int readdir64_r(DIR*, dirent*, dirent**);
  172. alias readdir64_r readdir_r;
  173. }
  174. else
  175. {
  176. int readdir_r(DIR*, dirent*, dirent**);
  177. }
  178. }
  179. else version( OSX )
  180. {
  181. int readdir_r(DIR*, dirent*, dirent**);
  182. }
  183. else version( FreeBSD )
  184. {
  185. int readdir_r(DIR*, dirent*, dirent**);
  186. }
  187. else version (Solaris)
  188. {
  189. static if (__USE_LARGEFILE64)
  190. {
  191. int readdir64_r(DIR*, dirent*, dirent**);
  192. alias readdir64_r readdir_r;
  193. }
  194. else
  195. {
  196. int readdir_r(DIR*, dirent*, dirent**);
  197. }
  198. }
  199. else
  200. {
  201. static assert(false, "Unsupported platform");
  202. }
  203. //
  204. // XOpen (XSI)
  205. //
  206. /*
  207. void seekdir(DIR*, c_long);
  208. c_long telldir(DIR*);
  209. */
  210. version( linux )
  211. {
  212. void seekdir(DIR*, c_long);
  213. c_long telldir(DIR*);
  214. }
  215. else version( FreeBSD )
  216. {
  217. void seekdir(DIR*, c_long);
  218. c_long telldir(DIR*);
  219. }
  220. else version (OSX)
  221. {
  222. }
  223. else version (Solaris)
  224. {
  225. c_long telldir(DIR*);
  226. void seekdir(DIR*, c_long);
  227. }
  228. else
  229. {
  230. static assert(false, "Unsupported platform");
  231. }