stat_.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Copyright (C) 1991, 2000 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: stat_.h,v 1.10 2003/04/10 18:45:12 alexcher Exp $ */
  14. /* Generic substitute for Unix sys/stat.h */
  15. #ifndef stat__INCLUDED
  16. # define stat__INCLUDED
  17. /* We must include std.h before any file that includes sys/types.h. */
  18. #include "std.h"
  19. /* Metrowerks Standard Library doesn't use subdirs */
  20. #ifdef __MWERKS__
  21. #include <stat.h>
  22. #else
  23. #include <sys/stat.h>
  24. #endif
  25. /*
  26. * Many environments, including the MS-DOS compilers, don't define
  27. * the st_blocks member of a stat structure.
  28. */
  29. #if defined(__SVR3) || defined(__EMX__) || defined(__DVX__) || defined(OSK) || defined(__MSDOS__) || defined(__QNX__) || defined(VMS) || defined(__WIN32__) || defined(__IBMC__) || defined(__BEOS__) || defined(Plan9) || defined(__WATCOMC__)
  30. # define stat_blocks(psbuf) (((psbuf)->st_size + 1023) >> 10)
  31. #else
  32. # define stat_blocks(psbuf) ((psbuf)->st_blocks)
  33. #endif
  34. /*
  35. * Microsoft C uses _stat instead of stat,
  36. * for both the function name and the structure name.
  37. */
  38. #ifdef _MSC_VER
  39. # define stat _stat
  40. #endif
  41. /*
  42. * Some (System V?) systems test for directories in a slightly different way.
  43. */
  44. #if defined(OSK) || !defined(S_ISDIR)
  45. # ifdef S_IFDIR
  46. # define stat_is_dir(stbuf) ((stbuf).st_mode & S_IFDIR)
  47. # else
  48. # ifdef _S_IFDIR
  49. # define stat_is_dir(stbuf) ((stbuf).st_mode & _S_IFDIR)
  50. # endif
  51. # endif
  52. #else
  53. # define stat_is_dir(stbuf) S_ISDIR((stbuf).st_mode)
  54. #endif
  55. /*
  56. * Some systems have S_IFMT and S_IFCHR but not S_ISCHR.
  57. */
  58. #if !defined(S_ISCHR) || !defined(S_ISREG)
  59. # ifndef S_IFMT
  60. # ifdef _S_IFMT
  61. # define S_IFMT _S_IFMT
  62. # define S_IFCHR _S_IFCHR
  63. # define S_IFREG _S_IFREG
  64. # else
  65. # ifdef __S_IFMT
  66. # define S_IFMT __S_IFMT
  67. # define S_IFCHR __S_IFCHR
  68. # define S_IFREG __S_IFREG
  69. # endif
  70. # endif
  71. # endif
  72. # define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
  73. # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
  74. #endif
  75. /*
  76. * Microsoft C doesn't define S_IRUSR or S_IWUSR.
  77. */
  78. #ifndef S_IRUSR
  79. # ifndef S_IREAD
  80. # define S_IRUSR _S_IREAD
  81. # else
  82. # define S_IRUSR S_IREAD
  83. # endif
  84. #endif
  85. #ifndef S_IWUSR
  86. # ifndef S_IWRITE
  87. # define S_IWUSR _S_IWRITE
  88. # else
  89. # define S_IWUSR S_IWRITE
  90. # endif
  91. #endif
  92. #endif /* stat__INCLUDED */