📄 conf.sh
字号:
$RM || exit if ($CL a.c $L && ./a.out) >&2 then h=1 else h=0 fiesacecho "$a#define has_getpwuid $h $z/* Does getpwuid() work? */": has_linkcat >a.c <<'EOF'#include "a.h"int main() { exitmain(link("a.c","a.d") != 0); }EOF$RM a.d || exitif ($CL a.c $L && ./a.out && cmp a.c a.d) >&2then h=1else h=0firm -f a.d || exitecho "#define has_link $h /* Does link() work? */": has_memcmpcat >a.c <<'EOF'#include "a.h"int main() { exitmain(memcmp("beautiful","beautiful",10) != 0); }EOF$RM || exitif ($CL a.c $L && ./a.out) >&2then h=1else h=0fiecho "#define has_memcmp $h /* Does memcmp() work? */": has_memcpycat >a.c <<'EOF'#include "a.h"char a[3];int main() { memcpy(a,"xy",3); exitmain(strcmp(a,"xy")!=0);}EOF$RM || exitif ($CL a.c $L && ./a.out) >&2then h=1else h=0fiecho "#define has_memcpy $h /* Does memcpy() work? */": has_memmovecat >a.c <<'EOF'#include "a.h"char a[4];int main() { strcpy(a, "xy"); memmove(a+1, a, 3); exitmain(strcmp(a,"xxy")!=0);}EOF$RM || exitif ($CL a.c $L && ./a.out) >&2then h=1else h=0fiecho "#define has_memmove $h /* Does memmove() work? */": has_mmap, has_madvisecat >a.c <<'EOF'#define CHAR1 '#' /* the first character in this file */#include "a.h"#ifndef mmap caddr_t mmap();#endifcaddr_t a;struct stat b;#ifndef MADVISE_OK# define MADVISE_OK (madvise(a,b.st_size,MADV_SEQUENTIAL)==0 && madvise(a,b.st_size,MADV_NORMAL)==0)#endifint main(){ if (fstat(fileno(stdin), &b) != 0) exitmain(1); a = mmap( (caddr_t)0, b.st_size, PROT_READ, MAP_SHARED, fileno(stdin), (off_t)0 ); exitmain( a == (caddr_t)-1 || !MADVISE_OK || *a != CHAR1 || munmap(a, b.st_size) != 0 );}EOFa=0 has_mmap=0$RM || exitif ($CL -DMADVISE_OK=1 a.c $L && ./a.out <a.c) >&2then has_mmap=1 $RM || exit ($CL a.c $L && ./a.out <a.c) >&2 && a=1fiecho "#define has_madvise $a /* Does madvise() work? */"echo "#define has_mmap $has_mmap /* Does mmap() work on regular files? */": has_rename, bad_a_rename, bad_b_renamecat >a.c <<'EOF'#include "a.h"int main() { exitmain(rename("a.a","a.b") != 0); }EOFecho a >a.a && $RM a.b || exitif ($CL a.c $L && ./a.out && test -f a.b) >&2then h=1 rm -f a.a a.b && echo a >a.a && chmod -w a.a || exit if ./a.out && test ! -f a.a && test -f a.b then a=0 else a=1 fi rm -f a.a a.b && echo a >a.a && echo b >a.b && chmod -w a.b || exit if ./a.out && test ! -f a.a && test -f a.b then b=0 else b=1 fi rm -f a.a a.b || exitelse h=0 a=0 b=0fiecho "#define has_rename $h /* Does rename() work? */"echo "#define bad_a_rename $a /* Does rename(A,B) fail if A is unwritable? */"echo "#define bad_b_rename $b /* Does rename(A,B) fail if B is unwritable? */": void, VOIDcat >a.c <<'EOF'#include "a.h"void f() {}int main() {f(); exitmain(0);}EOFif $CS a.c $LS >&2then v='(void) 'else v= echo 'typedef int void;'fiecho "#define VOID $v/* 'VOID e;' discards the value of an expression 'e'. */": has_seteuidcase $has_getuid in0) a='/* ' z='*/ ' has_seteuid=?;;*) a= z= cat >a.c <<'EOF'#include "a.h"#ifndef geteuid uid_t geteuid();#endifint main() {/* Guess, don't test. Ugh. Testing would require running conf.sh setuid. *//* seteuid() isn't standardized yet, so the guess below may well be wrong. */#if !_POSIX_VERSION || _POSIX_VERSION<=199009L&&!defined(sgi)&&!defined(__sgi__)&&!defined(sun)&&!defined(__sun__) exitmain(1);#else exitmain(seteuid(geteuid()) != 0);#endif}EOF $RM || exit if ($CL a.c $L && ./a.out) >&2 then has_seteuid=1 else has_seteuid=0 fiesacecho "$a#define has_seteuid $has_seteuid $z/* Does seteuid() work? See README. */": has_setuidh=$has_seteuidcase $h in0) cat >a.c <<'EOF'#include "a.h"#ifndef getuid uid_t getuid();#endifint main() { exitmain(setuid(getuid()) != 0); }EOF $RM || exit ($CL a.c $L && ./a.out) >&2 && h=1esacecho "$a#define has_setuid $h $z/* Does setuid() exist? */": has_signal, signal_args, signal_type, sig_zaps_handlercat >a.c <<'EOF'#include "a.h"#ifndef getpid pid_t getpid();#endif#if !defined(signal) && declare_signal signal_type (*signal P((int,signal_type(*)signal_args)))signal_args;#endifsignal_type nothing(i) int i; {}int main(argc, argv) int argc; char **argv;{ signal(SIGINT, nothing); while (--argc) kill(getpid(), SIGINT); exitmain(0);}EOFfor declare_signal in 1 0do for signal_type in void int do for signal_args in 'P((int))' '()' do $RM || exit ($CL \ -Ddeclare_signal=$declare_signal \ -Dsignal_args="$signal_args" \ -Dsignal_type=$signal_type \ a.c $L && ./a.out 1) >&2 && break done && break done && breakdone || { echo >&2 "cannot deduce signal_args, signal_type" exit 1}if ./a.out 1 2 >&2then z=0else z=1ficat <<EOF#define has_signal $has_signal /* Does signal() work? */#define signal_args $signal_args /* arguments of signal handlers */#define signal_type $signal_type /* type returned by signal handlers */#define sig_zaps_handler $z /* Must a signal handler reinvoke signal()? */EOF: has_sigactioncat >a.c <<'EOF'#include "a.h"#ifndef getpid pid_t getpid();#endifstatic sig_atomic_t volatile gotsig;static void getsig(i) int i; { gotsig = 1; }int main(argc, argv) int argc; char **argv;{ struct sigaction s; sigset_t t; if (sigemptyset(&t) != 0 || sigaddset(&t, SIGINT) != 0) exitmain(1); if (sigaction(SIGINT, (struct sigaction const*)0, &s) != 0) exitmain(1); s.sa_handler = getsig; s.sa_mask = t; if (sigaction(SIGINT, &s, (struct sigaction*)0) != 0) exitmain(1); kill(getpid(), SIGINT); exitmain(gotsig != 1);}EOF$RM || exitif ($CL a.c $L && ./a.out) >&2then has_sigaction=1else has_sigaction=0fiecho "#define has_sigaction $has_sigaction /* Does struct sigaction work? */": has_sigblock, sigmaska='/* ' z='*/ 'b='/* ' y='*/ 'case $has_sigaction in1) h=? n=?;;*) a= z= cat >a.c <<'EOF'#include "a.h"#include <signal.h>#if define_sigmask# define sigmask(s) (1 << ((s)-1))#endifint main(){ sigblock(sigmask(SIGHUP)); exitmain(kill(getpid(), SIGHUP) != 0);}EOF if $RM || exit; ($CL a.c $L && ./a.out) >&2 then h=1 elif $RM || exit; ($CL -Ddefine_sigmask=1 a.c $L && ./a.out) >&2 then h=1 b= y= else h=0 fiesacecho "$a#define has_sigblock $h $z/* Does sigblock() work? */"echo "$b#define sigmask(s) (1 << ((s)-1)) $y/* Yield mask for signal number. */": has_sys_siglistcat >a.c <<'EOF'#include "a.h"#ifndef sys_siglist extern char const *sys_siglist[];#endifint main() { exitmain(!sys_siglist[1][0]); }EOF$RM || exitif ($CL a.c $L && ./a.out) >&2then h=1else h=0fiecho "#define has_sys_siglist $h /* Does sys_siglist[] work? */": fread_type, Fread, Fwritecat >a.c <<'EOF'#define CHAR1 '#' /* the first character in this file */#include "a.h"#if !defined(fread) && declare_fread fread_type fread P((void*,freadarg_type,freadarg_type,FILE*));#endifint main(){ char b; exitmain(!( fread(&b, (freadarg_type)1, (freadarg_type)1, stdin) == 1 && b==CHAR1 ));}EOFfor declare_fread in 1 0do for fread_type in ssize_t size_t int unsigned do for freadarg_type in size_t ssize_t unsigned int do $RM || exit ( $CL \ -Ddeclare_fread=$declare_fread \ -Dfreadarg_type=$freadarg_type \ -Dfread_type=$fread_type \ a.c $L && ./a.out <a.c ) >&2 && break done && break done && breakdone || { echo >&2 "cannot deduce fread types" exit 1}cat <<EOFtypedef $fread_type fread_type; /* type returned by fread() and fwrite() */typedef $freadarg_type freadarg_type; /* type of their size arguments */EOF: malloc_typecat >a.c <<'EOF'#include "a.h"typedef void *malloc_type;#ifndef malloc malloc_type malloc();#endifint main() { exitmain(!malloc(1)); }EOFif $CS a.c $LS >&2then t=voidelse t=charfiecho "typedef $t *malloc_type; /* type returned by malloc() */": has_getcwdcat >a.c <<'EOF'#include "a.h"#ifndef getcwd char *getcwd();#endifchar buf[10000];int main() { exitmain(!getcwd(buf,10000)); }EOF$RM || exitif ($CL a.c $L && ./a.out) >&2then has_getcwd=1else has_getcwd=0fiecho "#define has_getcwd $has_getcwd /* Does getcwd() work? */": has_getwdcase $has_getcwd in1) a='/* ' z='*/ ' h=?;;*) a= z= cat >a.c <<'EOF'#include "a.h"#include <sys/param.h>#ifndef getwd char *getwd();#endifchar buf[MAXPATHLEN];int main() { exitmain(!getwd(buf)); }EOF $RM || exit if ($CL a.c $L && ./a.out) >&2 then h=1 else h=0 fiesacecho "$a#define has_getwd $h $z/* Does getwd() work? */": has_mktempcat >a.c <<'EOF'#include "a.h"#ifndef mktemp char *mktemp();#endifint main(){ char b[9]; strcpy(b, "a.XXXXXX"); exitmain(!mktemp(b));}EOF$RM || exitif ($CL a.c $L && ./a.out) >&2then h=1else h=0fiecho "#define has_mktemp $h /* Does mktemp() work? */": has_NFSecho "#define has_NFS 1 /* Might NFS be used? */": strchrcat >a.c <<'EOF'#include "a.h"#ifndef strchr char *strchr();#endifint main() {exitmain(!strchr("abc", 'c'));}EOF$RM || exitif ($CL a.c $L && ./a.out) >&2then a='/* ' z='*/ 'else a= z=fiecho "$a#define strchr index $z/* Use old-fashioned name for strchr()? */": strrchrcat >a.c <<'EOF'#include "a.h"#ifndef strrchr char *strrchr();#endifint main() {exitmain(!strrchr("abc", 'c'));}EOF$RM || exitif ($CL a.c $L && ./a.out) >&2then a='/* ' z='*/ 'else a= z=fiecho "$a#define strrchr rindex $z/* Use old-fashioned name for strrchr()? */": bad_unlinkcat >a.c <<'EOF'#include "a.h"int main() { exitmain(unlink("a.c") != 0); }EOF$RM && chmod -w a.c || exitif $CL a.c $L >&2 && ./a.out >/dev/null && test ! -f a.cthen b=0else b=1firm -f a.c || exitecho "#define bad_unlink $b /* Does unlink() fail on unwritable files? */": has_vfork, has_fork, has_spawn, has_wait, has_waitpid, RCS_SHELLcat >a.c <<'EOF'#include "a.h"#ifndef getpid pid_t getpid();#endif#if TRY_VFORK# ifndef vfork pid_t vfork();# endif#else# ifndef fork pid_t fork();# endif# undef vfork# define vfork fork#endif#if TRY_WAITPID# ifndef waitpid pid_t waitpid();# endif#else# ifndef wait pid_t wait();# endif#endifpid_t child;int status;struct stat st;int main(){ pid_t parent = getpid(); if (!(child = vfork())) { /* Tickle vfork/compiler bug (e.g. sparc gcc -O (1.37.1). */ pid_t i = getpid(), j = getpid(); if (i!=getpid() || j!=getpid()) _exit(!i); /* Tickle file descriptor bug (e.g. IRIX 3.3). */ _exit(close(1) != 0); } else {# if TRY_WAITPID if (waitpid(child, &status, 0) != child) exitmain(1);# else while (wait(&status) != child) ;# endif /* Test for presence of bugs. */ exitmain(status || parent != getpid() || fstat(1,&st) != 0); }}EOF$RM || exitif ($CL -DTRY_VFORK=1 a.c $L && ./a.out) >&2then has_vfork=1else has_vfork=0fiecho "#define has_vfork $has_vfork /* Does vfork() work? */"h=$has_vforkcase $h in0) $RM || exit ($CL a.c $L && ./a.out) >&2 && h=1esacecho "#define has_fork $h /* Does fork() work? */"$RM || exitif ($CL -DTRY_VFORK=$has_vfork -DTRY_WAITPID=1 a.c $L && ./a.out) >&2then h=1else h=0fiecho "#define has_spawn 0 /* Does spawn*() work? */"echo "#define has_wait 1 /* Does wait() work? */"echo "#define has_waitpid $h /* Does waitpid() work? */"echo '#define RCS_SHELL "/bin/sh" /* shell to run RCS subprograms */': has_vfprintfcat >a.c <<'EOF'#include "a.h"#if has_prototypesint p(char const*format,...)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -