home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / famapi.zip / INCLUDE.ZIP / SYS / STAT.H < prev    next >
C/C++ Source or Header  |  1993-06-13  |  4KB  |  129 lines

  1. //
  2. //      **************************************************************
  3. //       JdeBP C++ Library Routines      General Public Licence v1.00
  4. //          Copyright (c) 1991,1992  Jonathan de Boyne Pollard
  5. //      **************************************************************
  6. //
  7. //  STAT structures, and file mode bits
  8. //
  9.  
  10. #if !defined(__STDDEF_H_INCLUDED)
  11. #include <_stddef.h>
  12. #endif
  13. #if !defined(__ATTRIB_H_INCLUDED)
  14. #include <_attrib.h>        // File attribute constants
  15. #endif
  16.  
  17. //
  18. // Because POSIX.1 states that a file mode encoding is implementation
  19. // defined, we make it easy on ourselves by mushing all the bit flags
  20. // together.  Under MS-DOS, rwx permission for owner implies the same
  21. // for group and world.  The NETWARE trustee system does not match
  22. // POSIX.1, unfortunately.
  23. //
  24. // A mode_t is encoded as a short integer, with the lower byte being
  25. // the MS-DOS file attribute, and the upper byte being extra bits for
  26. // POSIX.1 derived from the lower.
  27. //
  28. // ┌───┬───┬───┬───┬───┬───┬───┬───┬───────────────────────────────┐
  29. // │ F │ E │ D │ C │ B │ A │ 9 │ 8 │  Lower byte as for MS-DOS     │
  30. // └─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴───────────────────────────────┘
  31. //   │   │   │   │   │   │   │   │
  32. //   │   │   │   │   │   │   │   └──── Executable (true for directories)
  33. //   │   │   │   │   │   │   └──── Writable (owner, group, & world)
  34. //   │   │   │   │   │   └──── Readable (owner, group, & world)
  35. //   │   │   │   │   └──── File is a device
  36. //   │   │   │   └──── Save text (because S_ISVTX must be non-zero)
  37. //   │   │   └──── Set GID (because S_ISGID must be non-zero)
  38. //   │   └──── Set UID (because S_ISUID must be non-zero)
  39. //   └──── Reserved
  40. //
  41. // Although MS-DOS has block special drivers, they are not in the namespace
  42. // for normal files, as under POSIX.1 they would be.
  43. //
  44.  
  45. //
  46. // POSIX.1 bit masks to apply to a mode_t.
  47. //
  48.  
  49. #define S_ISUID     0x04000U    /* Setting to 0 would break correct code */
  50. #define S_ISGID     0x02000U    /* Setting to 0 would break correct code */
  51. #define S_ISVTX     0x01000U    /* Non-POSIX (and non-MSDOS !)*/
  52. #define S_IRUSR     0x00400U
  53. #define S_IWUSR     0x00200U
  54. #define S_IXUSR     0x00100U
  55. #define S_IRGRP     0x00400U
  56. #define S_IWGRP     0x00200U
  57. #define S_IXGRP     0x00100U
  58. #define S_IROTH     0x00400U
  59. #define S_IWOTH     0x00200U
  60. #define S_IXOTH     0x00100U
  61.  
  62. #define S_IRWXU     (S_IRUSR|S_IWUSR|S_IXUSR)
  63. #define S_IRWXG     (S_IRGRP|S_IWGRP|S_IXGRP)
  64. #define S_IRWXO     (S_IROTH|S_IWOTH|S_IXOTH)
  65.  
  66. //
  67. // POSIX.1 macros to apply to a mode_t returning zero or non-zero
  68. //
  69.  
  70. #define S_ISBLK(m)  0
  71. #define S_ISCHR(m)  ((m) & 0x08FFU) == 0x0800U)
  72. #define S_ISDIR(m)  ((m) & _A_SUBDIR) == _A_SUBDIR)
  73. #define S_ISFIFO(m) 0
  74. #define S_ISREG(m)  ((m) & 0x08FFU) == (_A_NORMAL & ~0x0800))
  75.  
  76. //
  77. // Non-POSIX.1 bit flags
  78. //
  79. // We assume the use will be as ((m & S_IFMT) == S_IF...) otherwise
  80. // these values will not work.  It is not valid POSIX.1 usage anyway.
  81. //
  82.  
  83. #define S_IFMT      0x08FFU     /* file type mask */
  84. #define S_IFREG     0x0000U     /* regular (_A_NORMAL and not a device) */
  85. #define S_IFDIR     _A_SUBDIR   /* directory */
  86. #define S_IFCHR     0x0800U     /* character special */
  87. #define S_IFBLK     0x0000U     /* block special (not in MS-DOS namespace) */
  88. #define S_IFFIFO    0x0000U     /* FIFO */
  89.  
  90. #define S_IREAD     S_IRUSR
  91. #define S_IWRITE    S_IWUSR
  92. #define S_IEXEC     S_IXUSR
  93.  
  94. #ifndef _STAT_DEFINED
  95. struct stat {
  96.     mode_t  st_mode;
  97.     ino_t   st_ino;
  98.     dev_t   st_dev;
  99.     nlink_t st_nlink;
  100.     uid_t   st_uid;         // NETWARE only
  101.     gid_t   st_gid;         // Meaningless
  102.     off_t   st_size;
  103.     time_t  st_atime;       // NETWARE only, otherwise == st_mtime
  104.     time_t  st_mtime;
  105.     time_t  st_ctime;       // NETWARE only, otherwise == st_mtime
  106.     dev_t   st_rdev;
  107. };
  108. #define _STAT_DEFINED
  109. #endif
  110.  
  111. extern "C" {
  112.  
  113. int     _CDECL  chmod       (const char *, mode_t);
  114. int     _CDECL  fstat       (int, struct stat *);
  115. int     _CDECL  mkdir       (const char *);
  116. int     _CDECL  stat        (const char *, struct stat *);
  117. mode_t  _CDECL  umask       (mode_t);
  118.  
  119. extern  mode_t  _CDECL  _umaskval;
  120.  
  121. #if _POSIX1_SOURCE > 1
  122. int     _CDECL  fchmod      (int, mode_t);
  123. #endif
  124.  
  125. mode_t  _CDECL  _Dos2PosixFileMode (unsigned int) ;
  126. time_t  _CDECL  _Dos2PosixFileTime (unsigned short *, unsigned short *) ;
  127.  
  128. }
  129.