1#! /bin/sh 2# Output RCS compile-time configuration. 3Id='Id: conf.sh,v 5.25 1995/06/16 06:19:24 eggert Exp ' 4# Copyright 1990, 1991, 1992, 1993, 1994, 1995 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. 21# If not, write to the Free Software Foundation, 22# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 23# 24# Report problems and direct all questions to: 25# 26# rcs-bugs@cs.purdue.edu 27 28 29# Standard output should already be directed to "a.h"; 30# later parts of this procedure need it. 31# Standard error can be ignored if a.h is OK, 32# and can be inspected for clues otherwise. 33 34# The Makefile overrides the following defaults. 35: ${RCSPREFIX=/usr/local/bin/} 36: ${ALL_CFLAGS=-Dhas_conf_h} 37: ${CC=cc} 38: ${COMPAT2=0} 39: ${DIFF=${RCSPREFIX}diff} 40: ${DIFF3=${DIFF}3} 41: ${DIFF3_BIN=1} 42: ${DIFFFLAGS=-an} 43: ${DIFF_L=1} 44: ${DIFF_SUCCESS=0} ${DIFF_FAILURE=1} ${DIFF_TROUBLE=2} 45: ${ED=/bin/ed} 46: ${SENDMAIL='"/usr/lib/sendmail"'} 47# : ${LDFLAGS=} ${LIBS=} tickles old shell bug 48 49C="$CC $ALL_CFLAGS" 50CL="$CC $ALL_CFLAGS $LDFLAGS -o a.out" 51L=$LIBS 52 53cat <<EOF 54/* RCS compile-time configuration */ 55 56 /* $Id */ 57 58/* 59 * This file is generated automatically. 60 * If you edit it by hand your changes may be lost. 61 * Instead, please try to fix conf.sh, 62 * and send your fixes to rcs-bugs@cs.purdue.edu. 63 */ 64 65EOF 66 67n=' 68' 69case `echo -n` in 70-n) 71 ech='echo' dots='... \c';; 72*) 73 ech='echo -n' dots='... ' 74esac 75 76$ech >&3 "$0: testing permissions $dots" 77rm -f a.d && 78date >a.d && 79chmod 0 a.d && 80{ test -w a.d || cp /dev/null a.d 2>/dev/null; } && { 81 echo >&3 "$n$0: This command should not be run with superuser permissions." 82 exit 1 83} 84echo >&3 OK 85rm -f a.d || exit 86 87$ech >&3 "$0: testing compiler for plausibility $dots" 88echo 'main() { return 0; }' >a.c 89rm -f a.exe a.out || exit 90$CL a.c $L >&2 || { 91 echo >&3 "$n$0: The command '$CL a.c $L' failed on a trivial program." 92 exit 1 93} 94echo 'this is not a C source file' >a.c 95rm -f a.exe a.out || exit 96$CL a.c $L >&2 && { 97 echo >&3 "$n$0: The command '$CL a.c $L' succeeds when it should fail." 98 exit 1 99} 100echo >&3 OK 101 102$ech >&3 "$0: configuring exitmain $dots" 103cat >a.c <<EOF 104#include "a.h" 105int main(argc,argv) int argc; char **argv; { return argc-1; } 106EOF 107rm -f a.exe a.out || exit 108if $CL a.c $L >&2 109then A_H=a.h 110else 111 echo >&3 failed 112 $ech >&3 "$0: attempting to work around Domain/OS brain damage $dots" 113 cat >a.c <<EOF 114#include "a.hap" 115int main(argc,argv) int argc; char **argv; { return argc-1; } 116EOF 117 cat <a.h >a.hap && 118 $CL a.c $L >&2 || exit 1 119 # The Domain/OS C compiler refuses to read a.h because the file 120 # is currently open for writing. Work around this brain damage by 121 # copying it to a.hap before each compilation; include a.hap instead. 122 A_H=a.hap 123fi 124if test -f a.out 125then aout=./a.out 126elif test -f a.exe 127then aout=./a.exe 128else 129 echo >&3 "$n$0: C compiler creates neither a.out nor a.exe." 130 exit 1 131fi 132e='exit(n), 3 /* lint fodder */' 133if $aout - 134then : 135elif $aout 136then e=n 137fi 138case $e in 139n) echo >&3 OK;; 140*) echo >&3 "return does not work; using exit instead" 141esac 142echo "#define exitmain(n) return $e /* how to exit from main() */" 143 144: PREPARE_CC 145case $A_H in 146a.h) 147 PREPARE_CC="rm -f $aout";; 148*) 149 echo "rm -f $aout \$1 && cat <a.h >$A_H" >a.pre 150 PREPARE_CC="sh a.pre" 151esac 152 153for id in _POSIX_C_SOURCE _POSIX_SOURCE 154do 155 $ech >&3 "$0: configuring $id $dots" 156 cat >a.c <<EOF 157#include "$A_H" 158#include <stdio.h> 159int 160main() { 161# ifdef fileno 162# define f(x) fileno(x) 163# else 164 /* Force a compile-time error if fileno isn't declared. */ 165 int (*p)() = fileno; 166# define f(x) (*p)(x) 167# endif 168 /* Some buggy linkers seem to need the getchar. */ 169 exitmain(getchar() != '#' || fileno(stdout) != 1); 170} 171#if syntax_error 172syntax error 173#endif 174EOF 175 a='/* ' z='*/ ' 176 case $id in 177 _POSIX_SOURCE) 178 version=1003.1-1990 179 value=;; 180 _POSIX_C_SOURCE) 181 version='1003.1b-1993 or later' 182 value='2147483647L ';; 183 esac 184 $PREPARE_CC || exit 185 if ($CL a.c $L && $aout <a.c) >&2 186 then : 187 elif $PREPARE_CC || exit; ($CL -D$id=$value a.c $L && $aout <a.c) >&2 188 then a= z= 189 fi 190 case $a in 191 ?*) echo >&3 OK;; 192 '') echo >&3 "must define it, unfortunately" 193 esac 194 echo "$a#define $id $value$z/* if strict C + Posix $version */" 195done 196 197cat <<'EOF' 198 199#include <errno.h> 200#include <stdio.h> 201#include <time.h> 202 203/* Comment out #include lines below that do not work. */ 204EOF 205 206$ech >&3 "$0: configuring how to check for syntax errors $dots" 207# Run `$CS a.c $LS' instead of `$CL a.c $L' for compile-time checking only. 208# This speeds up the configuration process. 209if 210 rm -f a.s && $C -S a.c >&2 && test -s a.s && rm -f a.s && 211 if $C -S -Dsyntax_error=1 a.c >&2 && test -s a.s 212 then false 213 else : 214 fi 215then 216 # Generate assembly language output. 217 CS="$C -S" LS= o=a.s PREPARE_CC="$PREPARE_CC $o" 218elif 219 rm -f a.o a.obj && $C -c a.c >&2 && 220 if test -s a.o 221 then o=a.o 222 elif test -s a.obj 223 then o=a.obj 224 else false 225 fi && 226 if $C -c -Dsyntax_error=1 a.c >&2 && test -s $o 227 then false 228 else : 229 fi 230then 231 # Generate object code. 232 CS="$C -c" LS= PREPARE_CC="$PREPARE_CC $o" 233else 234 # Generate an executable. 235 CS=$CL LS=$L o=$aout 236fi 237CS_OK="test -s $o" 238echo >&3 $CS 239 240# standard include files 241# sys/types.h and sys/stat.h must come first because others depend on them. 242has_signal=1 243for h in \ 244 sys/types sys/stat \ 245 dirent fcntl limits mach/mach net/errno \ 246 pwd siginfo signal stdlib string \ 247 sys/mman sys/wait ucontext unistd utime vfork 248do 249 i="#include <$h.h>" 250 $ech >&3 "$0: configuring $i $dots" 251 cat >a.c <<EOF 252#include "$A_H" 253$i 254int main(){ exitmain(0); } 255EOF 256 ok=OK 257 $PREPARE_CC || exit 258 $CS a.c $LS >&2 && $CS_OK || { 259 case $h in 260 string) 261 i='#include <strings.h>' 262 ok="$i instead";; 263 *) 264 i="/* $i */" 265 ok="commenting it out" 266 esac 267 case $h in 268 signal) has_signal=0 269 esac 270 } 271 echo >&3 "$ok" 272 echo "$i" 273done 274 275cat <<'EOF' 276 277/* Define boolean symbols to be 0 (false, the default), or 1 (true). */ 278EOF 279 280# has_sys_param_h 281$ech >&3 "$0: configuring has_sys_param_h $dots" 282cat >a.c <<EOF 283#include "$A_H" 284#include <sys/param.h> 285int main() { exitmain(0); } 286EOF 287$PREPARE_CC || exit 288if $CS a.c $LS >&2 && $CS_OK 289then h=1 ok=OK 290else h=0 ok=absent 291fi 292echo >&3 $ok 293echo "#define has_sys_param_h $h /* Does #include <sys/param.h> work? */" 294 295# We must do errno next, because has_readlink needs it. 296/* <errno.h> */ 297$ech >&3 "$0: configuring errno $dots" 298cat >a.c <<EOF 299#include "$A_H" 300int main() { exitmain(errno != errno); } 301EOF 302$PREPARE_CC || exit 303if $CS a.c $LS >&2 304then a='/* ' z=' */' ok=OK 305else a= z= ok='declaration missing' 306fi 307echo >&3 $ok 308echo "${a}extern int errno;$z /* Uncomment if <errno.h> doesn't declare errno. */" 309rm -f a.c || exit 310 311# We must do has_readlink next, because it might generate 312# #include directives that affect later definitions. 313 314$ech >&3 "$0: configuring has_readlink, readlink_isreg_errno $dots" 315cat >a.c <<EOF 316#include "$A_H" 317static char b[7]; 318int 319main() { 320 if (readlink("a.sym2",b,7) == 6 && strcmp(b,"a.sym1") == 0 && 321 readlink("a.c",b,7) == -1 && errno != ENOENT 322 ) { 323 if (errno == EINVAL) 324 printf("EINVAL\n"); 325 else 326 printf("%d\n", errno); 327 exitmain(ferror(stdout) || fclose(stdout)!=0); 328 } 329 exitmain(1); 330} 331EOF 332$PREPARE_CC a.sym* || exit 333readlink_isreg_errno='?' 334if (ln -s a.sym1 a.sym2 && $CL a.c $L) >&2 && readlink_isreg_errno=`$aout` 335then h=1 336else h=0 337fi 338echo >&3 $h, $readlink_isreg_errno 339cat <<EOF 340#define has_readlink $h /* Does readlink() work? */ 341#define readlink_isreg_errno $readlink_isreg_errno /* errno after readlink on regular file */ 342 343#if has_readlink && !defined(MAXSYMLINKS) 344# if has_sys_param_h 345# include <sys/param.h> 346# endif 347# ifndef MAXSYMLINKS 348# define MAXSYMLINKS 20 /* BSD; not standard yet */ 349# endif 350#endif 351EOF 352 353# *_t 354cat <<'EOF' 355 356/* Comment out the typedefs below if the types are already declared. */ 357/* Fix any uncommented typedefs that are wrong. */ 358EOF 359cat >a.c <<EOF 360#include "$A_H" 361t x; 362int main() { exitmain(0); } 363EOF 364for t in mode_t off_t pid_t sig_atomic_t size_t ssize_t time_t uid_t 365do 366 $ech >&3 "$0: configuring $t $dots" 367 case $t in 368 size_t) i=unsigned;; 369 off_t|time_t) i=long;; 370 *) i=int;; 371 esac 372 $PREPARE_CC || exit 373 if $CS -Dt=$t a.c $LS >&2 && $CS_OK 374 then ok=OK a='/* ' z=' */' 375 else ok=$i a= z= 376 fi 377 echo >&3 $ok 378 echo "${a}typedef $i $t;$z" 379done 380 381cat <<'EOF' 382 383/* Comment out the keyword definitions below if the keywords work. */ 384EOF 385 386for i in const volatile 387do 388 $ech >&3 "$0: configuring $i $dots" 389 cat >a.c <<EOF 390# include "$A_H" 391 int main(); 392 enum Boolean { false, true }; 393 int hpux8_05barf(); 394 static enum Boolean $i zero; 395 int hpux8_05barf(x) int x; { return x; } 396 static enum Boolean $i * $i azero = &zero; 397 static enum Boolean $i * $i * $i aazero = &azero; 398 static enum Boolean * $i arzero[1]; 399 static sig_atomic_t $i sigzero; 400 int sco3_2v4barf() { 401 /* SCO 3.2v4 native compiler barfs on this. */ 402 char *t; 403 char $i *s = 0 ? (char *)0 : (char $i *)0; 404 *t++ = '\0'; 405 } 406 int main() { 407 enum Boolean *p = arzero[sigzero]; 408 switch (zero) { 409 case false: exitmain(!p || **aazero); 410 default: exitmain(hpux8_05barf(1)); 411 } 412 } 413EOF 414 a= z= ok='broken' 415 $PREPARE_CC || exit 416 if $CS a.c $LS >&2 && $CS_OK 417 then 418 cat >a.c <<EOF 419 char $i *p; 420 char *q; 421 typedef unsigned char $i *Iptr_type; 422 struct { Iptr_type lim; } s, *f = &s; 423 int main() { 424 Iptr_type lim; 425 lim = f->lim; 426 p = p == q ? p : ""; 427 p = p == "" ? p : q; 428 return !!lim; 429 } 430EOF 431 $PREPARE_CC || exit 432 if $CS a.c $LS >&2 && $CS_OK 433 then 434 case $i in 435 const) 436 # Check for common execv misdeclaration. 437 cat >a.c <<EOF 438# include "$A_H" 439 static char * const *p; 440 int main() { return execv("/bin/sh", p); } 441EOF 442 $PREPARE_CC || exit 443 $CS a.c $LS >&2 && $CS_OK 444 esac && a='/* ' z=' */' ok=OK 445 fi 446 fi 447 echo >&3 $ok 448 echo "$a#define $i$z" 449done 450 451echo >&3 "$0: configuring has_prototypes, has_stdarg, has_varargs, va_start_args $dots" 452cat >a.ha <<'EOF' 453#if has_prototypes 454# define P(params) params 455#else 456# define P(params) () 457#endif 458#if has_stdarg 459# include <stdarg.h> 460#else 461# if has_varargs 462# include <varargs.h> 463# else 464 typedef char *va_list; 465# define va_dcl int va_alist; 466# define va_start(ap) ((ap) = (va_list)&va_alist) 467# define va_arg(ap,t) (((t*) ((ap)+=sizeof(t))) [-1]) 468# define va_end(ap) 469# endif 470#endif 471#if va_start_args == 2 472# define vararg_start va_start 473#else 474# define vararg_start(ap,p) va_start(ap) 475#endif 476EOF 477cat >a.c <<EOF 478#include "$A_H" 479#include "a.ha" 480 481struct buf { int x; }; 482int pairnames P((int,char**,FILE*(*)P((struct buf*,struct stat*,int)),int,int)); /* a la rcsbase.h */ 483FILE *(*rcsopen)P((struct buf*,struct stat*,int)); /* a la rcsfnms.c */ 484 485static char *e(p,i) char **p; int i; { return p[i]; } 486#if has_prototypes 487static char *f(char *(*g)(char**,int), char **p, ...) 488#else 489static char *f(g, p, va_alist) char *(*g)(); char **p; va_dcl 490#endif 491{ 492 char *s; 493 va_list v; 494 vararg_start(v,p); 495 s = g(p, va_arg(v,int)); 496 va_end(v); 497 return s; 498} 499int main P((int, char**)); 500int 501main(argc, argv) int argc; char **argv; { 502 exitmain(f(e,argv,0) != argv[0] || f(e,argv,1) != argv[1]); 503} 504EOF 505for has_prototypes in 1 0 506do 507 for has_stdarg in 1 v 0 508 do 509 case $has_stdarg in 510 1) has_varargs=-1;; 511 v) has_varargs=1 has_stdarg=0;; 512 *) has_varargs=0 513 esac 514 case $has_stdarg in 515 0) as='1 2';; 516 1) as='2 1' 517 esac 518 for va_start_args in $as 519 do 520 $PREPARE_CC || exit 521 $CL \ 522 -Dhas_prototypes=$has_prototypes \ 523 -Dhas_stdarg=$has_stdarg \ 524 -Dhas_varargs=$has_varargs \ 525 -Dva_start_args=$va_start_args \ 526 a.c $L >&2 && $aout && break 527 done && break 528 done && break 529done || { 530 echo >&3 $0: cannot deduce has_prototypes, has_stdarg, va_start_args 531 exit 1 532} 533echo >&3 $has_prototypes, $has_stdarg, $has_varargs, $va_start_args 534case $has_varargs in 535-1) a='/* ' z='*/ ' has_varargs='?';; 536*) a= z= 537esac 538cat - a.ha <<EOF 539 540/* Define boolean symbols to be 0 (false, the default), or 1 (true). */ 541#define has_prototypes $has_prototypes /* Do function prototypes work? */ 542#define has_stdarg $has_stdarg /* Does <stdarg.h> work? */ 543$a#define has_varargs $has_varargs $z/* Does <varargs.h> work? */ 544#define va_start_args $va_start_args /* How many args does va_start() take? */ 545 546#if O_BINARY 547 /* Text and binary i/o behave differently. */ 548 /* This is incompatible with Posix and Unix. */ 549# define FOPEN_RB "rb" 550# define FOPEN_R_WORK (Expand==BINARY_EXPAND ? "r" : "rb") 551# define FOPEN_WB "wb" 552# define FOPEN_W_WORK (Expand==BINARY_EXPAND ? "w" : "wb") 553# define FOPEN_WPLUS_WORK (Expand==BINARY_EXPAND ? "w+" : "w+b") 554# define OPEN_O_BINARY O_BINARY 555#else 556 /* 557 * Text and binary i/o behave the same. 558 * Omit "b", since some nonstandard hosts reject it. 559 */ 560# define FOPEN_RB "r" 561# define FOPEN_R_WORK "r" 562# define FOPEN_WB "w" 563# define FOPEN_W_WORK "w" 564# define FOPEN_WPLUS_WORK "w+" 565# define OPEN_O_BINARY 0 566#endif 567 568/* This may need changing on non-Unix systems (notably DOS). */ 569#define OPEN_CREAT_READONLY (S_IRUSR|S_IRGRP|S_IROTH) /* lock file mode */ 570#define OPEN_O_LOCK 0 /* extra open flags for creating lock file */ 571#define OPEN_O_WRONLY O_WRONLY /* main open flag for creating a lock file */ 572 573/* Define or comment out the following symbols as needed. */ 574EOF 575 576$ech >&3 "$0: configuring bad_chmod_close $dots" 577cat >a.c <<EOF 578#include "$A_H" 579#ifndef O_RDONLY 580# define O_RDONLY 0 581#endif 582int 583main() { 584 int f; 585 exitmain( 586 (f = open("a.c", O_RDONLY)) < 0 || 587 chmod("a.c", 0) != 0 || 588 close(f) != 0 589 ); 590} 591EOF 592$PREPARE_CC || exit 593if $CL a.c $L >&2 && $aout 594then b=0 ok=OK 595else b=1 ok='will work around bug' 596fi 597echo >&3 $ok 598echo "#define bad_chmod_close $b /* Can chmod() close file descriptors? */" 599rm -f a.c || exit 600 601$ech >&3 "$0: configuring bad_creat0 $dots" 602cat >a.c <<EOF 603#include "$A_H" 604#if defined(O_CREAT) && defined(O_WRONLY) 605# define creat0(f) open(f, O_CREAT|O_WRONLY, 0) 606#else 607# define creat0(f) creat(f, 0) 608#endif 609char buf[17000]; 610int 611main() { 612 int f; 613 exitmain( 614 (f = creat0("a.d")) < 0 || 615 write(f, buf, sizeof(buf)) != sizeof(buf) || 616 close(f) != 0 617 ); 618} 619EOF 620$PREPARE_CC a.d || exit 621if $CL a.c $L >&2 && $aout && test -f a.d && test ! -w a.d 622then b=0 ok=OK 623else b=1 ok='will work around bug' 624fi 625echo >&3 $ok 626echo "#define bad_creat0 $b /* Do writes fail after creat(f,0)? */" 627rm -f a.d || exit 628 629$ech >&3 "$0: configuring bad_fopen_wplus $dots" 630cat >a.c <<EOF 631#include "$A_H" 632int main() { exitmain(!fopen("a.d","w+")); } 633EOF 634$PREPARE_CC || exit 635if echo nonempty >a.d && $CL a.c $L >&2 && $aout && test ! -s a.d 636then b=0 ok=OK 637else b=1 ok='will work around bug' 638fi 639echo >&3 $ok 640echo "#define bad_fopen_wplus $b /* Does fopen(f,\"w+\") fail to truncate f? */" 641 642echo "#define getlogin_is_secure 0 /* Is getlogin() secure? Usually it's not. */" 643 644$ech >&3 "$0: configuring has_attribute_noreturn $dots" 645cat >a.c <<EOF 646#include "$A_H" 647static void e P((int)) __attribute__((noreturn)); 648static void e(i) int i; { exit(i); } 649int main() { e(0); } 650EOF 651$PREPARE_CC || exit 652h=0 ok='does not work' 653if out=`$CS a.c $LS 2>&1` 654then 655 case $out in 656 *noreturn*) ;; 657 *) h=1 ok=OK 658 esac 659fi 660echo >&2 "$out" 661echo >&3 $ok 662cat <<EOF 663#define has_attribute_noreturn $h /* Does __attribute__((noreturn)) work? */ 664#if has_attribute_noreturn 665# define exiting __attribute__((noreturn)) 666#else 667# define exiting 668#endif 669EOF 670rm -f a.c || exit 671 672$ech >&3 "$0: configuring has_dirent, void_closedir $dots" 673cat >a.c <<EOF 674#include "$A_H" 675#if void_closedir 676# define close_directory(d) (closedir(d), 0) 677#else 678# define close_directory(d) closedir(d) 679#endif 680int 681main() { 682 DIR *d = opendir("."); 683 struct dirent *e; 684 while ((e = readdir(d))) 685 if (strcmp(e->d_name, "a.c") == 0 && close_directory(d) == 0) 686 exitmain(0); 687 exitmain(1); 688} 689EOF 690$PREPARE_CC || exit 691has_dirent=0 ok='does not work' 692void_closedir=? a='/* ' z='*/ ' 693for v in 0 1 694do 695 if $CL -Dvoid_closedir=$v a.c $L >&2 && $aout 696 then 697 has_dirent=1 ok=OK 698 void_closedir=$v a= z= 699 case $v in 700 1) ok='OK, but closedir yields void' 701 esac 702 break 703 fi 704done 705echo >&3 $ok 706echo "#define has_dirent $has_dirent /* Do opendir(), readdir(), closedir() work? */" 707echo "$a#define void_closedir $void_closedir $z/* Does closedir() yield void? */" 708 709$ech >&3 "$0: configuring has_fchmod $dots" 710cat >a.c <<EOF 711#include "$A_H" 712#ifndef STDIN_FILENO 713#define STDIN_FILENO 0 714#endif 715int main() { exitmain(fchmod(STDIN_FILENO,0) != 0); } 716EOF 717$PREPARE_CC || exit 718if $CL a.c $L >&2 && $aout <a.c && test ! -r a.c 719then h=1 ok=OK 720else h=0 ok='does not work' 721fi 722echo >&3 $ok 723echo "#define has_fchmod $h /* Does fchmod() work? */" 724rm -f a.c || exit 725 726$ech >&3 "$0: configuring has_fflush_input $dots" 727cat >a.c <<EOF 728#include "$A_H" 729#ifndef SEEK_SET 730#define SEEK_SET 0 731#endif 732#ifndef SEEK_CUR 733#define SEEK_CUR 1 734#endif 735#ifndef STDIN_FILENO 736#define STDIN_FILENO 0 737#endif 738int main() { 739 exitmain( 740 getchar() == EOF 741 || fseek(stdin, 0L, SEEK_SET) != 0 742 || fflush(stdin) != 0 743 || lseek(STDIN_FILENO, (off_t)0, SEEK_CUR) != 0 744 ); 745} 746EOF 747$PREPARE_CC || exit 748if $CL a.c $L >&2 && $aout <a.c 749then h=1 ok=OK 750else h=0 ok='does not work' 751fi 752echo >&3 $ok 753echo "#define has_fflush_input $h /* Does fflush() work on input files? */" 754rm -f a.c || exit 755 756$ech >&3 "$0: configuring has_fputs $dots" 757cat >a.c <<EOF 758#include "$A_H" 759int main() { exitmain(fputs("Hello\"\nworld", stdout) < 0); } 760EOF 761Hello='Hello" 762world' 763$PREPARE_CC a.a || exit 764if $CL a.c $L >&2 && $aout >a.a && x=`$aout` && test " $x" = " $Hello" 765then h=1 ok=OK 766else h=0 ok='does not work' 767fi 768echo >&3 $ok 769echo "#define has_fputs $h /* Does fputs() work? */" 770 771$ech >&3 "$0: configuring has_ftruncate $dots" 772cat >a.c <<EOF 773#include "$A_H" 774/* 775 * We'd like to test ftruncate(creat(f,0), 0), 776 * since that's the way RCS uses it, 777 * but a common bug causes it to fail over NFS. 778 * Since we must defend against this bug at run time anyway, 779 * we don't bother to check for it at compile time. 780 * So we test ftruncate(creat(f,0200), 0) instead. 781 */ 782#if defined(O_CREAT) && defined(O_WRONLY) && defined(S_IWUSR) 783# define creat0200(f) open(f, O_CREAT|O_WRONLY, S_IWUSR) 784#else 785# define creat0200(f) creat(f, 0200) 786#endif 787int 788main(argc, argv) int argc; char **argv; { 789 int f = creat0200(argv[1]); 790 if (f<0 || write(f,"abc",3)!=3 || ftruncate(f,(off_t)0)!=0 || close(f)!=0) 791 exitmain(1); 792 exitmain(0); 793} 794EOF 795$PREPARE_CC a.a || exit 796if ($CL a.c $L && $aout a.a && test -w a.a && test ! -s a.a) >&2 797then h=1 ok=OK 798else h=0 ok='does not work' 799fi 800echo >&3 $ok 801echo "#define has_ftruncate $h /* Does ftruncate() work? */" 802 803$ech >&3 "$0: configuring has_getuid $dots" 804cat >a.c <<EOF 805#include "$A_H" 806int main() { exitmain(getuid()!=getuid()); } 807EOF 808$PREPARE_CC || exit 809if ($CL a.c $L && $aout) >&2 810then has_getuid=1 ok=OK 811else has_getuid=0 ok='does not work' 812fi 813echo >&3 $ok 814echo "#define has_getuid $has_getuid /* Does getuid() work? */" 815 816case $has_getuid in 8170) 818 a='/* ' z='*/ ' h=?;; 819*) 820 $ech >&3 "$0: configuring has_getpwuid $dots" 821 a= z= 822 cat >a.c <<EOF 823#include "$A_H" 824int main() { exitmain(!getpwuid(0)); } 825EOF 826 $PREPARE_CC || exit 827 if ($CL a.c $L && $aout) >&2 828 then h=1 ok=OK 829 else h=0 ok='does not work' 830 fi 831 echo >&3 $ok 832esac 833echo "$a#define has_getpwuid $h $z/* Does getpwuid() work? */" 834 835$ech >&3 "$0: configuring has_kill $dots" 836cat >a.c <<EOF 837#include "$A_H" 838int main() { exitmain(kill(getpid(), 0) != 0); } 839EOF 840$PREPARE_CC || exit 841if ($CL a.c $L && $aout) >&2 842then has_kill=1 ok=OK 843else has_kill=0 ok='does not work' 844fi 845echo >&3 $ok 846# Used only by this script, not by RCS, so we don't output it to stdout. 847 848$ech >&3 "$0: configuring has_memcmp $dots" 849cat >a.c <<EOF 850#include "$A_H" 851int main() { exitmain(memcmp("beautiful","beautiful",10) != 0); } 852EOF 853$PREPARE_CC || exit 854if ($CL a.c $L && $aout) >&2 855then h=1 ok=OK 856else h=0 ok='does not work' 857fi 858echo >&3 $ok 859echo "#define has_memcmp $h /* Does memcmp() work? */" 860 861$ech >&3 "$0: configuring has_memcpy $dots" 862cat >a.c <<EOF 863#include "$A_H" 864char a[3]; 865int 866main() { 867 memcpy(a,"xy",3); 868 exitmain(strcmp(a,"xy")!=0); 869} 870EOF 871$PREPARE_CC || exit 872if ($CL a.c $L && $aout) >&2 873then h=1 ok=OK 874else h=0 ok='does not work' 875fi 876echo >&3 $ok 877echo "#define has_memcpy $h /* Does memcpy() work? */" 878 879$ech >&3 "$0: configuring has_memmove $dots" 880cat >a.c <<EOF 881#include "$A_H" 882static char a[4]; 883int 884main() { 885 strcpy(a, "xy"); 886 memmove(a+1, a, 3); 887 exitmain(strcmp(a,"xxy")!=0); 888} 889EOF 890$PREPARE_CC || exit 891if ($CL a.c $L && $aout) >&2 892then h=1 ok=OK 893else h=0 ok='does not work' 894fi 895echo >&3 $ok 896echo "#define has_memmove $h /* Does memmove() work? */" 897 898$ech >&3 "$0: configuring has_map_fd, has_mmap, has_madvise, mmap_signal $dots" 899rm -f a.c a.d a.e || exit 900cat >a.c <<EOF 901#define CHAR1 '#' /* the first character in this file */ 902#include "$A_H" 903static char *a; 904static struct stat b; 905#ifndef MADVISE_OK 906#define MADVISE_OK (madvise(a,b.st_size,MADV_SEQUENTIAL)==0 && madvise(a,b.st_size,MADV_NORMAL)==0) 907#endif 908#ifndef WTERMSIG 909#define WTERMSIG(s) ((s)&0177) 910#undef WIFSIGNALED /* Avoid 4.3BSD incompatibility with Posix. */ 911#endif 912#ifndef WIFSIGNALED 913#define WIFSIGNALED(s) (((s)&0377) != 0177 && WTERMSIG(s) != 0) 914#endif 915#ifndef MAP_FAILED 916#define MAP_FAILED (-1) 917#endif 918#ifndef STDIN_FILENO 919#define STDIN_FILENO 0 920#endif 921int 922main(argc, argv) int argc; char **argv; { 923 int s = 0; 924#if TRY_MAP_FD 925 kern_return_t kr; 926 vm_address_t va; 927#endif 928 929 if (fstat(STDIN_FILENO, &b) != 0) { 930 perror("fstat"); 931 exitmain(1); 932 } 933# if TRY_MAP_FD 934 kr = map_fd(STDIN_FILENO, 0, &va, TRUE, b.st_size); 935 if (kr != KERN_SUCCESS) { 936 mach_error("map_fd", kr); 937 exitmain(1); 938 } 939 a = (char *) va; 940# else 941 a = mmap( 942 (char *)0, b.st_size, PROT_READ, MAP_SHARED, 943 STDIN_FILENO, (off_t)0 944 ); 945 if (a == (char *)MAP_FAILED) { 946 perror("mmap"); 947 exitmain(1); 948 } 949 if (!MADVISE_OK) { 950 perror("madvise"); 951 exitmain(1); 952 } 953# endif 954 if (*a != CHAR1) 955 exitmain(1); 956 if (1 < argc) { 957 pid_t p, w; 958 int f = creat(argv[1], 0); 959 /* 960 * Some buggy hosts yield ETXTBSY if you try to use creat 961 * to truncate a file that is mmapped. On such hosts, 962 * don't bother to try to figure out what mmap_signal is. 963 */ 964# ifndef ETXTBSY 965# define ETXTBSY (-1) 966# endif 967 if (f<0 ? errno!=ETXTBSY : close(f)!=0) { 968 perror(argv[1]); 969 exitmain(1); 970 } 971 if ((p = fork()) < 0) { 972 perror("fork"); 973 exitmain(1); 974 } 975 if (!p) 976 /* Refer to nonexistent storage, causing a signal in the child. */ 977 _exit(a[0] != 0); 978 while ((w = wait(&s)) != p) 979 if (w < 0) { 980 perror("wait"); 981 exitmain(1); 982 } 983 s = WIFSIGNALED(s) ? WTERMSIG(s) : 0; 984 } 985# if TRY_MAP_FD 986 kr = vm_deallocate(task_self(), va, (vm_size_t) b.st_size); 987 if (kr != KERN_SUCCESS) { 988 mach_error("vm_deallocate", kr); 989 exitmain(1); 990 } 991# else 992 if (munmap(a, b.st_size) != 0) { 993 perror("munmap"); 994 exitmain(1); 995 } 996# endif 997 if (1 < argc) { 998# ifdef SIGBUS 999 if (s == SIGBUS) { printf("SIGBUS\n"); s = 0; } 1000# endif 1001# ifdef SIGSEGV 1002 if (s == SIGSEGV) { printf("SIGSEGV\n"); s = 0; } 1003# endif 1004 if (s) printf("%d\n", s); 1005 } 1006 exitmain(ferror(stdout) || fclose(stdout)!=0); 1007} 1008EOF 1009# AIX 3.2.0 read-only mmap updates last-modified time of file! Check for this. 1010sleep 2 1011cp a.c a.d || exit 1012sleep 2 1013has_map_fd=? has_mmap=? has_madvise=? mmap_signal= 1014case `(uname -s -r -v) 2>/dev/null` in 1015'HP-UX '[A-Z].08.07*) ;; 1016 # mmap can crash the OS under HP-UX 8.07, so don't even test for it. 1017'HP-UX '[A-Z].09.*) ;; 1018 # HP-UX 9.0[135]? s700 mmap has a data integrity problem 1019 # when a diskless cnode accesses data on the cnode's server disks. 1020 # We don't know of any way to test whether the bug is present. 1021 # HP patches PHKL_4605 and PHKL_4607 should fix the bug; 1022 # see <http://support.mayfield.hp.com/slx/html/ptc_hpux.html>. 1023 # The above code (perhaps rashly) assumes HP-UX 10 supports mmap. 1024'SunOS 5.4 Generic' | 'SunOS 5.4 Generic_101945-?') ;; 1025 # Early editions of SunOS 5.4 are reported to have problems with mmap 1026 # that generate NUL bytes in RCS files with a Solaris 2.2 NFS server. 1027 # This has been reported to be fixed as of patch 101945-10. 1028*) 1029 $PREPARE_CC || exit 1030 if ($CL -DTRY_MAP_FD=1 a.c $L && $aout <a.c) >&2 1031 then 1032 has_map_fd=1 1033 else 1034 has_map_fd=0 has_mmap=0 has_madvise=0 1035 if ($CL -DMADVISE_OK=1 a.c $L && $aout <a.c) >&2 1036 then 1037 case `ls -t a.c a.d` in 1038 a.d*) 1039 has_mmap=1 1040 rm -f a.ous 1041 mv $aout a.ous 1042 $PREPARE_CC || exit 1043 if ($CL a.c $L && $aout <a.c) >&2 1044 then has_madvise=1; rm -f a.ous 1045 else rm -f $aout && mv a.ous $aout 1046 fi || exit 1047 esac 1048 fi 1049 fi 1050 case $has_map_fd$has_mmap in 1051 *1*) 1052 # Find out what signal is sent to RCS 1053 # when someone unexpectedly truncates a file 1054 # while RCS has it mmapped. 1055 rm -f a.e && cp a.c a.e && 1056 mmap_signal=`$aout a.e <a.e` || exit 1057 esac 1058esac 1059echo >&3 $has_map_fd, $has_mmap, $has_madvise, $mmap_signal 1060case $has_map_fd in 1061'?') a='/* ' z='*/ ';; 1062*) a= z=;; 1063esac 1064echo "$a#define has_map_fd $has_map_fd $z/* Does map_fd() work? */" 1065case $has_mmap in 1066'?') a='/* ' z='*/ ';; 1067*) a= z=;; 1068esac 1069echo "$a#define has_mmap $has_mmap $z/* Does mmap() work on regular files? */" 1070echo "$a#define has_madvise $has_madvise $z/* Does madvise() work? */" 1071case $mmap_signal in 1072?*) a= z=;; 1073'') a='/* ' z='*/ ' mmap_signal='?' 1074esac 1075echo "$a#define mmap_signal $mmap_signal $z/* signal received if you reference nonexistent part of mmapped file */" 1076 1077$ech >&3 "$0: configuring has_rename, bad_a_rename, bad_b_rename $dots" 1078cat >a.c <<EOF 1079#include "$A_H" 1080int main() { exitmain(rename("a.a","a.b") != 0); } 1081EOF 1082echo a >a.a && $PREPARE_CC a.b || exit 1083if ($CL a.c $L && $aout && test -f a.b) >&2 1084then 1085 h=1 1086 rm -f a.a a.b && 1087 echo a >a.a && chmod -w a.a || exit 1088 if $aout && test ! -f a.a && test -f a.b 1089 then a=0 1090 else a=1 1091 fi 1092 rm -f a.a a.b && 1093 echo a >a.a && echo b >a.b && chmod -w a.b || exit 1094 if $aout && test ! -f a.a && test -f a.b 1095 then b=0 1096 else b=1 1097 fi 1098 rm -f a.a a.b || exit 1099else h=0 a=0 b=0 1100fi 1101echo >&3 $h, $a, $b 1102echo "#define has_rename $h /* Does rename() work? */" 1103echo "#define bad_a_rename $a /* Does rename(A,B) fail if A is unwritable? */" 1104echo "#define bad_b_rename $b /* Does rename(A,B) fail if B is unwritable? */" 1105echo "#define bad_NFS_rename 0 /* Can rename(A,B) falsely report success? */" 1106 1107$ech >&3 "$0: configuring void, VOID $dots" 1108cat >a.c <<EOF 1109#include "$A_H" 1110void f() {} 1111int main() {f(); exitmain(0);} 1112EOF 1113$PREPARE_CC || exit 1114if $CS a.c $LS >&2 && $CS_OK 1115then 1116 v='(void) ' 1117 echo '/* typedef int void; */ /* Some ancient compilers need this. */' 1118 ok=OK 1119else 1120 v= 1121 echo 'typedef int void;' 1122 ok='your compiler is a museum piece' 1123fi 1124echo >&3 $ok 1125echo "#define VOID $v/* 'VOID e;' discards the value of an expression 'e'. */" 1126 1127case $has_getuid in 11280) 1129 a='/* ' z='*/ ' has_seteuid=?;; 1130*) 1131 $ech >&3 "$0: configuring has_seteuid $dots" 1132 a= z= 1133 cat >a.c <<EOF 1134#include "$A_H" 1135int 1136main() { 1137/* Guess, don't test. Ugh. Testing would require running conf.sh setuid. */ 1138/* If the guess is wrong, a setuid RCS will detect the problem at runtime. */ 1139#if !_POSIX_VERSION 1140 exitmain(1); 1141#else 1142 exitmain(seteuid(geteuid()) != 0); 1143#endif 1144} 1145EOF 1146 $PREPARE_CC || exit 1147 if ($CL a.c $L && $aout) >&2 1148 then has_seteuid=1 ok='OK, I guess' 1149 else has_seteuid=0 ok='does not work' 1150 fi 1151 echo >&3 $ok 1152esac 1153echo "$a#define has_seteuid $has_seteuid $z/* Does seteuid() work? See ../INSTALL.RCS. */" 1154 1155echo "#define has_setreuid 0 /* Does setreuid() work? See ../INSTALL.RCS. */" 1156 1157$ech >&3 "$0: configuring has_setuid $dots" 1158h=$has_seteuid 1159case $h in 11600) 1161 cat >a.c <<EOF 1162#include "$A_H" 1163int main() { exitmain(setuid(getuid()) != 0); } 1164EOF 1165 $PREPARE_CC || exit 1166 ($CL a.c $L && $aout) >&2 && h=1 ok='OK, I guess' 1167esac 1168echo >&3 $ok 1169echo "$a#define has_setuid $h $z/* Does setuid() exist? */" 1170 1171$ech >&3 "$0: configuring has_sigaction $dots" 1172cat >a.c <<EOF 1173#include "$A_H" 1174static sig_atomic_t volatile gotsig; 1175#ifdef SA_SIGINFO 1176 static void catchsig(i, s, v) int i; siginfo_t *s; void *v; { gotsig = 1; } 1177#else 1178 static void catchsig(i) int i; { gotsig = 1; } 1179#endif 1180int 1181main(argc, argv) int argc; char **argv; { 1182 struct sigaction s; 1183 if (sigaction(SIGINT, (struct sigaction*)0, &s) != 0) 1184 exitmain(1); 1185# if has_sa_sigaction 1186 s.sa_sigaction = catchsig; 1187# else 1188 s.sa_handler = catchsig; 1189# endif 1190# ifdef SA_SIGINFO 1191 s.sa_flags |= SA_SIGINFO; 1192# endif 1193 if (sigaddset(&s.sa_mask, SIGINT) != 0) 1194 exitmain(1); 1195 if (sigaction(SIGINT, &s, (struct sigaction*)0) != 0) 1196 exitmain(1); 1197# if has_kill 1198 kill(getpid(), SIGINT); 1199# else 1200 raise(SIGINT); 1201# endif 1202 exitmain(gotsig != 1); 1203} 1204EOF 1205$PREPARE_CC || exit 1206if ($CL -Dhas_kill=$has_kill a.c $L && $aout) >&2 1207then has_sigaction=1 ok=OK 1208else has_sigaction=0 ok='does not work' 1209fi 1210echo >&3 $ok 1211echo "#define has_sigaction $has_sigaction /* Does struct sigaction work? */" 1212$ech >&3 "$0: configuring has_sa_sigaction $dots" 1213has_sa_sigaction=0 ok='does not work' 1214case $has_sigaction in 12151) 1216 $PREPARE_CC || exit 1217 if ($CL -Dhas_kill=$has_kill -Dhas_sa_sigaction=1 a.c $L && $aout) >&2 1218 then has_sa_sigaction=1 ok=OK 1219 fi 1220esac 1221echo >&3 $ok 1222echo "#define has_sa_sigaction $has_sa_sigaction /* Does struct sigaction have sa_sigaction? */" 1223 1224$ech >&3 "$0: configuring has_signal, signal_type, sig_zaps_handler $dots" 1225case $has_signal,$has_sigaction in 12261,0) 1227 cat >a.c <<EOF 1228#include "$A_H" 1229#if !defined(signal) && declare_signal 1230 signal_type (*signal P((int,signal_type(*)signal_args)))signal_args; 1231#endif 1232static signal_type nothing(i) int i; {} 1233int 1234main(argc, argv) int argc; char **argv; { 1235 signal(SIGINT, nothing); 1236# if has_kill 1237 while (--argc) 1238 kill(getpid(), SIGINT); 1239 exitmain(0); 1240# else 1241 /* Pretend that sig_zaps_handler; better safe than sorry. */ 1242 exitmain(2 < argc); 1243# endif 1244} 1245EOF 1246 for declare_signal in 1 0 1247 do 1248 for signal_type in void int 1249 do 1250 for signal_args in 'P((int))' '()' 1251 do 1252 $PREPARE_CC || exit 1253 ($CL \ 1254 -Ddeclare_signal=$declare_signal \ 1255 -Dhas_kill=$has_kill \ 1256 -Dsignal_args="$signal_args" \ 1257 -Dsignal_type=$signal_type \ 1258 a.c $L && $aout 1) >&2 && break 1259 done && break 1260 done && break 1261 done || { 1262 echo >&3 $0: cannot deduce signal_type 1263 exit 1 1264 } 1265 if $aout 1 2 >&2 1266 then sig_zaps_handler=0 1267 else sig_zaps_handler=1 1268 fi;; 1269*) 1270 signal_type=void 1271 sig_zaps_handler=0 1272esac 1273echo >&3 $has_signal, $signal_type, $sig_zaps_handler 1274cat <<EOF 1275#define has_signal $has_signal /* Does signal() work? */ 1276#define signal_type $signal_type /* type returned by signal handlers */ 1277#define sig_zaps_handler $sig_zaps_handler /* Must a signal handler reinvoke signal()? */ 1278EOF 1279 1280a='/* ' z='*/ ' 1281b='/* ' y='*/ ' 1282case $has_sigaction in 12831) 1284 h=?;; 1285*) 1286 $ech >&3 "$0: configuring has_sigblock, sigmask $dots" 1287 ok=OK 1288 a= z= 1289 cat >a.c <<EOF 1290#include "$A_H" 1291#include <signal.h> 1292#if define_sigmask 1293# define sigmask(s) (1 << ((s)-1)) 1294#endif 1295int 1296main() { 1297 sigblock(sigmask(SIGHUP)); 1298# if has_kill 1299 exitmain(kill(getpid(), SIGHUP) != 0); 1300# else 1301 exitmain(raise(SIGHUP) != 0); 1302# endif 1303} 1304EOF 1305 if 1306 $PREPARE_CC || exit 1307 ($CL -Dhas_kill=$has_kill a.c $L && $aout) >&2 1308 then h=1 1309 elif 1310 $PREPARE_CC || exit 1311 ($CL -Dhas_kill=$has_kill -Ddefine_sigmask=1 a.c $L && $aout) >&2 1312 then h=1 b= y= ok='definition needed' 1313 else h=0 1314 fi 1315 echo >&3 "$h, $ok" 1316esac 1317echo "$a#define has_sigblock $h $z/* Does sigblock() work? */" 1318echo "$b#define sigmask(s) (1 << ((s)-1)) $y/* Yield mask for signal number. */" 1319 1320$ech >&3 "$0: configuring fread_type, freadarg_type $dots" 1321cat >a.c <<EOF 1322#define CHAR1 '#' /* the first character in this file */ 1323#include "$A_H" 1324#if !defined(fread) && declare_fread 1325 fread_type fread P((void*,freadarg_type,freadarg_type,FILE*)); 1326#endif 1327int 1328main() { 1329 char b; 1330 exitmain(!( 1331 fread(&b, (freadarg_type)1, (freadarg_type)1, stdin) == 1 && 1332 b==CHAR1 1333 )); 1334} 1335EOF 1336for declare_fread in 1 0 1337do 1338 for fread_type in ssize_t size_t int unsigned 1339 do 1340 for freadarg_type in size_t ssize_t unsigned int 1341 do 1342 $PREPARE_CC || exit 1343 ( 1344 $CL \ 1345 -Ddeclare_fread=$declare_fread \ 1346 -Dfreadarg_type=$freadarg_type \ 1347 -Dfread_type=$fread_type \ 1348 a.c $L && 1349 $aout <a.c 1350 ) >&2 && break 1351 done && break 1352 done && break 1353done || { 1354 echo >&3 $0: cannot deduce fread types 1355 exit 1 1356} 1357echo >&3 $fread_type, $freadarg_type 1358cat <<EOF 1359typedef $fread_type fread_type; /* type returned by fread() and fwrite() */ 1360typedef $freadarg_type freadarg_type; /* type of their size arguments */ 1361EOF 1362 1363$ech >&3 "$0: configuring malloc_type $dots" 1364cat >a.c <<EOF 1365#include "$A_H" 1366typedef void *malloc_type; 1367#ifndef malloc 1368 malloc_type malloc(); 1369#endif 1370static malloc_type identity P((malloc_type)); 1371static malloc_type identity(x) malloc_type x; { return x; } 1372int main() { exitmain(!identity(malloc(1))); } 1373EOF 1374$PREPARE_CC || exit 1375if $CS a.c $LS >&2 && $CS_OK 1376then t=void 1377else t=char 1378fi 1379echo >&3 $t 1380echo "typedef $t *malloc_type; /* type returned by malloc() */" 1381 1382$ech >&3 "$0: configuring has_getcwd $dots" 1383cat >a.c <<EOF 1384#include "$A_H" 1385#ifndef getcwd 1386 char *getcwd(); 1387#endif 1388static char buf[10000]; 1389int main() { exitmain(!getcwd(buf,10000)); } 1390EOF 1391$PREPARE_CC || exit 1392if ($CL a.c $L && $aout) >&2 1393then has_getcwd=1 ok=OK 1394else has_getcwd=0 ok='does not work' 1395fi 1396echo >&3 $ok 1397echo "#define has_getcwd $has_getcwd /* Does getcwd() work? */" 1398 1399case $has_getcwd in 14001) 1401 a='/* ' z='*/ ' h=?;; 1402*) 1403 a= z= 1404 $ech >&3 "$0: configuring has_getwd $dots" 1405 cat >a.c <<EOF 1406#include "$A_H" 1407#include <sys/param.h> 1408#ifndef getwd 1409 char *getwd(); 1410#endif 1411static char buf[MAXPATHLEN]; 1412int main() { exitmain(!getwd(buf)); } 1413EOF 1414 $PREPARE_CC || exit 1415 if ($CL a.c $L && $aout) >&2 1416 then h=1 ok=OK 1417 else h=0 ok='does not work' 1418 fi 1419 echo >&3 $ok 1420esac 1421echo "$a#define has_getwd $h $z/* Does getwd() work? */" 1422echo "#define needs_getabsname 0 /* Must we define getabsname? */" 1423 1424$ech >&3 "$0: configuring has_mktemp $dots" 1425cat >a.c <<EOF 1426#include "$A_H" 1427#ifndef mktemp 1428 char *mktemp(); 1429#endif 1430int 1431main() { 1432 char b[9]; 1433 strcpy(b, "a.XXXXXX"); 1434 exitmain(!mktemp(b)); 1435} 1436EOF 1437$PREPARE_CC || exit 1438if ($CL a.c $L && $aout) >&2 1439then h=1 ok=OK 1440else h=0 ok=absent 1441fi 1442echo >&3 $ok 1443echo "#define has_mktemp $h /* Does mktemp() work? */" 1444 1445: configuring has_NFS 1446echo "#define has_NFS 1 /* Might NFS be used? */" 1447 1448case $has_signal,$has_sigaction in 14491,0) 1450 has_psiginfo=0;; 1451*) 1452 $ech >&3 "$0: configuring has_psiginfo $dots" 1453 cat >a.c <<EOF 1454#include "$A_H" 1455static signal_type 1456catchsig(s, i, c) int s; siginfo_t *i; void *c; { 1457 if (i) 1458 psiginfo(i, "test"); 1459 exit(0); 1460} 1461int 1462main() { 1463 struct sigaction s; 1464 if (sigaction(SIGINT, (struct sigaction*)0, &s) != 0) 1465 exitmain(1); 1466# if has_sa_sigaction 1467 s.sa_sigaction = catchsig; 1468# else 1469 s.sa_handler = catchsig; 1470# endif 1471 if (sigaddset(&s.sa_mask, SIGINT) != 0) 1472 exitmain(1); 1473 s.sa_flags |= SA_SIGINFO; 1474 if (sigaction(SIGINT, &s, (struct sigaction*)0) != 0) 1475 exitmain(1); 1476# if has_kill 1477 kill(getpid(), SIGINT); 1478# else 1479 raise(SIGINT); 1480# endif 1481 exitmain(1); 1482} 1483EOF 1484 $PREPARE_CC || exit 1485 if ($CL a.c $L && $aout) >&2 1486 then has_psiginfo=1 ok=OK 1487 else has_psiginfo=0 ok=absent 1488 fi 1489 echo >&3 $ok 1490esac 1491echo "#define has_psiginfo $has_psiginfo /* Does psiginfo() work? */" 1492 1493case $has_signal in 14941) 1495 $ech >&3 "$0: configuring has_psignal $dots" 1496 cat >a.c <<EOF 1497#include "$A_H" 1498int main() { psignal(SIGINT, ""); exitmain(0); } 1499EOF 1500 $PREPARE_CC || exit 1501 if ($CL a.c $L && $aout) >&2 1502 then has_psignal=1 ok=OK 1503 else has_psignal=0 ok=absent 1504 fi 1505 echo >&3 $ok;; 1506*) has_psignal=0 1507esac 1508echo "#define has_psignal $has_psignal /* Does psignal() work? */" 1509 1510case $has_psiginfo in 15111) 1512 $ech >&3 "$0: configuring has_si_errno $dots" 1513 cat >a.c <<EOF 1514#include "$A_H" 1515siginfo_t a; 1516int main() { exitmain(a.si_errno); } 1517EOF 1518 $PREPARE_CC || exit 1519 if $CS a.c $LS >&2 && $CS_OK 1520 then h=1 ok=OK 1521 else h=0 ok=absent 1522 fi 1523 echo >&3 $ok 1524 a= z=;; 1525*) h=? a='/* ' z='*/ ' 1526esac 1527echo "$a#define has_si_errno $h $z/* Does siginfo_t have si_errno? */" 1528 1529case $has_signal,$has_psignal in 15301,0) 1531 $ech >&3 "$0: configuring has_sys_siglist $dots" 1532 cat >a.c <<EOF 1533#include "$A_H" 1534#if !defined(sys_siglist) && declare_sys_siglist 1535 extern char const * const sys_siglist[]; 1536#endif 1537int main() { exitmain(!sys_siglist[1][0]); } 1538EOF 1539 $PREPARE_CC || exit 1540 h=0 ok=absent 1541 for d in 1 0 1542 do ($CL -Ddeclare_sys_siglist=$d a.c $L && $aout) >&2 && 1543 h=1 && ok=OK && break 1544 done 1545 echo >&3 $ok 1546 a= z=;; 1547*) h=? a='/* ' z='*/ ' 1548esac 1549echo "$a#define has_sys_siglist $h $z/* Does sys_siglist[] work? */" 1550 1551$ech >&3 "$0: configuring strchr $dots" 1552cat >a.c <<EOF 1553#include "$A_H" 1554#ifndef strchr 1555 char *strchr(); 1556#endif 1557int main() {exitmain(!strchr("abc", 'c'));} 1558EOF 1559$PREPARE_CC || exit 1560if ($CL a.c $L && $aout) >&2 1561then a='/* ' z='*/ ' ok=OK 1562else a= z= ok='does not work' 1563fi 1564echo >&3 $ok 1565echo "$a#define strchr index $z/* Use old-fashioned name for strchr()? */" 1566 1567$ech >&3 "$0: configuring strrchr $dots" 1568cat >a.c <<EOF 1569#include "$A_H" 1570#ifndef strrchr 1571 char *strrchr(); 1572#endif 1573int main() {exitmain(!strrchr("abc", 'c'));} 1574EOF 1575$PREPARE_CC || exit 1576if ($CL a.c $L && $aout) >&2 1577then a='/* ' z='*/ ' ok=OK 1578else a= z= ok='does not work' 1579fi 1580echo >&3 $ok 1581echo "$a#define strrchr rindex $z/* Use old-fashioned name for strrchr()? */" 1582 1583$ech >&3 "$0: configuring bad_unlink $dots" 1584cat >a.c <<EOF 1585#include "$A_H" 1586int main() { exitmain(unlink("a.c") != 0); } 1587EOF 1588$PREPARE_CC && chmod -w a.c || exit 1589if ($CL a.c $L && $aout) >&2 && test ! -f a.c 1590then b=0 ok=OK 1591else b=1 ok='will work around bug' 1592fi 1593rm -f a.c || exit 1594echo >&3 $ok 1595echo "#define bad_unlink $b /* Does unlink() fail on unwritable files? */" 1596 1597$ech >&3 "$0: configuring has_vfork $dots" 1598cat >a.c <<EOF 1599#include "$A_H" 1600#ifndef STDOUT_FILENO 1601#define STDOUT_FILENO 1 1602#endif 1603#if !TRY_VFORK 1604# undef vfork 1605# define vfork fork 1606#endif 1607#if !TRY_WAITPID 1608# undef waitpid 1609# define waitpid(p,s,o) wait(s) 1610#endif 1611 1612int 1613main() { 1614 pid_t parent = getpid(); 1615 pid_t child = vfork(); 1616 1617 if (child == 0) { 1618 /* 1619 * On sparc systems, changes by the child to local and incoming 1620 * argument registers are propagated back to the parent. 1621 * The compiler is told about this with #include <vfork.h>, 1622 * but some compilers (e.g. gcc -O) don't grok <vfork.h>. 1623 * Test for this by using lots of local variables, at least 1624 * as many local variables as 'main' has allocated so far 1625 * including compiler temporaries. 4 locals are enough for 1626 * gcc 1.40.3 on a sparc, but we use 8 to be safe. 1627 * A buggy compiler should reuse the register of 'parent' 1628 * for one of the local variables, since it will think that 1629 * 'parent' can't possibly be used any more in this routine. 1630 * Assigning to the local variable will thus munge 'parent' 1631 * in the parent process. 1632 */ 1633 pid_t 1634 p = getpid(), 1635 p1 = getpid(), p2 = getpid(), 1636 p3 = getpid(), p4 = getpid(), 1637 p5 = getpid(), p6 = getpid(), 1638 p7 = getpid(); 1639 /* 1640 * Convince the compiler that p..p7 are live; otherwise, it might 1641 * use the same hardware register for all 8 local variables. 1642 */ 1643 if (p!=p1 || p!=p2 || p!=p3 || p!=p4 || p!=p5 || p!=p6 || p!=p7) 1644 _exit(1); 1645 1646 /* 1647 * On some systems (e.g. IRIX 3.3), 1648 * vfork doesn't separate parent from child file descriptors. 1649 * If the child closes a descriptor before it execs or exits, 1650 * this munges the parent's descriptor as well. 1651 * Test for this by closing stdout in the child. 1652 */ 1653 _exit(close(STDOUT_FILENO) != 0); 1654 1655 } else { 1656 int status; 1657 struct stat st; 1658 exit( 1659 /* Was there some problem with vforking? */ 1660 child < 0 1661 1662 /* Was there some problem in waiting for the child? */ 1663 || waitpid(child, &status, 0) != child 1664 1665 /* Did the child fail? (This shouldn't happen.) */ 1666 || status 1667 1668 /* Did the vfork/compiler bug occur? */ 1669 || parent != getpid() 1670 1671 /* Did the file descriptor bug occur? */ 1672 || fstat(STDOUT_FILENO, &st) != 0 1673 ); 1674 } 1675} 1676EOF 1677$PREPARE_CC || exit 1678if ($CL -DTRY_VFORK=1 a.c $L && $aout) >&2 1679then has_vfork=1 ok=OK 1680else has_vfork=0 ok='absent or broken' 1681fi 1682echo >&3 $ok 1683echo "#define has_vfork $has_vfork /* Does vfork() work? */" 1684h=$has_vfork 1685case $h in 16860) 1687 $ech >&3 "$0: configuring has_fork $dots" 1688 $PREPARE_CC || exit 1689 ok='does not work' 1690 ($CL a.c $L && $aout) >&2 && h=1 ok=OK 1691 echo >&3 $ok 1692esac 1693echo "#define has_fork $h /* Does fork() work? */" 1694$PREPARE_CC || exit 1695$ech >&3 "$0: configuring has_waitpid $dots" 1696if ($CL -DTRY_VFORK=$has_vfork -DTRY_WAITPID=1 a.c $L && $aout) >&2 1697then h=1 ok=OK 1698else h=0 ok='does not work' 1699fi 1700echo >&3 $ok 1701echo "#define has_spawn 0 /* Does spawn*() work? */" 1702echo "#define has_waitpid $h /* Does waitpid() work? */" 1703 1704$ech >&3 "$0: configuring bad_wait_if_SIGCHLD_ignored $dots" 1705cat >a.c <<EOF 1706#include "$A_H" 1707#ifndef SIGCHLD 1708#define SIGCHLD SIGCLD 1709#endif 1710int main() { 1711 signal(SIGCHLD, SIG_IGN); 1712 { 1713# if has_fork 1714 int status; 1715 pid_t p = fork(); 1716 if (p < 0) { 1717 perror("fork"); 1718 exitmain(2); 1719 } 1720 if (p == 0) 1721 _exit(0); 1722 while (wait(&status) != p) { 1723 if (errno == ECHILD) 1724 exitmain(1); 1725 if (errno != EINTR) { 1726 perror("wait"); 1727 exitmain(2); 1728 } 1729 } 1730# else 1731# if has_system 1732 if (system("true") != 0) 1733 exitmain(1); 1734# endif 1735# endif 1736 } 1737 exitmain(0); 1738} 1739EOF 1740$PREPARE_CC || exit 1741b=0 ok=OK 1742if $CL a.c $L >&2 1743then 1744 $aout >&2 1745 case $? in 1746 0) ;; 1747 1) b=1 ok='will work around bug';; 1748 *) exit 1749 esac 1750fi 1751rm -f a.c || exit 1752echo >&3 $ok 1753echo "#define bad_wait_if_SIGCHLD_ignored $b /* Does ignoring SIGCHLD break wait()? */" 1754 1755 1756echo '#define RCS_SHELL "/bin/sh" /* shell to run RCS subprograms */' 1757 1758$ech >&3 "$0: configuring has_printf_dot $dots" 1759cat >a.c <<EOF 1760#include "$A_H" 1761int main() { printf("%.2d", 1); exitmain(ferror(stdout) || fclose(stdout)!=0); } 1762EOF 1763$PREPARE_CC && $CL a.c $L >&2 && r=`$aout` || exit 1764case $r in 176501) h=1 ok=OK;; 1766*) h=0 ok='does not work' 1767esac 1768echo >&3 $ok 1769echo "#define has_printf_dot $h /* Does \"%.2d\" print leading 0? */" 1770 1771$ech >&3 "$0: configuring has_vfprintf, has_attribute_format_printf $dots" 1772cat >a.c <<EOF 1773#include "$A_H" 1774#if has_attribute_format_printf 1775# define printf_string(m, n) __attribute__((format(printf, m, n))) 1776#else 1777# define printf_string(m, n) 1778#endif 1779int p P((char const*,...)) printf_string(1, 2); 1780#if has_prototypes 1781int p(char const*format,...) 1782#else 1783/*VARARGS1*/ int p(format, va_alist) char *format; va_dcl 1784#endif 1785{ 1786 int r; 1787 va_list args; 1788 vararg_start(args, format); 1789 r = vfprintf(stderr, format, args); 1790 va_end(args); 1791 return r; 1792} 1793int main() { exitmain(p("hello") != 5); } 1794EOF 1795$PREPARE_CC || exit 1796h=0 p=0 1797if ($CL a.c $L && sh -c 'pid=$$; (sleep 3; kill $pid)& exec '$aout) >&2 1798then 1799 h=1 1800 $PREPARE_CC || exit 1801 $CS -Dhas_attribute_format_printf=1 a.c >&2 && $CS_OK && p=1 1802else 1803 status=$? 1804 sh -c 'pid=$$; (sleep 3; kill $pid)& exec sleep 6' >&2 1805 if test $? = $status 1806 then 1807 echo >&3 "$0: stdio library loops forever. Giving up. 1808$0: (Perhaps you are using Solaris 2.x /usr/ucb/cc?) 1809$0: Please use a working stdio library instead." 1810 exit 1 1811 fi 1812fi 1813echo >&3 $h, $p 1814cat <<EOF 1815#define has_vfprintf $h /* Does vfprintf() work? */ 1816#define has_attribute_format_printf $p /* Does __attribute__((format(printf,N,N+1))) work? */ 1817#if has_attribute_format_printf 1818# define printf_string(m, n) __attribute__((format(printf, m, n))) 1819#else 1820# define printf_string(m, n) 1821#endif 1822#if has_attribute_format_printf && has_attribute_noreturn 1823 /* Work around a bug in GCC 2.5.x. */ 1824# define printf_string_exiting(m, n) __attribute__((format(printf, m, n), noreturn)) 1825#else 1826# define printf_string_exiting(m, n) printf_string(m, n) exiting 1827#endif 1828EOF 1829 1830case $h in 18311) 1832 h=? a='/* ' z='*/ ';; 1833*) 1834 $ech >&3 "$0: configuring has__doprintf $dots" 1835 a= z= 1836 cat >a.c <<EOF 1837#include "$A_H" 1838#if has_prototypes 1839static int 1840p(char const*format,...) 1841#else 1842/*VARARGS1*/ static int p(format, va_alist) char *format; va_dcl 1843#endif 1844{ 1845 va_list args; 1846 vararg_start(args, format); 1847# if TRY__DOPRINTF 1848 _doprintf(stderr, format, args); 1849# else 1850 _doprnt(format, args, stderr); 1851# endif 1852 va_end(args); 1853} 1854int main() { p(""); exitmain(0); } 1855EOF 1856 $PREPARE_CC || exit 1857 if ($CL -DTRY__DOPRINTF=1 a.c $L && $aout) >&2 1858 then h=1 ok=OK 1859 else h=0 ok='does not work' 1860 fi 1861 echo >&3 $ok 1862esac 1863echo "$a#define has__doprintf $h $z/* Does _doprintf() work? */" 1864case $h in 18650) 1866 $ech >&3 "$0: configuring has__doprnt $dots" 1867 $PREPARE_CC || exit 1868 if ($CL a.c $L && $aout) >&2 1869 then h=1 ok=OK 1870 else h=0 ok='does not work' 1871 fi 1872 echo >&3 $ok 1873 a= z=;; 1874*) 1875 h=? a='/* ' z='*/ ' 1876esac 1877echo "$a#define has__doprnt $h $z/* Does _doprnt() work? */" 1878 1879$ech >&3 "$0: configuring EXIT_FAILURE $dots" 1880cat >a.c <<EOF 1881#include "$A_H" 1882int main() { exitmain(EXIT_FAILURE); } 1883EOF 1884$PREPARE_CC || exit 1885if $CL a.c $L >&2 && $aout 1886then a= z= ok='will work around bug' 1887else a='/* ' z='*/ ' ok=OK 1888fi 1889echo >&3 $ok 1890echo "$a#undef EXIT_FAILURE $z/* Uncomment this if EXIT_FAILURE is broken. */" 1891 1892: configuring large_memory 1893case "$has_map_fd$has_mmap" in 1894*1*) l=1;; 1895*) l=0 1896esac 1897echo "#define large_memory $l /* Can main memory hold entire RCS files? */" 1898 1899$ech >&3 "$0: configuring LONG_MAX $dots" 1900cat >a.c <<EOF 1901#include "$A_H" 1902static unsigned long ulong_max; 1903static long long_max; 1904int 1905main() { 1906 ulong_max--; 1907 long_max = ulong_max >> 1; 1908 printf("#ifndef LONG_MAX\n"); 1909 printf("#define LONG_MAX %ldL /* long maximum */\n", long_max); 1910 printf("#endif\n"); 1911 exitmain(ferror(stdout) || fclose(stdout)!=0); 1912} 1913EOF 1914$PREPARE_CC && $CL a.c $L >&2 && $aout || exit 1915echo >&3 OK 1916 1917: configuring same_file 1918echo "/* Do struct stat s and t describe the same file? Answer d if unknown. */" 1919echo "#define same_file(s,t,d) ((s).st_ino==(t).st_ino && (s).st_dev==(t).st_dev)" 1920 1921$ech >&3 "$0: configuring struct utimbuf $dots" 1922cat >a.c <<EOF 1923#include "$A_H" 1924static struct utimbuf s; 1925int main() { s.actime = s.modtime = 1; exitmain(utime("a.c", &s) != 0); } 1926EOF 1927$PREPARE_CC || exit 1928if ($CL a.c $L && $aout) >&2 1929then h=1 ok=OK 1930else h=0 ok='does not work' 1931fi 1932echo >&3 $ok 1933echo "#define has_utimbuf $h /* Does struct utimbuf work? */" 1934 1935: configuring CO 1936echo "#define CO \"${RCSPREFIX}co\" /* name of 'co' program */" 1937 1938: configuring COMPAT2 1939echo "#define COMPAT2 $COMPAT2 /* Are version 2 files supported? */" 1940 1941: configuring DIFF 1942echo "#define DIFF \"${DIFF}\" /* name of 'diff' program */" 1943 1944: configuring DIFF3 1945echo "#define DIFF3 \"${DIFF3}\" /* name of 'diff3' program */" 1946 1947: configuring DIFF3_BIN 1948echo "#define DIFF3_BIN $DIFF3_BIN /* Is diff3 user-visible (not the /usr/lib auxiliary)? */" 1949 1950: configuring DIFFFLAGS 1951echo "#define DIFFFLAGS \"$DIFFFLAGS\" /* Make diff output suitable for RCS. */" 1952 1953: configuring DIFF_L 1954echo "#define DIFF_L $DIFF_L /* Does diff -L work? */" 1955 1956: configuring DIFF_SUCCESS, DIFF_FAILURE, DIFF_TROUBLE 1957cat <<EOF 1958#define DIFF_SUCCESS $DIFF_SUCCESS /* DIFF status if no differences are found */ 1959#define DIFF_FAILURE $DIFF_FAILURE /* DIFF status if differences are found */ 1960#define DIFF_TROUBLE $DIFF_TROUBLE /* DIFF status if trouble */ 1961EOF 1962 1963: configuring ED 1964echo "#define ED \"${ED}\" /* name of 'ed' program (used only if !DIFF3_BIN) */" 1965 1966: configuring MERGE 1967echo "#define MERGE \"${RCSPREFIX}merge\" /* name of 'merge' program */" 1968 1969: configuring '*SLASH*', ROOTPATH, TMPDIR, X_DEFAULT 1970case ${PWD-`pwd`} in 1971/*) # Posix 1972 SLASH=/ 1973 qSLASH="'/'" 1974 SLASHes=$qSLASH 1975 isSLASH='#define isSLASH(c) ((c) == SLASH)' 1976 ROOTPATH='isSLASH((p)[0])' 1977 X_DEFAULT=",v$SLASH";; 1978?:[/\\\\]*) # MS-DOS # \\\\ instead of \\ doesn't hurt, and avoids common bugs 1979 SLASH='\' 1980 qSLASH="'\\\\'" 1981 SLASHes="$qSLASH: case '/': case ':'" 1982 isSLASH='int isSLASH P((int));' 1983 ROOTPATH="(isSLASH((p)[0]) || (p)[0] && (p)[1]==':')" 1984 X_DEFAULT="$SLASH,v";; 1985*) 1986 echo >&3 $0: cannot deduce SLASH 1987 exit 1 1988esac 1989cat <<EOF 1990#define TMPDIR "${SLASH}tmp" /* default directory for temporary files */ 1991#define SLASH $qSLASH /* principal filename separator */ 1992#define SLASHes $SLASHes /* \`case SLASHes:' labels all filename separators */ 1993$isSLASH /* Is arg a filename separator? */ 1994#define ROOTPATH(p) $ROOTPATH /* Is p an absolute pathname? */ 1995#define X_DEFAULT "$X_DEFAULT" /* default value for -x option */ 1996EOF 1997 1998$ech >&3 "$0: configuring SLASHSLASH_is_SLASH $dots" 1999cat >a.c <<EOF 2000#include "$A_H" 2001static struct stat s, ss; 2002static char f[3]; 2003int 2004main() { 2005 f[0] = SLASH; if (stat(f, &s ) != 0) exitmain(1); 2006 f[1] = SLASH; if (stat(f, &ss) != 0) exitmain(1); 2007 exitmain(!same_file(s, ss, 0)); 2008} 2009EOF 2010$PREPARE_CC || exit 2011if ($CL a.c $L && $aout) >&2 2012then eq=1 ok=OK 2013else eq=0 ok=no 2014fi 2015echo >&3 $ok 2016echo "#define SLASHSLASH_is_SLASH $eq /* Are // and / the same directory? */" 2017 2018$ech >&3 "$0: configuring ALL_ABSOLUTE, DIFF_ABSOLUTE $dots" 2019cat >a.c <<EOF 2020#include "$A_H" 2021#ifndef isSLASH 2022static int 2023isSLASH(c) int c; { 2024 switch (c) { case SLASHes: return 1; } return 0; 2025} 2026#endif 2027int 2028main(argc, argv) int argc; char **argv; { 2029 exitmain(1<argc && !ROOTPATH(argv[1])); 2030} 2031EOF 2032$PREPARE_CC && ($CL a.c $L && $aout) >&2 || exit 2033a=1 2034for i in "$DIFF" "$DIFF3" "$ED" "$RCSPREFIX" "$SENDMAIL" 2035do 2036 case $i in 2037 \"*\") i=`expr "$i" : '"\(.*\)"'` 2038 esac 2039 case $i in 2040 ?*) $aout "$i" || { a=0; break; } 2041 esac 2042done 2043echo "#define ALL_ABSOLUTE $a /* Do all subprograms satisfy ROOTPATH? */" 2044if $aout "$DIFF" 2045then a=1 2046else a=0 2047fi 2048echo "#define DIFF_ABSOLUTE $a /* Is ROOTPATH(DIFF) true? */" 2049echo >&3 OK 2050 2051: configuring SENDMAIL 2052case $SENDMAIL in 2053'') a='/* ' z='*/ ';; 2054*) a= z= 2055esac 2056echo "$a#define SENDMAIL $SENDMAIL $z/* how to send mail */" 2057 2058: configuring TZ_must_be_set 2059echo "#define TZ_must_be_set 0 /* Must TZ be set for gmtime() to work? */" 2060 2061 2062$ech >&3 "$0: configuring standard library declarations $dots" 2063 2064cat <<'EOF' 2065 2066 2067 2068/* Adjust the following declarations as needed. */ 2069EOF 2070 2071cat >a.ha <<EOF 2072 2073 2074/* The rest is for the benefit of non-standard, traditional hosts. */ 2075/* Don't bother to declare functions that in traditional hosts do not appear, */ 2076/* or are declared in .h files, or return int or void. */ 2077 2078 2079/* traditional BSD */ 2080 2081#if has_sys_siglist && !defined(sys_siglist) 2082 extern char const * const sys_siglist[]; 2083#endif 2084 2085 2086/* Posix (ISO/IEC 9945-1: 1990 / IEEE Std 1003.1-1990) */ 2087 2088/* <fcntl.h> */ 2089#ifdef O_CREAT 2090# define open_can_creat 1 2091#else 2092# define open_can_creat 0 2093# define O_RDONLY 0 2094# define O_WRONLY 1 2095# define O_RDWR 2 2096# define O_CREAT 01000 2097# define O_TRUNC 02000 2098#endif 2099#ifndef O_EXCL 2100#define O_EXCL 0 2101#endif 2102 2103/* <sys/stat.h> */ 2104#ifndef S_IRUSR 2105# ifdef S_IREAD 2106# define S_IRUSR S_IREAD 2107# else 2108# define S_IRUSR 0400 2109# endif 2110# ifdef S_IWRITE 2111# define S_IWUSR S_IWRITE 2112# else 2113# define S_IWUSR (S_IRUSR/2) 2114# endif 2115#endif 2116#ifndef S_IRGRP 2117# if has_getuid 2118# define S_IRGRP (S_IRUSR / 0010) 2119# define S_IWGRP (S_IWUSR / 0010) 2120# define S_IROTH (S_IRUSR / 0100) 2121# define S_IWOTH (S_IWUSR / 0100) 2122# else 2123 /* single user OS -- not Posix or Unix */ 2124# define S_IRGRP 0 2125# define S_IWGRP 0 2126# define S_IROTH 0 2127# define S_IWOTH 0 2128# endif 2129#endif 2130#ifndef S_ISREG 2131#define S_ISREG(n) (((n) & S_IFMT) == S_IFREG) 2132#endif 2133 2134/* <sys/wait.h> */ 2135#ifndef WEXITSTATUS 2136#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) 2137#undef WIFEXITED /* Avoid 4.3BSD incompatibility with Posix. */ 2138#endif 2139#ifndef WIFEXITED 2140#define WIFEXITED(stat_val) (((stat_val) & 0377) == 0) 2141#endif 2142#ifndef WTERMSIG 2143#define WTERMSIG(stat_val) ((stat_val) & 0177) 2144#undef WIFSIGNALED /* Avoid 4.3BSD incompatibility with Posix. */ 2145#endif 2146#ifndef WIFSIGNALED 2147#define WIFSIGNALED(stat_val) ((unsigned)(stat_val) - 1 < 0377) 2148#endif 2149 2150/* <unistd.h> */ 2151char *getlogin P((void)); 2152#ifndef STDIN_FILENO 2153# define STDIN_FILENO 0 2154# define STDOUT_FILENO 1 2155# define STDERR_FILENO 2 2156#endif 2157#if has_fork && !has_vfork 2158# undef vfork 2159# define vfork fork 2160#endif 2161#if has_getcwd || !has_getwd 2162 char *getcwd P((char*,size_t)); 2163#else 2164 char *getwd P((char*)); 2165#endif 2166#if has_setuid && !has_seteuid 2167# undef seteuid 2168# define seteuid setuid 2169#endif 2170#if has_spawn 2171# if ALL_ABSOLUTE 2172# define spawn_RCS spawnv 2173# else 2174# define spawn_RCS spawnvp 2175# endif 2176#else 2177# if ALL_ABSOLUTE 2178# define exec_RCS execv 2179# else 2180# define exec_RCS execvp 2181# endif 2182#endif 2183 2184/* utime.h */ 2185#if !has_utimbuf 2186 struct utimbuf { time_t actime, modtime; }; 2187#endif 2188 2189 2190/* Standard C library */ 2191 2192/* <stdio.h> */ 2193#ifndef L_tmpnam 2194#define L_tmpnam 32 /* power of 2 > sizeof("/usr/tmp/xxxxxxxxxxxxxxx") */ 2195#endif 2196#ifndef SEEK_SET 2197#define SEEK_SET 0 2198#endif 2199#ifndef SEEK_CUR 2200#define SEEK_CUR 1 2201#endif 2202#if has_mktemp 2203 char *mktemp P((char*)); /* traditional */ 2204#else 2205 char *tmpnam P((char*)); 2206#endif 2207 2208/* <stdlib.h> */ 2209char *getenv P((char const*)); 2210void _exit P((int)) exiting; 2211void exit P((int)) exiting; 2212malloc_type malloc P((size_t)); 2213malloc_type realloc P((malloc_type,size_t)); 2214#ifndef EXIT_FAILURE 2215#define EXIT_FAILURE 1 2216#endif 2217#ifndef EXIT_SUCCESS 2218#define EXIT_SUCCESS 0 2219#endif 2220 2221/* <string.h> */ 2222char *strcpy P((char*,char const*)); 2223char *strchr P((char const*,int)); 2224char *strrchr P((char const*,int)); 2225void *memcpy P((void*,void const*,size_t)); 2226#if has_memmove 2227 void *memmove P((void*,void const*,size_t)); 2228#endif 2229 2230/* <time.h> */ 2231time_t time P((time_t*)); 2232EOF 2233 2234cat >a.c <<EOF 2235#include "$A_H" 2236#define a 0 2237#define b 1 2238#if H==a 2239# include "a.ha" 2240#else 2241# include "a.hb" 2242#endif 2243int main() { exitmain(0); } 2244EOF 2245 2246# Comment out lines in a.ha that the compiler rejects. 2247# a.ha may not contain comments that cross line boundaries. 2248# Leave the result in a.h$H. 2249H=a L=1 2250U=`wc -l <a.ha | sed 's| ||g'` 2251commentOut='s|^[^#/][^/]*|/* & */|' 2252 2253until 2254 test $U -lt $L || 2255 { $PREPARE_CC || exit; $CS -DH=$H a.c $LS >&2 && $CS_OK; } 2256do 2257 case $H in 2258 a) I=b;; 2259 *) I=a 2260 esac 2261 2262 # The compiler rejects some line in L..U. 2263 # Use binary search to set L to be the index of the first bad line in L..U. 2264 u=$U 2265 while test $L -lt $u 2266 do 2267 M=`expr '(' $L + $u ')' / 2` 2268 M1=`expr $M + 1` 2269 sed "$M1,\$$commentOut" a.h$H >a.h$I || exit 2270 $PREPARE_CC || exit 2271 if $CS -DH=$I a.c $LS >&2 && $CS_OK 2272 then L=$M1 2273 else u=$M 2274 fi 2275 done 2276 2277 # Comment out the bad line. 2278 badline=`sed -n "$L{p;q;}" a.h$H` 2279 echo >&3 "$n$0: commenting out \`$badline' $dots" 2280 sed "$L$commentOut" a.h$H >a.h$I || exit 2281 2282 H=$I 2283 L=`expr $L + 1` 2284done 2285 2286cat a.h$H 2287 2288echo >&3 OK 2289