home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / fileutils-3.6 / lib / system.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-19  |  6.0 KB  |  236 lines

  1. /* system-dependent definitions for fileutils programs.
  2.    Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.  
  9.    This program 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.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* Include sys/types.h before this file.  */
  19.  
  20. #include <sys/stat.h>
  21. #ifndef S_ISREG            /* Doesn't have POSIX.1 stat stuff. */
  22. #define mode_t unsigned short
  23. #endif
  24. #if !defined(S_ISBLK) && defined(S_IFBLK)
  25. #define    S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  26. #endif
  27. #if !defined(S_ISCHR) && defined(S_IFCHR)
  28. #define    S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  29. #endif
  30. #if !defined(S_ISDIR) && defined(S_IFDIR)
  31. #define    S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  32. #endif
  33. #if !defined(S_ISREG) && defined(S_IFREG)
  34. #define    S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  35. #endif
  36. #if !defined(S_ISFIFO) && defined(S_IFIFO)
  37. #define    S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  38. #endif
  39. #if !defined(S_ISLNK) && defined(S_IFLNK)
  40. #define    S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  41. #endif
  42. #if !defined(S_ISSOCK) && defined(S_IFSOCK)
  43. #define    S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  44. #endif
  45. #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
  46. #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
  47. #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
  48. #endif
  49. #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
  50. #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
  51. #endif
  52. #if !defined(HAVE_MKFIFO)
  53. #define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0))
  54. #endif
  55.  
  56. #ifndef _POSIX_SOURCE
  57. #include <sys/param.h>
  58. #endif
  59.  
  60. #include "pathmax.h"
  61.  
  62. #ifndef _POSIX_VERSION
  63. off_t lseek ();
  64. #endif
  65.  
  66. #ifdef TM_IN_SYS_TIME
  67. #include <sys/time.h>
  68. #else
  69. #include <time.h>
  70. #endif
  71.  
  72. /* Since major is a function on SVR4, we can't use `ifndef major'.  */
  73. #ifdef MAJOR_IN_MKDEV
  74. #include <sys/mkdev.h>
  75. #define HAVE_MAJOR
  76. #endif
  77. #ifdef MAJOR_IN_SYSMACROS
  78. #include <sys/sysmacros.h>
  79. #define HAVE_MAJOR
  80. #endif
  81. #ifdef major            /* Might be defined in sys/types.h.  */
  82. #define HAVE_MAJOR
  83. #endif
  84.  
  85. #ifndef HAVE_MAJOR
  86. #define major(dev)  (((dev) >> 8) & 0xff)
  87. #define minor(dev)  ((dev) & 0xff)
  88. #define makedev(maj, min)  (((maj) << 8) | (min))
  89. #endif
  90. #undef HAVE_MAJOR
  91.  
  92. #ifdef _POSIX_VERSION
  93. #include <utime.h>
  94. #else /* not _POSIX_VERSION */
  95. struct utimbuf
  96. {
  97.   long actime;
  98.   long modtime;
  99. };
  100. #endif /* _POSIX_VERSION */
  101.  
  102. #if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
  103. #include <string.h>
  104. #ifndef index
  105. #define index strchr
  106. #endif
  107. #ifndef rindex
  108. #define rindex strrchr
  109. #endif
  110. #ifndef bcopy
  111. #define bcopy(from, to, len) memcpy ((to), (from), (len))
  112. #endif
  113. #ifndef bzero
  114. #define bzero(s, n) memset ((s), 0, (n))
  115. #endif
  116. #else
  117. #include <strings.h>
  118. #endif
  119.  
  120. #include <errno.h>
  121. #ifdef STDC_HEADERS
  122. #define getopt system_getopt
  123. #include <stdlib.h>
  124. #undef getopt
  125. #else /* not STDC_HEADERS */
  126. char *getenv ();
  127. extern int errno;
  128. #endif /* STDC_HEADERS */
  129.  
  130. #if defined(HAVE_FCNTL_H) || defined(_POSIX_VERSION)
  131. #include <fcntl.h>
  132. #else
  133. #include <sys/file.h>
  134. #endif
  135.  
  136. #ifndef SEEK_SET
  137. #define SEEK_SET 0
  138. #define SEEK_CUR 1
  139. #define SEEK_END 2
  140. #endif
  141. #ifndef F_OK
  142. #define F_OK 0
  143. #define X_OK 1
  144. #define W_OK 2
  145. #define R_OK 4
  146. #endif
  147.  
  148. #if defined(DIRENT) || defined(_POSIX_VERSION)
  149. #include <dirent.h>
  150. #define NLENGTH(direct) (strlen((direct)->d_name))
  151. #else /* not (DIRENT or _POSIX_VERSION) */
  152. #define dirent direct
  153. #define NLENGTH(direct) ((direct)->d_namlen)
  154. #ifdef SYSNDIR
  155. #include <sys/ndir.h>
  156. #endif /* SYSNDIR */
  157. #ifdef SYSDIR
  158. #include <sys/dir.h>
  159. #endif /* SYSDIR */
  160. #ifdef NDIR
  161. #include <ndir.h>
  162. #endif /* NDIR */
  163. #endif /* DIRENT or _POSIX_VERSION */
  164.  
  165. #ifdef VOID_CLOSEDIR
  166. /* Fake a return value. */
  167. #define CLOSEDIR(d) (closedir (d), 0)
  168. #else
  169. #define CLOSEDIR(d) closedir (d)
  170. #endif
  171.  
  172. /* Get or fake the disk device blocksize.
  173.    Usually defined by sys/param.h (if at all).  */
  174. #ifndef DEV_BSIZE
  175. #ifdef BSIZE
  176. #define DEV_BSIZE BSIZE
  177. #else /* !BSIZE */
  178. #define DEV_BSIZE 4096
  179. #endif /* !BSIZE */
  180. #endif /* !DEV_BSIZE */
  181.  
  182. /* Extract or fake data from a `struct stat'.
  183.    ST_BLKSIZE: Optimal I/O blocksize for the file, in bytes.
  184.    ST_NBLOCKS: Number of 512-byte blocks in the file
  185.    (including indirect blocks). */
  186. #ifndef HAVE_ST_BLOCKS
  187. # define ST_BLKSIZE(statbuf) DEV_BSIZE
  188. # if defined(_POSIX_SOURCE) || !defined(BSIZE) /* fileblocks.c uses BSIZE.  */
  189. #  define ST_NBLOCKS(statbuf) (((statbuf).st_size + 512 - 1) / 512)
  190. # else /* !_POSIX_SOURCE && BSIZE */
  191. #  define ST_NBLOCKS(statbuf) (st_blocks ((statbuf).st_size))
  192. # endif /* !_POSIX_SOURCE && BSIZE */
  193. #else /* HAVE_ST_BLOCKS */
  194. /* Some systems, like Sequents, return st_blksize of 0 on pipes. */
  195. # define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
  196.                    ? (statbuf).st_blksize : DEV_BSIZE)
  197. # if defined(hpux) || defined(__hpux__) || defined(__hpux)
  198. /* HP-UX counts st_blocks in 1024-byte units.
  199.    This loses when mixing HP-UX and BSD filesystems with NFS.  */
  200. #  define ST_NBLOCKS(statbuf) ((statbuf).st_blocks * 2)
  201. # else /* !hpux */
  202. #  if defined(_AIX) && defined(_I386)
  203. /* AIX PS/2 counts st_blocks in 4K units.  */
  204. #    define ST_NBLOCKS(statbuf) ((statbuf).st_blocks * 8)
  205. #  else /* not AIX PS/2 */
  206. #    define ST_NBLOCKS(statbuf) ((statbuf).st_blocks)
  207. #  endif /* not AIX PS/2 */
  208. # endif /* !hpux */
  209. #endif /* HAVE_ST_BLOCKS */
  210.  
  211. /* Convert B 512-byte blocks to kilobytes if K is nonzero,
  212.    otherwise return it unchanged. */
  213. #define convert_blocks(b, k) ((k) ? ((b) + 1) / 2 : (b))
  214.  
  215. #ifndef S_ISLNK
  216. #define lstat stat
  217. #endif
  218.  
  219. #ifndef RETSIGTYPE
  220. #define RETSIGTYPE void
  221. #endif
  222.  
  223. #ifdef __GNUC__
  224. #undef alloca
  225. #define alloca __builtin_alloca
  226. #else
  227. #ifdef HAVE_ALLOCA_H
  228. #include <alloca.h>
  229. #else
  230. #ifndef _AIX
  231. /* AIX alloca decl has to be the first thing in the file, bletch! */
  232. char *alloca ();
  233. #endif
  234. #endif
  235. #endif
  236.