1 /* system-dependent definitions for fileutils, textutils, and sh-utils packages.
2 Copyright (C) 1989, 1991-2002 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. */
20 #if 2 <= __GLIBC__ && 2 <= __GLIBC_MINOR__
21 # if ! defined _SYS_TYPES_H
22 you must include
<sys
/types
.h
> before including
this file
28 #if !defined HAVE_MKFIFO
29 # define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0))
33 # include <sys/param.h>
36 /* <unistd.h> should be included before any preprocessor test
43 # define STDIN_FILENO 0
47 # define STDOUT_FILENO 1
51 # define STDERR_FILENO 2
56 /* limits.h must come before pathmax.h because limits.h on some systems
57 undefs PATH_MAX, whereas pathmax.h sets PATH_MAX. */
63 #if TIME_WITH_SYS_TIME
64 # include <sys/time.h>
68 # include <sys/time.h>
74 /* Since major is a function on SVR4, we can't use `ifndef major'. */
76 # include <sys/mkdev.h>
79 #if MAJOR_IN_SYSMACROS
80 # include <sys/sysmacros.h>
83 #ifdef major /* Might be defined in sys/types.h. */
88 # define major(dev) (((dev) >> 8) & 0xff)
89 # define minor(dev) ((dev) & 0xff)
90 # define makedev(maj, min) (((maj) << 8) | (min))
98 /* Some systems (even some that do have <utime.h>) don't declare this
99 structure anywhere. */
100 #ifndef HAVE_STRUCT_UTIMBUF
108 /* Don't use bcopy! Use memmove if source and destination may overlap,
112 # if !STDC_HEADERS && HAVE_MEMORY_H
117 # include <strings.h>
119 #if ! HAVE_DECL_MEMRCHR
120 void *memrchr (const void *, int, size_t);
129 # include <stdbool.h>
131 typedef enum {false = 0, true = 1} bool;
135 # define getopt system_getopt
140 /* The following test is to work around the gross typo in
141 systems like Sony NEWS-OS Release 4.0C, whereby EXIT_FAILURE
142 is defined to 0, not 1. */
145 # define EXIT_FAILURE 1
149 # define EXIT_SUCCESS 0
155 # include <sys/file.h>
158 #if !defined SEEK_SET
170 /* For systems that distinguish between text and binary I/O.
171 O_BINARY is usually declared in fcntl.h */
172 #if !defined O_BINARY && defined _O_BINARY
173 /* For MSC-compatible compilers. */
174 # define O_BINARY _O_BINARY
175 # define O_TEXT _O_TEXT
179 /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
186 # define setmode _setmode
187 # define fileno(_fp) _fileno (_fp)
188 # endif /* not DJGPP */
189 # define SET_MODE(_f, _m) setmode (_f, _m)
190 # define SET_BINARY(_f) do {if (!isatty(_f)) setmode (_f, O_BINARY);} while (0)
191 # define SET_BINARY2(_f1, _f2) \
195 setmode (_f1, O_BINARY); \
197 setmode (_f2, O_BINARY); \
201 # define SET_MODE(_f, _m) (void)0
202 # define SET_BINARY(f) (void)0
203 # define SET_BINARY2(f1,f2) (void)0
206 #endif /* O_BINARY */
210 # define NLENGTH(direct) (strlen((direct)->d_name))
211 #else /* not HAVE_DIRENT_H */
212 # define dirent direct
213 # define NLENGTH(direct) ((direct)->d_namlen)
215 # include <sys/ndir.h>
216 # endif /* HAVE_SYS_NDIR_H */
218 # include <sys/dir.h>
219 # endif /* HAVE_SYS_DIR_H */
222 # endif /* HAVE_NDIR_H */
223 #endif /* HAVE_DIRENT_H */
226 /* Fake a return value. */
227 # define CLOSEDIR(d) (closedir (d), 0)
229 # define CLOSEDIR(d) closedir (d)
232 /* Get or fake the disk device blocksize.
233 Usually defined by sys/param.h (if at all). */
234 #if !defined DEV_BSIZE && defined BSIZE
235 # define DEV_BSIZE BSIZE
237 #if !defined DEV_BSIZE && defined BBSIZE /* SGI */
238 # define DEV_BSIZE BBSIZE
241 # define DEV_BSIZE 4096
244 /* Extract or fake data from a `struct stat'.
245 ST_BLKSIZE: Preferred I/O blocksize for the file, in bytes.
246 ST_NBLOCKS: Number of blocks in the file, including indirect blocks.
247 ST_NBLOCKSIZE: Size of blocks used when calculating ST_NBLOCKS. */
248 #ifndef HAVE_STRUCT_STAT_ST_BLOCKS
249 # define ST_BLKSIZE(statbuf) DEV_BSIZE
250 # if defined _POSIX_SOURCE || !defined BSIZE /* fileblocks.c uses BSIZE. */
251 # define ST_NBLOCKS(statbuf) \
252 ((statbuf).st_size / ST_NBLOCKSIZE + ((statbuf).st_size % ST_NBLOCKSIZE != 0))
253 # else /* !_POSIX_SOURCE && BSIZE */
254 # define ST_NBLOCKS(statbuf) \
255 (S_ISREG ((statbuf).st_mode) \
256 || S_ISDIR ((statbuf).st_mode) \
257 ? st_blocks ((statbuf).st_size) : 0)
258 # endif /* !_POSIX_SOURCE && BSIZE */
259 #else /* HAVE_STRUCT_STAT_ST_BLOCKS */
260 /* Some systems, like Sequents, return st_blksize of 0 on pipes.
261 Also, when running `rsh hpux11-system cat any-file', cat would
262 determine that the output stream had an st_blksize of 2147421096.
263 So here we arbitrarily limit the `optimal' block size to 4MB.
264 If anyone knows of a system for which the legitimate value for
265 st_blksize can exceed 4MB, please report it as a bug in this code. */
266 # define ST_BLKSIZE(statbuf) ((0 < (statbuf).st_blksize \
267 && (statbuf).st_blksize <= (1 << 22)) /* 4MB */ \
268 ? (statbuf).st_blksize : DEV_BSIZE)
269 # if defined hpux || defined __hpux__ || defined __hpux
270 /* HP-UX counts st_blocks in 1024-byte units.
271 This loses when mixing HP-UX and BSD filesystems with NFS. */
272 # define ST_NBLOCKSIZE 1024
274 # if defined _AIX && defined _I386
275 /* AIX PS/2 counts st_blocks in 4K units. */
276 # define ST_NBLOCKSIZE (4 * 1024)
277 # else /* not AIX PS/2 */
279 # define ST_NBLOCKS(statbuf) \
280 (S_ISREG ((statbuf).st_mode) \
281 || S_ISDIR ((statbuf).st_mode) \
282 ? (statbuf).st_blocks * ST_BLKSIZE(statbuf)/ST_NBLOCKSIZE : 0)
284 # endif /* not AIX PS/2 */
286 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
289 # define ST_NBLOCKS(statbuf) ((statbuf).st_blocks)
292 #ifndef ST_NBLOCKSIZE
293 # define ST_NBLOCKSIZE 512