home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / utilit~1 / futilsrc.zoo / fileutil / lib / orig / system.h < prev   
Encoding:
C/C++ Source or Header  |  1991-10-20  |  5.2 KB  |  226 lines

  1. /* system-dependent definitions for fileutils programs.
  2.    Copyright (C) 1989-1991 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. #ifndef S_ISREG            /* Doesn't have POSIX.1 stat stuff. */
  22. #define mode_t unsigned short
  23. #endif
  24. #if !defined(S_ISBLK) && defined(S_IFBLK)
  25. #define    S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  26. #endif
  27. #if !defined(S_ISCHR) && defined(S_IFCHR)
  28. #define    S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  29. #endif
  30. #if !defined(S_ISDIR) && defined(S_IFDIR)
  31. #define    S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  32. #endif
  33. #if !defined(S_ISREG) && defined(S_IFREG)
  34. #define    S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  35. #endif
  36. #if !defined(S_ISFIFO) && defined(S_IFIFO)
  37. #define    S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  38. #endif
  39. #if !defined(S_ISLNK) && defined(S_IFLNK)
  40. #define    S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  41. #endif
  42. #if !defined(S_ISSOCK) && defined(S_IFSOCK)
  43. #define    S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  44. #endif
  45. #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
  46. #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
  47. #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
  48. #endif
  49. #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
  50. #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
  51. #endif
  52. #if defined(MKFIFO_MISSING)
  53. #define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0))
  54. #endif
  55.  
  56. #ifdef POSIX
  57. #include <unistd.h>
  58. #include <limits.h>
  59. #ifndef PATH_MAX
  60. #define PATH_MAX pathconf ("/", _PC_PATH_MAX)
  61. #endif
  62. #else
  63. off_t lseek ();
  64. #ifdef USG
  65. #include <sys/times.h>
  66. #else
  67. #include <sys/time.h>
  68. #endif
  69. #endif
  70.  
  71. #ifndef _POSIX_SOURCE
  72. #include <sys/param.h>
  73. #endif
  74.  
  75. #ifndef _POSIX_PATH_MAX
  76. #define _POSIX_PATH_MAX 255
  77. #endif
  78.  
  79. #ifndef PATH_MAX
  80. #ifdef MAXPATHLEN
  81. #define PATH_MAX MAXPATHLEN
  82. #else
  83. #define PATH_MAX _POSIX_PATH_MAX
  84. #endif
  85. #endif
  86.  
  87. #ifdef _POSIX_SOURCE
  88. #define major(dev)  (((dev) >> 8) & 0xff)
  89. #define minor(dev)  ((dev) & 0xff)
  90. #define makedev(maj, min)  (((maj) << 8) | (min))
  91. #else
  92. #ifdef USG
  93. #ifdef MAJOR_IN_MKDEV
  94. #include <sys/mkdev.h>
  95. #else
  96. #include <sys/sysmacros.h>
  97. #endif
  98. #endif
  99. #endif
  100.  
  101. #ifdef POSIX
  102. #include <utime.h>
  103. #else
  104. struct utimbuf
  105. {
  106.   long actime;
  107.   long modtime;
  108. };
  109. #endif
  110.  
  111. #if defined(USG) || defined(STDC_HEADERS)
  112. #include <string.h>
  113. #define index strchr
  114. #define rindex strrchr
  115. #define bcopy(from, to, len) memcpy ((to), (from), (len))
  116. #define bzero(s, n) memset ((s), 0, (n))
  117. #else
  118. #include <strings.h>
  119. #endif
  120.  
  121. #include <errno.h>
  122. #ifdef STDC_HEADERS
  123. #include <stdlib.h>
  124. #else
  125. char *getenv ();
  126. extern int errno;
  127. #endif
  128.  
  129. #if defined(USG) || defined(POSIX)
  130. #include <fcntl.h>
  131. char *getcwd ();
  132. #define getwd(buf) getcwd ((buf), PATH_MAX + 2)
  133. #else
  134. #include <sys/file.h>
  135. char *getwd ();
  136. #endif
  137.  
  138. #ifndef SEEK_SET
  139. #define SEEK_SET 0
  140. #define SEEK_CUR 1
  141. #define SEEK_END 2
  142. #endif
  143. #ifndef F_OK
  144. #define F_OK 0
  145. #define X_OK 1
  146. #define W_OK 2
  147. #define R_OK 4
  148. #endif
  149.  
  150. #ifdef DIRENT
  151. #include <dirent.h>
  152. #ifdef direct
  153. #undef direct
  154. #endif
  155. #define direct dirent
  156. #define NLENGTH(direct) (strlen((direct)->d_name))
  157. #else
  158. #define NLENGTH(direct) ((direct)->d_namlen)
  159. #ifdef USG
  160. #ifdef SYSNDIR
  161. #include <sys/ndir.h>
  162. #else
  163. #include <ndir.h>
  164. #endif
  165. #else /* must be BSD */
  166. #include <sys/dir.h>
  167. #endif
  168. #endif
  169.  
  170. #ifdef VOID_CLOSEDIR
  171. /* Fake a return value. */
  172. #define CLOSEDIR(d) (closedir (d), 0)
  173. #else
  174. #define CLOSEDIR(d) closedir (d)
  175. #endif
  176.  
  177. /* Extract or fake data from a `struct stat'.
  178.    ST_BLKSIZE: Optimal I/O blocksize for the file, in bytes.
  179.    ST_NBLOCKS: Number of 512-byte blocks in the file
  180.    (including indirect blocks). */
  181. #ifdef _POSIX_SOURCE
  182. #define ST_BLKSIZE(statbuf) 1024
  183. #define ST_NBLOCKS(statbuf) (((statbuf).st_size + 512 - 1) / 512)
  184. #else
  185. #ifdef ST_BLOCKS_MISSING
  186. #define ST_BLKSIZE(statbuf) BSIZE
  187. #define ST_NBLOCKS(statbuf) (st_blocks ((statbuf).st_size))
  188. #else
  189. /* Some systems, like Sequents, return st_blksize of 0 on pipes. */
  190. #define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
  191.                  ? (statbuf).st_blksize : DEV_BSIZE)
  192. #if defined(hpux) || defined(__hpux__)
  193. /* HP-UX, perhaps uniquely, counts st_blocks in 1024-byte units.
  194.    This loses when mixing HP-UX and 4BSD filesystems, though. */
  195. #define ST_NBLOCKS(statbuf) ((statbuf).st_blocks * 2)
  196. #else
  197. #define ST_NBLOCKS(statbuf) ((statbuf).st_blocks)
  198. #endif
  199. #endif
  200. #endif
  201.  
  202. /* Convert B 512-byte blocks to kilobytes if K is nonzero,
  203.    otherwise return it unchanged. */
  204. #define convert_blocks(b, k) ((k) ? ((b) + 1) / 2 : (b))
  205.  
  206. #ifndef S_ISLNK
  207. #define lstat stat
  208. #endif
  209.  
  210. #ifndef SIGTYPE
  211. #define SIGTYPE void
  212. #endif
  213.  
  214. #ifdef __GNUC__
  215. #define alloca __builtin_alloca
  216. #else
  217. #ifdef sparc
  218. #include <alloca.h>
  219. #else
  220. #ifndef _AIX
  221. /* AIX alloca decl has to be the first thing in the file, bletch! */
  222. char *alloca ();
  223. #endif
  224. #endif
  225. #endif
  226.