home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / rcs / sources / conf.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1992-02-17  |  42KB  |  1,846 lines

  1. #!/bin/sh
  2. # Output RCS compile-time configuration.
  3. Id='$Id: conf.sh,v 5.17 1992/02/17 23:02:10 eggert Exp $'
  4. #    Copyright 1990, 1991, 1992 by Paul Eggert
  5. #    Distributed under license by the Free Software Foundation, Inc.
  6.  
  7. # This file is part of RCS.
  8. #
  9. # RCS is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2, or (at your option)
  12. # any later version.
  13. #
  14. # RCS is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with RCS; see the file COPYING.  If not, write to
  21. # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22. #
  23. # Report problems and direct all questions to:
  24. #
  25. #     rcs-bugs@cs.purdue.edu
  26.  
  27.  
  28. # Standard output should already be directed to "a.h";
  29. # later parts of this procedure need it.
  30. # Standard error can be ignored if a.h is OK,
  31. # and can be inspected for clues otherwise.
  32.  
  33. # The Makefile overrides the following defaults.
  34. : ${RCSPREFIX=/usr/local/bin/}
  35. : ${CC=cc}
  36. : ${CFLAGS=-O}
  37. : ${COMPAT2=0}
  38. : ${DIFF3=${RCSPREFIX}diff3}
  39. : ${DIFF3_BIN=1}
  40. : ${DIFF=${RCSPREFIX}diff}
  41. : ${DIFF_FLAGS=-an}
  42. : ${DIFF_L=1}
  43. : ${DIFF_SUCCESS=0} ${DIFF_FAILURE=1} ${DIFF_TROUBLE=2}
  44. : ${ED=/bin/ed}
  45. : ${SENDMAIL='"/usr/lib/sendmail"'}
  46. # : ${LDFLAGS=} ${LDLIBS=} tickles old shell bug
  47.  
  48. C="$CC $CFLAGS"
  49. CL="$CC $CFLAGS $LDFLAGS"
  50. L=$LDLIBS
  51.  
  52. cat <<EOF
  53. /* RCS compile-time configuration */
  54.  
  55.     /* $Id */
  56.  
  57. /*
  58.  * This file is generated automatically.
  59.  * If you edit it by hand your changes may be lost.
  60.  * Instead, please try to fix conf.sh,
  61.  * and send your fixes to rcs-bugs@cs.purdue.edu.
  62.  */
  63.  
  64. EOF
  65.  
  66. : test compiler for plausibility
  67. echo 'this is not a C source file' >a.c
  68. rm -f a.exe a.out || exit
  69. $CL a.c $L >&2 && {
  70.     echo >&2 "C compiler command '$CL a.c $L' succeeds when it should fail."
  71.     exit 1
  72. }
  73.  
  74. : exitmain
  75. cat >a.c <<EOF
  76. #include "a.h"
  77. int main(argc,argv) int argc; char **argv; { return argc-1; }
  78. EOF
  79. rm -f a.exe a.out && $CL a.c $L >&2 || exit
  80. if test -f a.out
  81. then aout=./a.out
  82. elif test -f a.exe
  83. then aout=./a.exe
  84. else
  85.     echo >&2 "C compiler creates neither a.out nor a.exe."
  86.     exit 1
  87. fi
  88. e='exit(n), 3 /* lint fodder */'
  89. if $aout -
  90. then :
  91. elif $aout
  92. then e=n
  93. fi
  94. echo "#define exitmain(n) return $e /* how to exit from main() */"
  95.  
  96. : RM
  97. RM="rm -f $aout"
  98.  
  99. : _POSIX_SOURCE
  100. cat >a.c <<'EOF'
  101. #include "a.h"
  102. #include <stdio.h>
  103. int main() { exitmain(fileno(stdout) < 0); }
  104. EOF
  105. a='/* ' z='*/ '
  106. $RM || exit
  107. if ($CL a.c $L && $aout) >&2
  108. then :
  109. elif $RM || exit; ($CL -D_POSIX_SOURCE a.c $L && $aout) >&2
  110. then a= z=
  111. fi
  112. cat <<EOF
  113. $a#define _POSIX_SOURCE $z/* Define this if Posix + strict Standard C.  */
  114.  
  115. #include <errno.h>
  116. #include <stdio.h>
  117. #include <time.h>
  118. EOF
  119.  
  120. cat <<'EOF'
  121.  
  122. /* Comment out #include lines below that do not work.  */
  123. EOF
  124.  
  125. # Run `$CS a.c $LS' instead of `$CL a.c $L' for compile-time checking only.
  126. # This speeds up the configuration process.
  127. if rm -f a.s && $C -S a.c >&2 && test -f a.s
  128. then CS="$C -S" LS=    # Generate assembly language output.
  129. elif rm -f a.o a.obj && $C -c a.c >&2 && { test -f a.o || test -f a.obj; }
  130. then CS="$C -c" LS=    # Generate object code.
  131. else CS=$CL LS=$L    # Generate an executable.
  132. fi
  133.  
  134. # standard include files
  135. # sys/types.h and sys/stat.h must come first because others depend on them.
  136. has_signal=1
  137. for h in \
  138.     sys/types sys/stat \
  139.     dirent fcntl limits pwd signal stdlib string sys/mman sys/wait unistd utime vfork
  140. do
  141.     i="#include <$h.h>"
  142.     : $i
  143.     cat >a.c <<EOF
  144. #include "a.h"
  145. $i
  146. int main(){ exitmain(0); }
  147. EOF
  148.     $RM || exit
  149.     ($CL a.c $L && $aout) >&2 || {
  150.         case $h in
  151.         string)
  152.             i='#include <strings.h>';;
  153.         *)
  154.             i="/* $i */"
  155.         esac
  156.         case $h in
  157.         signal) has_signal=0
  158.         esac
  159.     }
  160.     echo "$i"
  161. done
  162.  
  163. cat <<'EOF'
  164.  
  165. /* Define the following symbols to be 1 or 0.  */
  166. EOF
  167.  
  168. # has_sys_*_h
  169. for H in dir param
  170. do
  171.     : has_sys_${H}_h
  172.     cat >a.c <<EOF
  173. #include "a.h"
  174. #include <sys/$H.h>
  175. int main() { exitmain(0); }
  176. EOF
  177.     $RM || exit
  178.     if ($CL a.c $L && $aout) >&2
  179.     then h=1
  180.     else h=0
  181.     fi
  182.     echo "#define has_sys_${H}_h $h /* Does #include <sys/$H.h> work?  */"
  183. done
  184.  
  185.  
  186. # We must do NAME_MAX and has_readlink next, because they might generate
  187. # #include directives that affect later definitions.
  188.  
  189. : NAME_MAX
  190. cat >a.c <<'EOF'
  191. #include "a.h"
  192. main()
  193. {
  194. #if !defined(NAME_MAX)
  195.     exitmain(1);
  196. #else
  197.     int i;
  198.     char b[NAME_MAX + 2];
  199.     b[0] = 'a'; b[1] = '.';
  200.     for (i = 2;  i < NAME_MAX;  i++)
  201.         b[i] = 'a';
  202.     b[i++] = 'b';
  203.     b[i] = 0;
  204.     exitmain(creat(b, 0) < 0);
  205. #endif
  206. }
  207. EOF
  208. $RM a.*ab || exit
  209. if $CL a.c $L >&2 && $aout && test -f a.*ab
  210. then a= z=
  211. else a='/* ' z='*/ '
  212. fi
  213. rm -f a.*ab || exit
  214.  
  215. : has_readlink
  216. cat >a.c <<'EOF'
  217. #include "a.h"
  218. char b[7];
  219. int main()
  220. {
  221.     exitmain(readlink("a.sym2",b,7) != 6  ||  strcmp(b, "a.sym1") != 0);
  222. }
  223. EOF
  224. $RM a.sym* || exit
  225. if (ln -s a.sym1 a.sym2 && $CL a.c $L && $aout) >&2
  226. then h=1
  227. else h=0
  228. fi
  229. cat <<EOF
  230. #define has_readlink $h /* Does readlink() work?  */
  231.  
  232. $a#undef NAME_MAX $z/* Uncomment this if NAME_MAX is broken.  */
  233.  
  234. #if !defined(NAME_MAX) && !defined(_POSIX_NAME_MAX)
  235. #    if has_sys_dir_h
  236. #        include <sys/dir.h>
  237. #    endif
  238. #    ifndef NAME_MAX
  239. #        ifndef MAXNAMLEN
  240. #            define MAXNAMLEN 14
  241. #        endif
  242. #        define NAME_MAX MAXNAMLEN
  243. #    endif
  244. #endif
  245. #if !defined(PATH_MAX) && !defined(_POSIX_PATH_MAX)
  246. #    if has_sys_param_h
  247. #        include <sys/param.h>
  248. #        define included_sys_param_h 1
  249. #    endif
  250. #    ifndef PATH_MAX
  251. #        ifndef MAXPATHLEN
  252. #            define MAXPATHLEN 1024
  253. #        endif
  254. #        define PATH_MAX (MAXPATHLEN-1)
  255. #    endif
  256. #endif
  257. #if has_readlink && !defined(MAXSYMLINKS)
  258. #    if has_sys_param_h && !included_sys_param_h
  259. #        include <sys/param.h>
  260. #    endif
  261. #    ifndef MAXSYMLINKS
  262. #        define MAXSYMLINKS 20 /* BSD; not standard yet */
  263. #    endif
  264. #endif
  265. EOF
  266.  
  267. # *_t
  268. cat <<'EOF'
  269.  
  270. /* Comment out the typedefs below if the types are already declared.  */
  271. /* Fix any uncommented typedefs that are wrong.  */
  272. EOF
  273. cat >a.c <<'EOF'
  274. #include "a.h"
  275. t x;
  276. int main() { exitmain(0); }
  277. EOF
  278. for t in mode_t pid_t sig_atomic_t size_t ssize_t time_t uid_t
  279. do
  280.     : $t
  281.     case $t in
  282.     size_t) i=unsigned;;
  283.     time_t) i=long;;
  284.     *) i=int;;
  285.     esac
  286.     if $CS -Dt=$t a.c $LS >&2
  287.     then a='/* ' z=' */'
  288.     else a= z=
  289.     fi
  290.     echo "${a}typedef $i $t;$z"
  291. done
  292.  
  293. cat <<'EOF'
  294.  
  295. /* Comment out the keyword definitions below if the keywords work.  */
  296. EOF
  297.  
  298. : const, volatile
  299. for i in const volatile
  300. do
  301.     cat >a.c <<EOF
  302. #    include "a.h"
  303.     enum Boolean { false, true };
  304.     static enum Boolean $i zero;
  305.     static enum Boolean $i * $i azero = &zero;
  306.     static enum Boolean $i * $i * $i aazero = &azero;
  307.     static enum Boolean * $i arzero[1];
  308.     static sig_atomic_t $i sigzero;
  309.     int main() {
  310.         enum Boolean *p = arzero[sigzero];
  311.         exitmain(!p || **aazero);
  312.     }
  313. EOF
  314.     a= z=
  315.     if $CS a.c $LS >&2
  316.     then
  317.         cat >a.c <<EOF
  318.             typedef unsigned char $i *Iptr_type;
  319.             struct { Iptr_type lim; } s, *f = &s;
  320.             int main() {
  321.                 Iptr_type lim;
  322.                 lim = f->lim;
  323.                 return !!lim;
  324.             }
  325. EOF
  326.         if $CS a.c $LS >&2
  327.         then a='/* ' z=' */'
  328.         fi
  329.     fi
  330.     echo "$a#define $i$z"
  331. done
  332.  
  333. : has_prototypes, has_stdarg, has_varargs, va_start_args
  334. cat >a.ha <<'EOF'
  335. #if has_prototypes
  336. #    define P(params) params
  337. #else
  338. #    define P(params) ()
  339. #endif
  340. #if has_stdarg
  341. #    include <stdarg.h>
  342. #else
  343. #    if has_varargs
  344. #        include <varargs.h>
  345. #    else
  346.         typedef char *va_list;
  347. #        define va_dcl int va_alist;
  348. #        define va_start(ap) ((ap) = (va_list)&va_alist)
  349. #        define va_arg(ap,t) (((t*) ((ap)+=sizeof(t)))  [-1])
  350. #        define va_end(ap)
  351. #    endif
  352. #endif
  353. #if va_start_args == 2
  354. #    define vararg_start va_start
  355. #else
  356. #    define vararg_start(ap,p) va_start(ap)
  357. #endif
  358. EOF
  359. cat >a.c <<'EOF'
  360. #include "a.h"
  361. #include "a.ha"
  362.  
  363. struct buf { int x; };
  364. int pairfilenames P((int,char**,FILE*(*)P((struct buf*,struct stat*,int)),int,int)); /* a la rcsbase.h */
  365. FILE *(*rcsopen)P((struct buf*,struct stat*,int));  /* a la rcsfnms.c */
  366.  
  367. char *e(p,i) char **p; int i; { return p[i]; }
  368. #if has_prototypes
  369. char *f(char *(*g)(char**,int), char **p, ...)
  370. #else
  371. char *f(g, p, va_alist) char *(*g)(); char **p; va_dcl
  372. #endif
  373. {
  374.     char *s;
  375.     va_list v;
  376.     vararg_start(v,p);
  377.     s = g(p, va_arg(v,int));
  378.     va_end(v);
  379.     return s;
  380. }
  381. int main P((int, char**));
  382. int main(argc, argv) int argc; char **argv; {
  383.     exitmain(f(e,argv,0) != argv[0]  ||  f(e,argv,1) != argv[1]);
  384. }
  385. EOF
  386. for has_prototypes in 1 0
  387. do
  388.     for has_stdarg in 1 v 0
  389.     do
  390.         case $has_stdarg in
  391.         v) has_varargs=1 has_stdarg=0;;
  392.         *) has_varargs=0
  393.         esac
  394.         case $has_stdarg in
  395.         0) as='1 2';;
  396.         1) as='2 1'
  397.         esac
  398.         for va_start_args in $as
  399.         do
  400.             $RM || exit
  401.             $CL \
  402.                 -Dhas_prototypes=$has_prototypes \
  403.                 -Dhas_stdarg=$has_stdarg \
  404.                 -Dhas_varargs=$has_varargs \
  405.                 -Dva_start_args=$va_start_args \
  406.                 a.c $L >&2 && $aout && break
  407.         done && break
  408.     done && break
  409. done || {
  410.     echo >&2 "cannot deduce has_prototypes, has_stdarg, va_start_args"
  411.     exit 1
  412. }
  413. cat - a.ha <<EOF
  414.  
  415. /* Define the following symbols to be 1 or 0.  */
  416. #define has_prototypes $has_prototypes /* Do function prototypes work?  */
  417. #define has_stdarg $has_stdarg /* Does <stdarg.h> work?  */
  418. #define has_varargs $has_varargs /* Does <varargs.h> work?  */
  419. #define va_start_args $va_start_args /* How many args does va_start() take?  */
  420. EOF
  421.  
  422. : text_equals_binary_stdio, FOPEN_...
  423. cat >a.c <<'EOF'
  424. #include "a.h"
  425.     int
  426. copy(from, to, mode)
  427.     char const *from, *to, *mode;
  428. {
  429.     int c;
  430.     FILE *f, *g;
  431.     if (!(f = fopen(from, "rb")) || !(g = fopen(to, mode)))
  432.         return 1;
  433.     while (c=getc(f), !feof(f))
  434.         if (ferror(f)  ||  putc(c,g)<0 && ferror(g))
  435.             return 1;
  436.     return fclose(f)!=0 || fclose(g)!=0;
  437. }
  438.     int
  439. main(argc, argv)
  440.     char **argv;
  441. {
  442.     exitmain(copy(argv[1], "a.d", "w+b") || copy(argv[1], "a.e", "w+"));
  443. }
  444. EOF
  445. e=1
  446. $RM && $CL a.c $L || exit
  447. for i in a.c $aout
  448. do
  449.     rm -f a.d a.e && $aout $i || exit
  450.     cmp $i a.d >&2  &&  { cmp $i a.e >&2 || { e=0; break; }; }
  451. done
  452. cat <<EOF
  453.  
  454. #define text_equals_binary_stdio $e /* Does stdio treat text like binary?  */
  455. #define text_work_stdio 0 /* Text i/o for working file, binary for RCS file?  */
  456. #if text_equals_binary_stdio
  457.     /* Text and binary i/o behave the same, or binary i/o does not work.  */
  458. #    define FOPEN_R "r"
  459. #    define FOPEN_W "w"
  460. #    define FOPEN_WPLUS "w+"
  461. #    define OPEN_O_BINARY 0
  462. #else
  463.     /* Text and binary i/o behave differently.  */
  464.     /* This is incompatible with Posix and Unix.  */
  465. #    define FOPEN_R "rb"
  466. #    define FOPEN_W "wb"
  467. #    define FOPEN_WPLUS "w+b"
  468. #    define OPEN_O_BINARY O_BINARY
  469. #    ifndef O_BINARY
  470. #    define O_BINARY 0
  471. #    endif
  472. #endif
  473. #if text_work_stdio
  474. #    define FOPEN_R_WORK "r"
  475. #    define FOPEN_W_WORK "w"
  476. #    define FOPEN_WPLUS_WORK "w+"
  477. #    define OPEN_O_WORK 0
  478. #else
  479. #    define FOPEN_R_WORK FOPEN_R
  480. #    define FOPEN_W_WORK FOPEN_W
  481. #    define FOPEN_WPLUS_WORK FOPEN_WPLUS
  482. #    define OPEN_O_WORK OPEN_O_BINARY
  483. #endif
  484.  
  485. /* Define or comment out the following symbols as needed.  */
  486. EOF
  487.  
  488. : bad_chmod_close
  489. cat >a.c <<'EOF'
  490. #include "a.h"
  491. #ifndef O_RDONLY
  492. #    define O_RDONLY 0
  493. #endif
  494. int main() {
  495.     int f;
  496.     exitmain(
  497.         (f = open("a.c", O_RDONLY)) < 0 ||
  498.         chmod("a.c", 0) != 0 ||
  499.         close(f) != 0
  500.     );
  501. }
  502. EOF
  503. $RM || exit
  504. if $CL a.c $L >&2 && $aout
  505. then b=0
  506. else b=1
  507. fi
  508. echo "#define bad_chmod_close $b /* Can chmod() close file descriptors?  */"
  509. rm -f a.c || exit
  510.  
  511. : bad_creat0
  512. cat >a.c <<'EOF'
  513. #include "a.h"
  514. #ifdef O_CREAT
  515. #    define creat0(f) open(f, O_CREAT|O_WRONLY, 0)
  516. #else
  517. #    define creat0(f) creat(f, 0)
  518. #endif
  519. char buf[17000];
  520. int main() {
  521.     int f;
  522.     exitmain(
  523.         (f = creat0("a.d")) < 0  ||
  524.         write(f, buf, sizeof(buf)) != sizeof(buf) ||
  525.         close(f) != 0
  526.     );
  527. }
  528. EOF
  529. $RM a.d || exit
  530. if $CL a.c $L >&2 && $aout && test -f a.d && test ! -w a.d
  531. then b=0
  532. else b=1
  533. fi
  534. echo "#define bad_creat0 $b /* Do writes fail after creat(f,0)?  */"
  535. rm -f a.d || exit
  536.  
  537. : bad_fopen_wplus
  538. cat >a.c <<'EOF'
  539. #include "a.h"
  540. int main() { exitmain(!fopen("a.d",FOPEN_WPLUS)); }
  541. EOF
  542. $RM || exit
  543. if echo nonempty >a.d && $CL a.c $L >&2 && $aout && test ! -s a.d
  544. then b=0
  545. else b=1
  546. fi
  547. echo "#define bad_fopen_wplus $b /* Does fopen(f,FOPEN_WPLUS) fail to truncate f?  */"
  548.  
  549. : getlogin_is_secure
  550. echo "#define getlogin_is_secure 0 /* Is getlogin() secure?  Usually it's not.  */"
  551.  
  552. : has_dirent
  553. cat >a.c <<'EOF'
  554. #include "a.h"
  555. int main() {
  556.     DIR *d = opendir(".");
  557.     struct dirent *e;
  558.     while ((e = readdir(d)))
  559.         if (strcmp(e->d_name, "a.c") == 0  &&  closedir(d) == 0)
  560.             exitmain(0);
  561.     exitmain(1);
  562. }
  563. EOF
  564. $RM || exit
  565. if $CL a.c $L >&2 && $aout
  566. then h=1
  567. else h=0
  568. fi
  569. echo "#define has_dirent $h /* Do opendir(), readdir(), closedir() work?  */"
  570.  
  571. : has_fchmod
  572. cat >a.c <<'EOF'
  573. #include "a.h"
  574. int main() { exitmain(fchmod(fileno(stdin),0) != 0); }
  575. EOF
  576. $RM || exit
  577. if $CL a.c $L >&2 && $aout <a.c && test ! -r a.c
  578. then h=1
  579. else h=0
  580. fi
  581. echo "#define has_fchmod $h /* Does fchmod() work?  */"
  582. rm -f a.c || exit
  583.  
  584. : has_fputs
  585. cat >a.c <<'EOF'
  586. #include "a.h"
  587. int main() { exitmain(fputs("Hello\"\nworld", stdout) != 12); }
  588. EOF
  589. Hello='Hello"
  590. world'
  591. $RM a.a || exit
  592. if $CL a.c $L >&2 && $aout >a.a && x=`$aout` && test " $x" = " $Hello"
  593. then h=1
  594. else h=0
  595. fi
  596. echo "#define has_fputs $h /* Does fputs() work?  */"
  597.  
  598. : has_ftruncate
  599. cat >a.c <<'EOF'
  600. #include "a.h"
  601. int main(argc, argv) int argc; char **argv; {
  602.     int f = creat(argv[1], 0);
  603.     if (f<0 || write(f,"abc",3)!=3 || ftruncate(f,(off_t)0)!=0 || close(f)!=0)
  604.             exitmain(1);
  605.     exitmain(0);
  606. }
  607. EOF
  608. $RM || exit
  609. if $CL a.c $L >&2
  610. then
  611.     h=1
  612.     # Check out /tmp too; it's buggy on some hosts.
  613.     for d in . /tmp
  614.     do
  615.         if test -d $d
  616.         then
  617.             f=$d/a.d
  618.             rm -f $f || exit
  619.             $aout $f && test ! -s $f && test -f $f  ||  h=0
  620.             rm -f $f || exit
  621.         fi
  622.     done
  623. else h=0
  624. fi
  625. echo "#define has_ftruncate $h /* Does ftruncate() work?  */"
  626.  
  627. : has_getuid
  628. cat >a.c <<'EOF'
  629. #include "a.h"
  630. #ifndef getuid
  631.     uid_t getuid();
  632. #endif
  633. int main() { exitmain(getuid()!=getuid()); }
  634. EOF
  635. $RM || exit
  636. if ($CL a.c $L && $aout) >&2
  637. then has_getuid=1
  638. else has_getuid=0
  639. fi
  640. echo "#define has_getuid $has_getuid /* Does getuid() work?  */"
  641.  
  642. : has_getpwuid
  643. case $has_getuid in
  644. 0)
  645.     a='/* ' z='*/ ' h=?;;
  646. *)
  647.     a= z=
  648.     cat >a.c <<'EOF'
  649. #include "a.h"
  650. int main() { exitmain(!getpwuid(0)); }
  651. EOF
  652.     $RM || exit
  653.     if ($CL a.c $L && $aout) >&2
  654.     then h=1
  655.     else h=0
  656.     fi
  657. esac
  658. echo "$a#define has_getpwuid $h $z/* Does getpwuid() work?  */"
  659.  
  660. : has_kill
  661. cat >a.c <<'EOF'
  662. #include "a.h"
  663. #ifndef getpid
  664.     pid_t getpid();
  665. #endif
  666. int main() { exitmain(kill(getpid(), 0) != 0); }
  667. EOF
  668. $RM || exit
  669. if ($CL a.c $L && $aout) >&2
  670. then has_kill=1
  671. else has_kill=0
  672. fi
  673. # Used only by this script, not by RCS, so we don't output it.
  674.  
  675. : has_memcmp
  676. cat >a.c <<'EOF'
  677. #include "a.h"
  678. int main() { exitmain(memcmp("beautiful","beautiful",10) != 0); }
  679. EOF
  680. $RM || exit
  681. if ($CL a.c $L && $aout) >&2
  682. then h=1
  683. else h=0
  684. fi
  685. echo "#define has_memcmp $h /* Does memcmp() work?  */"
  686.  
  687. : has_memcpy
  688. cat >a.c <<'EOF'
  689. #include "a.h"
  690. char a[3];
  691. int main() {
  692.     memcpy(a,"xy",3);
  693.     exitmain(strcmp(a,"xy")!=0);
  694. }
  695. EOF
  696. $RM || exit
  697. if ($CL a.c $L && $aout) >&2
  698. then h=1
  699. else h=0
  700. fi
  701. echo "#define has_memcpy $h /* Does memcpy() work?  */"
  702.  
  703. : has_memmove
  704. cat >a.c <<'EOF'
  705. #include "a.h"
  706. char a[4];
  707. int main() {
  708.     strcpy(a, "xy");
  709.     memmove(a+1, a, 3);
  710.     exitmain(strcmp(a,"xxy")!=0);
  711. }
  712. EOF
  713. $RM || exit
  714. if ($CL a.c $L && $aout) >&2
  715. then h=1
  716. else h=0
  717. fi
  718. echo "#define has_memmove $h /* Does memmove() work?  */"
  719.  
  720. : has_mmap, has_madvise
  721. cat >a.c <<'EOF'
  722. #define CHAR1 '#' /* the first character in this file */
  723. #include "a.h"
  724. caddr_t a;
  725. struct stat b;
  726. #ifndef MADVISE_OK
  727. #define MADVISE_OK (madvise(a,b.st_size,MADV_SEQUENTIAL)==0 && madvise(a,b.st_size,MADV_NORMAL)==0)
  728. #endif
  729. int main()
  730. {
  731.     if (fstat(fileno(stdin), &b) != 0)
  732.         exitmain(1);
  733.     a = mmap(
  734.         (caddr_t)0, b.st_size, PROT_READ, MAP_SHARED,
  735.         fileno(stdin), (off_t)0
  736.     );
  737.     exitmain(
  738.         a == (caddr_t)-1  ||
  739.         !MADVISE_OK ||
  740.         *a != CHAR1  ||
  741.         munmap(a, b.st_size)  !=  0
  742.     );
  743. }
  744. EOF
  745. a=0 has_mmap=0
  746. $RM || exit
  747. if ($CL -DMADVISE_OK=1 a.c $L && $aout <a.c) >&2
  748. then
  749.     has_mmap=1
  750.     $RM || exit
  751.     ($CL a.c $L && $aout <a.c) >&2 && a=1
  752. fi
  753. echo "#define has_madvise $a /* Does madvise() work?  */"
  754. echo "#define has_mmap $has_mmap /* Does mmap() work on regular files?  */"
  755.  
  756. : has_rename, bad_a_rename, bad_b_rename
  757. cat >a.c <<'EOF'
  758. #include "a.h"
  759. int main() { exitmain(rename("a.a","a.b") != 0); }
  760. EOF
  761. echo a >a.a && $RM a.b || exit
  762. if ($CL a.c $L && $aout && test -f a.b) >&2
  763. then
  764.     h=1
  765.     rm -f a.a a.b &&
  766.     echo a >a.a && chmod -w a.a || exit
  767.     if $aout && test ! -f a.a && test -f a.b
  768.     then a=0
  769.     else a=1
  770.     fi
  771.     rm -f a.a a.b &&
  772.     echo a >a.a && echo b >a.b && chmod -w a.b || exit
  773.     if $aout && test ! -f a.a && test -f a.b
  774.     then b=0
  775.     else b=1
  776.     fi
  777.     rm -f a.a a.b || exit
  778. else h=0 a=0 b=0
  779. fi
  780. echo "#define has_rename $h /* Does rename() work?  */"
  781. echo "#define bad_a_rename $a /* Does rename(A,B) fail if A is unwritable?  */"
  782. echo "#define bad_b_rename $b /* Does rename(A,B) fail if B is unwritable?  */"
  783.  
  784. : void, VOID
  785. cat >a.c <<'EOF'
  786. #include "a.h"
  787. void f() {}
  788. int main() {f(); exitmain(0);}
  789. EOF
  790. if $CS a.c $LS >&2
  791. then
  792.     v='(void) '
  793. else
  794.     v=
  795.     echo 'typedef int void;'
  796. fi
  797. echo "#define VOID $v/* 'VOID e;' discards the value of an expression 'e'.  */"
  798.  
  799. : has_seteuid
  800. case $has_getuid in
  801. 0)
  802.     a='/* ' z='*/ ' has_seteuid=?;;
  803. *)
  804.     a= z=
  805.     cat >a.c <<'EOF'
  806. #include "a.h"
  807. #ifndef geteuid
  808.     uid_t geteuid();
  809. #endif
  810. int main() {
  811. /* Guess, don't test.  Ugh.  Testing would require running conf.sh setuid.  */
  812. /* If the guess is wrong, a setuid RCS will detect the problem at runtime.  */
  813. #if !_POSIX_VERSION
  814.     exitmain(1);
  815. #else
  816.     exitmain(seteuid(geteuid()) != 0);
  817. #endif
  818. }
  819. EOF
  820.     $RM || exit
  821.     if ($CL a.c $L && $aout) >&2
  822.     then has_seteuid=1
  823.     else has_seteuid=0
  824.     fi
  825. esac
  826. echo "$a#define has_seteuid $has_seteuid $z/* Does seteuid() work?  See README.  */"
  827.  
  828. : has_setuid
  829. h=$has_seteuid
  830. case $h in
  831. 0)
  832.     cat >a.c <<'EOF'
  833. #include "a.h"
  834. #ifndef getuid
  835.     uid_t getuid();
  836. #endif
  837. int main() { exitmain(setuid(getuid()) != 0); }
  838. EOF
  839.     $RM || exit
  840.     ($CL a.c $L && $aout) >&2 && h=1
  841. esac
  842. echo "$a#define has_setuid $h $z/* Does setuid() exist?  */"
  843.  
  844. : has_signal, signal_args, signal_type, sig_zaps_handler
  845. cat >a.c <<'EOF'
  846. #include "a.h"
  847. #if has_kill && !defined(getpid)
  848.     pid_t getpid();
  849. #endif
  850. #if !defined(signal) && declare_signal
  851.     signal_type (*signal P((int,signal_type(*)signal_args)))signal_args;
  852. #endif
  853. signal_type nothing(i) int i; {}
  854. int main(argc, argv) int argc; char **argv;
  855. {
  856.     signal(SIGINT, nothing);
  857. #    if has_kill
  858.         while (--argc)
  859.             kill(getpid(), SIGINT);
  860.         exitmain(0);
  861. #    else
  862.         /* Pretend that sig_zaps_handler; better safe than sorry.  */
  863.         exitmain(2 < argc);
  864. #    endif
  865. }
  866. EOF
  867. for declare_signal in 1 0
  868. do
  869.     for signal_type in void int
  870.     do
  871.         for signal_args in 'P((int))' '()'
  872.         do
  873.             $RM || exit
  874.             ($CL \
  875.                 -Ddeclare_signal=$declare_signal \
  876.                 -Dhas_kill=$has_kill \
  877.                 -Dsignal_args="$signal_args" \
  878.                 -Dsignal_type=$signal_type \
  879.                     a.c $L && $aout 1) >&2 && break
  880.         done && break
  881.     done && break
  882. done || {
  883.     echo >&2 "cannot deduce signal_args, signal_type"
  884.     exit 1
  885. }
  886. if $aout 1 2 >&2
  887. then z=0
  888. else z=1
  889. fi
  890. cat <<EOF
  891. #define has_signal $has_signal /* Does signal() work?  */
  892. #define signal_args $signal_args /* arguments of signal handlers */
  893. #define signal_type $signal_type /* type returned by signal handlers */
  894. #define sig_zaps_handler $z /* Must a signal handler reinvoke signal()?  */
  895. EOF
  896.  
  897. : has_sigaction
  898. cat >a.c <<'EOF'
  899. #include "a.h"
  900. #ifndef getpid
  901.     pid_t getpid();
  902. #endif
  903. static sig_atomic_t volatile gotsig;
  904. static void getsig(i) int i; { gotsig = 1; }
  905. int main(argc, argv) int argc; char **argv;
  906. {
  907.     struct sigaction s;
  908.     sigset_t t;
  909.     if (sigemptyset(&t) != 0  ||  sigaddset(&t, SIGINT) != 0)
  910.         exitmain(1);
  911.     if (sigaction(SIGINT, (struct sigaction*)0, &s) != 0)
  912.         exitmain(1);
  913.     s.sa_handler = getsig;
  914.     s.sa_mask = t;
  915.     if (sigaction(SIGINT, &s, (struct sigaction*)0) != 0)
  916.         exitmain(1);
  917. #    if has_kill
  918.         kill(getpid(), SIGINT);
  919. #    else
  920.         raise(SIGINT);
  921. #    endif
  922.     exitmain(gotsig != 1);
  923. }
  924. EOF
  925. $RM || exit
  926. if ($CL -Dhas_kill=$has_kill a.c $L && $aout) >&2
  927. then has_sigaction=1
  928. else has_sigaction=0
  929. fi
  930. echo "#define has_sigaction $has_sigaction /* Does struct sigaction work?  */"
  931.  
  932. : has_sigblock, sigmask
  933. a='/* ' z='*/ '
  934. b='/* ' y='*/ '
  935. case $has_sigaction in
  936. 1)
  937.     h=? n=?;;
  938. *)
  939.     a= z=
  940.     cat >a.c <<'EOF'
  941. #include "a.h"
  942. #include <signal.h>
  943. #if define_sigmask
  944. #    define sigmask(s) (1 << ((s)-1))
  945. #endif
  946. int main()
  947. {
  948.     sigblock(sigmask(SIGHUP));
  949. #    if has_kill
  950.         exitmain(kill(getpid(), SIGHUP) != 0);
  951. #    else
  952.         exitmain(raise(SIGHUP) != 0);
  953. #    endif
  954. }
  955. EOF
  956.     if $RM || exit; ($CL -Dhas_kill=$has_kill a.c $L && $aout) >&2
  957.     then h=1
  958.     elif $RM || exit; ($CL -Dhas_kill=$has_kill -Ddefine_sigmask=1 a.c $L && $aout) >&2
  959.     then h=1 b= y=
  960.     else h=0
  961.     fi
  962. esac
  963. echo "$a#define has_sigblock $h $z/* Does sigblock() work?  */"
  964. echo "$b#define sigmask(s) (1 << ((s)-1)) $y/* Yield mask for signal number.  */"
  965.  
  966. : has_sys_siglist
  967. cat >a.c <<'EOF'
  968. #include "a.h"
  969. #ifndef sys_siglist
  970.     extern char const *sys_siglist[];
  971. #endif
  972. int main() { exitmain(!sys_siglist[1][0]); }
  973. EOF
  974. $RM || exit
  975. if ($CL a.c $L && $aout) >&2
  976. then h=1
  977. else h=0
  978. fi
  979. echo "#define has_sys_siglist $h /* Does sys_siglist[] work?  */"
  980.  
  981. : fread_type, Fread, Fwrite
  982. cat >a.c <<'EOF'
  983. #define CHAR1 '#' /* the first character in this file */
  984. #include "a.h"
  985. #if !defined(fread) && declare_fread
  986.     fread_type fread P((void*,freadarg_type,freadarg_type,FILE*));
  987. #endif
  988. int main()
  989. {
  990.     char b;
  991.     exitmain(!(
  992.         fread(&b, (freadarg_type)1, (freadarg_type)1, stdin) == 1  &&
  993.         b==CHAR1
  994.     ));
  995. }
  996. EOF
  997. for declare_fread in 1 0
  998. do
  999.     for fread_type in ssize_t size_t int unsigned
  1000.     do
  1001.         for freadarg_type in size_t ssize_t unsigned int
  1002.         do
  1003.             $RM || exit
  1004.             (
  1005.                 $CL \
  1006.                     -Ddeclare_fread=$declare_fread \
  1007.                     -Dfreadarg_type=$freadarg_type \
  1008.                     -Dfread_type=$fread_type \
  1009.                     a.c $L &&
  1010.                 $aout <a.c
  1011.             ) >&2 && break
  1012.         done && break
  1013.     done && break
  1014. done || {
  1015.     echo >&2 "cannot deduce fread types"
  1016.     exit 1
  1017. }
  1018. cat <<EOF
  1019. typedef $fread_type fread_type; /* type returned by fread() and fwrite() */
  1020. typedef $freadarg_type freadarg_type; /* type of their size arguments */
  1021. EOF
  1022.  
  1023. : malloc_type
  1024. cat >a.c <<'EOF'
  1025. #include "a.h"
  1026. typedef void *malloc_type;
  1027. #ifndef malloc
  1028.     malloc_type malloc();
  1029. #endif
  1030. int main() { exitmain(!malloc(1)); }
  1031. EOF
  1032. if $CS a.c $LS >&2
  1033. then t=void
  1034. else t=char
  1035. fi
  1036. echo "typedef $t *malloc_type; /* type returned by malloc() */"
  1037.  
  1038. : has_getcwd
  1039. cat >a.c <<'EOF'
  1040. #include "a.h"
  1041. #ifndef getcwd
  1042.     char *getcwd();
  1043. #endif
  1044. char buf[10000];
  1045. int main() { exitmain(!getcwd(buf,10000)); }
  1046. EOF
  1047. $RM || exit
  1048. if ($CL a.c $L && $aout) >&2
  1049. then has_getcwd=1
  1050. else has_getcwd=0
  1051. fi
  1052. echo "#define has_getcwd $has_getcwd /* Does getcwd() work?  */"
  1053.  
  1054. : has_getwd
  1055. case $has_getcwd in
  1056. 1)
  1057.     a='/* ' z='*/ ' h=?;;
  1058. *)
  1059.     a= z=
  1060.     cat >a.c <<'EOF'
  1061. #include "a.h"
  1062. #include <sys/param.h>
  1063. #ifndef getwd
  1064.     char *getwd();
  1065. #endif
  1066. char buf[MAXPATHLEN];
  1067. int main() { exitmain(!getwd(buf)); }
  1068. EOF
  1069.     $RM || exit
  1070.     if ($CL a.c $L && $aout) >&2
  1071.     then h=1
  1072.     else h=0
  1073.     fi
  1074. esac
  1075. echo "$a#define has_getwd $h $z/* Does getwd() work?  */"
  1076.  
  1077. : has_mktemp
  1078. cat >a.c <<'EOF'
  1079. #include "a.h"
  1080. #ifndef mktemp
  1081.     char *mktemp();
  1082. #endif
  1083. int main()
  1084. {
  1085.     char b[9];
  1086.     strcpy(b, "a.XXXXXX");
  1087.     exitmain(!mktemp(b));
  1088. }
  1089. EOF
  1090. $RM || exit
  1091. if ($CL a.c $L && $aout) >&2
  1092. then h=1
  1093. else h=0
  1094. fi
  1095. echo "#define has_mktemp $h /* Does mktemp() work?  */"
  1096.  
  1097. : has_NFS
  1098. echo "#define has_NFS 1 /* Might NFS be used?  */"
  1099.  
  1100. : strchr
  1101. cat >a.c <<'EOF'
  1102. #include "a.h"
  1103. #ifndef strchr
  1104.     char *strchr();
  1105. #endif
  1106. int main() {exitmain(!strchr("abc", 'c'));}
  1107. EOF
  1108. $RM || exit
  1109. if ($CL a.c $L && $aout) >&2
  1110. then a='/* ' z='*/ '
  1111. else a= z=
  1112. fi
  1113. echo "$a#define strchr index $z/* Use old-fashioned name for strchr()?  */"
  1114.  
  1115. : strrchr
  1116. cat >a.c <<'EOF'
  1117. #include "a.h"
  1118. #ifndef strrchr
  1119.     char *strrchr();
  1120. #endif
  1121. int main() {exitmain(!strrchr("abc", 'c'));}
  1122. EOF
  1123. $RM || exit
  1124. if ($CL a.c $L && $aout) >&2
  1125. then a='/* ' z='*/ '
  1126. else a= z=
  1127. fi
  1128. echo "$a#define strrchr rindex $z/* Use old-fashioned name for strrchr()?  */"
  1129.  
  1130. : bad_unlink
  1131. cat >a.c <<'EOF'
  1132. #include "a.h"
  1133. int main() { exitmain(unlink("a.c") != 0); }
  1134. EOF
  1135. $RM && chmod -w a.c || exit
  1136. if ($CL a.c $L && $aout) >&2 && test ! -f a.c
  1137. then b=0
  1138. else b=1
  1139. fi
  1140. rm -f a.c || exit
  1141. echo "#define bad_unlink $b /* Does unlink() fail on unwritable files?  */"
  1142.  
  1143. : has_vfork, has_fork, has_spawn, has_wait, has_waitpid, RCS_SHELL
  1144. cat >a.c <<'EOF'
  1145. #include "a.h"
  1146. #ifndef getpid
  1147.     pid_t getpid();
  1148. #endif
  1149. #if TRY_VFORK
  1150. #    ifndef vfork
  1151.         pid_t vfork();
  1152. #    endif
  1153. #else
  1154. #    ifndef fork
  1155.         pid_t fork();
  1156. #    endif
  1157. #    undef vfork
  1158. #    define vfork fork
  1159. #endif
  1160. #if TRY_WAITPID
  1161. #    ifndef waitpid
  1162.         pid_t waitpid();
  1163. #    endif
  1164. #else
  1165. #    ifndef wait
  1166.         pid_t wait();
  1167. #    endif
  1168. #endif
  1169.  
  1170. int main()
  1171. {
  1172.     pid_t parent = getpid();
  1173.     pid_t child = vfork();
  1174.  
  1175.     if (child == 0) {
  1176.         /*
  1177.          * On sparc systems, changes by the child to local and incoming
  1178.          * argument registers are propagated back to the parent.
  1179.          * The compiler is told about this with #include <vfork.h>,
  1180.          * but some compilers (e.g. gcc -O) don't grok <vfork.h>.
  1181.          * Test for this by using lots of local variables, at least
  1182.          * as many local variables as `main' has allocated so far
  1183.          * including compiler temporaries.  4 locals are enough for
  1184.          * gcc 1.40.3 on a sparc, but we use 8 to be safe.
  1185.          * A buggy compiler should reuse the register of `parent'
  1186.          * for one of the local variables, since it will think that
  1187.          * `parent' can't possibly be used any more in this routine.
  1188.          * Assigning to the local variable will thus munge `parent'
  1189.          * in the parent process.
  1190.          */
  1191.         pid_t
  1192.             p = getpid(),
  1193.             p1 = getpid(), p2 = getpid(),
  1194.             p3 = getpid(), p4 = getpid(),
  1195.             p5 = getpid(), p6 = getpid(),
  1196.             p7 = getpid();
  1197.         /*
  1198.          * Convince the compiler that p..p7 are live; otherwise, it might
  1199.          * use the same hardware register for all 8 local variables.
  1200.          */
  1201.         if (p!=p1 || p!=p2 || p!=p3 || p!=p4 || p!=p5 || p!=p6 || p!=p7)
  1202.             _exit(1);
  1203.  
  1204.         /*
  1205.          * On some systems (e.g. IRIX 3.3),
  1206.          * vfork doesn't separate parent from child file descriptors.
  1207.          * If the child closes a descriptor before it execs or exits,
  1208.          * this munges the parent's descriptor as well.
  1209.          * Test for this by closing stdout in the child.
  1210.          */
  1211.         _exit(close(fileno(stdout)) != 0);
  1212.  
  1213.     } else {
  1214.         int status;
  1215.         struct stat st;
  1216.         while (wait(&status) != child)
  1217.             ;
  1218.         exit(
  1219.             /* Was there some problem with vforking?  */
  1220.             child < 0
  1221.  
  1222.             /* Did the child fail?  (This shouldn't happen.)  */
  1223.             || status
  1224.  
  1225.             /* Did the vfork/compiler bug occur?  */
  1226.             || parent != getpid()
  1227.  
  1228.             /* Did the file descriptor bug occur?  */
  1229.             || fstat(fileno(stdout), &st) != 0
  1230.         );
  1231.     }
  1232. }
  1233. EOF
  1234. $RM || exit
  1235. if ($CL -DTRY_VFORK=1 a.c $L && $aout) >&2
  1236. then has_vfork=1
  1237. else has_vfork=0
  1238. fi
  1239. echo "#define has_vfork $has_vfork /* Does vfork() work?  */"
  1240. h=$has_vfork
  1241. case $h in
  1242. 0)
  1243.     $RM || exit
  1244.     ($CL a.c $L && $aout) >&2 && h=1
  1245. esac
  1246. echo "#define has_fork $h /* Does fork() work?  */"
  1247. $RM || exit
  1248. if ($CL -DTRY_VFORK=$has_vfork -DTRY_WAITPID=1 a.c $L && $aout) >&2
  1249. then h=1
  1250. else h=0
  1251. fi
  1252. echo "#define has_spawn 0 /* Does spawn*() work?  */"
  1253. echo "#define has_wait 1 /* Does wait() work?  */"
  1254. echo "#define has_waitpid $h /* Does waitpid() work?  */"
  1255. echo '#define RCS_SHELL "/bin/sh" /* shell to run RCS subprograms */'
  1256.  
  1257. : has_vfprintf
  1258. cat >a.c <<'EOF'
  1259. #include "a.h"
  1260. #if has_prototypes
  1261. int p(char const*format,...)
  1262. #else
  1263. /*VARARGS1*/ int p(format, va_alist) char *format; va_dcl
  1264. #endif
  1265. {
  1266.     int r;
  1267.     va_list args;
  1268.     vararg_start(args, format);
  1269.     r = vfprintf(stderr, format, args);
  1270.     va_end(args);
  1271.     return r;
  1272. }
  1273. int main() { exitmain(p("") != 0); }
  1274. EOF
  1275. $RM || exit
  1276. if ($CL a.c $L && $aout) >&2
  1277. then h=1
  1278. else h=0
  1279. fi
  1280. echo "#define has_vfprintf $h /* Does vfprintf() work?  */"
  1281.  
  1282. : has__doprintf, has__doprnt
  1283. case $h in
  1284. 1)
  1285.     h=? a='/* ' z='*/ ';;
  1286. *)
  1287.     a= z=
  1288.     cat >a.c <<'EOF'
  1289. #include "a.h"
  1290. #if has_prototypes
  1291. int p(char const*format,...)
  1292. #else
  1293. /*VARARGS1*/ int p(format, va_alist) char *format; va_dcl
  1294. #endif
  1295. {
  1296.     va_list args;
  1297.     vararg_start(args, format);
  1298. #    if TRY__DOPRINTF
  1299.         _doprintf(stderr, format, args);
  1300. #    else
  1301.         _doprnt(format, args, stderr);
  1302. #    endif
  1303.     va_end(args);
  1304. }
  1305. int main() { p(""); exitmain(ferror(stderr) != 0); }
  1306. EOF
  1307.     $RM || exit
  1308.     if ($CL -DTRY__DOPRINTF=1 a.c $L && $aout) >&2
  1309.     then h=1
  1310.     else h=0
  1311.     fi
  1312. esac
  1313. echo "$a#define has__doprintf $h $z/* Does _doprintf() work?  */"
  1314. case $h in
  1315. 0)
  1316.     $RM || exit
  1317.     if ($CL a.c $L && $aout) >&2
  1318.     then h=1
  1319.     else h=0
  1320.     fi
  1321.     a= z=;;
  1322. *)
  1323.     h=? a='/* ' z='*/ '
  1324. esac
  1325. echo "$a#define has__doprnt $h $z/* Does _doprnt() work?  */"
  1326.  
  1327. : EXIT_FAILURE
  1328. cat >a.c <<'EOF'
  1329. #include "a.h"
  1330. int main() { exitmain(EXIT_FAILURE); }
  1331. EOF
  1332. $RM || exit
  1333. if $CL a.c $L >&2 && $aout
  1334. then a= z=
  1335. else a='/* ' z='*/ '
  1336. fi
  1337. echo "$a#undef EXIT_FAILURE $z/* Uncomment this if EXIT_FAILURE is broken.  */"
  1338.  
  1339. : large_memory
  1340. echo "#define large_memory $has_mmap /* Can main memory hold entire RCS files?  */"
  1341.  
  1342. : ULONG_MAX
  1343. cat >a.c <<'EOF'
  1344. #include "a.h"
  1345. unsigned long ulong_max;
  1346. int undef;
  1347. int main()
  1348. {
  1349.     ulong_max--;
  1350. #    ifdef ULONG_MAX
  1351.         if (ulong_max != ULONG_MAX)
  1352.             undef = 1;
  1353. #    endif
  1354.     printf("%s#undef ULONG_MAX %s/* Uncomment this if ULONG_MAX is wrong.  */\n", undef?"":"/* ", undef?"":"*/ ");
  1355.     printf("#ifndef ULONG_MAX\n");
  1356.     printf("#define ULONG_MAX %lu /* unsigned long maximum */\n", ulong_max);
  1357.     printf("#endif\n");
  1358.     exitmain(0);
  1359. }
  1360. EOF
  1361. $RM || exit
  1362. $CL a.c $L >&2 && $aout || exit
  1363.  
  1364. : ULONG_MAX_OVER_10
  1365. cat >a.c <<'EOF'
  1366. #include "a.h"
  1367. unsigned long ulong_max = ULONG_MAX;
  1368. int main()
  1369. {
  1370.     unsigned long ulong_max_over_10 = ulong_max/10;
  1371.     unsigned long u = 10*ulong_max_over_10;
  1372.     if (u < u+10) {
  1373.         fprintf(stderr, "unsigned long arithmetic is broken\n");
  1374.         exitmain(1);
  1375.     }
  1376.     printf("#define ULONG_MAX_OVER_10 ");
  1377.     if (ulong_max_over_10 == ULONG_MAX/10)
  1378.         printf("(ULONG_MAX/10)");
  1379.     else
  1380.         printf("%lu", ulong_max_over_10);
  1381.     printf(" /* ULONG_MAX/10, discarding remainder */\n");
  1382.     exitmain(0);
  1383. }
  1384. EOF
  1385. $RM || exit
  1386. $CL a.c $L >&2 && $aout || exit
  1387.  
  1388. : struct utimbuf
  1389. cat >a.c <<'EOF'
  1390. #include "a.h"
  1391. struct utimbuf s;
  1392. int main() { s.actime = s.modtime = 1; exitmain(utime("a.c", &s) != 0); }
  1393. EOF
  1394. $RM || exit
  1395. if ($CL a.c $L && $aout) >&2
  1396. then h=1
  1397. else h=0
  1398. fi
  1399. echo "#define has_utimbuf $h /* Does struct utimbuf work?  */"
  1400.  
  1401. : CO
  1402. echo "#define CO \"${RCSPREFIX}co\" /* name of 'co' program */"
  1403.  
  1404. : COMPAT2
  1405. echo "#define COMPAT2 $COMPAT2 /* Are version 2 files supported?  */"
  1406.  
  1407. : DATEFORM
  1408. cat >a.c <<'EOF'
  1409. #include "a.h"
  1410. int main() { printf("%.2d", 1); exitmain(0); }
  1411. EOF
  1412. $RM && $CL a.c $L >&2 && r=`$aout` || exit
  1413. case $r in
  1414. 01)    f=%.2d;;
  1415. *)    f=%02d
  1416. esac
  1417. echo "#define DATEFORM \"$f.$f.$f.$f.$f.${f}\" /* e.g. 01.01.01.01.01.01 */"
  1418.  
  1419. : DIFF
  1420. echo "#define DIFF \"${DIFF}\" /* name of 'diff' program */"
  1421.  
  1422. : DIFF3
  1423. echo "#define DIFF3 \"${DIFF3}\" /* name of 'diff3' program */"
  1424.  
  1425. echo "#define DIFF3_BIN $DIFF3_BIN /* Is diff3 user-visible (not the /usr/lib auxiliary)?  */"
  1426.  
  1427. : DIFF_FLAGS
  1428. dfs=
  1429. for df in $DIFF_FLAGS
  1430. do dfs="$dfs, \"${df}\""
  1431. done
  1432. echo "#define DIFF_FLAGS $dfs /* Make diff output suitable for RCS.  */"
  1433.  
  1434. : DIFF_L
  1435. echo "#define DIFF_L $DIFF_L /* Does diff -L work? */"
  1436.  
  1437. : DIFF_SUCCESS, DIFF_FAILURE, DIFF_TROUBLE
  1438. cat <<EOF
  1439. #define DIFF_SUCCESS $DIFF_SUCCESS /* DIFF status if no differences are found */
  1440. #define DIFF_FAILURE $DIFF_FAILURE /* DIFF status if differences are found */
  1441. #define DIFF_TROUBLE $DIFF_TROUBLE /* DIFF status if trouble */
  1442. EOF
  1443.  
  1444. : ED
  1445. echo "#define ED \"${ED}\" /* name of 'ed' program (used only if !DIFF3_BIN) */"
  1446.  
  1447. : MERGE
  1448. echo "#define MERGE \"${RCSPREFIX}merge\" /* name of 'merge' program */"
  1449.  
  1450. : '*SLASH*', ROOTPATH, TMPDIR, X_DEFAULT
  1451. case ${PWD-`pwd`} in
  1452. /*) # Posix
  1453.     SLASH=/
  1454.     qSLASH="'/'"
  1455.     SLASHes=$qSLASH
  1456.     isSLASH='#define isSLASH(c) ((c) == SLASH)'
  1457.     ROOTPATH='isSLASH((p)[0])'
  1458.     X_DEFAULT=",v$SLASH";;
  1459. ?:[/\\\\]*) # MS-DOS # \\\\ instead of \\ doesn't hurt, and avoids common bugs
  1460.     SLASH='\'
  1461.     qSLASH="'\\\\'"
  1462.     SLASHes="$qSLASH: case '/': case ':'"
  1463.     isSLASH='int isSLASH P((int));'
  1464.     ROOTPATH="(isSLASH((p)[0]) || (p)[0] && (p)[1]==':')"
  1465.     X_DEFAULT="$SLASH,v";;
  1466. *)
  1467.     echo >&2 "cannot deduce SLASH"; exit 1
  1468. esac
  1469. cat <<EOF
  1470. #define TMPDIR "${SLASH}tmp" /* default directory for temporary files */
  1471. #define SLASH $qSLASH /* principal pathname separator */
  1472. #define SLASHes $SLASHes /* \`case SLASHes:' labels all pathname separators */
  1473. $isSLASH /* Is arg a pathname separator?  */
  1474. #define ROOTPATH(p) $ROOTPATH /* Is p an absolute pathname?  */
  1475. #define X_DEFAULT "$X_DEFAULT" /* default value for -x option */
  1476. EOF
  1477.  
  1478. : ALL_ABSOLUTE, DIFF_ABSOLUTE
  1479. cat >a.c <<'EOF'
  1480. #include "a.h"
  1481. #ifndef isSLASH
  1482. int isSLASH(c) int c; { switch (c) { case SLASHes: return 1; } return 0; }
  1483. #endif
  1484. main(argc, argv) char **argv; { exitmain(1<argc && !ROOTPATH(argv[1])); }
  1485. EOF
  1486. $RM && ($CL a.c $L && $aout) >&2 || exit
  1487. a=1
  1488. for i in "$DIFF" "$DIFF3" "$ED" "$RCSPREFIX" "$SENDMAIL"
  1489. do
  1490.     case $i in
  1491.     \"*\") i=`expr "$i" : '"\(.*\)"'`
  1492.     esac
  1493.     case $i in
  1494.     ?*) $aout "$i" || { a=0; break; }
  1495.     esac
  1496. done
  1497. echo "#define ALL_ABSOLUTE $a /* Do all subprograms satisfy ROOTPATH?  */"
  1498. if $aout "$DIFF"
  1499. then a=1
  1500. else a=0
  1501. fi
  1502. echo "#define DIFF_ABSOLUTE $a /* Is ROOTPATH(DIFF) true?  */"
  1503.  
  1504. : SENDMAIL
  1505. case $SENDMAIL in
  1506. '') a='/* ' z='*/ ';;
  1507. *) a= z=
  1508. esac
  1509. echo "$a#define SENDMAIL $SENDMAIL $z/* how to send mail */"
  1510.  
  1511. : TZ_must_be_set
  1512. echo "#define TZ_must_be_set 0 /* Must TZ be set for gmtime() to work?  */"
  1513.  
  1514.  
  1515. : standard function declarations
  1516.  
  1517. cat <<'EOF'
  1518.  
  1519.  
  1520.  
  1521. /* Adjust the following declarations as needed.  */
  1522.  
  1523.  
  1524. #ifndef exiting
  1525. #    if __GNUC__ && !__STRICT_ANSI__
  1526. #        define exiting volatile /* GCC extension: function cannot return */
  1527. #    else
  1528. #        define exiting
  1529. #    endif
  1530. #endif
  1531. EOF
  1532.  
  1533. cat >a.ha <<EOF
  1534.  
  1535. #if has_ftruncate
  1536.     int ftruncate P((int,off_t));
  1537. #endif
  1538.  
  1539. /* <sys/mman.h> */
  1540. #if has_madvise
  1541.     int madvise P((caddr_t,size_t,int));
  1542. #endif
  1543. #if has_mmap
  1544.     caddr_t mmap P((caddr_t,size_t,int,int,int,off_t));
  1545.     int munmap P((caddr_t,size_t));
  1546. #endif
  1547.  
  1548.  
  1549. /* Posix (ISO/IEC 9945-1: 1990 / IEEE Std 1003.1-1990) */
  1550. /* These definitions are for the benefit of non-Posix hosts, and */
  1551. /* Posix hosts that have Standard C compilers but traditional include files.  */
  1552. /* Unfortunately, mixed-up hosts are all too common.  */
  1553.  
  1554. /* <fcntl.h> */
  1555. #ifdef F_DUPFD
  1556.     int fcntl P((int,int,...));
  1557. #else
  1558.     int dup2 P((int,int));
  1559. #endif
  1560. #ifdef O_CREAT
  1561. #    define open_can_creat 1
  1562. #else
  1563. #    define open_can_creat 0
  1564. #    define O_RDONLY 0
  1565. #    define O_WRONLY 1
  1566. #    define O_RDWR 2
  1567. #    define O_CREAT 01000
  1568. #    define O_TRUNC 02000
  1569.     int creat P((char const*,mode_t));
  1570. #endif
  1571. #ifndef O_EXCL
  1572. #define O_EXCL 0
  1573. #endif
  1574.  
  1575. /* <pwd.h> */
  1576. #if has_getpwuid
  1577.     struct passwd *getpwuid P((uid_t));
  1578. #endif
  1579.  
  1580. /* <signal.h> */
  1581. #if has_sigaction
  1582.     int sigaction P((int,struct sigaction const*,struct sigaction*));
  1583.     int sigaddset P((sigset_t*,int));
  1584.     int sigemptyset P((sigset_t*));
  1585. #else
  1586. #if has_sigblock
  1587.     /* BSD */
  1588.     int sigblock P((int));
  1589.     int sigmask P((int));
  1590.     int sigsetmask P((int));
  1591. #endif
  1592. #endif
  1593.  
  1594. /* <stdio.h> */
  1595. FILE *fdopen P((int,char const*));
  1596. int fileno P((FILE*));
  1597.  
  1598. /* <sys/stat.h> */
  1599. int chmod P((char const*,mode_t));
  1600. int fstat P((int,struct stat*));
  1601. int stat P((char const*,struct stat*));
  1602. #if has_fchmod
  1603.     int fchmod P((int,mode_t));
  1604. #endif
  1605. #ifndef S_IRUSR
  1606. #    ifdef S_IREAD
  1607. #        define S_IRUSR S_IREAD
  1608. #    else
  1609. #        define S_IRUSR 0400
  1610. #    endif
  1611. #    ifdef S_IWRITE
  1612. #        define S_IWUSR S_IWRITE
  1613. #    else
  1614. #        define S_IWUSR (S_IRUSR/2)
  1615. #    endif
  1616. #endif
  1617. #ifndef S_IRGRP
  1618. #    if has_getuid
  1619. #        define S_IRGRP (S_IRUSR / 0010)
  1620. #        define S_IWGRP (S_IWUSR / 0010)
  1621. #        define S_IROTH (S_IRUSR / 0100)
  1622. #        define S_IWOTH (S_IWUSR / 0100)
  1623. #    else
  1624.         /* single user OS -- not Posix or Unix */
  1625. #        define S_IRGRP 0
  1626. #        define S_IWGRP 0
  1627. #        define S_IROTH 0
  1628. #        define S_IWOTH 0
  1629. #    endif
  1630. #endif
  1631. #ifndef S_ISREG
  1632. #define S_ISREG(n) (((n) & S_IFMT) == S_IFREG)
  1633. #endif
  1634.  
  1635. /* <sys/wait.h> */
  1636. #if has_wait
  1637.     pid_t wait P((int*));
  1638. #endif
  1639. #ifndef WEXITSTATUS
  1640. #define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
  1641. #undef WIFEXITED /* Avoid 4.3BSD incompatibility with Posix.  */
  1642. #endif
  1643. #ifndef WIFEXITED
  1644. #define WIFEXITED(stat_val) (!((stat_val) & 255))
  1645. #endif
  1646.  
  1647. /* <unistd.h> */
  1648. char *getlogin P((void));
  1649. int close P((int));
  1650. int isatty P((int));
  1651. int link P((char const*,char const*));
  1652. int open P((char const*,int,...));
  1653. int unlink P((char const*));
  1654. int _filbuf P((FILE*)); /* keeps lint quiet in traditional C */
  1655. int _flsbuf P((int,FILE*)); /* keeps lint quiet in traditional C */
  1656. long pathconf P((char const*,int));
  1657. ssize_t write P((int,void const*,size_t));
  1658. #ifndef STDIN_FILENO
  1659. #    define STDIN_FILENO 0
  1660. #    define STDOUT_FILENO 1
  1661. #    define STDERR_FILENO 2
  1662. #endif
  1663. #if has_fork
  1664. #    if !has_vfork
  1665. #        undef vfork
  1666. #        define vfork fork
  1667. #    endif
  1668.     pid_t vfork P((void)); /* vfork is nonstandard but faster */
  1669. #endif
  1670. #if has_getcwd || !has_getwd
  1671.     char *getcwd P((char*,size_t));
  1672. #else
  1673.     char *getwd P((char*));
  1674. #endif
  1675. #if has_getuid
  1676.     uid_t getuid P((void));
  1677. #endif
  1678. #if has_readlink
  1679.     ssize_t readlink P((char const*,char*,size_t)); /* BSD; not standard yet */
  1680. #endif
  1681. #if has_setuid
  1682. #    if !has_seteuid
  1683. #        undef seteuid
  1684. #        define seteuid setuid
  1685. #    endif
  1686.     int seteuid P((uid_t));
  1687.     uid_t geteuid P((void));
  1688. #endif
  1689. #if has_spawn
  1690.     int spawnv P((int,char const*,char*const*));
  1691. #    if ALL_ABSOLUTE
  1692. #        define spawn_RCS spawnv
  1693. #    else
  1694. #        define spawn_RCS spawnvp
  1695.         int spawnvp P((int,char const*,char*const*));
  1696. #    endif
  1697. #else
  1698.     int execv P((char const*,char*const*));
  1699. #    if ALL_ABSOLUTE
  1700. #        define exec_RCS execv
  1701. #    else
  1702. #        define exec_RCS execvp
  1703.         int execvp P((char const*,char*const*));
  1704. #    endif
  1705. #endif
  1706.  
  1707. /* utime.h */
  1708. #if !has_utimbuf
  1709.     struct utimbuf { time_t actime, modtime; };
  1710. #endif
  1711. int utime P((char const*,struct utimbuf const*));
  1712.  
  1713.  
  1714. /* Standard C library */
  1715. /* These definitions are for the benefit of hosts that have */
  1716. /* traditional C include files, possibly with Standard C compilers.  */
  1717. /* Unfortunately, mixed-up hosts are all too common.  */
  1718.  
  1719. /* <errno.h> */
  1720. extern int errno;
  1721.  
  1722. /* <signal.h> */
  1723. #if has_signal
  1724.     signal_type (*signal P((int,signal_type(*)signal_args)))signal_args;
  1725. #endif
  1726.  
  1727. /* <stdio.h> */
  1728. FILE *fopen P((char const*,char const*));
  1729. fread_type fread P((void*,freadarg_type,freadarg_type,FILE*));
  1730. fread_type fwrite P((void const*,freadarg_type,freadarg_type,FILE*));
  1731. int fclose P((FILE*));
  1732. int feof P((FILE*));
  1733. int ferror P((FILE*));
  1734. int fflush P((FILE*));
  1735. int fprintf P((FILE*,char const*,...));
  1736. int fputs P((char const*,FILE*));
  1737. int fseek P((FILE*,long,int));
  1738. int printf P((char const*,...));
  1739. int rename P((char const*,char const*));
  1740. int sprintf P((char*,char const*,...));
  1741. long ftell P((FILE*));
  1742. void clearerr P((FILE*));
  1743. void perror P((char const*));
  1744. #ifndef L_tmpnam
  1745. #define L_tmpnam 32 /* power of 2 > sizeof("/usr/tmp/xxxxxxxxxxxxxxx") */
  1746. #endif
  1747. #ifndef SEEK_SET
  1748. #define SEEK_SET 0
  1749. #endif
  1750. #if has_mktemp
  1751.     char *mktemp P((char*)); /* traditional */
  1752. #else
  1753.     char *tmpnam P((char*));
  1754. #endif
  1755. #if has_vfprintf
  1756.     int vfprintf P((FILE*,char const*,va_list));
  1757. #else
  1758. #if has__doprintf
  1759.     void _doprintf P((FILE*,char const*,va_list)); /* Minix */
  1760. #else
  1761.     void _doprnt P((char const*,va_list,FILE*)); /* BSD */
  1762. #endif
  1763. #endif
  1764.  
  1765. /* <stdlib.h> */
  1766. char *getenv P((char const*));
  1767. exiting void _exit P((int));
  1768. exiting void exit P((int));
  1769. malloc_type malloc P((size_t));
  1770. malloc_type realloc P((malloc_type,size_t));
  1771. void free P((malloc_type));
  1772. #ifndef EXIT_FAILURE
  1773. #define EXIT_FAILURE 1
  1774. #endif
  1775. #ifndef EXIT_SUCCESS
  1776. #define EXIT_SUCCESS 0
  1777. #endif
  1778. #if !has_fork && !has_spawn
  1779.     int system P((char const*));
  1780. #endif
  1781.  
  1782. /* <string.h> */
  1783. char *strcpy P((char*,char const*));
  1784. char *strchr P((char const*,int));
  1785. char *strrchr P((char const*,int));
  1786. int memcmp P((void const*,void const*,size_t));
  1787. int strcmp P((char const*,char const*));
  1788. size_t strlen P((char const*));
  1789. void *memcpy P((void*,void const*,size_t));
  1790. #if has_memmove
  1791.     void *memmove P((void*,void const*,size_t));
  1792. #endif
  1793.  
  1794. /* <time.h> */
  1795. time_t time P((time_t*));
  1796. EOF
  1797.  
  1798. cat >a.c <<'EOF'
  1799. #include "a.h"
  1800. #define a 0
  1801. #define b 1
  1802. #if H==a
  1803. #    include "a.ha"
  1804. #else
  1805. #    include "a.hb"
  1806. #endif
  1807. int main() { exitmain(0); }
  1808. EOF
  1809.  
  1810. # Comment out lines in a.ha that the compiler rejects.
  1811. # a.ha may not contain comments that cross line boundaries.
  1812. # Leave the result in a.h$H.
  1813. H=a L=1
  1814. U=`wc -l <a.ha | sed 's| ||g'`
  1815. commentOut='s|^[^#/][^/]*|/* & */|'
  1816.  
  1817. until  test $U -lt $L  ||  $CS -DH=$H a.c $LS >&2
  1818. do
  1819.     case $H in
  1820.     a) I=b;;
  1821.     *) I=a
  1822.     esac
  1823.  
  1824.     # The compiler rejects some line in L..U.
  1825.     # Use binary search to set L to be the index of the first bad line in L..U.
  1826.     u=$U
  1827.     while test $L -lt $u
  1828.     do
  1829.         M=`expr '(' $L + $u ')' / 2`
  1830.         M1=`expr $M + 1`
  1831.         sed "$M1,\$$commentOut" a.h$H >a.h$I || exit
  1832.         if $CS -DH=$I a.c $LS >&2
  1833.         then L=$M1
  1834.         else u=$M
  1835.         fi
  1836.     done
  1837.  
  1838.     # Comment out the bad line.
  1839.     sed "$L$commentOut" a.h$H >a.h$I || exit
  1840.  
  1841.     H=$I
  1842.     L=`expr $L + 1`
  1843. done
  1844.  
  1845. cat a.h$H
  1846.