00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <sys/stat.h>
00021
00022 #if !defined(HAVE_MKFIFO)
00023 # define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0))
00024 #endif
00025
00026 #if HAVE_SYS_PARAM_H
00027 # include <sys/param.h>
00028 #endif
00029
00030
00031
00032 #if HAVE_UNISTD_H
00033 # include <unistd.h>
00034 #endif
00035
00036 #ifndef STDIN_FILENO
00037 # define STDIN_FILENO 0
00038 #endif
00039
00040 #ifndef STDOUT_FILENO
00041 # define STDOUT_FILENO 1
00042 #endif
00043
00044 #ifndef STDERR_FILENO
00045 # define STDERR_FILENO 2
00046 #endif
00047
00048
00049 #if HAVE_LIMITS_H
00050
00051
00052 # include <limits.h>
00053 #endif
00054
00055 #include "pathmax.h"
00056
00057 #if TIME_WITH_SYS_TIME
00058 # include <sys/time.h>
00059 # include <time.h>
00060 #else
00061 # if HAVE_SYS_TIME_H
00062 # include <sys/time.h>
00063 # else
00064 # include <time.h>
00065 # endif
00066 #endif
00067
00068
00069 #if MAJOR_IN_MKDEV
00070 # include <sys/mkdev.h>
00071 # define HAVE_MAJOR
00072 #endif
00073 #if MAJOR_IN_SYSMACROS
00074 # include <sys/sysmacros.h>
00075 # define HAVE_MAJOR
00076 #endif
00077 #ifdef major
00078 # define HAVE_MAJOR
00079 #endif
00080
00081 #ifndef HAVE_MAJOR
00082 # define major(dev) (((dev) >> 8) & 0xff)
00083 # define minor(dev) ((dev) & 0xff)
00084 # define makedev(maj, min) (((maj) << 8) | (min))
00085 #endif
00086 #undef HAVE_MAJOR
00087
00088 #if HAVE_UTIME_H
00089 # include <utime.h>
00090 #endif
00091
00092
00093
00094 #ifndef HAVE_STRUCT_UTIMBUF
00095 struct utimbuf
00096 {
00097 long actime;
00098 long modtime;
00099 };
00100 #endif
00101
00102
00103
00104
00105 #if HAVE_STRING_H
00106 # if !STDC_HEADERS && HAVE_MEMORY_H
00107 # include <memory.h>
00108 # endif
00109 # include <string.h>
00110 #else
00111 # include <strings.h>
00112 #endif
00113
00114 #include <errno.h>
00115 #ifndef errno
00116 extern int errno;
00117 #endif
00118
00119 #if HAVE_STDLIB_H
00120 # define getopt system_getopt
00121 # include <stdlib.h>
00122 # undef getopt
00123 #endif
00124
00125
00126
00127
00128 #if !EXIT_FAILURE
00129 # undef EXIT_FAILURE
00130 # define EXIT_FAILURE 1
00131 #endif
00132
00133 #ifndef EXIT_SUCCESS
00134 # define EXIT_SUCCESS 0
00135 #endif
00136
00137 #if HAVE_FCNTL_H
00138 # include <fcntl.h>
00139 #else
00140 # include <sys/file.h>
00141 #endif
00142
00143 #if !defined (SEEK_SET)
00144 # define SEEK_SET 0
00145 # define SEEK_CUR 1
00146 # define SEEK_END 2
00147 #endif
00148 #ifndef F_OK
00149 # define F_OK 0
00150 # define X_OK 1
00151 # define W_OK 2
00152 # define R_OK 4
00153 #endif
00154
00155
00156
00157 #if !defined O_BINARY && defined _O_BINARY
00158
00159 # define O_BINARY _O_BINARY
00160 # define O_TEXT _O_TEXT
00161 #endif
00162
00163 #ifdef __BEOS__
00164
00165 # undef O_BINARY
00166 # undef O_TEXT
00167 #endif
00168
00169 #if O_BINARY
00170 # ifndef __DJGPP__
00171 # define setmode _setmode
00172 # define fileno(_fp) _fileno (_fp)
00173 # endif
00174 # define SET_BINARY(_f) do {if (!isatty(_f)) setmode (_f, O_BINARY);} while (0)
00175 # define SET_BINARY2(_f1, _f2) \
00176 do { \
00177 if (!isatty (_f1)) \
00178 { \
00179 setmode (_f1, O_BINARY); \
00180 if (!isatty (_f2)) \
00181 setmode (_f2, O_BINARY); \
00182 } \
00183 } while(0)
00184 #else
00185 # define SET_BINARY(f) (void)0
00186 # define SET_BINARY2(f1,f2) (void)0
00187 # define O_BINARY 0
00188 # define O_TEXT 0
00189 #endif
00190
00191 #if HAVE_DIRENT_H
00192 # include <dirent.h>
00193 # define NLENGTH(direct) (strlen((direct)->d_name))
00194 #else
00195 # define dirent direct
00196 # define NLENGTH(direct) ((direct)->d_namlen)
00197 # if HAVE_SYS_NDIR_H
00198 # include <sys/ndir.h>
00199 # endif
00200 # if HAVE_SYS_DIR_H
00201 # include <sys/dir.h>
00202 # endif
00203 # if HAVE_NDIR_H
00204 # include <ndir.h>
00205 # endif
00206 #endif
00207
00208 #if CLOSEDIR_VOID
00209
00210 # define CLOSEDIR(d) (closedir (d), 0)
00211 #else
00212 # define CLOSEDIR(d) closedir (d)
00213 #endif
00214
00215
00216
00217 #if !defined DEV_BSIZE && defined BSIZE
00218 # define DEV_BSIZE BSIZE
00219 #endif
00220 #if !defined DEV_BSIZE && defined BBSIZE
00221 # define DEV_BSIZE BBSIZE
00222 #endif
00223 #ifndef DEV_BSIZE
00224 # define DEV_BSIZE 4096
00225 #endif
00226
00227
00228
00229
00230
00231 #ifndef HAVE_STRUCT_STAT_ST_BLOCKS
00232 # define ST_BLKSIZE(statbuf) DEV_BSIZE
00233 # if defined(_POSIX_SOURCE) || !defined(BSIZE)
00234 # define ST_NBLOCKS(statbuf) \
00235 (S_ISREG ((statbuf).st_mode) \
00236 || S_ISDIR ((statbuf).st_mode) \
00237 ? (statbuf).st_size / ST_NBLOCKSIZE + ((statbuf).st_size % ST_NBLOCKSIZE != 0) : 0)
00238 # else
00239 # define ST_NBLOCKS(statbuf) \
00240 (S_ISREG ((statbuf).st_mode) \
00241 || S_ISDIR ((statbuf).st_mode) \
00242 ? st_blocks ((statbuf).st_size) : 0)
00243 # endif
00244 #else
00245
00246 # define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
00247 ? (statbuf).st_blksize : DEV_BSIZE)
00248 # if defined(hpux) || defined(__hpux__) || defined(__hpux)
00249
00250
00251 # define ST_NBLOCKSIZE 1024
00252 # else
00253 # if defined(_AIX) && defined(_I386)
00254
00255 # define ST_NBLOCKSIZE (4 * 1024)
00256 # else
00257 # if defined(_CRAY)
00258 # define ST_NBLOCKS(statbuf) \
00259 (S_ISREG ((statbuf).st_mode) \
00260 || S_ISDIR ((statbuf).st_mode) \
00261 ? (statbuf).st_blocks * ST_BLKSIZE(statbuf)/ST_NBLOCKSIZE : 0)
00262 # endif
00263 # endif
00264 # endif
00265 #endif
00266
00267 #ifndef ST_NBLOCKS
00268 # define ST_NBLOCKS(statbuf) \
00269 (S_ISREG ((statbuf).st_mode) \
00270 || S_ISDIR ((statbuf).st_mode) \
00271 ? (statbuf).st_blocks : 0)
00272 #endif
00273
00274 #ifndef ST_NBLOCKSIZE
00275 # define ST_NBLOCKSIZE 512
00276 #endif
00277
00278 #include "sys2.h"