1 /* system-dependent definitions for fileutils, textutils, and sh-utils packages.
2 Copyright (C) 1989, 1991-2000 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 #if !defined(HAVE_MKFIFO)
23 # define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0))
27 # include <sys/param.h>
30 /* <unistd.h> should be included before any preprocessor test
37 # define STDIN_FILENO 0
41 # define STDOUT_FILENO 1
45 # define STDERR_FILENO 2
50 /* limits.h must come before pathmax.h because limits.h on some systems
51 undefs PATH_MAX, whereas pathmax.h sets PATH_MAX. */
57 #if TIME_WITH_SYS_TIME
58 # include <sys/time.h>
62 # include <sys/time.h>
68 /* Since major is a function on SVR4, we can't use `ifndef major'. */
70 # include <sys/mkdev.h>
73 #if MAJOR_IN_SYSMACROS
74 # include <sys/sysmacros.h>
77 #ifdef major /* Might be defined in sys/types.h. */
82 # define major(dev) (((dev) >> 8) & 0xff)
83 # define minor(dev) ((dev) & 0xff)
84 # define makedev(maj, min) (((maj) << 8) | (min))
92 /* Some systems (even some that do have <utime.h>) don't declare this
93 structure anywhere. */
94 #ifndef HAVE_STRUCT_UTIMBUF
102 /* Don't use bcopy! Use memmove if source and destination may overlap,
106 # if !STDC_HEADERS && HAVE_MEMORY_H
111 # include <strings.h>
120 # define getopt system_getopt
125 /* The following test is to work around the gross typo in
126 systems like Sony NEWS-OS Release 4.0C, whereby EXIT_FAILURE
127 is defined to 0, not 1. */
130 # define EXIT_FAILURE 1
134 # define EXIT_SUCCESS 0
140 # include <sys/file.h>
143 #if !defined (SEEK_SET)
155 /* For systems that distinguish between text and binary I/O.
156 O_BINARY is usually declared in fcntl.h */
157 #if !defined O_BINARY && defined _O_BINARY
158 /* For MSC-compatible compilers. */
159 # define O_BINARY _O_BINARY
160 # define O_TEXT _O_TEXT
164 /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
171 # define setmode _setmode
172 # define fileno(_fp) _fileno (_fp)
173 # endif /* not DJGPP */
174 # define SET_BINARY(_f) do {if (!isatty(_f)) setmode (_f, O_BINARY);} while (0)
175 # define SET_BINARY2(_f1, _f2) \
179 setmode (_f1, O_BINARY); \
181 setmode (_f2, O_BINARY); \
185 # define SET_BINARY(f) (void)0
186 # define SET_BINARY2(f1,f2) (void)0
189 #endif /* O_BINARY */
193 # define NLENGTH(direct) (strlen((direct)->d_name))
194 #else /* not HAVE_DIRENT_H */
195 # define dirent direct
196 # define NLENGTH(direct) ((direct)->d_namlen)
198 # include <sys/ndir.h>
199 # endif /* HAVE_SYS_NDIR_H */
201 # include <sys/dir.h>
202 # endif /* HAVE_SYS_DIR_H */
205 # endif /* HAVE_NDIR_H */
206 #endif /* HAVE_DIRENT_H */
209 /* Fake a return value. */
210 # define CLOSEDIR(d) (closedir (d), 0)
212 # define CLOSEDIR(d) closedir (d)
215 /* Get or fake the disk device blocksize.
216 Usually defined by sys/param.h (if at all). */
217 #if !defined DEV_BSIZE && defined BSIZE
218 # define DEV_BSIZE BSIZE
220 #if !defined DEV_BSIZE && defined BBSIZE /* SGI */
221 # define DEV_BSIZE BBSIZE
224 # define DEV_BSIZE 4096
227 /* Extract or fake data from a `struct stat'.
228 ST_BLKSIZE: Preferred I/O blocksize for the file, in bytes.
229 ST_NBLOCKS: Number of blocks in the file, including indirect blocks.
230 ST_NBLOCKSIZE: Size of blocks used when calculating ST_NBLOCKS. */
231 #ifndef HAVE_STRUCT_STAT_ST_BLOCKS
232 # define ST_BLKSIZE(statbuf) DEV_BSIZE
233 # if defined(_POSIX_SOURCE) || !defined(BSIZE) /* fileblocks.c uses BSIZE. */
234 # define ST_NBLOCKS(statbuf) \
235 (S_ISREG ((statbuf).st_mode) \
236 || S_ISDIR ((statbuf).st_mode) \
237 ? (statbuf).st_size / ST_NBLOCKSIZE + ((statbuf).st_size % ST_NBLOCKSIZE != 0) : 0)
238 # else /* !_POSIX_SOURCE && BSIZE */
239 # define ST_NBLOCKS(statbuf) \
240 (S_ISREG ((statbuf).st_mode) \
241 || S_ISDIR ((statbuf).st_mode) \
242 ? st_blocks ((statbuf).st_size) : 0)
243 # endif /* !_POSIX_SOURCE && BSIZE */
244 #else /* HAVE_STRUCT_STAT_ST_BLOCKS */
245 /* Some systems, like Sequents, return st_blksize of 0 on pipes. */
246 # define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
247 ? (statbuf).st_blksize : DEV_BSIZE)
248 # if defined(hpux) || defined(__hpux__) || defined(__hpux)
249 /* HP-UX counts st_blocks in 1024-byte units.
250 This loses when mixing HP-UX and BSD filesystems with NFS. */
251 # define ST_NBLOCKSIZE 1024
253 # if defined(_AIX) && defined(_I386)
254 /* AIX PS/2 counts st_blocks in 4K units. */
255 # define ST_NBLOCKSIZE (4 * 1024)
256 # else /* not AIX PS/2 */
258 # define ST_NBLOCKS(statbuf) \
259 (S_ISREG ((statbuf).st_mode) \
260 || S_ISDIR ((statbuf).st_mode) \
261 ? (statbuf).st_blocks * ST_BLKSIZE(statbuf)/ST_NBLOCKSIZE : 0)
263 # endif /* not AIX PS/2 */
265 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
268 # define ST_NBLOCKS(statbuf) \
269 (S_ISREG ((statbuf).st_mode) \
270 || S_ISDIR ((statbuf).st_mode) \
271 ? (statbuf).st_blocks : 0)
274 #ifndef ST_NBLOCKSIZE
275 # define ST_NBLOCKSIZE 512