Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

root/trunk/tango/stdc/posix/sys/stat.d

Revision 5249, 15.3 kB (checked in by larsivi, 9 months ago)

Change C style arrays to D style, thanks to Christian Kamm

  • Property svn:mime-type set to text/x-dsrc
  • Property svn:eol-style set to native
Line 
1 /**
2  * D header file for POSIX.
3  *
4  * Copyright: Public Domain
5  * License:   Public Domain
6  * Authors:   Sean Kelly
7  * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8  */
9 module tango.stdc.posix.sys.stat;
10
11 private import tango.stdc.posix.config;
12 private import tango.stdc.stdint;
13 private import tango.stdc.posix.time;     // for timespec
14 public import tango.stdc.stddef;          // for size_t
15 public import tango.stdc.posix.sys.types; // for off_t, mode_t
16
17 extern (C):
18
19 //
20 // Required
21 //
22 /*
23 struct stat
24 {
25     dev_t   st_dev;
26     ino_t   st_ino;
27     mode_t  st_mode;
28     nlink_t st_nlink;
29     uid_t   st_uid;
30     gid_t   st_gid;
31     off_t   st_size;
32     time_t  st_atime;
33     time_t  st_mtime;
34     time_t  st_ctime;
35 }
36
37 S_IRWXU
38     S_IRUSR
39     S_IWUSR
40     S_IXUSR
41 S_IRWXG
42     S_IRGRP
43     S_IWGRP
44     S_IXGRP
45 S_IRWXO
46     S_IROTH
47     S_IWOTH
48     S_IXOTH
49 S_ISUID
50 S_ISGID
51 S_ISVTX
52
53 S_ISBLK(m)
54 S_ISCHR(m)
55 S_ISDIR(m)
56 S_ISFIFO(m)
57 S_ISREG(m)
58 S_ISLNK(m)
59 S_ISSOCK(m)
60
61 S_TYPEISMQ(buf)
62 S_TYPEISSEM(buf)
63 S_TYPEISSHM(buf)
64
65 int    chmod(in char*, mode_t);
66 int    fchmod(int, mode_t);
67 int    fstat(int, stat*);
68 int    lstat(in char*, stat*);
69 int    mkdir(in char*, mode_t);
70 int    mkfifo(in char*, mode_t);
71 int    stat(in char*, stat*);
72 mode_t umask(mode_t);
73 */
74
75 version( linux )
76 {
77     static if( __USE_LARGEFILE64 )
78     {
79         private alias uint _pad_t;
80     }
81     else
82     {
83         private alias ushort _pad_t;
84     }
85
86     align (4) struct stat_t
87     {
88         dev_t       st_dev;             /* Device.  */
89       version (X86_64) {} else {
90         _pad_t      __pad1;
91       }
92       static if( __USE_LARGEFILE64 )
93       {
94         ino_t      __st_ino;            /* 32bit file serial number.    */
95       }
96       else
97       {
98         ino_t       st_ino;             /* File serial number.  */
99       }
100       version (X86_64) {
101         nlink_t     st_nlink;
102         mode_t      st_mode;
103       } else {
104         mode_t      st_mode;            /* File mode.  */
105         nlink_t     st_nlink;           /* Link count.  */
106       }
107         uid_t       st_uid;             /* User ID of the file's owner. */
108         gid_t       st_gid;             /* Group ID of the file's group.*/
109       version (X86_64) {
110         int         pad0;
111         dev_t       st_rdev;
112       } else {
113         dev_t       st_rdev;            /* Device number, if device.  */
114         _pad_t      __pad2;
115       }
116         off_t       st_size;            /* Size of file, in bytes.  */
117         blksize_t   st_blksize;         /* Optimal block size for I/O.  */
118         blkcnt_t    st_blocks;          /* Number 512-byte blocks allocated. */
119       static if( false /*__USE_MISC*/ ) // true if _BSD_SOURCE || _SVID_SOURCE
120       {
121         timespec    st_atim;
122         timespec    st_mtim;
123         timespec    st_ctim;
124         alias st_atim.tv_sec st_atime;
125         alias st_mtim.tv_sec st_mtime;
126         alias st_ctim.tv_sec st_ctime;
127       }
128       else
129       {
130         time_t      st_atime;
131         c_ulong     st_atimensec;
132         time_t      st_mtime;
133         c_ulong     st_mtimensec;
134         time_t      st_ctime;
135         c_ulong     st_ctimensec;
136       }
137       version (X86_64) {
138         c_long[3]  __unused;
139       }
140       else static if( __USE_LARGEFILE64 )
141       {
142         ino64_t     st_ino;             /* File serial number.  */
143       }
144       else
145       {
146         c_ulong     __unused4;
147         c_ulong     __unused5;
148       }
149     }
150
151     const S_IRUSR   = 0400;
152     const S_IWUSR   = 0200;
153     const S_IXUSR   = 0100;
154     const S_IRWXU   = S_IRUSR | S_IWUSR | S_IXUSR;
155
156     const S_IRGRP   = S_IRUSR >> 3;
157     const S_IWGRP   = S_IWUSR >> 3;
158     const S_IXGRP   = S_IXUSR >> 3;
159     const S_IRWXG   = S_IRWXU >> 3;
160
161     const S_IROTH   = S_IRGRP >> 3;
162     const S_IWOTH   = S_IWGRP >> 3;
163     const S_IXOTH   = S_IXGRP >> 3;
164     const S_IRWXO   = S_IRWXG >> 3;
165
166     const S_ISUID   = 04000;
167     const S_ISGID   = 02000;
168     const S_ISVTX   = 01000;
169
170     private
171     {
172         extern (D) bool S_ISTYPE( mode_t mode, uint mask )
173         {
174             return ( mode & S_IFMT ) == mask;
175         }
176     }
177
178     extern (D) bool S_ISBLK( mode_t mode )  { return S_ISTYPE( mode, S_IFBLK );  }
179     extern (D) bool S_ISCHR( mode_t mode )  { return S_ISTYPE( mode, S_IFCHR );  }
180     extern (D) bool S_ISDIR( mode_t mode )  { return S_ISTYPE( mode, S_IFDIR );  }
181     extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO );  }
182     extern (D) bool S_ISREG( mode_t mode )  { return S_ISTYPE( mode, S_IFREG );  }
183     extern (D) bool S_ISLNK( mode_t mode )  { return S_ISTYPE( mode, S_IFLNK );  }
184     extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); }
185
186     static if( true /*__USE_POSIX199309*/ )
187     {
188         extern bool S_TYPEISMQ( stat_t* buf )  { return false; }
189         extern bool S_TYPEISSEM( stat_t* buf ) { return false; }
190         extern bool S_TYPEISSHM( stat_t* buf ) { return false; }
191     }
192 }
193 else version( darwin )
194 {
195     struct stat_t
196     {
197         dev_t       st_dev;
198         ino_t       st_ino;
199         mode_t      st_mode;
200         nlink_t     st_nlink;
201         uid_t       st_uid;
202         gid_t       st_gid;
203         dev_t       st_rdev;
204         time_t      st_atime;
205         c_ulong     st_atimensec;
206         time_t      st_mtime;
207         c_ulong     st_mtimensec;
208         time_t      st_ctime;
209         c_ulong     st_ctimensec;
210         off_t       st_size;
211         blkcnt_t    st_blocks;
212         blksize_t   st_blksize;
213         uint        st_flags;
214         uint        st_gen;
215         int         st_lspare;
216         long[2]     st_qspare;
217     }
218
219     const S_IRUSR   = 0400;
220     const S_IWUSR   = 0200;
221     const S_IXUSR   = 0100;
222     const S_IRWXU   = S_IRUSR | S_IWUSR | S_IXUSR;
223
224     const S_IRGRP   = S_IRUSR >> 3;
225     const S_IWGRP   = S_IWUSR >> 3;
226     const S_IXGRP   = S_IXUSR >> 3;
227     const S_IRWXG   = S_IRWXU >> 3;
228
229     const S_IROTH   = S_IRGRP >> 3;
230     const S_IWOTH   = S_IWGRP >> 3;
231     const S_IXOTH   = S_IXGRP >> 3;
232     const S_IRWXO   = S_IRWXG >> 3;
233
234     const S_ISUID   = 04000;
235     const S_ISGID   = 02000;
236     const S_ISVTX   = 01000;
237
238     private
239     {
240         extern (D) bool S_ISTYPE( mode_t mode, uint mask )
241         {
242             return ( mode & S_IFMT ) == mask;
243         }
244     }
245
246     extern (D) bool S_ISBLK( mode_t mode )  { return S_ISTYPE( mode, S_IFBLK );  }
247     extern (D) bool S_ISCHR( mode_t mode )  { return S_ISTYPE( mode, S_IFCHR );  }
248     extern (D) bool S_ISDIR( mode_t mode )  { return S_ISTYPE( mode, S_IFDIR );  }
249     extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO );  }
250     extern (D) bool S_ISREG( mode_t mode )  { return S_ISTYPE( mode, S_IFREG );  }
251     extern (D) bool S_ISLNK( mode_t mode )  { return S_ISTYPE( mode, S_IFLNK );  }
252     extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); }
253 }
254 else version( freebsd )
255 {
256     struct stat_t
257     {
258         dev_t   st_dev;
259         ino_t   st_ino;
260         mode_t  st_mode;
261         nlink_t st_nlink;
262         uid_t   st_uid;
263         gid_t   st_gid;
264         dev_t   st_rdev;
265         time_t  st_atime;
266         c_ulong st_atimensec;
267         time_t  st_mtime;
268         c_ulong st_mtimensec;
269         time_t  st_ctime;
270         c_ulong st_ctimensec;
271     /*  Defined in C as:
272         timespec    st_atimespec;
273         timespec    st_mtimespec;
274         timespec    st_ctimespec; */
275         off_t       st_size;
276         blkcnt_t    st_blocks;
277         blksize_t   st_blksize;
278         fflags_t    st_flags;
279         uint        st_gen;
280         int         st_lspare;
281         timespec    st_birthtimespec;
282
283         byte[16 - timespec.sizeof] padding;
284     }
285
286     const S_IRUSR   = 0000400;
287     const S_IWUSR   = 0000200;
288     const S_IXUSR   = 0000100;
289     const S_IRWXU   = 0000700;
290
291     const S_IRGRP   = 0000040;
292     const S_IWGRP   = 0000020;
293     const S_IXGRP   = 0000010;
294     const S_IRWXG   = 0000070;
295
296     const S_IROTH   = 0000004;
297     const S_IWOTH   = 0000002;
298     const S_IXOTH   = 0000001;
299     const S_IRWXO   = 0000007;
300
301     const S_ISUID   = 0004000;
302     const S_ISGID   = 0002000;
303     const S_ISVTX   = 0001000;
304
305     private
306     {
307         extern (D) bool S_ISTYPE( mode_t mode, uint mask )
308         {
309             return ( mode & S_IFMT ) == mask;
310         }
311     }
312
313     extern (D) bool S_ISBLK( mode_t mode )  { return S_ISTYPE( mode, S_IFBLK );  }
314     extern (D) bool S_ISCHR( mode_t mode )  { return S_ISTYPE( mode, S_IFCHR );  }
315     extern (D) bool S_ISDIR( mode_t mode )  { return S_ISTYPE( mode, S_IFDIR );  }
316     extern (D) bool S_ISFIFO( mode_t mode ) { return S_ISTYPE( mode, S_IFIFO );  }
317     extern (D) bool S_ISREG( mode_t mode )  { return S_ISTYPE( mode, S_IFREG );  }
318     extern (D) bool S_ISLNK( mode_t mode )  { return S_ISTYPE( mode, S_IFLNK );  }
319     extern (D) bool S_ISSOCK( mode_t mode ) { return S_ISTYPE( mode, S_IFSOCK ); }
320 }
321 else version( solaris )
322 {
323     const _ST_FSTYPSZ = 16;     /* array size for file system type name */
324    
325     struct stat_t
326     {
327         version (X86_64)
328         {
329             dev_t               st_dev;
330             ino_t               st_ino;
331             mode_t              st_mode;
332             nlink_t             st_nlink;
333             uid_t               st_uid;
334             gid_t               st_gid;
335             dev_t               st_rdev;
336             off_t               st_size;
337            
338             time_t              st_atime;
339             c_ulong             st_atimensec;
340             time_t              st_mtime;
341             c_ulong             st_mtimensec;
342             time_t              st_ctime;
343             c_ulong             st_ctimensec;
344         /*  Defined in C as:
345             timespec            st_atim;
346             timespec            st_mtim;
347             timespec            st_ctim; */
348             blksize_t           st_blksize;
349             blkcnt_t            st_blocks;
350             char[_ST_FSTYPSZ]   st_fstype;
351         }
352         else
353         {
354             dev_t               st_dev;
355             c_long[3]           st_pad1;    /* reserved for network id */
356             ino_t               st_ino;
357             mode_t              st_mode;
358             nlink_t             st_nlink;
359             uid_t               st_uid;
360             gid_t               st_gid;
361             dev_t               st_rdev;
362             c_long[2]           st_pad2;
363             off_t               st_size;
364           static if( !__USE_LARGEFILE64 ) {
365             c_long              st_pad3;    /* future off_t expansion */
366           }
367             time_t              st_atime;
368             c_ulong             st_atimensec;
369             time_t              st_mtime;
370             c_ulong             st_mtimensec;
371             time_t              st_ctime;
372             c_ulong             st_ctimensec;
373         /*  Defined in C as:
374             timespec            st_atim;
375             timespec            st_mtim;
376             timespec            st_ctim; */
377             blksize_t           st_blksize;
378             blkcnt_t            st_blocks;
379             char[_ST_FSTYPSZ]   st_fstype;
380             c_long[8]           st_pad4;    /* expansion area */
381         }
382     }
383    
384     /* MODE MASKS */
385   enum {
386     /* de facto standard definitions */
387     S_IFMT      = 0xF000,   /* type of file */
388     S_IAMB      = 0x1FF,    /* access mode bits */
389     S_IFIFO     = 0x1000,   /* fifo */
390     S_IFCHR     = 0x2000,   /* character special */
391     S_IFDIR     = 0x4000,   /* directory */
392     /* XENIX definitions are not relevant to Solaris */
393     S_IFNAM     = 0x5000,   /* XENIX special named file */
394     S_INSEM     = 0x1,      /* XENIX semaphore subtype of IFNAM */
395     S_INSHD     = 0x2,      /* XENIX shared data subtype of IFNAM */
396     S_IFBLK     = 0x6000,   /* block special */
397     S_IFREG     = 0x8000,   /* regular */
398     S_IFLNK     = 0xA000,   /* symbolic link */
399     S_IFSOCK    = 0xC000,   /* socket */
400     S_IFDOOR    = 0xD000,   /* door */
401     S_IFPORT    = 0xE000,   /* event port */
402     S_ISUID     = 0x800,    /* set user id on execution */
403     S_ISGID     = 0x400,    /* set group id on execution */
404     S_ISVTX     = 0x200,    /* save swapped text even after use */
405     S_IREAD     = 00400,    /* read permission, owner */
406     S_IWRITE    = 00200,    /* write permission, owner */
407     S_IEXEC     = 00100,    /* execute/search permission, owner */
408     S_ENFMT     = S_ISGID,  /* record locking enforcement flag */
409
410     S_IRWXU     = 00700,    /* read, write, execute: owner */
411     S_IRUSR     = 00400,    /* read permission: owner */
412     S_IWUSR     = 00200,    /* write permission: owner */
413     S_IXUSR     = 00100,    /* execute permission: owner */
414     S_IRWXG     = 00070,    /* read, write, execute: group */
415     S_IRGRP     = 00040,    /* read permission: group */
416     S_IWGRP     = 00020,    /* write permission: group */
417     S_IXGRP     = 00010,    /* execute permission: group */
418     S_IRWXO     = 00007,    /* read, write, execute: other */
419     S_IROTH     = 00004,    /* read permission: other */
420     S_IWOTH     = 00002,    /* write permission: other */
421     S_IXOTH     = 00001     /* execute permission: other */
422   }
423
424     extern (D) bool S_ISFIFO(mode_t mode)   { return (mode & 0xF000) == 0x1000; }
425     extern (D) bool S_ISCHR(mode_t mode)    { return (mode & 0xF000) == 0x2000; }
426     extern (D) bool S_ISDIR(mode_t mode)    { return (mode & 0xF000) == 0x4000; }
427     extern (D) bool S_ISBLK(mode_t mode)    { return (mode & 0xF000) == 0x6000; }
428     extern (D) bool S_ISREG(mode_t mode)    { return (mode & 0xF000) == 0x8000; }
429     extern (D) bool S_ISLNK(mode_t mode)    { return (mode & 0xF000) == 0xa000; }
430     extern (D) bool S_ISSOCK(mode_t mode)   { return (mode & 0xF000) == 0xc000; }
431     extern (D) bool S_ISDOOR(mode_t mode)   { return (mode & 0xF000) == 0xd000; }
432     extern (D) bool S_ISPORT(mode_t mode)   { return (mode & 0xF000) == 0xe000; }
433
434 }
435
436 int    chmod(in char*, mode_t);
437 int    fchmod(int, mode_t);
438 //int    fstat(int, stat_t*);
439 //int    lstat(in char*, stat_t*);
440 int    mkdir(in char*, mode_t);
441 int    mkfifo(in char*, mode_t);
442 //int    stat(in char*, stat_t*);
443 mode_t umask(mode_t);
444
445 static if (__USE_LARGEFILE64)
446 {
447     int   fstat64(int, stat_t*);
448     alias fstat64 fstat;
449
450     int   lstat64(in char*, stat_t*);
451     alias lstat64 lstat;
452
453     int   stat64(in char*, stat_t*);
454     alias stat64 stat;
455 }
456 else
457 {
458     int   fstat(int, stat_t*);
459     int   lstat(in char*, stat_t*);
460     int   stat(in char*, stat_t*);
461 }
462
463 //
464 // Typed Memory Objects (TYM)
465 //
466 /*
467 S_TYPEISTMO(buf)
468 */
469
470 //
471 // XOpen (XSI)
472 //
473 /*
474 S_IFMT
475 S_IFBLK
476 S_IFCHR
477 S_IFIFO
478 S_IFREG
479 S_IFDIR
480 S_IFLNK
481 S_IFSOCK
482
483 int mknod(in 3char*, mode_t, dev_t);
484 */
485
486 version( linux )
487 {
488     const S_IFMT    = 0170000;
489     const S_IFBLK   = 0060000;
490     const S_IFCHR   = 0020000;
491     const S_IFIFO   = 0010000;
492     const S_IFREG   = 0100000;
493     const S_IFDIR   = 0040000;
494     const S_IFLNK   = 0120000;
495     const S_IFSOCK  = 0140000;
496
497     int mknod(in char*, mode_t, dev_t);
498 }
499 else version( darwin )
500 {
501     const S_IFMT    = 0170000;
502     const S_IFBLK   = 0060000;
503     const S_IFCHR   = 0020000;
504     const S_IFIFO   = 0010000;
505     const S_IFREG   = 0100000;
506     const S_IFDIR   = 0040000;
507     const S_IFLNK   = 0120000;
508     const S_IFSOCK  = 0140000;
509
510     int mknod(in char*, mode_t, dev_t);
511 }
512 else version( freebsd )
513 {
514     const S_IFMT    = 0170000;
515     const S_IFBLK   = 0060000;
516     const S_IFCHR   = 0020000;
517     const S_IFIFO   = 0010000;
518     const S_IFREG   = 0100000;
519     const S_IFDIR   = 0040000;
520     const S_IFLNK   = 0120000;
521     const S_IFSOCK  = 0140000;
522
523     int mknod(in char*, mode_t, dev_t);
524 }
525 else version( solaris )
526 {
527     // Constants defined above
528     int mknod(in char*, mode_t, dev_t);
529 }
Note: See TracBrowser for help on using the browser.