Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

system.h

Go to the documentation of this file.
00001 /* system-dependent definitions for fileutils, textutils, and sh-utils packages.
00002    Copyright (C) 1989, 1991-2000 Free Software Foundation, Inc.
00003 
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 2, or (at your option)
00007    any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; if not, write to the Free Software Foundation,
00016    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00017 
00018 /* Include sys/types.h before this file.  */
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 /* <unistd.h> should be included before any preprocessor test
00031    of _POSIX_VERSION.  */
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 /* limits.h must come before pathmax.h because limits.h on some systems
00051    undefs PATH_MAX, whereas pathmax.h sets PATH_MAX.  */
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 /* Since major is a function on SVR4, we can't use `ifndef major'.  */
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         /* Might be defined in sys/types.h.  */
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 /* Some systems (even some that do have <utime.h>) don't declare this
00093    structure anywhere.  */
00094 #ifndef HAVE_STRUCT_UTIMBUF
00095 struct utimbuf
00096 {
00097   long actime;
00098   long modtime;
00099 };
00100 #endif
00101 
00102 /* Don't use bcopy!  Use memmove if source and destination may overlap,
00103    memcpy otherwise.  */
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 /* The following test is to work around the gross typo in
00126    systems like Sony NEWS-OS Release 4.0C, whereby EXIT_FAILURE
00127    is defined to 0, not 1.  */
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 /* For systems that distinguish between text and binary I/O.
00156    O_BINARY is usually declared in fcntl.h  */
00157 #if !defined O_BINARY && defined _O_BINARY
00158   /* For MSC-compatible compilers.  */
00159 # define O_BINARY _O_BINARY
00160 # define O_TEXT _O_TEXT
00161 #endif
00162 
00163 #ifdef __BEOS__
00164   /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect.  */
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 /* not DJGPP */
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 /* O_BINARY */
00190 
00191 #if HAVE_DIRENT_H
00192 # include <dirent.h>
00193 # define NLENGTH(direct) (strlen((direct)->d_name))
00194 #else /* not HAVE_DIRENT_H */
00195 # define dirent direct
00196 # define NLENGTH(direct) ((direct)->d_namlen)
00197 # if HAVE_SYS_NDIR_H
00198 #  include <sys/ndir.h>
00199 # endif /* HAVE_SYS_NDIR_H */
00200 # if HAVE_SYS_DIR_H
00201 #  include <sys/dir.h>
00202 # endif /* HAVE_SYS_DIR_H */
00203 # if HAVE_NDIR_H
00204 #  include <ndir.h>
00205 # endif /* HAVE_NDIR_H */
00206 #endif /* HAVE_DIRENT_H */
00207 
00208 #if CLOSEDIR_VOID
00209 /* Fake a return value. */
00210 # define CLOSEDIR(d) (closedir (d), 0)
00211 #else
00212 # define CLOSEDIR(d) closedir (d)
00213 #endif
00214 
00215 /* Get or fake the disk device blocksize.
00216    Usually defined by sys/param.h (if at all).  */
00217 #if !defined DEV_BSIZE && defined BSIZE
00218 # define DEV_BSIZE BSIZE
00219 #endif
00220 #if !defined DEV_BSIZE && defined BBSIZE /* SGI */
00221 # define DEV_BSIZE BBSIZE
00222 #endif
00223 #ifndef DEV_BSIZE
00224 # define DEV_BSIZE 4096
00225 #endif
00226 
00227 /* Extract or fake data from a `struct stat'.
00228    ST_BLKSIZE: Preferred I/O blocksize for the file, in bytes.
00229    ST_NBLOCKS: Number of blocks in the file, including indirect blocks.
00230    ST_NBLOCKSIZE: Size of blocks used when calculating ST_NBLOCKS.  */
00231 #ifndef HAVE_STRUCT_STAT_ST_BLOCKS
00232 # define ST_BLKSIZE(statbuf) DEV_BSIZE
00233 # if defined(_POSIX_SOURCE) || !defined(BSIZE) /* fileblocks.c uses 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 /* !_POSIX_SOURCE && BSIZE */
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 /* !_POSIX_SOURCE && BSIZE */
00244 #else /* HAVE_STRUCT_STAT_ST_BLOCKS */
00245 /* Some systems, like Sequents, return st_blksize of 0 on pipes. */
00246 # define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
00247                 ? (statbuf).st_blksize : DEV_BSIZE)
00248 # if defined(hpux) || defined(__hpux__) || defined(__hpux)
00249 /* HP-UX counts st_blocks in 1024-byte units.
00250    This loses when mixing HP-UX and BSD filesystems with NFS.  */
00251 #  define ST_NBLOCKSIZE 1024
00252 # else /* !hpux */
00253 #  if defined(_AIX) && defined(_I386)
00254 /* AIX PS/2 counts st_blocks in 4K units.  */
00255 #   define ST_NBLOCKSIZE (4 * 1024)
00256 #  else /* not AIX PS/2 */
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 /* _CRAY */
00263 #  endif /* not AIX PS/2 */
00264 # endif /* !hpux */
00265 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
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"

Generated on Mon Apr 7 19:41:46 2003 for DuTree by doxygen1.2.18