| 1 | /* system-dependent definitions for coreutils
|
|---|
| 2 | Copyright (C) 1989, 1991-2005 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 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)
|
|---|
| 7 | any later version.
|
|---|
| 8 |
|
|---|
| 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.
|
|---|
| 13 |
|
|---|
| 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
|---|
| 17 |
|
|---|
| 18 | #include <alloca.h>
|
|---|
| 19 |
|
|---|
| 20 | /* Include sys/types.h before this file. */
|
|---|
| 21 |
|
|---|
| 22 | #if 2 <= __GLIBC__ && 2 <= __GLIBC_MINOR__
|
|---|
| 23 | # if ! defined _SYS_TYPES_H
|
|---|
| 24 | you must include <sys/types.h> before including this file
|
|---|
| 25 | # endif
|
|---|
| 26 | #endif
|
|---|
| 27 |
|
|---|
| 28 | #include <sys/stat.h>
|
|---|
| 29 |
|
|---|
| 30 | #if !defined HAVE_MKFIFO
|
|---|
| 31 | # define mkfifo(name, mode) mknod (name, (mode) | S_IFIFO, 0)
|
|---|
| 32 | #endif
|
|---|
| 33 |
|
|---|
| 34 | #if HAVE_SYS_PARAM_H
|
|---|
| 35 | # include <sys/param.h>
|
|---|
| 36 | #endif
|
|---|
| 37 |
|
|---|
| 38 | #include <unistd.h>
|
|---|
| 39 |
|
|---|
| 40 | #ifndef STDIN_FILENO
|
|---|
| 41 | # define STDIN_FILENO 0
|
|---|
| 42 | #endif
|
|---|
| 43 |
|
|---|
| 44 | #ifndef STDOUT_FILENO
|
|---|
| 45 | # define STDOUT_FILENO 1
|
|---|
| 46 | #endif
|
|---|
| 47 |
|
|---|
| 48 | #ifndef STDERR_FILENO
|
|---|
| 49 | # define STDERR_FILENO 2
|
|---|
| 50 | #endif
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 | /* limits.h must come before pathmax.h because limits.h on some systems
|
|---|
| 54 | undefs PATH_MAX, whereas pathmax.h sets PATH_MAX. */
|
|---|
| 55 | #include <limits.h>
|
|---|
| 56 |
|
|---|
| 57 | #include "pathmax.h"
|
|---|
| 58 | #include "localedir.h"
|
|---|
| 59 |
|
|---|
| 60 | #if TIME_WITH_SYS_TIME
|
|---|
| 61 | # include <sys/time.h>
|
|---|
| 62 | # include <time.h>
|
|---|
| 63 | #else
|
|---|
| 64 | # if HAVE_SYS_TIME_H
|
|---|
| 65 | # include <sys/time.h>
|
|---|
| 66 | # else
|
|---|
| 67 | # include <time.h>
|
|---|
| 68 | # endif
|
|---|
| 69 | #endif
|
|---|
| 70 |
|
|---|
| 71 | /* Since major is a function on SVR4, we can't use `ifndef major'. */
|
|---|
| 72 | #if MAJOR_IN_MKDEV
|
|---|
| 73 | # include <sys/mkdev.h>
|
|---|
| 74 | # define HAVE_MAJOR
|
|---|
| 75 | #endif
|
|---|
| 76 | #if MAJOR_IN_SYSMACROS
|
|---|
| 77 | # include <sys/sysmacros.h>
|
|---|
| 78 | # define HAVE_MAJOR
|
|---|
| 79 | #endif
|
|---|
| 80 | #ifdef major /* Might be defined in sys/types.h. */
|
|---|
| 81 | # define HAVE_MAJOR
|
|---|
| 82 | #endif
|
|---|
| 83 |
|
|---|
| 84 | #ifndef HAVE_MAJOR
|
|---|
| 85 | # define major(dev) (((dev) >> 8) & 0xff)
|
|---|
| 86 | # define minor(dev) ((dev) & 0xff)
|
|---|
| 87 | # define makedev(maj, min) (((maj) << 8) | (min))
|
|---|
| 88 | #endif
|
|---|
| 89 | #undef HAVE_MAJOR
|
|---|
| 90 |
|
|---|
| 91 | #if ! defined makedev && defined mkdev
|
|---|
| 92 | # define makedev(maj, min) mkdev (maj, min)
|
|---|
| 93 | #endif
|
|---|
| 94 |
|
|---|
| 95 | /* Don't use bcopy! Use memmove if source and destination may overlap,
|
|---|
| 96 | memcpy otherwise. */
|
|---|
| 97 |
|
|---|
| 98 | #include <string.h>
|
|---|
| 99 | #include "memrchr.h"
|
|---|
| 100 |
|
|---|
| 101 | #include <errno.h>
|
|---|
| 102 |
|
|---|
| 103 | /* Some systems don't define the following symbols. */
|
|---|
| 104 | #ifndef ENOSYS
|
|---|
| 105 | # define ENOSYS (-1)
|
|---|
| 106 | #endif
|
|---|
| 107 | #ifndef EISDIR
|
|---|
| 108 | # define EISDIR (-1)
|
|---|
| 109 | #endif
|
|---|
| 110 |
|
|---|
| 111 | #include <stdbool.h>
|
|---|
| 112 | #include <stdlib.h>
|
|---|
| 113 |
|
|---|
| 114 | /* The following test is to work around the gross typo in
|
|---|
| 115 | systems like Sony NEWS-OS Release 4.0C, whereby EXIT_FAILURE
|
|---|
| 116 | is defined to 0, not 1. */
|
|---|
| 117 | #if !EXIT_FAILURE
|
|---|
| 118 | # undef EXIT_FAILURE
|
|---|
| 119 | # define EXIT_FAILURE 1
|
|---|
| 120 | #endif
|
|---|
| 121 |
|
|---|
| 122 | #ifndef EXIT_SUCCESS
|
|---|
| 123 | # define EXIT_SUCCESS 0
|
|---|
| 124 | #endif
|
|---|
| 125 |
|
|---|
| 126 | /* Exit statuses for programs like 'env' that exec other programs.
|
|---|
| 127 | EXIT_FAILURE might not be 1, so use EXIT_FAIL in such programs. */
|
|---|
| 128 | enum
|
|---|
| 129 | {
|
|---|
| 130 | EXIT_FAIL = 1,
|
|---|
| 131 | EXIT_CANNOT_INVOKE = 126,
|
|---|
| 132 | EXIT_ENOENT = 127
|
|---|
| 133 | };
|
|---|
| 134 |
|
|---|
| 135 | #include "exitfail.h"
|
|---|
| 136 |
|
|---|
| 137 | /* Set exit_failure to STATUS if that's not the default already. */
|
|---|
| 138 | static inline void
|
|---|
| 139 | initialize_exit_failure (int status)
|
|---|
| 140 | {
|
|---|
| 141 | if (status != EXIT_FAILURE)
|
|---|
| 142 | exit_failure = status;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | #include <fcntl.h>
|
|---|
| 146 |
|
|---|
| 147 | #if !defined SEEK_SET
|
|---|
| 148 | # define SEEK_SET 0
|
|---|
| 149 | # define SEEK_CUR 1
|
|---|
| 150 | # define SEEK_END 2
|
|---|
| 151 | #endif
|
|---|
| 152 | #ifndef F_OK
|
|---|
| 153 | # define F_OK 0
|
|---|
| 154 | # define X_OK 1
|
|---|
| 155 | # define W_OK 2
|
|---|
| 156 | # define R_OK 4
|
|---|
| 157 | #endif
|
|---|
| 158 |
|
|---|
| 159 | #if !defined O_DIRECT
|
|---|
| 160 | # define O_DIRECT 0
|
|---|
| 161 | #endif
|
|---|
| 162 |
|
|---|
| 163 | #if !defined O_DSYNC
|
|---|
| 164 | # define O_DSYNC 0
|
|---|
| 165 | #endif
|
|---|
| 166 |
|
|---|
| 167 | #if !defined O_NDELAY
|
|---|
| 168 | # define O_NDELAY 0
|
|---|
| 169 | #endif
|
|---|
| 170 |
|
|---|
| 171 | #if !defined O_NONBLOCK
|
|---|
| 172 | # define O_NONBLOCK O_NDELAY
|
|---|
| 173 | #endif
|
|---|
| 174 |
|
|---|
| 175 | #if !defined O_NOCTTY
|
|---|
| 176 | # define O_NOCTTY 0
|
|---|
| 177 | #endif
|
|---|
| 178 |
|
|---|
| 179 | #if !defined O_NOFOLLOW
|
|---|
| 180 | # define O_NOFOLLOW 0
|
|---|
| 181 | #endif
|
|---|
| 182 |
|
|---|
| 183 | #if !defined O_RSYNC
|
|---|
| 184 | # define O_RSYNC 0
|
|---|
| 185 | #endif
|
|---|
| 186 |
|
|---|
| 187 | #if !defined O_SYNC
|
|---|
| 188 | # define O_SYNC 0
|
|---|
| 189 | #endif
|
|---|
| 190 |
|
|---|
| 191 | /* For systems that distinguish between text and binary I/O.
|
|---|
| 192 | O_BINARY is usually declared in fcntl.h */
|
|---|
| 193 | #if !defined O_BINARY && defined _O_BINARY
|
|---|
| 194 | /* For MSC-compatible compilers. */
|
|---|
| 195 | # define O_BINARY _O_BINARY
|
|---|
| 196 | # define O_TEXT _O_TEXT
|
|---|
| 197 | #endif
|
|---|
| 198 |
|
|---|
| 199 | #ifdef __BEOS__
|
|---|
| 200 | /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
|
|---|
| 201 | # undef O_BINARY
|
|---|
| 202 | # undef O_TEXT
|
|---|
| 203 | #endif
|
|---|
| 204 |
|
|---|
| 205 | #ifndef O_BINARY
|
|---|
| 206 | # define O_BINARY 0
|
|---|
| 207 | # define O_TEXT 0
|
|---|
| 208 | #endif
|
|---|
| 209 |
|
|---|
| 210 | #if HAVE_DIRENT_H
|
|---|
| 211 | # include <dirent.h>
|
|---|
| 212 | # define NLENGTH(direct) (strlen((direct)->d_name))
|
|---|
| 213 | #else /* not HAVE_DIRENT_H */
|
|---|
| 214 | # define dirent direct
|
|---|
| 215 | # define NLENGTH(direct) ((direct)->d_namlen)
|
|---|
| 216 | # if HAVE_SYS_NDIR_H
|
|---|
| 217 | # include <sys/ndir.h>
|
|---|
| 218 | # endif /* HAVE_SYS_NDIR_H */
|
|---|
| 219 | # if HAVE_SYS_DIR_H
|
|---|
| 220 | # include <sys/dir.h>
|
|---|
| 221 | # endif /* HAVE_SYS_DIR_H */
|
|---|
| 222 | # if HAVE_NDIR_H
|
|---|
| 223 | # include <ndir.h>
|
|---|
| 224 | # endif /* HAVE_NDIR_H */
|
|---|
| 225 | #endif /* HAVE_DIRENT_H */
|
|---|
| 226 |
|
|---|
| 227 | #if CLOSEDIR_VOID
|
|---|
| 228 | /* Fake a return value. */
|
|---|
| 229 | # define CLOSEDIR(d) (closedir (d), 0)
|
|---|
|
|---|