1 /* system-dependent definitions for fileutils, textutils, and sh-utils packages.
2 Copyright (C) 1989, 1991-1999 Free Software Foundation, Inc.
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)
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.
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 Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /* Include sys/types.h before this file. */
22 #ifdef STAT_MACROS_BROKEN
34 #endif /* STAT_MACROS_BROKEN. */
37 # define S_IFMT 0170000
39 #if !defined(S_ISBLK) && defined(S_IFBLK)
40 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
42 #if !defined(S_ISCHR) && defined(S_IFCHR)
43 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
45 #if !defined(S_ISDIR) && defined(S_IFDIR)
46 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
48 #if !defined(S_ISREG) && defined(S_IFREG)
49 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
51 #if !defined(S_ISFIFO) && defined(S_IFIFO)
52 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
54 #if !defined(S_ISLNK) && defined(S_IFLNK)
55 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
57 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
58 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
60 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
61 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
62 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
64 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
65 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
67 #if !defined(S_ISDOOR) && defined(S_IFDOOR) /* Solaris 2.5 and up */
68 # define S_ISDOOR(m) (((m) & S_IFMT) == S_IFDOOR)
72 # define S_ISUID 04000
75 # define S_ISGID 02000
78 /* S_ISVTX is a common extension to POSIX.1. */
80 # define S_ISVTX 01000
85 # define S_IWUSR S_IWRITE
87 # define S_IWUSR 00200
93 # define S_IWUSR S_IWRITE
95 # define S_IWUSR 00200
100 # define S_IEXEC S_IXUSR
104 # define S_IXUSR S_IEXEC
107 # define S_IXGRP (S_IEXEC >> 3)
110 # define S_IXOTH (S_IEXEC >> 6)
114 # define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
117 # define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
120 # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
123 /* S_IXUGO is a common extension to POSIX.1. */
125 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
128 /* All the mode bits that can be affected by chmod. */
129 #define CHMOD_MODE_BITS \
130 (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
133 # define ST_TIME_CMP_NS(a, b, ns) ((a).ns < (b).ns ? -1 : (a).ns > (b).ns)
135 # define ST_TIME_CMP_NS(a, b, ns) 0
137 #define ST_TIME_CMP(a, b, s, ns) \
138 ((a).s < (b).s ? -1 : (a).s > (b).s ? 1 : ST_TIME_CMP_NS(a, b, ns))
139 #define ATIME_CMP(a, b) ST_TIME_CMP (a, b, st_atime, st_atim.ST_MTIM_NSEC)
140 #define CTIME_CMP(a, b) ST_TIME_CMP (a, b, st_ctime, st_ctim.ST_MTIM_NSEC)
141 #define MTIME_CMP(a, b) ST_TIME_CMP (a, b, st_mtime, st_mtim.ST_MTIM_NSEC)
143 #if !defined(HAVE_MKFIFO)
144 # define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0))
147 #ifdef HAVE_SYS_PARAM_H
148 # include <sys/param.h>
151 /* <unistd.h> should be included before any preprocessor test
152 of _POSIX_VERSION. */
158 # define STDIN_FILENO 0
161 #ifndef STDOUT_FILENO
162 # define STDOUT_FILENO 1
165 #ifndef STDERR_FILENO
166 # define STDERR_FILENO 2
171 /* limits.h must come before pathmax.h because limits.h on some systems
172 undefs PATH_MAX, whereas pathmax.h sets PATH_MAX. */
178 #if TIME_WITH_SYS_TIME
179 # include <sys/time.h>
183 # include <sys/time.h>
189 /* Since major is a function on SVR4, we can't use `ifndef major'. */
190 #ifdef MAJOR_IN_MKDEV
191 # include <sys/mkdev.h>
194 #ifdef MAJOR_IN_SYSMACROS
195 # include <sys/sysmacros.h>
198 #ifdef major /* Might be defined in sys/types.h. */
203 # define major(dev) (((dev) >> 8) & 0xff)
204 # define minor(dev) ((dev) & 0xff)
205 # define makedev(maj, min) (((maj) << 8) | (min))
213 /* Some systems (even some that do have <utime.h>) don't declare this
214 structure anywhere. */
215 #ifndef HAVE_STRUCT_UTIMBUF
223 /* Don't use bcopy! Use memmove if source and destination may overlap,
227 # if !STDC_HEADERS && HAVE_MEMORY_H
232 # include <strings.h>
241 # define getopt system_getopt
246 /* The following test is to work around the gross typo in
247 systems like Sony NEWS-OS Release 4.0C, whereby EXIT_FAILURE
248 is defined to 0, not 1. */
251 # define EXIT_FAILURE 1
255 # define EXIT_SUCCESS 0
261 # include <sys/file.h>
264 #if !defined (SEEK_SET)
278 # define NLENGTH(direct) (strlen((direct)->d_name))
279 #else /* not HAVE_DIRENT_H */
280 # define dirent direct
281 # define NLENGTH(direct) ((direct)->d_namlen)
282 # ifdef HAVE_SYS_NDIR_H
283 # include <sys/ndir.h>
284 # endif /* HAVE_SYS_NDIR_H */
285 # ifdef HAVE_SYS_DIR_H
286 # include <sys/dir.h>
287 # endif /* HAVE_SYS_DIR_H */
290 # endif /* HAVE_NDIR_H */
291 #endif /* HAVE_DIRENT_H */
294 /* Fake a return value. */
295 # define CLOSEDIR(d) (closedir (d), 0)
297 # define CLOSEDIR(d) closedir (d)
300 /* Get or fake the disk device blocksize.
301 Usually defined by sys/param.h (if at all). */
304 # define DEV_BSIZE BSIZE
306 # define DEV_BSIZE 4096
308 #endif /* !DEV_BSIZE */
310 /* Extract or fake data from a `struct stat'.
311 ST_BLKSIZE: Preferred I/O blocksize for the file, in bytes.
312 ST_NBLOCKS: Number of blocks in the file, including indirect blocks.
313 ST_NBLOCKSIZE: Size of blocks used when calculating ST_NBLOCKS. */
314 #ifndef HAVE_ST_BLOCKS
315 # define ST_BLKSIZE(statbuf) DEV_BSIZE
316 # if defined(_POSIX_SOURCE) || !defined(BSIZE) /* fileblocks.c uses BSIZE. */
317 # define ST_NBLOCKS(statbuf) ((statbuf).st_size / ST_NBLOCKSIZE + ((statbuf).st_size % ST_NBLOCKSIZE != 0))
318 # else /* !_POSIX_SOURCE && BSIZE */
319 # define ST_NBLOCKS(statbuf) (st_blocks ((statbuf).st_size))
320 # endif /* !_POSIX_SOURCE && BSIZE */
321 #else /* HAVE_ST_BLOCKS */
322 /* Some systems, like Sequents, return st_blksize of 0 on pipes. */
323 # define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
324 ? (statbuf).st_blksize : DEV_BSIZE)
325 # if defined(hpux) || defined(__hpux__) || defined(__hpux)
326 /* HP-UX counts st_blocks in 1024-byte units.
327 This loses when mixing HP-UX and BSD filesystems with NFS. */
328 # define ST_NBLOCKSIZE 1024
330 # if defined(_AIX) && defined(_I386)
331 /* AIX PS/2 counts st_blocks in 4K units. */
332 # define ST_NBLOCKSIZE (4 * 1024)
333 # else /* not AIX PS/2 */
335 # define ST_NBLOCKS(statbuf) ((statbuf).st_blocks * ST_BLKSIZE(statbuf)/ST_NBLOCKSIZE)
337 # endif /* not AIX PS/2 */
339 #endif /* HAVE_ST_BLOCKS */
342 # define ST_NBLOCKS(statbuf) ((statbuf).st_blocks)
345 #ifndef ST_NBLOCKSIZE
346 # define ST_NBLOCKSIZE 512