PageRenderTime 36ms CodeModel.GetById 14ms app.highlight 18ms RepoModel.GetById 2ms app.codeStats 0ms

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