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>
126 # include <stdbool.h>
128 typedef enum {false = 0, true = 1} bool;
132 # define getopt system_getopt
137 /* The following test is to work around the gross typo in
138 systems like Sony NEWS-OS Release 4.0C, whereby EXIT_FAILURE
139 is defined to 0, not 1. */
142 # define EXIT_FAILURE 1
146 # define EXIT_SUCCESS 0
152 # include <sys/file.h>
155 #if !defined SEEK_SET
167 /* For systems that distinguish between text and binary I/O.
168 O_BINARY is usually declared in fcntl.h */
169 #if !defined O_BINARY && defined _O_BINARY
170 /* For MSC-compatible compilers. */
171 # define O_BINARY _O_BINARY
172 # define O_TEXT _O_TEXT
176 /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
183 # define setmode _setmode
184 # define fileno(_fp) _fileno (_fp)
185 # endif /* not DJGPP */
186 # define SET_MODE(_f, _m) setmode (_f, _m)
187 # define SET_BINARY(_f) do {if (!isatty(_f)) setmode (_f, O_BINARY);} while (0)
188 # define SET_BINARY2(_f1, _f2) \
192 setmode (_f1, O_BINARY); \
194 setmode (_f2, O_BINARY); \
198 # define SET_MODE(_f, _m) (void)0
199 # define SET_BINARY(f) (void)0
200 # define SET_BINARY2(f1,f2) (void)0
203 #endif /* O_BINARY */
207 # define NLENGTH(direct) (strlen((direct)->d_name))
208 #else /* not HAVE_DIRENT_H */
209 # define dirent direct
210 # define NLENGTH(direct) ((direct)->d_namlen)
212 # include <sys/ndir.h>
213 # endif /* HAVE_SYS_NDIR_H */
215 # include <sys/dir.h>
216 # endif /* HAVE_SYS_DIR_H */
219 # endif /* HAVE_NDIR_H */
220 #endif /* HAVE_DIRENT_H */
223 /* Fake a return value. */
224 # define CLOSEDIR(d) (closedir (d), 0)
226 # define CLOSEDIR(d) closedir (d)
229 /* Get or fake the disk device blocksize.
230 Usually defined by sys/param.h (if at all). */
231 #if !defined DEV_BSIZE && defined BSIZE
232 # define DEV_BSIZE BSIZE
234 #if !defined DEV_BSIZE && defined BBSIZE /* SGI */
235 # define DEV_BSIZE BBSIZE
238 # define DEV_BSIZE 4096
241 /* Extract or fake data from a `struct stat'.
242 ST_BLKSIZE: Preferred I/O blocksize for the file, in bytes.
243 ST_NBLOCKS: Number of blocks in the file, including indirect blocks.
244 ST_NBLOCKSIZE: Size of blocks used when calculating ST_NBLOCKS. */
245 #ifndef HAVE_STRUCT_STAT_ST_BLOCKS
246 # define ST_BLKSIZE(statbuf) DEV_BSIZE
247 # if defined _POSIX_SOURCE || !defined BSIZE /* fileblocks.c uses BSIZE. */
248 # define ST_NBLOCKS(statbuf) \
249 (S_ISREG ((statbuf).st_mode) \
250 || S_ISDIR ((statbuf).st_mode) \
251 ? (statbuf).st_size / ST_NBLOCKSIZE + ((statbuf).st_size % ST_NBLOCKSIZE != 0) : 0)
252 # else /* !_POSIX_SOURCE && BSIZE */
253 # define ST_NBLOCKS(statbuf) \
254 (S_ISREG ((statbuf).st_mode) \
255 || S_ISDIR ((statbuf).st_mode) \
256 ? st_blocks ((statbuf).st_size) : 0)
257 # endif /* !_POSIX_SOURCE && BSIZE */
258 #else /* HAVE_STRUCT_STAT_ST_BLOCKS */
259 /* Some systems, like Sequents, return st_blksize of 0 on pipes. */
260 # define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
261 ? (statbuf).st_blksize : DEV_BSIZE)
262 # if defined hpux || defined __hpux__ || defined __hpux
263 /* HP-UX counts st_blocks in 1024-byte units.
264 This loses when mixing HP-UX and BSD filesystems with NFS. */
265 # define ST_NBLOCKSIZE 1024
267 # if defined _AIX && defined _I386
268 /* AIX PS/2 counts st_blocks in 4K units. */
269 # define ST_NBLOCKSIZE (4 * 1024)
270 # else /* not AIX PS/2 */
272 # define ST_NBLOCKS(statbuf) \
273 (S_ISREG ((statbuf).st_mode) \
274 || S_ISDIR ((statbuf).st_mode) \
275 ? (statbuf).st_blocks * ST_BLKSIZE(statbuf)/ST_NBLOCKSIZE : 0)
277 # endif /* not AIX PS/2 */
279 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
282 # define ST_NBLOCKS(statbuf) \
283 (S_ISREG ((statbuf).st_mode) \
284 || S_ISDIR ((statbuf).st_mode) \
285 ? (statbuf).st_blocks : 0)
288 #ifndef ST_NBLOCKSIZE
289 # define ST_NBLOCKSIZE 512