1 /* system-dependent definitions for fileutils, textutils, and sh-utils packages.
2 Copyright (C) 89, 91, 92, 93, 94, 96, 1997 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
33 #endif /* STAT_MACROS_BROKEN. */
36 # define S_IFMT 0170000
38 #if !defined(S_ISBLK) && defined(S_IFBLK)
39 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
41 #if !defined(S_ISCHR) && defined(S_IFCHR)
42 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
44 #if !defined(S_ISDIR) && defined(S_IFDIR)
45 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
47 #if !defined(S_ISREG) && defined(S_IFREG)
48 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
50 #if !defined(S_ISFIFO) && defined(S_IFIFO)
51 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
53 #if !defined(S_ISLNK) && defined(S_IFLNK)
54 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
56 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
57 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
59 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
60 # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
61 # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
63 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
64 # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
68 # define S_IEXEC S_IXUSR
72 # define S_IXUSR S_IEXEC
75 # define S_IXGRP (S_IEXEC >> 3)
78 # define S_IXOTH (S_IEXEC >> 6)
81 # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
84 #if !defined(HAVE_MKFIFO)
85 # define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0))
88 #ifdef HAVE_SYS_PARAM_H
89 # include <sys/param.h>
92 /* <unistd.h> should be included before any preprocessor test
99 # define STDIN_FILENO 0
102 #ifndef STDOUT_FILENO
103 # define STDOUT_FILENO 1
106 #ifndef STDERR_FILENO
107 # define STDERR_FILENO 2
112 /* limits.h must come before pathmax.h because limits.h on some systems
113 undefs PATH_MAX, whereas pathmax.h sets PATH_MAX. */
121 /* The extra casts work around common compiler bugs. */
122 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
123 #define TYPE_MINIMUM(t) (TYPE_SIGNED (t) ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0)
124 #define TYPE_MAXIMUM(t) (~ (t) 0 - TYPE_MINIMUM (t))
127 # define INT_MAX TYPE_MAXIMUM (int)
131 # define UINT_MAX TYPE_MAXIMUM (unsigned int)
136 #ifdef TM_IN_SYS_TIME
137 # include <sys/time.h>
142 /* Since major is a function on SVR4, we can't use `ifndef major'. */
143 #ifdef MAJOR_IN_MKDEV
144 # include <sys/mkdev.h>
147 #ifdef MAJOR_IN_SYSMACROS
148 # include <sys/sysmacros.h>
151 #ifdef major /* Might be defined in sys/types.h. */
156 # define major(dev) (((dev) >> 8) & 0xff)
157 # define minor(dev) ((dev) & 0xff)
158 # define makedev(maj, min) (((maj) << 8) | (min))
166 /* Some systems (even some that do have <utime.h>) don't declare this
167 structure anywhere. */
168 #ifndef HAVE_STRUCT_UTIMBUF
176 /* Don't use bcopy! Use memmove if source and destination may overlap,
180 # if !STDC_HEADERS && HAVE_MEMORY_H
185 # include <strings.h>
194 # define getopt system_getopt
199 /* The following test is to work around the gross typo in
200 systems like Sony NEWS-OS Release 4.0C, whereby EXIT_FAILURE
201 is defined to 0, not 1. */
204 # define EXIT_FAILURE 1
208 # define EXIT_SUCCESS 0
214 # include <sys/file.h>
217 #if !defined (SEEK_SET)
231 # define NLENGTH(direct) (strlen((direct)->d_name))
232 #else /* not HAVE_DIRENT_H */
233 # define dirent direct
234 # define NLENGTH(direct) ((direct)->d_namlen)
235 # ifdef HAVE_SYS_NDIR_H
236 # include <sys/ndir.h>
237 # endif /* HAVE_SYS_NDIR_H */
238 # ifdef HAVE_SYS_DIR_H
239 # include <sys/dir.h>
240 # endif /* HAVE_SYS_DIR_H */
243 # endif /* HAVE_NDIR_H */
244 #endif /* HAVE_DIRENT_H */
247 /* Fake a return value. */
248 # define CLOSEDIR(d) (closedir (d), 0)
250 # define CLOSEDIR(d) closedir (d)
253 /* Get or fake the disk device blocksize.
254 Usually defined by sys/param.h (if at all). */
257 # define DEV_BSIZE BSIZE
259 # define DEV_BSIZE 4096
261 #endif /* !DEV_BSIZE */
263 /* Extract or fake data from a `struct stat'.
264 ST_BLKSIZE: Preferred I/O blocksize for the file, in bytes.
265 ST_NBLOCKS: Number of blocks in the file, including indirect blocks.
266 ST_NBLOCKSIZE: Size of blocks used when calculating ST_NBLOCKS. */
267 #ifndef HAVE_ST_BLOCKS
268 # define ST_BLKSIZE(statbuf) DEV_BSIZE
269 # if defined(_POSIX_SOURCE) || !defined(BSIZE) /* fileblocks.c uses BSIZE. */
270 # define ST_NBLOCKS(statbuf) ((statbuf).st_size / ST_NBLOCKSIZE + ((statbuf).st_size % ST_NBLOCKSIZE != 0))
271 # else /* !_POSIX_SOURCE && BSIZE */
272 # define ST_NBLOCKS(statbuf) (st_blocks ((statbuf).st_size))
273 # endif /* !_POSIX_SOURCE && BSIZE */
274 #else /* HAVE_ST_BLOCKS */
275 /* Some systems, like Sequents, return st_blksize of 0 on pipes. */
276 # define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
277 ? (statbuf).st_blksize : DEV_BSIZE)
278 # if defined(hpux) || defined(__hpux__) || defined(__hpux)
279 /* HP-UX counts st_blocks in 1024-byte units.
280 This loses when mixing HP-UX and BSD filesystems with NFS. */
281 # define ST_NBLOCKSIZE 1024
283 # if defined(_AIX) && defined(_I386)
284 /* AIX PS/2 counts st_blocks in 4K units. */
285 # define ST_NBLOCKSIZE (4 * 1024)
286 # else /* not AIX PS/2 */
288 # define ST_NBLOCKS(statbuf) ((statbuf).st_blocks * ST_BLKSIZE(statbuf)/ST_NBLOCKSIZE)
290 # endif /* not AIX PS/2 */
292 #endif /* HAVE_ST_BLOCKS */
295 # define ST_NBLOCKS(statbuf) ((statbuf).st_blocks)
298 #ifndef ST_NBLOCKSIZE
299 # define ST_NBLOCKSIZE 512