posixstat.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* posixstat.h -- Posix stat(2) definitions for systems that
  2. don't have them. */
  3. /* Copyright (C) 1987,1991 Free Software Foundation, Inc.
  4. This file is part of GNU Bash, the Bourne Again SHell.
  5. Bash is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. Bash is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Bash. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. /* This file should be included instead of <sys/stat.h>.
  17. It relies on the local sys/stat.h to work though. */
  18. #if !defined (_POSIXSTAT_H_)
  19. #define _POSIXSTAT_H_
  20. #include <sys/stat.h>
  21. #if defined (STAT_MACROS_BROKEN)
  22. # undef S_ISBLK
  23. # undef S_ISCHR
  24. # undef S_ISDIR
  25. # undef S_ISFIFO
  26. # undef S_ISREG
  27. # undef S_ISLNK
  28. #endif /* STAT_MACROS_BROKEN */
  29. /* These are guaranteed to work only on isc386 */
  30. #if !defined (S_IFDIR) && !defined (S_ISDIR)
  31. # define S_IFDIR 0040000
  32. #endif /* !S_IFDIR && !S_ISDIR */
  33. #if !defined (S_IFMT)
  34. # define S_IFMT 0170000
  35. #endif /* !S_IFMT */
  36. /* Posix 1003.1 5.6.1.1 <sys/stat.h> file types */
  37. /* Some Posix-wannabe systems define _S_IF* macros instead of S_IF*, but
  38. do not provide the S_IS* macros that Posix requires. */
  39. #if defined (_S_IFMT) && !defined (S_IFMT)
  40. #define S_IFMT _S_IFMT
  41. #endif
  42. #if defined (_S_IFIFO) && !defined (S_IFIFO)
  43. #define S_IFIFO _S_IFIFO
  44. #endif
  45. #if defined (_S_IFCHR) && !defined (S_IFCHR)
  46. #define S_IFCHR _S_IFCHR
  47. #endif
  48. #if defined (_S_IFDIR) && !defined (S_IFDIR)
  49. #define S_IFDIR _S_IFDIR
  50. #endif
  51. #if defined (_S_IFBLK) && !defined (S_IFBLK)
  52. #define S_IFBLK _S_IFBLK
  53. #endif
  54. #if defined (_S_IFREG) && !defined (S_IFREG)
  55. #define S_IFREG _S_IFREG
  56. #endif
  57. #if defined (_S_IFLNK) && !defined (S_IFLNK)
  58. #define S_IFLNK _S_IFLNK
  59. #endif
  60. #if defined (_S_IFSOCK) && !defined (S_IFSOCK)
  61. #define S_IFSOCK _S_IFSOCK
  62. #endif
  63. /* Test for each symbol individually and define the ones necessary (some
  64. systems claiming Posix compatibility define some but not all). */
  65. #if defined (S_IFBLK) && !defined (S_ISBLK)
  66. #define S_ISBLK(m) (((m)&S_IFMT) == S_IFBLK) /* block device */
  67. #endif
  68. #if defined (S_IFCHR) && !defined (S_ISCHR)
  69. #define S_ISCHR(m) (((m)&S_IFMT) == S_IFCHR) /* character device */
  70. #endif
  71. #if defined (S_IFDIR) && !defined (S_ISDIR)
  72. #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) /* directory */
  73. #endif
  74. #if defined (S_IFREG) && !defined (S_ISREG)
  75. #define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) /* file */
  76. #endif
  77. #if defined (S_IFIFO) && !defined (S_ISFIFO)
  78. #define S_ISFIFO(m) (((m)&S_IFMT) == S_IFIFO) /* fifo - named pipe */
  79. #endif
  80. #if defined (S_IFLNK) && !defined (S_ISLNK)
  81. #define S_ISLNK(m) (((m)&S_IFMT) == S_IFLNK) /* symbolic link */
  82. #endif
  83. #if defined (S_IFSOCK) && !defined (S_ISSOCK)
  84. #define S_ISSOCK(m) (((m)&S_IFMT) == S_IFSOCK) /* socket */
  85. #endif
  86. /*
  87. * POSIX 1003.1 5.6.1.2 <sys/stat.h> File Modes
  88. */
  89. #if !defined (S_IRWXU)
  90. # if !defined (S_IREAD)
  91. # define S_IREAD 00400
  92. # define S_IWRITE 00200
  93. # define S_IEXEC 00100
  94. # endif /* S_IREAD */
  95. # if !defined (S_IRUSR)
  96. # define S_IRUSR S_IREAD /* read, owner */
  97. # define S_IWUSR S_IWRITE /* write, owner */
  98. # define S_IXUSR S_IEXEC /* execute, owner */
  99. # define S_IRGRP (S_IREAD >> 3) /* read, group */
  100. # define S_IWGRP (S_IWRITE >> 3) /* write, group */
  101. # define S_IXGRP (S_IEXEC >> 3) /* execute, group */
  102. # define S_IROTH (S_IREAD >> 6) /* read, other */
  103. # define S_IWOTH (S_IWRITE >> 6) /* write, other */
  104. # define S_IXOTH (S_IEXEC >> 6) /* execute, other */
  105. # endif /* !S_IRUSR */
  106. # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
  107. # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
  108. # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
  109. #endif /* !S_IRWXU */
  110. /* These are non-standard, but are used in builtins.c$symbolic_umask() */
  111. #define S_IRUGO (S_IRUSR | S_IRGRP | S_IROTH)
  112. #define S_IWUGO (S_IWUSR | S_IWGRP | S_IWOTH)
  113. #define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
  114. #endif /* _POSIXSTAT_H_ */