home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / cvs-1.8.7-src.tgz / tar.out / fsf / cvs / lib / system.h < prev    next >
C/C++ Source or Header  |  1996-09-28  |  13KB  |  514 lines

  1. /* system-dependent definitions for CVS.
  2.    Copyright (C) 1989-1992 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. /* $CVSid: @(#)system.h 1.18 94/09/25 $ */
  19.  
  20. #include <sys/types.h>
  21. #include <sys/stat.h>
  22.  
  23. #ifdef STAT_MACROS_BROKEN
  24. #undef S_ISBLK
  25. #undef S_ISCHR
  26. #undef S_ISDIR
  27. #undef S_ISREG
  28. #undef S_ISFIFO
  29. #undef S_ISLNK
  30. #undef S_ISSOCK
  31. #undef S_ISMPB
  32. #undef S_ISMPC
  33. #undef S_ISNWK
  34. #endif
  35.  
  36. /* Not all systems have S_IFMT, but we probably want to use it if we
  37.    do.  See ChangeLog for a more detailed discussion. */
  38.  
  39. #if !defined(S_ISBLK) && defined(S_IFBLK)
  40. # if defined(S_IFMT)
  41. # define    S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  42. # else
  43. # define S_ISBLK(m) ((m) & S_IFBLK)
  44. # endif
  45. #endif
  46.  
  47. #if !defined(S_ISCHR) && defined(S_IFCHR)
  48. # if defined(S_IFMT)
  49. # define    S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  50. # else
  51. # define S_ISCHR(m) ((m) & S_IFCHR)
  52. # endif
  53. #endif
  54.  
  55. #if !defined(S_ISDIR) && defined(S_IFDIR)
  56. # if defined(S_IFMT)
  57. # define    S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  58. # else
  59. # define S_ISDIR(m) ((m) & S_IFDIR)
  60. # endif
  61. #endif
  62.  
  63. #if !defined(S_ISREG) && defined(S_IFREG)
  64. # if defined(S_IFMT)
  65. # define    S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  66. # else
  67. # define S_ISREG(m) ((m) & S_IFREG)
  68. # endif
  69. #endif
  70.  
  71. #if !defined(S_ISFIFO) && defined(S_IFIFO)
  72. # if defined(S_IFMT)
  73. # define    S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  74. # else
  75. # define S_ISFIFO(m) ((m) & S_IFIFO)
  76. # endif
  77. #endif
  78.  
  79. #if !defined(S_ISLNK) && defined(S_IFLNK)
  80. # if defined(S_IFMT)
  81. # define    S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  82. # else
  83. # define S_ISLNK(m) ((m) & S_IFLNK)
  84. # endif
  85. #endif
  86.  
  87. #if !defined(S_ISSOCK) && defined(S_IFSOCK)
  88. # if defined(S_IFMT)
  89. # define    S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  90. # else
  91. # define S_ISSOCK(m) ((m) & S_IFSOCK)
  92. # endif
  93. #endif
  94.  
  95. #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
  96. # if defined(S_IFMT)
  97. # define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
  98. # define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
  99. # else
  100. # define S_ISMPB(m) ((m) & S_IFMPB)
  101. # define S_ISMPC(m) ((m) & S_IFMPC)
  102. # endif
  103. #endif
  104.  
  105. #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
  106. # if defined(S_IFMT)
  107. # define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
  108. # else
  109. # define S_ISNWK(m) ((m) & S_IFNWK)
  110. # endif
  111. #endif
  112.  
  113. #if !defined(HAVE_MKFIFO)
  114. #define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0))
  115. #endif
  116.  
  117. #ifdef NEED_DECOY_PERMISSIONS        /* OS/2, really */
  118.  
  119. #define    S_IRUSR S_IREAD
  120. #define    S_IWUSR S_IWRITE
  121. #define    S_IXUSR S_IEXEC
  122. #define    S_IRWXU    (S_IRUSR | S_IWUSR | S_IXUSR)
  123. #define    S_IRGRP S_IREAD
  124. #define    S_IWGRP S_IWRITE
  125. #define    S_IXGRP S_IEXEC
  126. #define    S_IRWXG    (S_IRGRP | S_IWGRP | S_IXGRP)
  127. #define    S_IROTH S_IREAD
  128. #define    S_IWOTH S_IWRITE
  129. #define    S_IXOTH S_IEXEC
  130. #define    S_IRWXO    (S_IROTH | S_IWOTH | S_IXOTH)
  131.  
  132. #else /* ! NEED_DECOY_PERMISSIONS */
  133.  
  134. #ifndef S_IRUSR
  135. #define    S_IRUSR 0400
  136. #define    S_IWUSR 0200
  137. #define    S_IXUSR 0100
  138. /* Read, write, and execute by owner.  */
  139. #define    S_IRWXU    (S_IRUSR|S_IWUSR|S_IXUSR)
  140.  
  141. #define    S_IRGRP    (S_IRUSR >> 3)    /* Read by group.  */
  142. #define    S_IWGRP    (S_IWUSR >> 3)    /* Write by group.  */
  143. #define    S_IXGRP    (S_IXUSR >> 3)    /* Execute by group.  */
  144. /* Read, write, and execute by group.  */
  145. #define    S_IRWXG    (S_IRWXU >> 3)
  146.  
  147. #define    S_IROTH    (S_IRGRP >> 3)    /* Read by others.  */
  148. #define    S_IWOTH    (S_IWGRP >> 3)    /* Write by others.  */
  149. #define    S_IXOTH    (S_IXGRP >> 3)    /* Execute by others.  */
  150. /* Read, write, and execute by others.  */
  151. #define    S_IRWXO    (S_IRWXG >> 3)
  152. #endif /* !def S_IRUSR */
  153. #endif /* NEED_DECOY_PERMISSIONS */
  154.  
  155. #if defined(POSIX) || defined(HAVE_UNISTD_H)
  156. #include <unistd.h>
  157. #include <limits.h>
  158. #else
  159. off_t lseek ();
  160. #endif
  161.  
  162. #if TIME_WITH_SYS_TIME
  163. # include <sys/time.h>
  164. # include <time.h>
  165. #else
  166. # if HAVE_SYS_TIME_H
  167. #  include <sys/time.h>
  168. # else
  169. #  include <time.h>
  170. # endif
  171. #endif
  172.  
  173. #ifdef HAVE_IO_H
  174. #include <io.h>
  175. #endif
  176.  
  177. #ifdef HAVE_DIRECT_H
  178. #include <direct.h>
  179. #endif
  180.  
  181. #ifdef timezone
  182. #undef timezone /* needed for sgi */
  183. #endif
  184.  
  185. #ifdef HAVE_SYS_TIMEB_H
  186. #include <sys/timeb.h>
  187. #else
  188. struct timeb {
  189.     time_t        time;        /* Seconds since the epoch    */
  190.     unsigned short    millitm;    /* Field not used        */
  191.     short        timezone;
  192.     short        dstflag;    /* Field not used        */
  193. };
  194. #endif
  195.  
  196. #if !defined(HAVE_FTIME) && !defined(HAVE_TIMEZONE)
  197. #if !defined(timezone)
  198. extern long timezone;
  199. #endif
  200. #endif
  201.  
  202.  
  203. /*
  204. **  MAXPATHLEN and PATH_MAX
  205. **
  206. **     On most systems MAXPATHLEN is defined in sys/param.h to be 1024. Of
  207. **     those that this is not true, again most define PATH_MAX in limits.h
  208. **     or sys/limits.h which usually gets included by limits.h. On the few
  209. **     remaining systems that neither statement is true, _POSIX_PATH_MAX 
  210. **     is defined.
  211. **
  212. **     So:
  213. **         1. If PATH_MAX is defined just use it.
  214. **         2. If MAXPATHLEN is defined but not PATH_MAX, then define
  215. **            PATH_MAX in terms of MAXPATHLEN.
  216. **         3. If neither is defined, include limits.h and check for
  217. **            PATH_MAX again.
  218. **         3.1 If we now have PATHSIZE, define PATH_MAX in terms of that.
  219. **             and ignore the rest.  Since _POSIX_PATH_MAX (checked for
  220. **             next) is the *most* restrictive (smallest) value, if we
  221. **             trust _POSIX_PATH_MAX, several of our buffers are too small.
  222. **         4. If PATH_MAX is still not defined but _POSIX_PATH_MAX is,
  223. **            then define PATH_MAX in terms of _POSIX_PATH_MAX.
  224. **         5. And if even _POSIX_PATH_MAX doesn't exist just put in
  225. **            a reasonable value.
  226. **         *. All in all, this is an excellent argument for using pathconf()
  227. **            when at all possible.  Or better yet, dynamically allocate
  228. **            our buffers and use getcwd() not getwd().
  229. **
  230. **     This works on:
  231. **         Sun Sparc 10        SunOS 4.1.3  &  Solaris 1.2
  232. **         HP 9000/700         HP/UX 8.07   &  HP/UX 9.01
  233. **         Tektronix XD88/10   UTekV 3.2e
  234. **         IBM RS6000          AIX 3.2
  235. **         Dec Alpha           OSF 1 ????
  236. **         Intel 386           BSDI BSD/386
  237. **         Intel 386           SCO OpenServer Release 5
  238. **         Apollo              Domain 10.4
  239. **         NEC                 SVR4
  240. */
  241.  
  242. /* On MOST systems this will get you MAXPATHLEN.
  243.    Windows NT doesn't have this file, tho.  */
  244. #ifdef HAVE_SYS_PARAM_H
  245. #include <sys/param.h>
  246. #endif
  247.  
  248. #ifndef PATH_MAX  
  249. #  ifdef MAXPATHLEN
  250. #    define PATH_MAX                 MAXPATHLEN
  251. #  else
  252. #    include <limits.h>
  253. #    ifndef PATH_MAX
  254. #      ifdef PATHSIZE
  255. #         define PATH_MAX               PATHSIZE
  256. #      else /* no PATHSIZE */
  257. #        ifdef _POSIX_PATH_MAX
  258. #          define PATH_MAX             _POSIX_PATH_MAX
  259. #        else
  260. #          define PATH_MAX             1024
  261. #        endif  /* no _POSIX_PATH_MAX */
  262. #      endif  /* no PATHSIZE */
  263. #    endif /* no PATH_MAX   */
  264. #  endif  /* MAXPATHLEN */
  265. #endif  /* PATH_MAX   */
  266.  
  267.  
  268. /* The NeXT (without _POSIX_SOURCE, which we don't want) has a utime.h
  269.    which doesn't define anything.  It would be cleaner to have configure
  270.    check for struct utimbuf, but for now I'm checking NeXT here (so I don't
  271.    have to debug the configure check across all the machines).  */
  272. #if defined (HAVE_UTIME_H) && !defined (NeXT)
  273. #  include <utime.h>
  274. #else
  275. #  if defined (HAVE_SYS_UTIME_H)
  276. #    include <sys/utime.h>
  277. #  else
  278. #    ifndef ALTOS
  279. struct utimbuf
  280. {
  281.   long actime;
  282.   long modtime;
  283. };
  284. #    endif
  285. int utime ();
  286. #  endif
  287. #endif
  288.  
  289. #if STDC_HEADERS || HAVE_STRING_H
  290. #  include <string.h>
  291.    /* An ANSI string.h and pre-ANSI memory.h might conflict. */
  292. #  if !STDC_HEADERS && HAVE_MEMORY_H
  293. #    include <memory.h>
  294. #  endif /* not STDC_HEADERS and HAVE_MEMORY_H */
  295. #else /* not STDC_HEADERS and not HAVE_STRING_H */
  296. #  include <strings.h>
  297.    /* memory.h and strings.h conflict on some systems. */
  298. #endif /* not STDC_HEADERS and not HAVE_STRING_H */
  299.  
  300. #ifndef ERRNO_H_MISSING
  301. #include <errno.h>
  302. #endif
  303.  
  304. /* Not all systems set the same error code on a non-existent-file
  305.    error.  This tries to ask the question somewhat portably.
  306.    On systems that don't have ENOTEXIST, this should behave just like
  307.    x == ENOENT.  "x" is probably errno, of course. */
  308.  
  309. #ifdef ENOTEXIST
  310. #  ifdef EOS2ERR
  311. #    define existence_error(x) \
  312.      (((x) == ENOTEXIST) || ((x) == ENOENT) || ((x) == EOS2ERR))
  313. #  else
  314. #    define existence_error(x) \
  315.      (((x) == ENOTEXIST) || ((x) == ENOENT))
  316. #  endif
  317. #else
  318. #  ifdef EVMSERR
  319. #     define existence_error(x) \
  320. ((x) == ENOENT || (x) == EINVAL || (x) == EVMSERR)
  321. #  else
  322. #    define existence_error(x) ((x) == ENOENT)
  323. #  endif
  324. #endif
  325.  
  326.  
  327. #ifdef STDC_HEADERS
  328. #include <stdlib.h>
  329. #else
  330. char *getenv ();
  331. char *malloc ();
  332. char *realloc ();
  333. char *calloc ();
  334. extern int errno;
  335. #endif
  336.  
  337. /* SunOS4 apparently does not define this in stdlib.h.  */
  338. #ifndef EXIT_FAILURE
  339. #define EXIT_FAILURE 1
  340. #endif
  341.  
  342. #if defined(USG) || defined(POSIX)
  343. char *getcwd ();
  344. #else
  345. char *getwd ();
  346. #endif
  347.  
  348. /* check for POSIX signals */
  349. #if defined(HAVE_SIGACTION) && defined(HAVE_SIGPROCMASK)
  350. # define POSIX_SIGNALS
  351. #endif
  352.  
  353. /* MINIX 1.6 doesn't properly support sigaction */
  354. #if defined(_MINIX)
  355. # undef POSIX_SIGNALS
  356. #endif
  357.  
  358. /* If !POSIX, try for BSD.. Reason: 4.4BSD implements these as wrappers */
  359. #if !defined(POSIX_SIGNALS)
  360. # if defined(HAVE_SIGVEC) && defined(HAVE_SIGSETMASK) && defined(HAVE_SIGBLOCK)
  361. #  define BSD_SIGNALS
  362. # endif
  363. #endif
  364.  
  365. /* Under OS/2, this must be included _after_ stdio.h; that's why we do
  366.    it here. */
  367. #ifdef USE_OWN_TCPIP_H
  368. #include "tcpip.h"
  369. #endif
  370.  
  371. #ifdef HAVE_FCNTL_H
  372. #include <fcntl.h>
  373. #else
  374. #include <sys/file.h>
  375. #endif
  376.  
  377. #ifndef SEEK_SET
  378. #define SEEK_SET 0
  379. #define SEEK_CUR 1
  380. #define SEEK_END 2
  381. #endif
  382.  
  383. #ifndef F_OK
  384. #define F_OK 0
  385. #define X_OK 1
  386. #define W_OK 2
  387. #define R_OK 4
  388. #endif
  389.  
  390. #if HAVE_DIRENT_H
  391. # include <dirent.h>
  392. # define NAMLEN(dirent) strlen((dirent)->d_name)
  393. #else
  394. # define dirent direct
  395. # define NAMLEN(dirent) (dirent)->d_namlen
  396. # if HAVE_SYS_NDIR_H
  397. #  include <sys/ndir.h>
  398. # endif
  399. # if HAVE_SYS_DIR_H
  400. #  include <sys/dir.h>
  401. # endif
  402. # if HAVE_NDIR_H
  403. #  include <ndir.h>
  404. # endif
  405. #endif
  406.  
  407. /* Convert B 512-byte blocks to kilobytes if K is nonzero,
  408.    otherwise return it unchanged. */
  409. #define convert_blocks(b, k) ((k) ? ((b) + 1) / 2 : (b))
  410.  
  411. #ifndef S_ISLNK
  412. #define lstat stat
  413. #endif
  414.  
  415. /*
  416.  * Some UNIX distributions don't include these in their stat.h Defined here
  417.  * because "config.h" is always included last.
  418.  */
  419. #ifndef S_IWRITE
  420. #define    S_IWRITE    0000200        /* write permission, owner */
  421. #endif
  422. #ifndef S_IWGRP
  423. #define    S_IWGRP        0000020        /* write permission, grougroup */
  424. #endif
  425. #ifndef S_IWOTH
  426. #define    S_IWOTH        0000002        /* write permission, other */
  427. #endif
  428.  
  429. /* Under non-UNIX operating systems (MS-DOS, WinNT, MacOS), many filesystem
  430.    calls take  only one argument; permission is handled very differently on
  431.    those systems than in Unix.  So we leave such systems a hook on which they
  432.    can hang their own definitions.  */
  433.  
  434. #ifndef CVS_ACCESS
  435. #define CVS_ACCESS access
  436. #endif
  437.  
  438. #ifndef CVS_CHDIR
  439. #define CVS_CHDIR chdir
  440. #endif
  441.  
  442. #ifndef CVS_CREAT
  443. #define CVS_CREAT creat
  444. #endif
  445.  
  446. #ifndef CVS_FOPEN
  447. #define CVS_FOPEN fopen
  448. #endif
  449.  
  450. #ifndef CVS_MKDIR
  451. #define CVS_MKDIR mkdir
  452. #endif
  453.  
  454. #ifndef CVS_OPEN
  455. #define CVS_OPEN open
  456. #endif
  457.  
  458. #ifndef CVS_OPENDIR
  459. #define CVS_OPENDIR opendir
  460. #endif
  461.  
  462. #ifndef CVS_RENAME
  463. #define CVS_RENAME rename
  464. #endif
  465.  
  466. #ifndef CVS_RMDIR
  467. #define CVS_RMDIR rmdir
  468. #endif
  469.  
  470. #ifndef CVS_STAT
  471. #define CVS_STAT stat
  472. #endif
  473.  
  474. #ifndef CVS_UNLINK
  475. #define CVS_UNLINK unlink
  476. #endif
  477.  
  478. /* Some file systems are case-insensitive.  If FOLD_FN_CHAR is
  479.    #defined, it maps the character C onto its "canonical" form.  In a
  480.    case-insensitive system, it would map all alphanumeric characters
  481.    to lower case.  Under Windows NT, / and \ are both path component
  482.    separators, so FOLD_FN_CHAR would map them both to /.  */
  483. #ifndef FOLD_FN_CHAR
  484. #define FOLD_FN_CHAR(c) (c)
  485. #define fnfold(filename) (filename)
  486. #define fncmp strcmp
  487. #endif
  488.  
  489. /* Different file systems have different path component separators.
  490.    For the VMS port we might need to abstract further back than this.  */
  491. #ifndef ISDIRSEP
  492. #define ISDIRSEP(c) ((c) == '/')
  493. #endif
  494.  
  495.  
  496. /* On some systems, lines in text files should be terminated with CRLF,
  497.    not just LF, and the read and write routines do this translation
  498.    for you.  LINES_CRLF_TERMINATED is #defined on such systems.
  499.    - OPEN_BINARY is the flag to pass to the open function for
  500.      untranslated I/O.
  501.    - FOPEN_BINARY_READ is the string to pass to fopen to get
  502.      untranslated reading.
  503.    - FOPEN_BINARY_WRITE is the string to pass to fopen to get
  504.      untranslated writing.  */
  505. #if LINES_CRLF_TERMINATED
  506. #define OPEN_BINARY (O_BINARY)
  507. #define FOPEN_BINARY_READ ("rb")
  508. #define FOPEN_BINARY_WRITE ("wb")
  509. #else
  510. #define OPEN_BINARY (0)
  511. #define FOPEN_BINARY_READ ("r")
  512. #define FOPEN_BINARY_WRITE ("w")
  513. #endif
  514.