home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / fileutils-3.12-src.lha / fileutils-3.12 / src / system.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-20  |  6.5 KB  |  270 lines

  1. /* system-dependent definitions for fileutils programs.
  2.    Copyright (C) 89, 91, 92, 93, 1994 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
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* Include sys/types.h before this file.  */
  19.  
  20. #include <sys/stat.h>
  21.  
  22. #ifdef STAT_MACROS_BROKEN
  23. #undef S_ISBLK
  24. #undef S_ISCHR
  25. #undef S_ISDIR
  26. #undef S_ISFIFO
  27. #undef S_ISLNK
  28. #undef S_ISMPB
  29. #undef S_ISMPC
  30. #undef S_ISNWK
  31. #undef S_ISREG
  32. #undef S_ISSOCK
  33. #endif /* STAT_MACROS_BROKEN.  */
  34.  
  35. #ifndef S_IFMT
  36. #define S_IFMT 0170000
  37. #endif
  38. #if !defined(S_ISBLK) && defined(S_IFBLK)
  39. #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  40. #endif
  41. #if !defined(S_ISCHR) && defined(S_IFCHR)
  42. #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  43. #endif
  44. #if !defined(S_ISDIR) && defined(S_IFDIR)
  45. #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  46. #endif
  47. #if !defined(S_ISREG) && defined(S_IFREG)
  48. #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  49. #endif
  50. #if !defined(S_ISFIFO) && defined(S_IFIFO)
  51. #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  52. #endif
  53. #if !defined(S_ISLNK) && defined(S_IFLNK)
  54. #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  55. #endif
  56. #if !defined(S_ISSOCK) && defined(S_IFSOCK)
  57. #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  58. #endif
  59. #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
  60. #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
  61. #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
  62. #endif
  63. #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
  64. #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
  65. #endif
  66.  
  67. #ifndef S_IEXEC
  68. #define S_IEXEC S_IXUSR
  69. #endif
  70.  
  71. #ifdef S_IEXEC
  72. #ifndef S_IXUSR
  73. #define S_IXUSR S_IEXEC
  74. #endif
  75. #ifndef S_IXGRP
  76. #define S_IXGRP (S_IEXEC >> 3)
  77. #endif
  78. #ifndef S_IXOTH
  79. #define S_IXOTH (S_IEXEC >> 6)
  80. #endif
  81. #endif /* S_IEXEC */
  82.  
  83. #if !defined(HAVE_MKFIFO)
  84. #define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0))
  85. #endif
  86.  
  87. #ifdef HAVE_SYS_PARAM_H
  88. #include <sys/param.h>
  89. #endif
  90.  
  91. /* <unistd.h> should be included before any preprocessor test
  92.    of _POSIX_VERSION.  */
  93. #ifdef HAVE_UNISTD_H
  94. #include <unistd.h>
  95. #endif
  96.  
  97. #include "pathmax.h"
  98.  
  99. /* FIXME: Don't use _POSIX_VERSION.  */
  100. #ifndef _POSIX_VERSION
  101. off_t lseek ();
  102. #endif
  103.  
  104. #ifdef TM_IN_SYS_TIME
  105. #include <sys/time.h>
  106. #else
  107. #include <time.h>
  108. #endif
  109.  
  110. /* Since major is a function on SVR4, we can't use `ifndef major'.  */
  111. #ifdef MAJOR_IN_MKDEV
  112. #include <sys/mkdev.h>
  113. #define HAVE_MAJOR
  114. #endif
  115. #ifdef MAJOR_IN_SYSMACROS
  116. #include <sys/sysmacros.h>
  117. #define HAVE_MAJOR
  118. #endif
  119. #ifdef major            /* Might be defined in sys/types.h.  */
  120. #define HAVE_MAJOR
  121. #endif
  122.  
  123. #ifndef HAVE_MAJOR
  124. #define major(dev)  (((dev) >> 8) & 0xff)
  125. #define minor(dev)  ((dev) & 0xff)
  126. #define makedev(maj, min)  (((maj) << 8) | (min))
  127. #endif
  128. #undef HAVE_MAJOR
  129.  
  130. #ifdef HAVE_UTIME_H
  131. #include <utime.h>
  132. #else
  133. struct utimbuf
  134. {
  135.   long actime;
  136.   long modtime;
  137. };
  138. #endif
  139.  
  140. #if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
  141. #include <string.h>
  142. #ifndef index
  143. #define index strchr
  144. #endif
  145. #ifndef rindex
  146. #define rindex strrchr
  147. #endif
  148. #ifndef bcopy
  149. #define bcopy(from, to, len) memcpy ((to), (from), (len))
  150. #endif
  151. #ifndef bzero
  152. #define bzero(s, n) memset ((s), 0, (n))
  153. #endif
  154. #else
  155. #include <strings.h>
  156. #endif
  157.  
  158. #include <errno.h>
  159. #ifdef STDC_HEADERS
  160. #define getopt system_getopt
  161. #include <stdlib.h>
  162. #undef getopt
  163. #else /* not STDC_HEADERS */
  164. char *getenv ();
  165. extern int errno;
  166. #endif /* STDC_HEADERS */
  167.  
  168. #ifdef HAVE_FCNTL_H
  169. #include <fcntl.h>
  170. #else
  171. #include <sys/file.h>
  172. #endif
  173.  
  174. #ifndef SEEK_SET
  175. #define SEEK_SET 0
  176. #define SEEK_CUR 1
  177. #define SEEK_END 2
  178. #endif
  179. #ifndef F_OK
  180. #define F_OK 0
  181. #define X_OK 1
  182. #define W_OK 2
  183. #define R_OK 4
  184. #endif
  185.  
  186. #ifdef HAVE_DIRENT_H
  187. # include <dirent.h>
  188. # define NLENGTH(direct) (strlen((direct)->d_name))
  189. #else /* not HAVE_DIRENT_H */
  190. # define dirent direct
  191. # define NLENGTH(direct) ((direct)->d_namlen)
  192. # ifdef HAVE_SYS_NDIR_H
  193. #  include <sys/ndir.h>
  194. # endif /* HAVE_SYS_NDIR_H */
  195. # ifdef HAVE_SYS_DIR_H
  196. #  include <sys/dir.h>
  197. # endif /* HAVE_SYS_DIR_H */
  198. # ifdef HAVE_NDIR_H
  199. #  include <ndir.h>
  200. # endif /* HAVE_NDIR_H */
  201. #endif /* HAVE_DIRENT_H */
  202.  
  203. #ifdef CLOSEDIR_VOID
  204. /* Fake a return value. */
  205. #define CLOSEDIR(d) (closedir (d), 0)
  206. #else
  207. #define CLOSEDIR(d) closedir (d)
  208. #endif
  209.  
  210. /* Get or fake the disk device blocksize.
  211.    Usually defined by sys/param.h (if at all).  */
  212. #ifndef DEV_BSIZE
  213. #ifdef BSIZE
  214. #define DEV_BSIZE BSIZE
  215. #else /* !BSIZE */
  216. #define DEV_BSIZE 4096
  217. #endif /* !BSIZE */
  218. #endif /* !DEV_BSIZE */
  219.  
  220. /* Extract or fake data from a `struct stat'.
  221.    ST_BLKSIZE: Optimal I/O blocksize for the file, in bytes.
  222.    ST_NBLOCKS: Number of 512-byte blocks in the file
  223.    (including indirect blocks). */
  224. #ifndef HAVE_ST_BLOCKS
  225. # define ST_BLKSIZE(statbuf) DEV_BSIZE
  226. # if defined(_POSIX_SOURCE) || !defined(BSIZE) /* fileblocks.c uses BSIZE.  */
  227. #  define ST_NBLOCKS(statbuf) (((statbuf).st_size + 512 - 1) / 512)
  228. # else /* !_POSIX_SOURCE && BSIZE */
  229. #  define ST_NBLOCKS(statbuf) (st_blocks ((statbuf).st_size))
  230. # endif /* !_POSIX_SOURCE && BSIZE */
  231. #else /* HAVE_ST_BLOCKS */
  232. /* Some systems, like Sequents, return st_blksize of 0 on pipes. */
  233. # define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
  234.                    ? (statbuf).st_blksize : DEV_BSIZE)
  235. # if defined(hpux) || defined(__hpux__) || defined(__hpux)
  236. /* HP-UX counts st_blocks in 1024-byte units.
  237.    This loses when mixing HP-UX and BSD filesystems with NFS.  */
  238. #  define ST_NBLOCKS(statbuf) ((statbuf).st_blocks * 2)
  239. # else /* !hpux */
  240. #  if defined(_AIX) && defined(_I386)
  241. /* AIX PS/2 counts st_blocks in 4K units.  */
  242. #    define ST_NBLOCKS(statbuf) ((statbuf).st_blocks * 8)
  243. #  else /* not AIX PS/2 */
  244. #    define ST_NBLOCKS(statbuf) ((statbuf).st_blocks)
  245. #  endif /* not AIX PS/2 */
  246. # endif /* !hpux */
  247. #endif /* HAVE_ST_BLOCKS */
  248.  
  249. /* Convert B 512-byte blocks to kilobytes if K is nonzero,
  250.    otherwise return it unchanged. */
  251. #define convert_blocks(b, k) ((k) ? ((b) + 1) / 2 : (b))
  252.  
  253. #ifndef RETSIGTYPE
  254. #define RETSIGTYPE void
  255. #endif
  256.  
  257. #ifdef __GNUC__
  258. #undef alloca
  259. #define alloca __builtin_alloca
  260. #else
  261. #ifdef HAVE_ALLOCA_H
  262. #include <alloca.h>
  263. #else
  264. #ifndef _AIX
  265. /* AIX alloca decl has to be the first thing in the file, bletch! */
  266. char *alloca ();
  267. #endif
  268. #endif
  269. #endif
  270.