commit ddfb769806986bf2835aacb2746d28c81f06211a
parent 030cb3d1f30b7dc1c225acf0309c86254cca1f23
Author: Gerrit Pape <pape@smarden.org>
Date: Sat, 18 May 2002 17:30:16 +0000
* src/: include public domain sources to build byte.a, unix.a, time.a:
runit builds without having daemontools' sources installed.
0.3.3.
Diffstat:
157 files changed, 3519 insertions(+), 61 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,6 +1,6 @@
DESTDIR=
-PACKAGE=runit-0.3.2
+PACKAGE=runit-0.3.3
DIRS=doc man etc package src
MANPAGES=man/runit.8 man/runit-init.8 man/svwaitdown.8 man/svwaitup.8
DAEMONTOOLS_PD=daemontools-pd-0.76
diff --git a/debian/changelog b/debian/changelog
@@ -1,3 +1,9 @@
+runit (0.3.3-1) woody; urgency=low
+
+ * See /package/admin/runit/package/CHANGES.
+
+ -- Gerrit Pape <pape@smarden.org> Sat, 18 May 2002 19:26:51 +0200
+
runit (0.3.2-2) woody; urgency=low
* getty service directory /etc/runit/getty-tty5 moved to
diff --git a/debian/postinst b/debian/postinst
@@ -25,7 +25,7 @@ set -e
case "$1" in
configure)
( \
- cd /package/admin/runit-0.3.2
+ cd /package/admin/runit-0.3.3
package/upgrade
)
;;
diff --git a/debian/rules b/debian/rules
@@ -23,22 +23,18 @@ build-stamp:
# $(MAKE)
#/usr/bin/docbook-to-man debian/runit.sgml > runit.1
- tar xfzvp runit-0.3.2.tar.gz
- mkdir -p admin/runit-0.3.2/compile
- tar xfzvp daemontools-pd-0.76.tar.gz \
- -C admin/runit-0.3.2/compile
+ tar xfzvp runit-0.3.3.tar.gz
( \
- cd admin/runit-0.3.2/compile ; \
- ln -s daemontools-pd-0.76 support ; \
- echo 'diet gcc -O2 -Wall' > support/conf-cc ; \
- echo 'diet gcc -s -Os -pipe' > support/conf-ld ; \
+ cd admin/runit-0.3.3/src ; \
+ echo 'diet gcc -O2 -Wall' > conf-cc ; \
+ echo 'diet gcc -s -Os -pipe' > conf-ld ; \
)
( \
- cd admin/runit-0.3.2 ; \
+ cd admin/runit-0.3.3 ; \
package/compile ; \
- echo "/package/admin/runit-0.3.2" > compile/home ; \
+ echo "/package/admin/runit-0.3.3" > compile/home ; \
rm -f compile/src ; \
- ln -s /package/admin/runit-0.3.2/src compile/src ; \
+ ln -s /package/admin/runit-0.3.3/src compile/src ; \
)
touch build-stamp
@@ -65,40 +61,40 @@ install: build
chmod 1755 debian/runit/package
cp -a admin debian/runit/package/
- rm -rf debian/runit/package/admin/runit-0.3.2/compile
- cp -a debian/runit/package/admin/runit-0.3.2/man .
- rm -rf debian/runit/package/admin/runit-0.3.2/man
- cp -a debian/runit/package/admin/runit-0.3.2/doc .
- rm -rf debian/runit/package/admin/runit-0.3.2/doc
- cp -a debian/runit/package/admin/runit-0.3.2/etc .
- rm -rf debian/runit/package/admin/runit-0.3.2/etc
- cp -a debian/runit/package/admin/runit-0.3.2/package .
+ rm -rf debian/runit/package/admin/runit-0.3.3/compile
+ cp -a debian/runit/package/admin/runit-0.3.3/man .
+ rm -rf debian/runit/package/admin/runit-0.3.3/man
+ cp -a debian/runit/package/admin/runit-0.3.3/doc .
+ rm -rf debian/runit/package/admin/runit-0.3.3/doc
+ cp -a debian/runit/package/admin/runit-0.3.3/etc .
+ rm -rf debian/runit/package/admin/runit-0.3.3/etc
+ cp -a debian/runit/package/admin/runit-0.3.3/package .
# /etc/runit
- cp -p admin/runit-0.3.2/etc/debian/[123] \
+ cp -p admin/runit-0.3.3/etc/debian/[123] \
debian/runit/etc/runit/
- cp -p admin/runit-0.3.2/etc/debian/ctrlaltdel \
+ cp -p admin/runit-0.3.3/etc/debian/ctrlaltdel \
debian/runit/etc/runit/
- cp -p admin/runit-0.3.2/etc/debian/getty-tty5/run \
+ cp -p admin/runit-0.3.3/etc/debian/getty-tty5/run \
debian/runit/etc/runit/getty-5/
# runit programs
- cp -p debian/runit/package/admin/runit-0.3.2/command/runit* \
+ cp -p debian/runit/package/admin/runit-0.3.3/command/runit* \
debian/runit/sbin/
# cleanup
- rm -rf debian/runit/package/admin/runit-0.3.2/compile
+ rm -rf debian/runit/package/admin/runit-0.3.3/compile
# create debian/links
rm -f debian/links
for i in \
- `cat debian/runit/package/admin/runit-0.3.2/package/commands` ; \
+ `cat debian/runit/package/admin/runit-0.3.3/package/commands` ; \
do \
echo "/package/admin/runit/command/$$i /command/$$i" \
>> debian/links ; \
done
# for i in \
-# `cat debian/runit/package/admin/runit-0.3.2/package/commands` ; \
+# `cat debian/runit/package/admin/runit-0.3.3/package/commands` ; \
# do \
# echo "/command/$$i /usr/local/bin/$$i" \
# >> debian/links ; \
diff --git a/doc/index.html b/doc/index.html
@@ -84,7 +84,7 @@ This is from the second machine where I replaced <i>sysvinit</i> with
<i>runit</i>:
<pre>
# strings /proc/1/exe |grep Id
- $Id$
+ $Id: runit.c,v 1.5 2001/12/30 16:28:53 pape Exp $
# uptime
10:35:18 up 107 days, 15:46, 2 users, load average: 0.00, 0.00, 0.00
# ps axuw |head
@@ -130,7 +130,7 @@ This is from the second machine where I replaced <i>sysvinit</i> with
This is from a more busy system:
<pre>
# strings /proc/1/exe |grep Id
- $Id$
+ $Id: runit.c,v 1.6 2002/01/29 18:56:36 pape Exp $
# uptime
10:44:34 up 68 days, 10:48, 3 users, load average: 0.24, 0.45, 0.34
# ps axuw |head
diff --git a/doc/install.html b/doc/install.html
@@ -13,14 +13,14 @@ Check that you have the recent version of
<a href="http://cr.yp.to/daemontools.html">daemontools</a> installed.
<p>
Download
-<a href="runit-0.3.2.tar.gz">runit-0.3.2.tar.gz</a> into <tt>/package</tt>
+<a href="runit-0.3.3.tar.gz">runit-0.3.3.tar.gz</a> into <tt>/package</tt>
and unpack the archive
<pre>
# cd /package
- # gunzip runit-0.3.2.tar
- # tar -xpf runit-0.3.2.tar
- # rm runit-0.3.2.tar
- # cd admin/runit-0.3.2
+ # gunzip runit-0.3.3.tar
+ # tar -xpf runit-0.3.3.tar
+ # rm runit-0.3.3.tar
+ # cd admin/runit-0.3.3
</pre>
Compile and install the <i>runit</i> programs
<pre>
diff --git a/doc/replaceinit.html b/doc/replaceinit.html
@@ -107,7 +107,7 @@ default Unix process no 1 <i>runit</i>.
</pre>
To report success:
<pre>
- # ( uname -a ; cat /etc/runit/[123] ) | mail pape-runit-0.3.2@smarden.org
+ # ( uname -a ; cat /etc/runit/[123] ) | mail pape-runit-0.3.3@smarden.org
</pre>
<hr>
@@ -187,7 +187,7 @@ Use <b>init 6</b> to reboot and <b>init 0</b> to halt a system that runs
<p>
To report success:
<pre>
- # ( uname -a ; cat /etc/runit/[123] ) | mail pape-runit-0.3.2@smarden.org
+ # ( uname -a ; cat /etc/runit/[123] ) | mail pape-runit-0.3.3@smarden.org
</pre>
<h3>Step 5: Service migration</h3>
The goal is to migrate all services from <i>/etc/rc.*</i> scheme to the
diff --git a/package/CHANGES b/package/CHANGES
@@ -1,3 +1,8 @@
+runit 0.3.3
+Sat, 18 May 2002 19:20:46 +0200
+ * src/: include public domain sources to build byte.a, unix.a, time.a:
+ runit builds without having daemontools' sources installed.
+
runit 0.3.2
Wed, 13 Feb 2002 10:56:17 +0100
* runit.c: support ctrl-alt-del also on Linux/i386, dietlibc.
diff --git a/package/compile b/package/compile
@@ -10,11 +10,6 @@ mkdir -p compile command
test -r compile/home || echo $here > compile/home
test -h compile/src || ln -s $here/src compile/src
-# support, default: ../daemontools/compile
-test -h src/support || ln -s ../../daemontools/compile src/support
-test -d src/support || \
- ( echo 'daemontools not found.'; rm -f src/support; exit 1 )
-
echo 'Linking ./src/* into ./compile...'
for i in `ls src`
do
diff --git a/package/upgrade b/package/upgrade
@@ -7,9 +7,9 @@ test -d src || ( echo 'Wrong working directory.'; exit 1 )
here=`env - PATH=$PATH pwd`
parent=`dirname $here`
-echo 'Creating symlink runit -> runit-0.3.2...'
+echo 'Creating symlink runit -> runit-0.3.3...'
rm -f runit
-ln -s runit-0.3.2 runit
+ln -s runit-0.3.3 runit
mv -f runit ..
echo 'Making command links in /command...'
diff --git a/src/Makefile b/src/Makefile
@@ -1,31 +1,379 @@
-DESTDIR=
+IT=runit runit-init svwaitup svwaitdown
-CC=./support/compile
-LD=./support/load
+default: $(IT)
-CFLAGS=-Isupport
+runit: load runit.o unix.a byte.a
+ ./load runit unix.a byte.a -static
-all: runit runit-init svwaitup svwaitdown
+runit-init: load runit-init.o unix.a byte.a
+ ./load runit-init unix.a byte.a -static
-runit: djb-publicdomain runit.o
- $(LD) runit support/unix.a support/byte.a -static
+svwaitup: load svwaitup.o unix.a byte.a time.a
+ ./load svwaitup unix.a byte.a time.a
-runit-init: djb-publicdomain runit-init.o
- $(LD) runit-init support/unix.a support/byte.a -static
+svwaitdown: load svwaitdown.o unix.a byte.a time.a
+ ./load svwaitdown unix.a byte.a time.a
-svwaitup: djb-publicdomain svwaitup.o
- $(LD) svwaitup support/unix.a support/byte.a support/time.a
+runit.o: compile runit.c iopause.h uint64.h
+ ./compile runit.c
-svwaitdown: djb-publicdomain svwaitdown.o
- $(LD) svwaitdown support/unix.a support/byte.a support/time.a
+runit-init.o: compile runit-init.c
+ ./compile runit-init.c
-djb-publicdomain:
- ( cd support ; make )
+svwaitup.o: compile svwaitup.c uint64.h
+ ./compile svwaitup.c
+
+svwaitdown.o: compile svwaitdown.c uint64.h
+ ./compile svwaitdown.c
clean:
find . -name \*~ -exec rm -f {} \;
find . -name .??*~ -exec rm -f {} \;
find . -name \#?* -exec rm -f {} \;
- if test -h support; \
- then ( cd support ; $(MAKE) clean ); fi
rm -f `cat TARGETS`
+
+alloc.o: alloc.c alloc.h compile error.h
+ ./compile alloc.c
+
+alloc_re.o: alloc.h alloc_re.c byte.h compile
+ ./compile alloc_re.c
+
+buffer.o: buffer.c buffer.h compile
+ ./compile buffer.c
+
+buffer_0.o: buffer.h buffer_0.c compile
+ ./compile buffer_0.c
+
+buffer_1.o: buffer.h buffer_1.c compile
+ ./compile buffer_1.c
+
+buffer_2.o: buffer.h buffer_2.c compile
+ ./compile buffer_2.c
+
+buffer_get.o: buffer.h buffer_get.c byte.h compile error.h
+ ./compile buffer_get.c
+
+buffer_put.o: buffer.h buffer_put.c byte.h compile error.h str.h
+ ./compile buffer_put.c
+
+buffer_read.o: buffer.h buffer_read.c compile
+ ./compile buffer_read.c
+
+buffer_write.o: buffer.h buffer_write.c compile
+ ./compile buffer_write.c
+
+byte.a: byte_chr.o byte_copy.o byte_cr.o byte_diff.o byte_rchr.o \
+fmt_uint.o fmt_uint0.o fmt_ulong.o makelib scan_ulong.o str_chr.o \
+str_diff.o str_len.o str_start.o
+ ./makelib byte.a byte_chr.o byte_copy.o byte_cr.o byte_diff.o \
+ byte_rchr.o fmt_uint.o fmt_uint0.o fmt_ulong.o scan_ulong.o str_chr.o \
+ str_diff.o str_len.o str_start.o
+
+byte_chr.o: byte.h byte_chr.c compile
+ ./compile byte_chr.c
+
+byte_copy.o: byte.h byte_copy.c compile
+ ./compile byte_copy.c
+
+byte_cr.o: byte.h byte_cr.c compile
+ ./compile byte_cr.c
+
+byte_diff.o: byte.h byte_diff.c compile
+ ./compile byte_diff.c
+
+byte_rchr.o: byte.h byte_rchr.c compile
+ ./compile byte_rchr.c
+
+#chkshsgr: chkshsgr.o load
+# ./load chkshsgr
+#
+#chkshsgr.o: chkshsgr.c compile
+# ./compile chkshsgr.c
+
+choose: choose.sh warn-auto.sh
+ rm -f choose
+ cat warn-auto.sh choose.sh \
+ > choose
+ chmod 555 choose
+
+coe.o: coe.c coe.h compile
+ ./compile coe.c
+
+compile: conf-cc print-cc.sh systype warn-auto.sh
+ rm -f compile
+ sh print-cc.sh > compile
+ chmod 555 compile
+
+#direntry.h: choose compile direntry.h1 direntry.h2 trydrent.c
+# ./choose c trydrent direntry.h1 direntry.h2 > direntry.h
+
+env.o: compile env.c env.h str.h
+ ./compile env.c
+
+error.o: compile error.c error.h
+ ./compile error.c
+
+error_str.o: compile error.h error_str.c
+ ./compile error_str.c
+
+fd_copy.o: compile fd.h fd_copy.c
+ ./compile fd_copy.c
+
+fd_move.o: compile fd.h fd_move.c
+ ./compile fd_move.c
+
+fifo.o: compile fifo.c fifo.h hasmkffo.h
+ ./compile fifo.c
+
+fmt_uint.o: compile fmt.h fmt_uint.c
+ ./compile fmt_uint.c
+
+fmt_uint0.o: compile fmt.h fmt_uint0.c
+ ./compile fmt_uint0.c
+
+fmt_ulong.o: compile fmt.h fmt_ulong.c
+ ./compile fmt_ulong.c
+
+hasflock.h: choose compile hasflock.h1 hasflock.h2 load tryflock.c
+ ./choose cl tryflock hasflock.h1 hasflock.h2 > hasflock.h
+
+hasmkffo.h: choose compile hasmkffo.h1 hasmkffo.h2 load trymkffo.c
+ ./choose cl trymkffo hasmkffo.h1 hasmkffo.h2 > hasmkffo.h
+
+hassgact.h: choose compile hassgact.h1 hassgact.h2 load trysgact.c
+ ./choose cl trysgact hassgact.h1 hassgact.h2 > hassgact.h
+
+hassgprm.h: choose compile hassgprm.h1 hassgprm.h2 load trysgprm.c
+ ./choose cl trysgprm hassgprm.h1 hassgprm.h2 > hassgprm.h
+
+hasshsgr.h: chkshsgr choose compile hasshsgr.h1 hasshsgr.h2 load \
+tryshsgr.c warn-shsgr
+ ./chkshsgr || ( cat warn-shsgr; exit 1 )
+ ./choose clr tryshsgr hasshsgr.h1 hasshsgr.h2 > hasshsgr.h
+
+haswaitp.h: choose compile haswaitp.h1 haswaitp.h2 load trywaitp.c
+ ./choose cl trywaitp haswaitp.h1 haswaitp.h2 > haswaitp.h
+
+iopause.h: choose compile iopause.h1 iopause.h2 load trypoll.c
+ ./choose clr trypoll iopause.h1 iopause.h2 > iopause.h
+
+iopause.o: compile iopause.c iopause.h select.h tai.h taia.h uint64.h
+ ./compile iopause.c
+
+load: conf-ld print-ld.sh systype warn-auto.sh
+ rm -f load
+ sh print-ld.sh > load
+ chmod 555 load
+
+lock_ex.o: compile hasflock.h lock.h lock_ex.c
+ ./compile lock_ex.c
+
+lock_exnb.o: compile hasflock.h lock.h lock_exnb.c
+ ./compile lock_exnb.c
+
+makelib: print-ar.sh systype warn-auto.sh
+ rm -f makelib
+ sh print-ar.sh > makelib
+ chmod 555 makelib
+
+ndelay_off.o: compile ndelay.h ndelay_off.c
+ ./compile ndelay_off.c
+
+ndelay_on.o: compile ndelay.h ndelay_on.c
+ ./compile ndelay_on.c
+
+open_append.o: compile open.h open_append.c
+ ./compile open_append.c
+
+open_read.o: compile open.h open_read.c
+ ./compile open_read.c
+
+open_trunc.o: compile open.h open_trunc.c
+ ./compile open_trunc.c
+
+open_write.o: compile open.h open_write.c
+ ./compile open_write.c
+
+openreadclose.o: compile error.h gen_alloc.h open.h openreadclose.c \
+openreadclose.h readclose.h stralloc.h
+ ./compile openreadclose.c
+
+pathexec_env.o: alloc.h byte.h compile env.h gen_alloc.h pathexec.h \
+pathexec_env.c str.h stralloc.h
+ ./compile pathexec_env.c
+
+pathexec_run.o: compile env.h error.h gen_alloc.h pathexec.h \
+pathexec_run.c str.h stralloc.h
+ ./compile pathexec_run.c
+
+prot.o: compile hasshsgr.h prot.c prot.h
+ ./compile prot.c
+
+readclose.o: compile error.h gen_alloc.h readclose.c readclose.h \
+stralloc.h
+ ./compile readclose.c
+
+scan_ulong.o: compile scan.h scan_ulong.c
+ ./compile scan_ulong.c
+
+seek_set.o: compile seek.h seek_set.c
+ ./compile seek_set.c
+
+select.h: choose compile select.h1 select.h2 trysysel.c
+ ./choose c trysysel select.h1 select.h2 > select.h
+
+sgetopt.o: buffer.h compile sgetopt.c sgetopt.h subgetopt.h
+ ./compile sgetopt.c
+
+sig.o: compile sig.c sig.h
+ ./compile sig.c
+
+sig_block.o: compile hassgprm.h sig.h sig_block.c
+ ./compile sig_block.c
+
+sig_catch.o: compile hassgact.h sig.h sig_catch.c
+ ./compile sig_catch.c
+
+sig_pause.o: compile hassgprm.h sig.h sig_pause.c
+ ./compile sig_pause.c
+
+str_chr.o: compile str.h str_chr.c
+ ./compile str_chr.c
+
+str_diff.o: compile str.h str_diff.c
+ ./compile str_diff.c
+
+str_len.o: compile str.h str_len.c
+ ./compile str_len.c
+
+str_start.o: compile str.h str_start.c
+ ./compile str_start.c
+
+stralloc_cat.o: byte.h compile gen_alloc.h stralloc.h stralloc_cat.c
+ ./compile stralloc_cat.c
+
+stralloc_catb.o: byte.h compile gen_alloc.h stralloc.h \
+stralloc_catb.c
+ ./compile stralloc_catb.c
+
+stralloc_cats.o: byte.h compile gen_alloc.h str.h stralloc.h \
+stralloc_cats.c
+ ./compile stralloc_cats.c
+
+stralloc_eady.o: alloc.h compile gen_alloc.h gen_allocdefs.h \
+stralloc.h stralloc_eady.c
+ ./compile stralloc_eady.c
+
+stralloc_opyb.o: byte.h compile gen_alloc.h stralloc.h \
+stralloc_opyb.c
+ ./compile stralloc_opyb.c
+
+stralloc_opys.o: byte.h compile gen_alloc.h str.h stralloc.h \
+stralloc_opys.c
+ ./compile stralloc_opys.c
+
+stralloc_pend.o: alloc.h compile gen_alloc.h gen_allocdefs.h \
+stralloc.h stralloc_pend.c
+ ./compile stralloc_pend.c
+
+strerr_die.o: buffer.h compile strerr.h strerr_die.c
+ ./compile strerr_die.c
+
+strerr_sys.o: compile error.h strerr.h strerr_sys.c
+ ./compile strerr_sys.c
+
+subgetopt.o: compile subgetopt.c subgetopt.h
+ ./compile subgetopt.c
+
+sysdeps: compile direntry.h hasflock.h hasmkffo.h hassgact.h \
+hassgprm.h hasshsgr.h haswaitp.h iopause.h load select.h systype \
+uint64.h
+ rm -f sysdeps
+ cat systype compile load >> sysdeps
+ grep sysdep direntry.h >> sysdeps
+ grep sysdep haswaitp.h >> sysdeps
+ grep sysdep hassgact.h >> sysdeps
+ grep sysdep hassgprm.h >> sysdeps
+ grep sysdep select.h >> sysdeps
+ grep sysdep uint64.h >> sysdeps
+ grep sysdep iopause.h >> sysdeps
+ grep sysdep hasmkffo.h >> sysdeps
+ grep sysdep hasflock.h >> sysdeps
+ grep sysdep hasshsgr.h >> sysdeps
+
+systype: find-systype.sh trycpp.c x86cpuid.c
+ sh find-systype.sh > systype
+
+tai_now.o: compile tai.h tai_now.c uint64.h
+ ./compile tai_now.c
+
+tai_pack.o: compile tai.h tai_pack.c uint64.h
+ ./compile tai_pack.c
+
+tai_sub.o: compile tai.h tai_sub.c uint64.h
+ ./compile tai_sub.c
+
+tai_unpack.o: compile tai.h tai_unpack.c uint64.h
+ ./compile tai_unpack.c
+
+taia_add.o: compile tai.h taia.h taia_add.c uint64.h
+ ./compile taia_add.c
+
+taia_approx.o: compile tai.h taia.h taia_approx.c uint64.h
+ ./compile taia_approx.c
+
+taia_frac.o: compile tai.h taia.h taia_frac.c uint64.h
+ ./compile taia_frac.c
+
+taia_less.o: compile tai.h taia.h taia_less.c uint64.h
+ ./compile taia_less.c
+
+taia_now.o: compile tai.h taia.h taia_now.c uint64.h
+ ./compile taia_now.c
+
+taia_pack.o: compile tai.h taia.h taia_pack.c uint64.h
+ ./compile taia_pack.c
+
+taia_sub.o: compile tai.h taia.h taia_sub.c uint64.h
+ ./compile taia_sub.c
+
+taia_uint.o: compile tai.h taia.h taia_uint.c uint64.h
+ ./compile taia_uint.c
+
+time.a: iopause.o makelib tai_now.o tai_pack.o tai_sub.o tai_unpack.o \
+taia_add.o taia_approx.o taia_frac.o taia_less.o taia_now.o \
+taia_pack.o taia_sub.o taia_uint.o
+ ./makelib time.a iopause.o tai_now.o tai_pack.o tai_sub.o \
+ tai_unpack.o taia_add.o taia_approx.o taia_frac.o taia_less.o \
+ taia_now.o taia_pack.o taia_sub.o taia_uint.o
+
+uint64.h: choose compile load tryulong64.c uint64.h1 uint64.h2
+ ./choose clr tryulong64 uint64.h1 uint64.h2 > uint64.h
+
+unix.a: alloc.o alloc_re.o buffer.o buffer_0.o buffer_1.o buffer_2.o \
+buffer_get.o buffer_put.o buffer_read.o buffer_write.o coe.o env.o \
+error.o error_str.o fd_copy.o fd_move.o fifo.o lock_ex.o lock_exnb.o \
+makelib ndelay_off.o ndelay_on.o open_append.o open_read.o \
+open_trunc.o open_write.o openreadclose.o pathexec_env.o \
+pathexec_run.o prot.o readclose.o seek_set.o sgetopt.o sig.o \
+sig_block.o sig_catch.o sig_pause.o stralloc_cat.o stralloc_catb.o \
+stralloc_cats.o stralloc_eady.o stralloc_opyb.o stralloc_opys.o \
+stralloc_pend.o strerr_die.o strerr_sys.o subgetopt.o wait_nohang.o \
+wait_pid.o
+ ./makelib unix.a alloc.o alloc_re.o buffer.o buffer_0.o buffer_1.o \
+ buffer_2.o buffer_get.o buffer_put.o buffer_read.o buffer_write.o \
+ coe.o env.o error.o error_str.o fd_copy.o fd_move.o fifo.o lock_ex.o \
+ lock_exnb.o ndelay_off.o ndelay_on.o open_append.o open_read.o \
+ open_trunc.o open_write.o openreadclose.o pathexec_env.o \
+ pathexec_run.o prot.o readclose.o seek_set.o sgetopt.o sig.o \
+ sig_block.o sig_catch.o sig_pause.o stralloc_cat.o stralloc_catb.o \
+ stralloc_cats.o stralloc_eady.o stralloc_opyb.o stralloc_opys.o \
+ stralloc_pend.o strerr_die.o strerr_sys.o subgetopt.o wait_nohang.o \
+ wait_pid.o
+
+wait_nohang.o: compile haswaitp.h wait_nohang.c
+ ./compile wait_nohang.c
+
+wait_pid.o: compile error.h haswaitp.h wait_pid.c
+ ./compile wait_pid.c
+
diff --git a/src/TARGETS b/src/TARGETS
@@ -6,3 +6,95 @@ svwaitdown
svwaitdown.o
svwaitup
svwaitup.o
+alloc.o
+alloc_re.o
+buffer.o
+buffer_0.o
+buffer_1.o
+buffer_2.o
+buffer_get.o
+buffer_put.o
+buffer_read.o
+buffer_write.o
+byte.a
+byte_chr.o
+byte_copy.o
+byte_cr.o
+byte_diff.o
+byte_rchr.o
+chkshsgr
+choose
+coe.o
+compile
+env.o
+error.o
+error_str.o
+fd_copy.o
+fd_move.o
+fifo.o
+fmt_uint.o
+fmt_uint0.o
+fmt_ulong.o
+hasflock.h
+hasmkffo.h
+hassgact.h
+hassgprm.h
+hasshsgr.h
+haswaitp.h
+iopause.h
+iopause.o
+load
+lock_ex.o
+lock_exnb.o
+makelib
+ndelay_off.o
+ndelay_on.o
+open_append.o
+open_read.o
+open_trunc.o
+open_write.o
+openreadclose.o
+pathexec_env.o
+pathexec_run.o
+prot.o
+readclose.o
+scan_ulong.o
+seek_set.o
+select.h
+sgetopt.o
+sig.o
+sig_block.o
+sig_catch.o
+sig_pause.o
+str_chr.o
+str_diff.o
+str_len.o
+str_start.o
+stralloc_cat.o
+stralloc_catb.o
+stralloc_cats.o
+stralloc_eady.o
+stralloc_opyb.o
+stralloc_opys.o
+stralloc_pend.o
+strerr_die.o
+strerr_sys.o
+subgetopt.o
+systype
+tai_now.o
+tai_pack.o
+tai_sub.o
+tai_unpack.o
+taia_add.o
+taia_approx.o
+taia_frac.o
+taia_less.o
+taia_now.o
+taia_pack.o
+taia_sub.o
+taia_uint.o
+time.a
+uint64.h
+unix.a
+wait_nohang.o
+wait_pid.o
diff --git a/src/alloc.c b/src/alloc.c
@@ -0,0 +1,33 @@
+/* Public domain. */
+
+#include <stdlib.h>
+#include "alloc.h"
+#include "error.h"
+
+#define ALIGNMENT 16 /* XXX: assuming that this alignment is enough */
+#define SPACE 2048 /* must be multiple of ALIGNMENT */
+
+typedef union { char irrelevant[ALIGNMENT]; double d; } aligned;
+static aligned realspace[SPACE / ALIGNMENT];
+#define space ((char *) realspace)
+static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */
+
+/*@null@*//*@out@*/char *alloc(n)
+unsigned int n;
+{
+ char *x;
+ n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */
+ if (n <= avail) { avail -= n; return space + avail; }
+ x = malloc(n);
+ if (!x) errno = error_nomem;
+ return x;
+}
+
+void alloc_free(x)
+char *x;
+{
+ if (x >= space)
+ if (x < space + SPACE)
+ return; /* XXX: assuming that pointers are flat */
+ free(x);
+}
diff --git a/src/alloc.h b/src/alloc.h
@@ -0,0 +1,10 @@
+/* Public domain. */
+
+#ifndef ALLOC_H
+#define ALLOC_H
+
+extern /*@null@*//*@out@*/char *alloc();
+extern void alloc_free();
+extern int alloc_re();
+
+#endif
diff --git a/src/alloc_re.c b/src/alloc_re.c
@@ -0,0 +1,19 @@
+/* Public domain. */
+
+#include "alloc.h"
+#include "byte.h"
+
+int alloc_re(x,m,n)
+char **x;
+unsigned int m;
+unsigned int n;
+{
+ char *y;
+
+ y = alloc(n);
+ if (!y) return 0;
+ byte_copy(y,m,*x);
+ alloc_free(*x);
+ *x = y;
+ return 1;
+}
diff --git a/src/buffer.c b/src/buffer.c
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#include "buffer.h"
+
+void buffer_init(buffer *s,int (*op)(),int fd,char *buf,unsigned int len)
+{
+ s->x = buf;
+ s->fd = fd;
+ s->op = op;
+ s->p = 0;
+ s->n = len;
+}
diff --git a/src/buffer.h b/src/buffer.h
@@ -0,0 +1,61 @@
+/* Public domain. */
+
+#ifndef BUFFER_H
+#define BUFFER_H
+
+typedef struct buffer {
+ char *x;
+ unsigned int p;
+ unsigned int n;
+ int fd;
+ int (*op)();
+} buffer;
+
+#define BUFFER_INIT(op,fd,buf,len) { (buf), 0, (len), (fd), (op) }
+#define BUFFER_INSIZE 8192
+#define BUFFER_OUTSIZE 8192
+
+extern void buffer_init(buffer *,int (*)(),int,char *,unsigned int);
+
+extern int buffer_flush(buffer *);
+extern int buffer_put(buffer *,const char *,unsigned int);
+extern int buffer_putalign(buffer *,const char *,unsigned int);
+extern int buffer_putflush(buffer *,const char *,unsigned int);
+extern int buffer_puts(buffer *,const char *);
+extern int buffer_putsalign(buffer *,const char *);
+extern int buffer_putsflush(buffer *,const char *);
+
+#define buffer_PUTC(s,c) \
+ ( ((s)->n != (s)->p) \
+ ? ( (s)->x[(s)->p++] = (c), 0 ) \
+ : buffer_put((s),&(c),1) \
+ )
+
+extern int buffer_get(buffer *,char *,unsigned int);
+extern int buffer_bget(buffer *,char *,unsigned int);
+extern int buffer_feed(buffer *);
+
+extern char *buffer_peek(buffer *);
+extern void buffer_seek(buffer *,unsigned int);
+
+#define buffer_PEEK(s) ( (s)->x + (s)->n )
+#define buffer_SEEK(s,len) ( ( (s)->p -= (len) ) , ( (s)->n += (len) ) )
+
+#define buffer_GETC(s,c) \
+ ( ((s)->p > 0) \
+ ? ( *(c) = (s)->x[(s)->n], buffer_SEEK((s),1), 1 ) \
+ : buffer_get((s),(c),1) \
+ )
+
+extern int buffer_copy(buffer *,buffer *);
+
+extern int buffer_unixread(int,char *,unsigned int);
+extern int buffer_unixwrite(int,const char *,unsigned int);
+
+extern buffer *buffer_0;
+extern buffer *buffer_0small;
+extern buffer *buffer_1;
+extern buffer *buffer_1small;
+extern buffer *buffer_2;
+
+#endif
diff --git a/src/buffer_0.c b/src/buffer_0.c
@@ -0,0 +1,13 @@
+/* Public domain. */
+
+#include "buffer.h"
+
+int buffer_0_read(fd,buf,len) int fd; char *buf; int len;
+{
+ if (buffer_flush(buffer_1) == -1) return -1;
+ return buffer_unixread(fd,buf,len);
+}
+
+char buffer_0_space[BUFFER_INSIZE];
+static buffer it = BUFFER_INIT(buffer_0_read,0,buffer_0_space,sizeof buffer_0_space);
+buffer *buffer_0 = ⁢
diff --git a/src/buffer_1.c b/src/buffer_1.c
@@ -0,0 +1,7 @@
+/* Public domain. */
+
+#include "buffer.h"
+
+char buffer_1_space[BUFFER_OUTSIZE];
+static buffer it = BUFFER_INIT(buffer_unixwrite,1,buffer_1_space,sizeof buffer_1_space);
+buffer *buffer_1 = ⁢
diff --git a/src/buffer_2.c b/src/buffer_2.c
@@ -0,0 +1,7 @@
+/* Public domain. */
+
+#include "buffer.h"
+
+char buffer_2_space[256];
+static buffer it = BUFFER_INIT(buffer_unixwrite,2,buffer_2_space,sizeof buffer_2_space);
+buffer *buffer_2 = ⁢
diff --git a/src/buffer_get.c b/src/buffer_get.c
@@ -0,0 +1,69 @@
+/* Public domain. */
+
+#include "buffer.h"
+#include "byte.h"
+#include "error.h"
+
+static int oneread(int (*op)(),int fd,char *buf,unsigned int len)
+{
+ int r;
+
+ for (;;) {
+ r = op(fd,buf,len);
+ if (r == -1) if (errno == error_intr) continue;
+ return r;
+ }
+}
+
+static int getthis(buffer *s,char *buf,unsigned int len)
+{
+ if (len > s->p) len = s->p;
+ s->p -= len;
+ byte_copy(buf,len,s->x + s->n);
+ s->n += len;
+ return len;
+}
+
+int buffer_feed(buffer *s)
+{
+ int r;
+
+ if (s->p) return s->p;
+ r = oneread(s->op,s->fd,s->x,s->n);
+ if (r <= 0) return r;
+ s->p = r;
+ s->n -= r;
+ if (s->n > 0) byte_copyr(s->x + s->n,r,s->x);
+ return r;
+}
+
+int buffer_bget(buffer *s,char *buf,unsigned int len)
+{
+ int r;
+
+ if (s->p > 0) return getthis(s,buf,len);
+ if (s->n <= len) return oneread(s->op,s->fd,buf,s->n);
+ r = buffer_feed(s); if (r <= 0) return r;
+ return getthis(s,buf,len);
+}
+
+int buffer_get(buffer *s,char *buf,unsigned int len)
+{
+ int r;
+
+ if (s->p > 0) return getthis(s,buf,len);
+ if (s->n <= len) return oneread(s->op,s->fd,buf,len);
+ r = buffer_feed(s); if (r <= 0) return r;
+ return getthis(s,buf,len);
+}
+
+char *buffer_peek(buffer *s)
+{
+ return s->x + s->n;
+}
+
+void buffer_seek(buffer *s,unsigned int len)
+{
+ s->n += len;
+ s->p -= len;
+}
diff --git a/src/buffer_put.c b/src/buffer_put.c
@@ -0,0 +1,90 @@
+/* Public domain. */
+
+#include "buffer.h"
+#include "str.h"
+#include "byte.h"
+#include "error.h"
+
+static int allwrite(int (*op)(),int fd,const char *buf,unsigned int len)
+{
+ int w;
+
+ while (len) {
+ w = op(fd,buf,len);
+ if (w == -1) {
+ if (errno == error_intr) continue;
+ return -1; /* note that some data may have been written */
+ }
+ if (w == 0) ; /* luser's fault */
+ buf += w;
+ len -= w;
+ }
+ return 0;
+}
+
+int buffer_flush(buffer *s)
+{
+ int p;
+
+ p = s->p;
+ if (!p) return 0;
+ s->p = 0;
+ return allwrite(s->op,s->fd,s->x,p);
+}
+
+int buffer_putalign(buffer *s,const char *buf,unsigned int len)
+{
+ unsigned int n;
+
+ while (len > (n = s->n - s->p)) {
+ byte_copy(s->x + s->p,n,buf); s->p += n; buf += n; len -= n;
+ if (buffer_flush(s) == -1) return -1;
+ }
+ /* now len <= s->n - s->p */
+ byte_copy(s->x + s->p,len,buf);
+ s->p += len;
+ return 0;
+}
+
+int buffer_put(buffer *s,const char *buf,unsigned int len)
+{
+ unsigned int n;
+
+ n = s->n;
+ if (len > n - s->p) {
+ if (buffer_flush(s) == -1) return -1;
+ /* now s->p == 0 */
+ if (n < BUFFER_OUTSIZE) n = BUFFER_OUTSIZE;
+ while (len > s->n) {
+ if (n > len) n = len;
+ if (allwrite(s->op,s->fd,buf,n) == -1) return -1;
+ buf += n;
+ len -= n;
+ }
+ }
+ /* now len <= s->n - s->p */
+ byte_copy(s->x + s->p,len,buf);
+ s->p += len;
+ return 0;
+}
+
+int buffer_putflush(buffer *s,const char *buf,unsigned int len)
+{
+ if (buffer_flush(s) == -1) return -1;
+ return allwrite(s->op,s->fd,buf,len);
+}
+
+int buffer_putsalign(buffer *s,const char *buf)
+{
+ return buffer_putalign(s,buf,str_len(buf));
+}
+
+int buffer_puts(buffer *s,const char *buf)
+{
+ return buffer_put(s,buf,str_len(buf));
+}
+
+int buffer_putsflush(buffer *s,const char *buf)
+{
+ return buffer_putflush(s,buf,str_len(buf));
+}
diff --git a/src/buffer_read.c b/src/buffer_read.c
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+#include <unistd.h>
+#include "buffer.h"
+
+int buffer_unixread(int fd,char *buf,unsigned int len)
+{
+ return read(fd,buf,len);
+}
diff --git a/src/buffer_write.c b/src/buffer_write.c
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+#include <unistd.h>
+#include "buffer.h"
+
+int buffer_unixwrite(int fd,const char *buf,unsigned int len)
+{
+ return write(fd,buf,len);
+}
diff --git a/src/byte.h b/src/byte.h
@@ -0,0 +1,15 @@
+/* Public domain. */
+
+#ifndef BYTE_H
+#define BYTE_H
+
+extern unsigned int byte_chr();
+extern unsigned int byte_rchr();
+extern void byte_copy();
+extern void byte_copyr();
+extern int byte_diff();
+extern void byte_zero();
+
+#define byte_equal(s,n,t) (!byte_diff((s),(n),(t)))
+
+#endif
diff --git a/src/byte_chr.c b/src/byte_chr.c
@@ -0,0 +1,22 @@
+/* Public domain. */
+
+#include "byte.h"
+
+unsigned int byte_chr(s,n,c)
+char *s;
+register unsigned int n;
+int c;
+{
+ register char ch;
+ register char *t;
+
+ ch = c;
+ t = s;
+ for (;;) {
+ if (!n) break; if (*t == ch) break; ++t; --n;
+ if (!n) break; if (*t == ch) break; ++t; --n;
+ if (!n) break; if (*t == ch) break; ++t; --n;
+ if (!n) break; if (*t == ch) break; ++t; --n;
+ }
+ return t - s;
+}
diff --git a/src/byte_copy.c b/src/byte_copy.c
@@ -0,0 +1,16 @@
+/* Public domain. */
+
+#include "byte.h"
+
+void byte_copy(to,n,from)
+register char *to;
+register unsigned int n;
+register char *from;
+{
+ for (;;) {
+ if (!n) return; *to++ = *from++; --n;
+ if (!n) return; *to++ = *from++; --n;
+ if (!n) return; *to++ = *from++; --n;
+ if (!n) return; *to++ = *from++; --n;
+ }
+}
diff --git a/src/byte_cr.c b/src/byte_cr.c
@@ -0,0 +1,18 @@
+/* Public domain. */
+
+#include "byte.h"
+
+void byte_copyr(to,n,from)
+register char *to;
+register unsigned int n;
+register char *from;
+{
+ to += n;
+ from += n;
+ for (;;) {
+ if (!n) return; *--to = *--from; --n;
+ if (!n) return; *--to = *--from; --n;
+ if (!n) return; *--to = *--from; --n;
+ if (!n) return; *--to = *--from; --n;
+ }
+}
diff --git a/src/byte_diff.c b/src/byte_diff.c
@@ -0,0 +1,18 @@
+/* Public domain. */
+
+#include "byte.h"
+
+int byte_diff(s,n,t)
+register char *s;
+register unsigned int n;
+register char *t;
+{
+ for (;;) {
+ if (!n) return 0; if (*s != *t) break; ++s; ++t; --n;
+ if (!n) return 0; if (*s != *t) break; ++s; ++t; --n;
+ if (!n) return 0; if (*s != *t) break; ++s; ++t; --n;
+ if (!n) return 0; if (*s != *t) break; ++s; ++t; --n;
+ }
+ return ((int)(unsigned int)(unsigned char) *s)
+ - ((int)(unsigned int)(unsigned char) *t);
+}
diff --git a/src/byte_rchr.c b/src/byte_rchr.c
@@ -0,0 +1,25 @@
+/* Public domain. */
+
+#include "byte.h"
+
+unsigned int byte_rchr(s,n,c)
+char *s;
+register unsigned int n;
+int c;
+{
+ register char ch;
+ register char *t;
+ register char *u;
+
+ ch = c;
+ t = s;
+ u = 0;
+ for (;;) {
+ if (!n) break; if (*t == ch) u = t; ++t; --n;
+ if (!n) break; if (*t == ch) u = t; ++t; --n;
+ if (!n) break; if (*t == ch) u = t; ++t; --n;
+ if (!n) break; if (*t == ch) u = t; ++t; --n;
+ }
+ if (!u) u = t;
+ return u - s;
+}
diff --git a/src/chkshsgr.c b/src/chkshsgr.c
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#include <unistd.h>
+
+int main()
+{
+ short x[4];
+
+ x[0] = x[1] = 0;
+ if (getgroups(1,x) == 0) if (setgroups(1,x) == -1) _exit(1);
+ _exit(0);
+}
diff --git a/src/choose.sh b/src/choose.sh
@@ -0,0 +1,18 @@
+
+result="$4"
+
+case "$1" in
+ *c*) ./compile $2.c >/dev/null 2>&1 || result="$3" ;;
+esac
+
+case "$1" in
+ *l*) ./load $2 >/dev/null 2>&1 || result="$3" ;;
+esac
+
+case "$1" in
+ *r*) ./$2 >/dev/null 2>&1 || result="$3" ;;
+esac
+
+rm -f $2.o $2
+
+exec cat "$result"
diff --git a/src/coe.c b/src/coe.c
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+#include <fcntl.h>
+#include "coe.h"
+
+int coe(int fd)
+{
+ return fcntl(fd,F_SETFD,1);
+}
diff --git a/src/coe.h b/src/coe.h
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#ifndef COE_H
+#define COE_H
+
+extern int coe(int);
+
+#endif
diff --git a/src/conf-cc b/src/conf-cc
@@ -0,0 +1,5 @@
+gcc -O2 -Wall
+
+gcc -O2 -Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized -Wshadow -Wcast-qual -Wcast-align -Wwrite-strings
+
+This will be used to compile .c files.
diff --git a/src/conf-ld b/src/conf-ld
@@ -0,0 +1,3 @@
+gcc -s
+
+This will be used to link .o files into an executable.
diff --git a/src/direntry.h1 b/src/direntry.h1
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#ifndef DIRENTRY_H
+#define DIRENTRY_H
+
+/* sysdep: -dirent */
+
+#include <sys/types.h>
+#include <sys/dir.h>
+#define direntry struct direct
+
+#endif
diff --git a/src/direntry.h2 b/src/direntry.h2
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#ifndef DIRENTRY_H
+#define DIRENTRY_H
+
+/* sysdep: +dirent */
+
+#include <sys/types.h>
+#include <dirent.h>
+#define direntry struct dirent
+
+#endif
diff --git a/src/env.c b/src/env.c
@@ -0,0 +1,17 @@
+/* Public domain. */
+
+#include "str.h"
+#include "env.h"
+
+extern /*@null@*/char *env_get(const char *s)
+{
+ int i;
+ unsigned int len;
+
+ if (!s) return 0;
+ len = str_len(s);
+ for (i = 0;environ[i];++i)
+ if (str_start(environ[i],s) && (environ[i][len] == '='))
+ return environ[i] + len + 1;
+ return 0;
+}
diff --git a/src/env.h b/src/env.h
@@ -0,0 +1,10 @@
+/* Public domain. */
+
+#ifndef ENV_H
+#define ENV_H
+
+extern char **environ;
+
+extern /*@null@*/char *env_get(const char *);
+
+#endif
diff --git a/src/error.c b/src/error.c
@@ -0,0 +1,132 @@
+/* Public domain. */
+
+#include <errno.h>
+#include "error.h"
+
+/* warning: as coverage improves here, should update error_{str,temp} */
+
+int error_intr =
+#ifdef EINTR
+EINTR;
+#else
+-1;
+#endif
+
+int error_nomem =
+#ifdef ENOMEM
+ENOMEM;
+#else
+-2;
+#endif
+
+int error_noent =
+#ifdef ENOENT
+ENOENT;
+#else
+-3;
+#endif
+
+int error_txtbsy =
+#ifdef ETXTBSY
+ETXTBSY;
+#else
+-4;
+#endif
+
+int error_io =
+#ifdef EIO
+EIO;
+#else
+-5;
+#endif
+
+int error_exist =
+#ifdef EEXIST
+EEXIST;
+#else
+-6;
+#endif
+
+int error_timeout =
+#ifdef ETIMEDOUT
+ETIMEDOUT;
+#else
+-7;
+#endif
+
+int error_inprogress =
+#ifdef EINPROGRESS
+EINPROGRESS;
+#else
+-8;
+#endif
+
+int error_wouldblock =
+#ifdef EWOULDBLOCK
+EWOULDBLOCK;
+#else
+-9;
+#endif
+
+int error_again =
+#ifdef EAGAIN
+EAGAIN;
+#else
+-10;
+#endif
+
+int error_pipe =
+#ifdef EPIPE
+EPIPE;
+#else
+-11;
+#endif
+
+int error_perm =
+#ifdef EPERM
+EPERM;
+#else
+-12;
+#endif
+
+int error_acces =
+#ifdef EACCES
+EACCES;
+#else
+-13;
+#endif
+
+int error_nodevice =
+#ifdef ENXIO
+ENXIO;
+#else
+-14;
+#endif
+
+int error_proto =
+#ifdef EPROTO
+EPROTO;
+#else
+-15;
+#endif
+
+int error_isdir =
+#ifdef EISDIR
+EISDIR;
+#else
+-16;
+#endif
+
+int error_connrefused =
+#ifdef ECONNREFUSED
+ECONNREFUSED;
+#else
+-17;
+#endif
+
+int error_notdir =
+#ifdef ENOTDIR
+ENOTDIR;
+#else
+-18;
+#endif
diff --git a/src/error.h b/src/error.h
@@ -0,0 +1,30 @@
+/* Public domain. */
+
+#ifndef ERROR_H
+#define ERROR_H
+
+extern int errno;
+
+extern int error_intr;
+extern int error_nomem;
+extern int error_noent;
+extern int error_txtbsy;
+extern int error_io;
+extern int error_exist;
+extern int error_timeout;
+extern int error_inprogress;
+extern int error_wouldblock;
+extern int error_again;
+extern int error_pipe;
+extern int error_perm;
+extern int error_acces;
+extern int error_nodevice;
+extern int error_proto;
+extern int error_isdir;
+extern int error_connrefused;
+extern int error_notdir;
+
+extern const char *error_str(int);
+extern int error_temp(int);
+
+#endif
diff --git a/src/error_str.c b/src/error_str.c
@@ -0,0 +1,267 @@
+/* Public domain. */
+
+#include <errno.h>
+#include "error.h"
+
+#define X(e,s) if (i == e) return s;
+
+const char *error_str(int i)
+{
+ X(0,"no error")
+ X(error_intr,"interrupted system call")
+ X(error_nomem,"out of memory")
+ X(error_noent,"file does not exist")
+ X(error_txtbsy,"text busy")
+ X(error_io,"input/output error")
+ X(error_exist,"file already exists")
+ X(error_timeout,"timed out")
+ X(error_inprogress,"operation in progress")
+ X(error_again,"temporary failure")
+ X(error_wouldblock,"input/output would block")
+ X(error_pipe,"broken pipe")
+ X(error_perm,"permission denied")
+ X(error_acces,"access denied")
+ X(error_nodevice,"device not configured")
+ X(error_proto,"protocol error")
+ X(error_isdir,"is a directory")
+ X(error_connrefused,"connection refused")
+ X(error_notdir,"not a directory")
+#ifdef ESRCH
+ X(ESRCH,"no such process")
+#endif
+#ifdef E2BIG
+ X(E2BIG,"argument list too long")
+#endif
+#ifdef ENOEXEC
+ X(ENOEXEC,"exec format error")
+#endif
+#ifdef EBADF
+ X(EBADF,"file descriptor not open")
+#endif
+#ifdef ECHILD
+ X(ECHILD,"no child processes")
+#endif
+#ifdef EDEADLK
+ X(EDEADLK,"operation would cause deadlock")
+#endif
+#ifdef EFAULT
+ X(EFAULT,"bad address")
+#endif
+#ifdef ENOTBLK
+ X(ENOTBLK,"not a block device")
+#endif
+#ifdef EBUSY
+ X(EBUSY,"device busy")
+#endif
+#ifdef EXDEV
+ X(EXDEV,"cross-device link")
+#endif
+#ifdef ENODEV
+ X(ENODEV,"device does not support operation")
+#endif
+#ifdef EINVAL
+ X(EINVAL,"invalid argument")
+#endif
+#ifdef ENFILE
+ X(ENFILE,"system cannot open more files")
+#endif
+#ifdef EMFILE
+ X(EMFILE,"process cannot open more files")
+#endif
+#ifdef ENOTTY
+ X(ENOTTY,"not a tty")
+#endif
+#ifdef EFBIG
+ X(EFBIG,"file too big")
+#endif
+#ifdef ENOSPC
+ X(ENOSPC,"out of disk space")
+#endif
+#ifdef ESPIPE
+ X(ESPIPE,"unseekable descriptor")
+#endif
+#ifdef EROFS
+ X(EROFS,"read-only file system")
+#endif
+#ifdef EMLINK
+ X(EMLINK,"too many links")
+#endif
+#ifdef EDOM
+ X(EDOM,"input out of range")
+#endif
+#ifdef ERANGE
+ X(ERANGE,"output out of range")
+#endif
+#ifdef EALREADY
+ X(EALREADY,"operation already in progress")
+#endif
+#ifdef ENOTSOCK
+ X(ENOTSOCK,"not a socket")
+#endif
+#ifdef EDESTADDRREQ
+ X(EDESTADDRREQ,"destination address required")
+#endif
+#ifdef EMSGSIZE
+ X(EMSGSIZE,"message too long")
+#endif
+#ifdef EPROTOTYPE
+ X(EPROTOTYPE,"incorrect protocol type")
+#endif
+#ifdef ENOPROTOOPT
+ X(ENOPROTOOPT,"protocol not available")
+#endif
+#ifdef EPROTONOSUPPORT
+ X(EPROTONOSUPPORT,"protocol not supported")
+#endif
+#ifdef ESOCKTNOSUPPORT
+ X(ESOCKTNOSUPPORT,"socket type not supported")
+#endif
+#ifdef EOPNOTSUPP
+ X(EOPNOTSUPP,"operation not supported")
+#endif
+#ifdef EPFNOSUPPORT
+ X(EPFNOSUPPORT,"protocol family not supported")
+#endif
+#ifdef EAFNOSUPPORT
+ X(EAFNOSUPPORT,"address family not supported")
+#endif
+#ifdef EADDRINUSE
+ X(EADDRINUSE,"address already used")
+#endif
+#ifdef EADDRNOTAVAIL
+ X(EADDRNOTAVAIL,"address not available")
+#endif
+#ifdef ENETDOWN
+ X(ENETDOWN,"network down")
+#endif
+#ifdef ENETUNREACH
+ X(ENETUNREACH,"network unreachable")
+#endif
+#ifdef ENETRESET
+ X(ENETRESET,"network reset")
+#endif
+#ifdef ECONNABORTED
+ X(ECONNABORTED,"connection aborted")
+#endif
+#ifdef ECONNRESET
+ X(ECONNRESET,"connection reset")
+#endif
+#ifdef ENOBUFS
+ X(ENOBUFS,"out of buffer space")
+#endif
+#ifdef EISCONN
+ X(EISCONN,"already connected")
+#endif
+#ifdef ENOTCONN
+ X(ENOTCONN,"not connected")
+#endif
+#ifdef ESHUTDOWN
+ X(ESHUTDOWN,"socket shut down")
+#endif
+#ifdef ETOOMANYREFS
+ X(ETOOMANYREFS,"too many references")
+#endif
+#ifdef ELOOP
+ X(ELOOP,"symbolic link loop")
+#endif
+#ifdef ENAMETOOLONG
+ X(ENAMETOOLONG,"file name too long")
+#endif
+#ifdef EHOSTDOWN
+ X(EHOSTDOWN,"host down")
+#endif
+#ifdef EHOSTUNREACH
+ X(EHOSTUNREACH,"host unreachable")
+#endif
+#ifdef ENOTEMPTY
+ X(ENOTEMPTY,"directory not empty")
+#endif
+#ifdef EPROCLIM
+ X(EPROCLIM,"too many processes")
+#endif
+#ifdef EUSERS
+ X(EUSERS,"too many users")
+#endif
+#ifdef EDQUOT
+ X(EDQUOT,"disk quota exceeded")
+#endif
+#ifdef ESTALE
+ X(ESTALE,"stale NFS file handle")
+#endif
+#ifdef EREMOTE
+ X(EREMOTE,"too many levels of remote in path")
+#endif
+#ifdef EBADRPC
+ X(EBADRPC,"RPC structure is bad")
+#endif
+#ifdef ERPCMISMATCH
+ X(ERPCMISMATCH,"RPC version mismatch")
+#endif
+#ifdef EPROGUNAVAIL
+ X(EPROGUNAVAIL,"RPC program unavailable")
+#endif
+#ifdef EPROGMISMATCH
+ X(EPROGMISMATCH,"program version mismatch")
+#endif
+#ifdef EPROCUNAVAIL
+ X(EPROCUNAVAIL,"bad procedure for program")
+#endif
+#ifdef ENOLCK
+ X(ENOLCK,"no locks available")
+#endif
+#ifdef ENOSYS
+ X(ENOSYS,"system call not available")
+#endif
+#ifdef EFTYPE
+ X(EFTYPE,"bad file type")
+#endif
+#ifdef EAUTH
+ X(EAUTH,"authentication error")
+#endif
+#ifdef ENEEDAUTH
+ X(ENEEDAUTH,"not authenticated")
+#endif
+#ifdef ENOSTR
+ X(ENOSTR,"not a stream device")
+#endif
+#ifdef ETIME
+ X(ETIME,"timer expired")
+#endif
+#ifdef ENOSR
+ X(ENOSR,"out of stream resources")
+#endif
+#ifdef ENOMSG
+ X(ENOMSG,"no message of desired type")
+#endif
+#ifdef EBADMSG
+ X(EBADMSG,"bad message type")
+#endif
+#ifdef EIDRM
+ X(EIDRM,"identifier removed")
+#endif
+#ifdef ENONET
+ X(ENONET,"machine not on network")
+#endif
+#ifdef ERREMOTE
+ X(ERREMOTE,"object not local")
+#endif
+#ifdef ENOLINK
+ X(ENOLINK,"link severed")
+#endif
+#ifdef EADV
+ X(EADV,"advertise error")
+#endif
+#ifdef ESRMNT
+ X(ESRMNT,"srmount error")
+#endif
+#ifdef ECOMM
+ X(ECOMM,"communication error")
+#endif
+#ifdef EMULTIHOP
+ X(EMULTIHOP,"multihop attempted")
+#endif
+#ifdef EREMCHG
+ X(EREMCHG,"remote address changed")
+#endif
+ return "unknown error";
+}
diff --git a/src/fd.h b/src/fd.h
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+#ifndef FD_H
+#define FD_H
+
+extern int fd_copy(int,int);
+extern int fd_move(int,int);
+
+#endif
diff --git a/src/fd_copy.c b/src/fd_copy.c
@@ -0,0 +1,14 @@
+/* Public domain. */
+
+#include <unistd.h>
+#include <fcntl.h>
+#include "fd.h"
+
+int fd_copy(int to,int from)
+{
+ if (to == from) return 0;
+ if (fcntl(from,F_GETFL,0) == -1) return -1;
+ close(to);
+ if (fcntl(from,F_DUPFD,to) == -1) return -1;
+ return 0;
+}
diff --git a/src/fd_move.c b/src/fd_move.c
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#include <unistd.h>
+#include "fd.h"
+
+int fd_move(int to,int from)
+{
+ if (to == from) return 0;
+ if (fd_copy(to,from) == -1) return -1;
+ close(from);
+ return 0;
+}
diff --git a/src/fifo.c b/src/fifo.c
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include "hasmkffo.h"
+#include "fifo.h"
+
+#ifdef HASMKFIFO
+int fifo_make(const char *fn,int mode) { return mkfifo(fn,mode); }
+#else
+int fifo_make(const char *fn,int mode) { return mknod(fn,S_IFIFO | mode,0); }
+#endif
diff --git a/src/fifo.h b/src/fifo.h
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#ifndef FIFO_H
+#define FIFO_H
+
+extern int fifo_make(const char *,int);
+
+#endif
diff --git a/src/find-systype.sh b/src/find-systype.sh
@@ -0,0 +1,143 @@
+# oper-:arch-:syst-:chip-:kern-
+# oper = operating system type; e.g., sunos-4.1.4
+# arch = machine language; e.g., sparc
+# syst = which binaries can run; e.g., sun4
+# chip = chip model; e.g., micro-2-80
+# kern = kernel version; e.g., sun4m
+# dependence: arch --- chip
+# \ \
+# oper --- syst --- kern
+# so, for example, syst is interpreted in light of oper, but chip is not.
+# anyway, no slashes, no extra colons, no uppercase letters.
+# the point of the extra -'s is to ease parsing: can add hierarchies later.
+# e.g., *:i386-*:*:pentium-*:* would handle pentium-100 as well as pentium,
+# and i386-486 (486s do have more instructions, you know) as well as i386.
+# the idea here is to include ALL useful available information.
+
+exec 2>/dev/null
+
+sys="`uname -s | tr '/:[A-Z]' '..[a-z]'`"
+if [ x"$sys" != x ]
+then
+ unamer="`uname -r | tr /: ..`"
+ unamem="`uname -m | tr /: ..`"
+ unamev="`uname -v | tr /: ..`"
+
+ case "$sys" in
+ bsd.os|freebsd|netbsd|openbsd)
+ # in bsd 4.4, uname -v does not have useful info.
+ # in bsd 4.4, uname -m is arch, not chip.
+ oper="$sys-$unamer"
+ arch="$unamem"
+ syst=""
+ chip="`sysctl -n hw.model`" # hopefully
+ kern=""
+ ;;
+ linux)
+ # as in bsd 4.4, uname -v does not have useful info.
+ oper="$sys-$unamer"
+ syst=""
+ chip="$unamem"
+ kern=""
+ case "$chip" in
+ i386|i486|i586|i686)
+ arch="i386"
+ ;;
+ alpha)
+ arch="alpha"
+ ;;
+ esac
+ ;;
+ aix)
+ # naturally IBM has to get uname -r and uname -v backwards. dorks.
+ oper="$sys-$unamev-$unamer"
+ arch="`arch | tr /: ..`"
+ syst=""
+ chip="$unamem"
+ kern=""
+ ;;
+ sunos)
+ oper="$sys-$unamer-$unamev"
+ arch="`(uname -p || mach) | tr /: ..`"
+ syst="`arch | tr /: ..`"
+ chip="$unamem" # this is wrong; is there any way to get the real info?
+ kern="`arch -k | tr /: ..`"
+ ;;
+ unix_sv)
+ oper="$sys-$unamer-$unamev"
+ arch="`uname -m`"
+ syst=""
+ chip="$unamem"
+ kern=""
+ ;;
+ *)
+ oper="$sys-$unamer-$unamev"
+ arch="`arch | tr /: ..`"
+ syst=""
+ chip="$unamem"
+ kern=""
+ ;;
+ esac
+else
+ gcc -c trycpp.c
+ gcc -o trycpp trycpp.o
+ case `./trycpp` in
+ nextstep)
+ oper="nextstep-`hostinfo | sed -n 's/^[ ]*NeXT Mach \([^:]*\):.*$/\1/p'`"
+ arch="`hostinfo | sed -n 's/^Processor type: \(.*\) (.*)$/\1/p' | tr /: ..`"
+ syst=""
+ chip="`hostinfo | sed -n 's/^Processor type: .* (\(.*\))$/\1/p' | tr ' /:' '...'`"
+ kern=""
+ ;;
+ *)
+ oper="unknown"
+ arch=""
+ syst=""
+ chip=""
+ kern=""
+ ;;
+ esac
+ rm -f trycpp.o trycpp
+fi
+
+case "$chip" in
+80486)
+ # let's try to be consistent here. (BSD/OS)
+ chip=i486
+ ;;
+i486DX)
+ # respect the hyphen hierarchy. (FreeBSD)
+ chip=i486-dx
+ ;;
+i486.DX2)
+ # respect the hyphen hierarchy. (FreeBSD)
+ chip=i486-dx2
+ ;;
+Intel.586)
+ # no, you nitwits, there is no such chip. (NeXTStep)
+ chip=pentium
+ ;;
+i586)
+ # no, you nitwits, there is no such chip. (Linux)
+ chip=pentium
+ ;;
+i686)
+ # STOP SAYING THAT! (Linux)
+ chip=ppro
+esac
+
+if gcc -c x86cpuid.c
+then
+ if gcc -o x86cpuid x86cpuid.o
+ then
+ x86cpuid="`./x86cpuid | tr /: ..`"
+ case "$x86cpuid" in
+ ?*)
+ chip="$x86cpuid"
+ ;;
+ esac
+ fi
+fi
+rm -f x86cpuid x86cpuid.o
+
+echo "$oper-:$arch-:$syst-:$chip-:$kern-" | tr ' [A-Z]' '.[a-z]'
diff --git a/src/fmt.h b/src/fmt.h
@@ -0,0 +1,27 @@
+/* Public domain. */
+
+#ifndef FMT_H
+#define FMT_H
+
+#define FMT_ULONG 40 /* enough space to hold 2^128 - 1 in decimal, plus \0 */
+#define FMT_LEN ((char *) 0) /* convenient abbreviation */
+
+extern unsigned int fmt_uint(char *,unsigned int);
+extern unsigned int fmt_uint0(char *,unsigned int,unsigned int);
+extern unsigned int fmt_xint(char *,unsigned int);
+extern unsigned int fmt_nbbint(char *,unsigned int,unsigned int,unsigned int,unsigned int);
+extern unsigned int fmt_ushort(char *,unsigned short);
+extern unsigned int fmt_xshort(char *,unsigned short);
+extern unsigned int fmt_nbbshort(char *,unsigned int,unsigned int,unsigned int,unsigned short);
+extern unsigned int fmt_ulong(char *,unsigned long);
+extern unsigned int fmt_xlong(char *,unsigned long);
+extern unsigned int fmt_nbblong(char *,unsigned int,unsigned int,unsigned int,unsigned long);
+
+extern unsigned int fmt_plusminus(char *,int);
+extern unsigned int fmt_minus(char *,int);
+extern unsigned int fmt_0x(char *,int);
+
+extern unsigned int fmt_str(char *,const char *);
+extern unsigned int fmt_strn(char *,const char *,unsigned int);
+
+#endif
diff --git a/src/fmt_uint.c b/src/fmt_uint.c
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#include "fmt.h"
+
+unsigned int fmt_uint(register char *s,register unsigned int u)
+{
+ return fmt_ulong(s,u);
+}
diff --git a/src/fmt_uint0.c b/src/fmt_uint0.c
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#include "fmt.h"
+
+unsigned int fmt_uint0(char *s,unsigned int u,unsigned int n)
+{
+ unsigned int len;
+ len = fmt_uint(FMT_LEN,u);
+ while (len < n) { if (s) *s++ = '0'; ++len; }
+ if (s) fmt_uint(s,u);
+ return len;
+}
diff --git a/src/fmt_ulong.c b/src/fmt_ulong.c
@@ -0,0 +1,15 @@
+/* Public domain. */
+
+#include "fmt.h"
+
+unsigned int fmt_ulong(register char *s,register unsigned long u)
+{
+ register unsigned int len; register unsigned long q;
+ len = 1; q = u;
+ while (q > 9) { ++len; q /= 10; }
+ if (s) {
+ s += len;
+ do { *--s = '0' + (u % 10); u /= 10; } while(u); /* handles u == 0 */
+ }
+ return len;
+}
diff --git a/src/gen_alloc.h b/src/gen_alloc.h
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+#ifndef GEN_ALLOC_H
+#define GEN_ALLOC_H
+
+#define GEN_ALLOC_typedef(ta,type,field,len,a) \
+ typedef struct ta { type *field; unsigned int len; unsigned int a; } ta;
+
+#endif
diff --git a/src/gen_allocdefs.h b/src/gen_allocdefs.h
@@ -0,0 +1,36 @@
+/* Public domain. */
+
+#ifndef GEN_ALLOC_DEFS_H
+#define GEN_ALLOC_DEFS_H
+
+#define GEN_ALLOC_ready(ta,type,field,len,a,i,n,x,base,ta_ready) \
+int ta_ready(register ta *x,register unsigned int n) \
+{ register unsigned int i; \
+ if (x->field) { \
+ i = x->a; \
+ if (n > i) { \
+ x->a = base + n + (n >> 3); \
+ if (alloc_re(&x->field,i * sizeof(type),x->a * sizeof(type))) return 1; \
+ x->a = i; return 0; } \
+ return 1; } \
+ x->len = 0; \
+ return !!(x->field = (type *) alloc((x->a = n) * sizeof(type))); }
+
+#define GEN_ALLOC_readyplus(ta,type,field,len,a,i,n,x,base,ta_rplus) \
+int ta_rplus(register ta *x,register unsigned int n) \
+{ register unsigned int i; \
+ if (x->field) { \
+ i = x->a; n += x->len; \
+ if (n > i) { \
+ x->a = base + n + (n >> 3); \
+ if (alloc_re(&x->field,i * sizeof(type),x->a * sizeof(type))) return 1; \
+ x->a = i; return 0; } \
+ return 1; } \
+ x->len = 0; \
+ return !!(x->field = (type *) alloc((x->a = n) * sizeof(type))); }
+
+#define GEN_ALLOC_append(ta,type,field,len,a,i,n,x,base,ta_rplus,ta_append) \
+int ta_append(register ta *x,register const type *i) \
+{ if (!ta_rplus(x,1)) return 0; x->field[x->len++] = *i; return 1; }
+
+#endif
diff --git a/src/hasflock.h1 b/src/hasflock.h1
@@ -0,0 +1,3 @@
+/* Public domain. */
+
+/* sysdep: -flock */
diff --git a/src/hasflock.h2 b/src/hasflock.h2
@@ -0,0 +1,4 @@
+/* Public domain. */
+
+/* sysdep: +flock */
+#define HASFLOCK 1
diff --git a/src/hasmkffo.h1 b/src/hasmkffo.h1
@@ -0,0 +1,3 @@
+/* Public domain. */
+
+/* sysdep: -mkfifo */
diff --git a/src/hasmkffo.h2 b/src/hasmkffo.h2
@@ -0,0 +1,4 @@
+/* Public domain. */
+
+/* sysdep: +mkfifo */
+#define HASMKFIFO 1
diff --git a/src/hassgact.h1 b/src/hassgact.h1
@@ -0,0 +1,3 @@
+/* Public domain. */
+
+/* sysdep: -sigaction */
diff --git a/src/hassgact.h2 b/src/hassgact.h2
@@ -0,0 +1,4 @@
+/* Public domain. */
+
+/* sysdep: +sigaction */
+#define HASSIGACTION 1
diff --git a/src/hassgprm.h1 b/src/hassgprm.h1
@@ -0,0 +1,3 @@
+/* Public domain. */
+
+/* sysdep: -sigprocmask */
diff --git a/src/hassgprm.h2 b/src/hassgprm.h2
@@ -0,0 +1,4 @@
+/* Public domain. */
+
+/* sysdep: +sigprocmask */
+#define HASSIGPROCMASK 1
diff --git a/src/hasshsgr.h1 b/src/hasshsgr.h1
@@ -0,0 +1,3 @@
+/* Public domain. */
+
+/* sysdep: -shortsetgroups */
diff --git a/src/hasshsgr.h2 b/src/hasshsgr.h2
@@ -0,0 +1,4 @@
+/* Public domain. */
+
+/* sysdep: +shortsetgroups */
+#define HASSHORTSETGROUPS 1
diff --git a/src/haswaitp.h1 b/src/haswaitp.h1
@@ -0,0 +1,3 @@
+/* Public domain. */
+
+/* sysdep: -waitpid */
diff --git a/src/haswaitp.h2 b/src/haswaitp.h2
@@ -0,0 +1,4 @@
+/* Public domain. */
+
+/* sysdep: +waitpid */
+#define HASWAITPID 1
diff --git a/src/iopause.c b/src/iopause.c
@@ -0,0 +1,78 @@
+/* Public domain. */
+
+#include "taia.h"
+#include "select.h"
+#include "iopause.h"
+
+void iopause(iopause_fd *x,unsigned int len,struct taia *deadline,struct taia *stamp)
+{
+ struct taia t;
+ int millisecs;
+ double d;
+ int i;
+
+ if (taia_less(deadline,stamp))
+ millisecs = 0;
+ else {
+ t = *stamp;
+ taia_sub(&t,deadline,&t);
+ d = taia_approx(&t);
+ if (d > 1000.0) d = 1000.0;
+ millisecs = d * 1000.0 + 20.0;
+ }
+
+ for (i = 0;i < len;++i)
+ x[i].revents = 0;
+
+#ifdef IOPAUSE_POLL
+
+ poll(x,len,millisecs);
+ /* XXX: some kernels apparently need x[0] even if len is 0 */
+ /* XXX: how to handle EAGAIN? are kernels really this dumb? */
+ /* XXX: how to handle EINVAL? when exactly can this happen? */
+
+#else
+{
+
+ struct timeval tv;
+ fd_set rfds;
+ fd_set wfds;
+ int nfds;
+ int fd;
+
+ FD_ZERO(&rfds);
+ FD_ZERO(&wfds);
+
+ nfds = 1;
+ for (i = 0;i < len;++i) {
+ fd = x[i].fd;
+ if (fd < 0) continue;
+ if (fd >= 8 * sizeof(fd_set)) continue; /*XXX*/
+
+ if (fd >= nfds) nfds = fd + 1;
+ if (x[i].events & IOPAUSE_READ) FD_SET(fd,&rfds);
+ if (x[i].events & IOPAUSE_WRITE) FD_SET(fd,&wfds);
+ }
+
+ tv.tv_sec = millisecs / 1000;
+ tv.tv_usec = 1000 * (millisecs % 1000);
+
+ if (select(nfds,&rfds,&wfds,(fd_set *) 0,&tv) <= 0)
+ return;
+ /* XXX: for EBADF, could seek out and destroy the bad descriptor */
+
+ for (i = 0;i < len;++i) {
+ fd = x[i].fd;
+ if (fd < 0) continue;
+ if (fd >= 8 * sizeof(fd_set)) continue; /*XXX*/
+
+ if (x[i].events & IOPAUSE_READ)
+ if (FD_ISSET(fd,&rfds)) x[i].revents |= IOPAUSE_READ;
+ if (x[i].events & IOPAUSE_WRITE)
+ if (FD_ISSET(fd,&wfds)) x[i].revents |= IOPAUSE_WRITE;
+ }
+
+}
+#endif
+
+}
diff --git a/src/iopause.h1 b/src/iopause.h1
@@ -0,0 +1,21 @@
+/* Public domain. */
+
+#ifndef IOPAUSE_H
+#define IOPAUSE_H
+
+/* sysdep: -poll */
+
+typedef struct {
+ int fd;
+ short events;
+ short revents;
+} iopause_fd;
+
+#define IOPAUSE_READ 1
+#define IOPAUSE_WRITE 4
+
+#include "taia.h"
+
+extern void iopause(iopause_fd *,unsigned int,struct taia *,struct taia *);
+
+#endif
diff --git a/src/iopause.h2 b/src/iopause.h2
@@ -0,0 +1,20 @@
+/* Public domain. */
+
+#ifndef IOPAUSE_H
+#define IOPAUSE_H
+
+/* sysdep: +poll */
+#define IOPAUSE_POLL
+
+#include <sys/types.h>
+#include <poll.h>
+
+typedef struct pollfd iopause_fd;
+#define IOPAUSE_READ POLLIN
+#define IOPAUSE_WRITE POLLOUT
+
+#include "taia.h"
+
+extern void iopause(iopause_fd *,unsigned int,struct taia *,struct taia *);
+
+#endif
diff --git a/src/lock.h b/src/lock.h
@@ -0,0 +1,10 @@
+/* Public domain. */
+
+#ifndef LOCK_H
+#define LOCK_H
+
+extern int lock_ex(int);
+extern int lock_un(int);
+extern int lock_exnb(int);
+
+#endif
diff --git a/src/lock_ex.c b/src/lock_ex.c
@@ -0,0 +1,13 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include <sys/file.h>
+#include <fcntl.h>
+#include "hasflock.h"
+#include "lock.h"
+
+#ifdef HASFLOCK
+int lock_ex(int fd) { return flock(fd,LOCK_EX); }
+#else
+int lock_ex(int fd) { return lockf(fd,1,0); }
+#endif
diff --git a/src/lock_exnb.c b/src/lock_exnb.c
@@ -0,0 +1,13 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include <sys/file.h>
+#include <fcntl.h>
+#include "hasflock.h"
+#include "lock.h"
+
+#ifdef HASFLOCK
+int lock_exnb(int fd) { return flock(fd,LOCK_EX | LOCK_NB); }
+#else
+int lock_exnb(int fd) { return lockf(fd,2,0); }
+#endif
diff --git a/src/ndelay.h b/src/ndelay.h
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+#ifndef NDELAY_H
+#define NDELAY_H
+
+extern int ndelay_on(int);
+extern int ndelay_off(int);
+
+#endif
diff --git a/src/ndelay_off.c b/src/ndelay_off.c
@@ -0,0 +1,14 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include "ndelay.h"
+
+#ifndef O_NONBLOCK
+#define O_NONBLOCK O_NDELAY
+#endif
+
+int ndelay_off(int fd)
+{
+ return fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0) & ~O_NONBLOCK);
+}
diff --git a/src/ndelay_on.c b/src/ndelay_on.c
@@ -0,0 +1,14 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include "ndelay.h"
+
+#ifndef O_NONBLOCK
+#define O_NONBLOCK O_NDELAY
+#endif
+
+int ndelay_on(int fd)
+{
+ return fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0) | O_NONBLOCK);
+}
diff --git a/src/open.h b/src/open.h
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#ifndef OPEN_H
+#define OPEN_H
+
+extern int open_read(const char *);
+extern int open_excl(const char *);
+extern int open_append(const char *);
+extern int open_trunc(const char *);
+extern int open_write(const char *);
+
+#endif
diff --git a/src/open_append.c b/src/open_append.c
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include "open.h"
+
+int open_append(const char *fn)
+{ return open(fn,O_WRONLY | O_NDELAY | O_APPEND | O_CREAT,0600); }
diff --git a/src/open_read.c b/src/open_read.c
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include "open.h"
+
+int open_read(const char *fn)
+{ return open(fn,O_RDONLY | O_NDELAY); }
diff --git a/src/open_trunc.c b/src/open_trunc.c
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include "open.h"
+
+int open_trunc(const char *fn)
+{ return open(fn,O_WRONLY | O_NDELAY | O_TRUNC | O_CREAT,0644); }
diff --git a/src/open_write.c b/src/open_write.c
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include "open.h"
+
+int open_write(const char *fn)
+{ return open(fn,O_WRONLY | O_NDELAY); }
diff --git a/src/openreadclose.c b/src/openreadclose.c
@@ -0,0 +1,18 @@
+/* Public domain. */
+
+#include "error.h"
+#include "open.h"
+#include "readclose.h"
+#include "openreadclose.h"
+
+int openreadclose(const char *fn,stralloc *sa,unsigned int bufsize)
+{
+ int fd;
+ fd = open_read(fn);
+ if (fd == -1) {
+ if (errno == error_noent) return 0;
+ return -1;
+ }
+ if (readclose(fd,sa,bufsize) == -1) return -1;
+ return 1;
+}
diff --git a/src/openreadclose.h b/src/openreadclose.h
@@ -0,0 +1,10 @@
+/* Public domain. */
+
+#ifndef OPENREADCLOSE_H
+#define OPENREADCLOSE_H
+
+#include "stralloc.h"
+
+extern int openreadclose(const char *,stralloc *,unsigned int);
+
+#endif
diff --git a/src/pathexec.h b/src/pathexec.h
@@ -0,0 +1,10 @@
+/* Public domain. */
+
+#ifndef PATHEXEC_H
+#define PATHEXEC_H
+
+extern void pathexec_run(const char *,const char * const *,const char * const *);
+extern int pathexec_env(const char *,const char *);
+extern void pathexec(const char * const *);
+
+#endif
diff --git a/src/pathexec_env.c b/src/pathexec_env.c
@@ -0,0 +1,69 @@
+/* Public domain. */
+
+#include "stralloc.h"
+#include "alloc.h"
+#include "str.h"
+#include "byte.h"
+#include "env.h"
+#include "pathexec.h"
+
+static stralloc plus;
+static stralloc tmp;
+
+int pathexec_env(const char *s,const char *t)
+{
+ if (!s) return 1;
+ if (!stralloc_copys(&tmp,s)) return 0;
+ if (t) {
+ if (!stralloc_cats(&tmp,"=")) return 0;
+ if (!stralloc_cats(&tmp,t)) return 0;
+ }
+ if (!stralloc_0(&tmp)) return 0;
+ return stralloc_cat(&plus,&tmp);
+}
+
+void pathexec(const char *const *argv)
+{
+ const char **e;
+ unsigned int elen;
+ unsigned int i;
+ unsigned int j;
+ unsigned int split;
+ unsigned int t;
+
+ if (!stralloc_cats(&plus,"")) return;
+
+ elen = 0;
+ for (i = 0;environ[i];++i)
+ ++elen;
+ for (i = 0;i < plus.len;++i)
+ if (!plus.s[i])
+ ++elen;
+
+ e = (const char **) alloc((elen + 1) * sizeof(char *));
+ if (!e) return;
+
+ elen = 0;
+ for (i = 0;environ[i];++i)
+ e[elen++] = environ[i];
+
+ j = 0;
+ for (i = 0;i < plus.len;++i)
+ if (!plus.s[i]) {
+ split = str_chr(plus.s + j,'=');
+ for (t = 0;t < elen;++t)
+ if (byte_equal(plus.s + j,split,e[t]))
+ if (e[t][split] == '=') {
+ --elen;
+ e[t] = e[elen];
+ break;
+ }
+ if (plus.s[j + split])
+ e[elen++] = plus.s + j;
+ j = i + 1;
+ }
+ e[elen] = 0;
+
+ pathexec_run(*argv,argv,e);
+ alloc_free(e);
+}
diff --git a/src/pathexec_run.c b/src/pathexec_run.c
@@ -0,0 +1,48 @@
+/* Public domain. */
+
+#include "error.h"
+#include "stralloc.h"
+#include "str.h"
+#include "env.h"
+#include "pathexec.h"
+
+static stralloc tmp;
+
+void pathexec_run(const char *file,const char * const *argv,const char * const *envp)
+{
+ const char *path;
+ unsigned int split;
+ int savederrno;
+
+ if (file[str_chr(file,'/')]) {
+ execve(file,argv,envp);
+ return;
+ }
+
+ path = env_get("PATH");
+ if (!path) path = "/bin:/usr/bin";
+
+ savederrno = 0;
+ for (;;) {
+ split = str_chr(path,':');
+ if (!stralloc_copyb(&tmp,path,split)) return;
+ if (!split)
+ if (!stralloc_cats(&tmp,".")) return;
+ if (!stralloc_cats(&tmp,"/")) return;
+ if (!stralloc_cats(&tmp,file)) return;
+ if (!stralloc_0(&tmp)) return;
+
+ execve(tmp.s,argv,envp);
+ if (errno != error_noent) {
+ savederrno = errno;
+ if ((errno != error_acces) && (errno != error_perm) && (errno != error_isdir)) return;
+ }
+
+ if (!path[split]) {
+ if (savederrno) errno = savederrno;
+ return;
+ }
+ path += split;
+ path += 1;
+ }
+}
diff --git a/src/print-ar.sh b/src/print-ar.sh
@@ -0,0 +1,14 @@
+cat warn-auto.sh
+echo 'main="$1"; shift'
+echo 'rm -f "$main"'
+echo 'ar cr "$main" ${1+"$@"}'
+case "`cat systype`" in
+ sunos-5.*) ;;
+ unix_sv*) ;;
+ irix64-*) ;;
+ irix-*) ;;
+ dgux-*) ;;
+ hp-ux-*) ;;
+ sco*) ;;
+ *) echo 'ranlib "$main"' ;;
+esac
diff --git a/src/print-cc.sh b/src/print-cc.sh
@@ -0,0 +1,5 @@
+cc="`head -1 conf-cc`"
+systype="`cat systype`"
+
+cat warn-auto.sh
+echo exec "$cc" '-c ${1+"$@"}'
diff --git a/src/print-ld.sh b/src/print-ld.sh
@@ -0,0 +1,6 @@
+ld="`head -1 conf-ld`"
+systype="`cat systype`"
+
+cat warn-auto.sh
+echo 'main="$1"; shift'
+echo exec "$ld" '-o "$main" "$main".o ${1+"$@"}'
diff --git a/src/prot.c b/src/prot.c
@@ -0,0 +1,21 @@
+/* Public domain. */
+
+#include "hasshsgr.h"
+#include "prot.h"
+
+int prot_gid(int gid)
+{
+#ifdef HASSHORTSETGROUPS
+ short x[2];
+ x[0] = gid; x[1] = 73; /* catch errors */
+ if (setgroups(1,x) == -1) return -1;
+#else
+ if (setgroups(1,&gid) == -1) return -1;
+#endif
+ return setgid(gid); /* _should_ be redundant, but on some systems it isn't */
+}
+
+int prot_uid(int uid)
+{
+ return setuid(uid);
+}
diff --git a/src/prot.h b/src/prot.h
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+#ifndef PROT_H
+#define PROT_H
+
+extern int prot_gid(int);
+extern int prot_uid(int);
+
+#endif
diff --git a/src/readclose.c b/src/readclose.c
@@ -0,0 +1,23 @@
+/* Public domain. */
+
+#include <unistd.h>
+#include "error.h"
+#include "readclose.h"
+
+int readclose_append(int fd,stralloc *sa,unsigned int bufsize)
+{
+ int r;
+ for (;;) {
+ if (!stralloc_readyplus(sa,bufsize)) { close(fd); return -1; }
+ r = read(fd,sa->s + sa->len,bufsize);
+ if (r == -1) if (errno == error_intr) continue;
+ if (r <= 0) { close(fd); return r; }
+ sa->len += r;
+ }
+}
+
+int readclose(int fd,stralloc *sa,unsigned int bufsize)
+{
+ if (!stralloc_copys(sa,"")) { close(fd); return -1; }
+ return readclose_append(fd,sa,bufsize);
+}
diff --git a/src/readclose.h b/src/readclose.h
@@ -0,0 +1,11 @@
+/* Public domain. */
+
+#ifndef READCLOSE_H
+#define READCLOSE_H
+
+#include "stralloc.h"
+
+extern int readclose_append(int,stralloc *,unsigned int);
+extern int readclose(int,stralloc *,unsigned int);
+
+#endif
diff --git a/src/scan.h b/src/scan.h
@@ -0,0 +1,30 @@
+/* Public domain. */
+
+#ifndef SCAN_H
+#define SCAN_H
+
+extern unsigned int scan_uint(const char *,unsigned int *);
+extern unsigned int scan_xint(const char *,unsigned int *);
+extern unsigned int scan_nbbint(const char *,unsigned int,unsigned int,unsigned int,unsigned int *);
+extern unsigned int scan_ushort(const char *,unsigned short *);
+extern unsigned int scan_xshort(const char *,unsigned short *);
+extern unsigned int scan_nbbshort(const char *,unsigned int,unsigned int,unsigned int,unsigned short *);
+extern unsigned int scan_ulong(const char *,unsigned long *);
+extern unsigned int scan_xlong(const char *,unsigned long *);
+extern unsigned int scan_nbblong(const char *,unsigned int,unsigned int,unsigned int,unsigned long *);
+
+extern unsigned int scan_plusminus(const char *,int *);
+extern unsigned int scan_0x(const char *,unsigned int *);
+
+extern unsigned int scan_whitenskip(const char *,unsigned int);
+extern unsigned int scan_nonwhitenskip(const char *,unsigned int);
+extern unsigned int scan_charsetnskip(const char *,const char *,unsigned int);
+extern unsigned int scan_noncharsetnskip(const char *,const char *,unsigned int);
+
+extern unsigned int scan_strncmp(const char *,const char *,unsigned int);
+extern unsigned int scan_memcmp(const char *,const char *,unsigned int);
+
+extern unsigned int scan_long(const char *,long *);
+extern unsigned int scan_8long(const char *,unsigned long *);
+
+#endif
diff --git a/src/scan_ulong.c b/src/scan_ulong.c
@@ -0,0 +1,16 @@
+/* Public domain. */
+
+#include "scan.h"
+
+unsigned int scan_ulong(register const char *s,register unsigned long *u)
+{
+ register unsigned int pos = 0;
+ register unsigned long result = 0;
+ register unsigned long c;
+ while ((c = (unsigned long) (unsigned char) (s[pos] - '0')) < 10) {
+ result = result * 10 + c;
+ ++pos;
+ }
+ *u = result;
+ return pos;
+}
diff --git a/src/seek.h b/src/seek.h
@@ -0,0 +1,17 @@
+/* Public domain. */
+
+#ifndef SEEK_H
+#define SEEK_H
+
+typedef unsigned long seek_pos;
+
+extern seek_pos seek_cur(int);
+
+extern int seek_set(int,seek_pos);
+extern int seek_end(int);
+
+extern int seek_trunc(int,seek_pos);
+
+#define seek_begin(fd) (seek_set((fd),(seek_pos) 0))
+
+#endif
diff --git a/src/seek_set.c b/src/seek_set.c
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include "seek.h"
+
+#define SET 0 /* sigh */
+
+int seek_set(int fd,seek_pos pos)
+{ if (lseek(fd,(off_t) pos,SET) == -1) return -1; return 0; }
diff --git a/src/select.h1 b/src/select.h1
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#ifndef SELECT_H
+#define SELECT_H
+
+/* sysdep: -sysselect */
+
+#include <sys/types.h>
+#include <sys/time.h>
+extern int select();
+
+#endif
diff --git a/src/select.h2 b/src/select.h2
@@ -0,0 +1,13 @@
+/* Public domain. */
+
+#ifndef SELECT_H
+#define SELECT_H
+
+/* sysdep: +sysselect */
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/select.h>
+extern int select();
+
+#endif
diff --git a/src/sgetopt.c b/src/sgetopt.c
@@ -0,0 +1,53 @@
+/* Public domain. */
+
+/* sgetopt.c, sgetopt.h: (yet another) improved getopt clone, outer layer
+D. J. Bernstein, djb@pobox.com.
+Depends on subgetopt.h, buffer.h.
+No system requirements.
+19991219: Switched to buffer.h.
+19970208: Cleanups.
+931201: Baseline.
+No known patent problems.
+
+Documentation in sgetopt.3.
+*/
+
+#include "buffer.h"
+#define SGETOPTNOSHORT
+#include "sgetopt.h"
+#define SUBGETOPTNOSHORT
+#include "subgetopt.h"
+
+#define getopt sgetoptmine
+#define optind subgetoptind
+#define opterr sgetopterr
+#define optproblem subgetoptproblem
+#define optprogname sgetoptprogname
+
+int opterr = 1;
+const char *optprogname = 0;
+
+int getopt(int argc,const char *const *argv,const char *opts)
+{
+ int c;
+ const char *s;
+
+ if (!optprogname) {
+ optprogname = *argv;
+ if (!optprogname) optprogname = "";
+ for (s = optprogname;*s;++s) if (*s == '/') optprogname = s + 1;
+ }
+ c = subgetopt(argc,argv,opts);
+ if (opterr)
+ if (c == '?') {
+ char chp[2]; chp[0] = optproblem; chp[1] = '\n';
+ buffer_puts(buffer_2,optprogname);
+ if (argv[optind] && (optind < argc))
+ buffer_puts(buffer_2,": illegal option -- ");
+ else
+ buffer_puts(buffer_2,": option requires an argument -- ");
+ buffer_put(buffer_2,chp,2);
+ buffer_flush(buffer_2);
+ }
+ return c;
+}
diff --git a/src/sgetopt.h b/src/sgetopt.h
@@ -0,0 +1,23 @@
+/* Public domain. */
+
+#ifndef SGETOPT_H
+#define SGETOPT_H
+
+#ifndef SGETOPTNOSHORT
+#define getopt sgetoptmine
+#define optarg subgetoptarg
+#define optind subgetoptind
+#define optpos subgetoptpos
+#define opterr sgetopterr
+#define optproblem subgetoptproblem
+#define optprogname sgetoptprogname
+#define opteof subgetoptdone
+#endif
+
+#include "subgetopt.h"
+
+extern int sgetoptmine(int,const char *const *,const char *);
+extern int sgetopterr;
+extern const char *sgetoptprogname;
+
+#endif
diff --git a/src/sig.c b/src/sig.c
@@ -0,0 +1,15 @@
+/* Public domain. */
+
+#include <signal.h>
+#include "sig.h"
+
+int sig_alarm = SIGALRM;
+int sig_child = SIGCHLD;
+int sig_cont = SIGCONT;
+int sig_hangup = SIGHUP;
+int sig_int = SIGINT;
+int sig_pipe = SIGPIPE;
+int sig_term = SIGTERM;
+
+void (*sig_defaulthandler)() = SIG_DFL;
+void (*sig_ignorehandler)() = SIG_IGN;
diff --git a/src/sig.h b/src/sig.h
@@ -0,0 +1,28 @@
+/* Public domain. */
+
+#ifndef SIG_H
+#define SIG_H
+
+extern int sig_alarm;
+extern int sig_child;
+extern int sig_cont;
+extern int sig_hangup;
+extern int sig_int;
+extern int sig_pipe;
+extern int sig_term;
+
+extern void (*sig_defaulthandler)();
+extern void (*sig_ignorehandler)();
+
+extern void sig_catch(int,void (*)());
+#define sig_ignore(s) (sig_catch((s),sig_ignorehandler))
+#define sig_uncatch(s) (sig_catch((s),sig_defaulthandler))
+
+extern void sig_block(int);
+extern void sig_unblock(int);
+extern void sig_blocknone(void);
+extern void sig_pause(void);
+
+extern void sig_dfl(int);
+
+#endif
diff --git a/src/sig_block.c b/src/sig_block.c
@@ -0,0 +1,40 @@
+/* Public domain. */
+
+#include <signal.h>
+#include "sig.h"
+#include "hassgprm.h"
+
+void sig_block(int sig)
+{
+#ifdef HASSIGPROCMASK
+ sigset_t ss;
+ sigemptyset(&ss);
+ sigaddset(&ss,sig);
+ sigprocmask(SIG_BLOCK,&ss,(sigset_t *) 0);
+#else
+ sigblock(1 << (sig - 1));
+#endif
+}
+
+void sig_unblock(int sig)
+{
+#ifdef HASSIGPROCMASK
+ sigset_t ss;
+ sigemptyset(&ss);
+ sigaddset(&ss,sig);
+ sigprocmask(SIG_UNBLOCK,&ss,(sigset_t *) 0);
+#else
+ sigsetmask(sigsetmask(~0) & ~(1 << (sig - 1)));
+#endif
+}
+
+void sig_blocknone(void)
+{
+#ifdef HASSIGPROCMASK
+ sigset_t ss;
+ sigemptyset(&ss);
+ sigprocmask(SIG_SETMASK,&ss,(sigset_t *) 0);
+#else
+ sigsetmask(0);
+#endif
+}
diff --git a/src/sig_catch.c b/src/sig_catch.c
@@ -0,0 +1,18 @@
+/* Public domain. */
+
+#include <signal.h>
+#include "sig.h"
+#include "hassgact.h"
+
+void sig_catch(int sig,void (*f)())
+{
+#ifdef HASSIGACTION
+ struct sigaction sa;
+ sa.sa_handler = f;
+ sa.sa_flags = 0;
+ sigemptyset(&sa.sa_mask);
+ sigaction(sig,&sa,(struct sigaction *) 0);
+#else
+ signal(sig,f); /* won't work under System V, even nowadays---dorks */
+#endif
+}
diff --git a/src/sig_pause.c b/src/sig_pause.c
@@ -0,0 +1,16 @@
+/* Public domain. */
+
+#include <signal.h>
+#include "sig.h"
+#include "hassgprm.h"
+
+void sig_pause(void)
+{
+#ifdef HASSIGPROCMASK
+ sigset_t ss;
+ sigemptyset(&ss);
+ sigsuspend(&ss);
+#else
+ sigpause(0);
+#endif
+}
diff --git a/src/str.h b/src/str.h
@@ -0,0 +1,16 @@
+/* Public domain. */
+
+#ifndef STR_H
+#define STR_H
+
+extern unsigned int str_copy(char *,const char *);
+extern int str_diff(const char *,const char *);
+extern int str_diffn(const char *,const char *,unsigned int);
+extern unsigned int str_len(const char *);
+extern unsigned int str_chr(const char *,int);
+extern unsigned int str_rchr(const char *,int);
+extern int str_start(const char *,const char *);
+
+#define str_equal(s,t) (!str_diff((s),(t)))
+
+#endif
diff --git a/src/str_chr.c b/src/str_chr.c
@@ -0,0 +1,19 @@
+/* Public domain. */
+
+#include "str.h"
+
+unsigned int str_chr(register const char *s,int c)
+{
+ register char ch;
+ register const char *t;
+
+ ch = c;
+ t = s;
+ for (;;) {
+ if (!*t) break; if (*t == ch) break; ++t;
+ if (!*t) break; if (*t == ch) break; ++t;
+ if (!*t) break; if (*t == ch) break; ++t;
+ if (!*t) break; if (*t == ch) break; ++t;
+ }
+ return t - s;
+}
diff --git a/src/str_diff.c b/src/str_diff.c
@@ -0,0 +1,17 @@
+/* Public domain. */
+
+#include "str.h"
+
+int str_diff(register const char *s,register const char *t)
+{
+ register char x;
+
+ for (;;) {
+ x = *s; if (x != *t) break; if (!x) break; ++s; ++t;
+ x = *s; if (x != *t) break; if (!x) break; ++s; ++t;
+ x = *s; if (x != *t) break; if (!x) break; ++s; ++t;
+ x = *s; if (x != *t) break; if (!x) break; ++s; ++t;
+ }
+ return ((int)(unsigned int)(unsigned char) x)
+ - ((int)(unsigned int)(unsigned char) *t);
+}
diff --git a/src/str_len.c b/src/str_len.c
@@ -0,0 +1,16 @@
+/* Public domain. */
+
+#include "str.h"
+
+unsigned int str_len(const char *s)
+{
+ register const char *t;
+
+ t = s;
+ for (;;) {
+ if (!*t) return t - s; ++t;
+ if (!*t) return t - s; ++t;
+ if (!*t) return t - s; ++t;
+ if (!*t) return t - s; ++t;
+ }
+}
diff --git a/src/str_start.c b/src/str_start.c
@@ -0,0 +1,15 @@
+/* Public domain. */
+
+#include "str.h"
+
+int str_start(register const char *s,register const char *t)
+{
+ register char x;
+
+ for (;;) {
+ x = *t++; if (!x) return 1; if (x != *s++) return 0;
+ x = *t++; if (!x) return 1; if (x != *s++) return 0;
+ x = *t++; if (!x) return 1; if (x != *s++) return 0;
+ x = *t++; if (!x) return 1; if (x != *s++) return 0;
+ }
+}
diff --git a/src/stralloc.h b/src/stralloc.h
@@ -0,0 +1,31 @@
+/* Public domain. */
+
+#ifndef STRALLOC_H
+#define STRALLOC_H
+
+#include "gen_alloc.h"
+
+GEN_ALLOC_typedef(stralloc,char,s,len,a)
+
+extern int stralloc_ready(stralloc *,unsigned int);
+extern int stralloc_readyplus(stralloc *,unsigned int);
+extern int stralloc_copy(stralloc *,const stralloc *);
+extern int stralloc_cat(stralloc *,const stralloc *);
+extern int stralloc_copys(stralloc *,const char *);
+extern int stralloc_cats(stralloc *,const char *);
+extern int stralloc_copyb(stralloc *,const char *,unsigned int);
+extern int stralloc_catb(stralloc *,const char *,unsigned int);
+extern int stralloc_append(stralloc *,const char *); /* beware: this takes a pointer to 1 char */
+extern int stralloc_starts(stralloc *,const char *);
+
+#define stralloc_0(sa) stralloc_append(sa,"")
+
+extern int stralloc_catulong0(stralloc *,unsigned long,unsigned int);
+extern int stralloc_catlong0(stralloc *,long,unsigned int);
+
+#define stralloc_catlong(sa,l) (stralloc_catlong0((sa),(l),0))
+#define stralloc_catuint0(sa,i,n) (stralloc_catulong0((sa),(i),(n)))
+#define stralloc_catint0(sa,i,n) (stralloc_catlong0((sa),(i),(n)))
+#define stralloc_catint(sa,i) (stralloc_catlong0((sa),(i),0))
+
+#endif
diff --git a/src/stralloc_cat.c b/src/stralloc_cat.c
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+#include "byte.h"
+#include "stralloc.h"
+
+int stralloc_cat(stralloc *sato,const stralloc *safrom)
+{
+ return stralloc_catb(sato,safrom->s,safrom->len);
+}
diff --git a/src/stralloc_catb.c b/src/stralloc_catb.c
@@ -0,0 +1,14 @@
+/* Public domain. */
+
+#include "stralloc.h"
+#include "byte.h"
+
+int stralloc_catb(stralloc *sa,const char *s,unsigned int n)
+{
+ if (!sa->s) return stralloc_copyb(sa,s,n);
+ if (!stralloc_readyplus(sa,n + 1)) return 0;
+ byte_copy(sa->s + sa->len,n,s);
+ sa->len += n;
+ sa->s[sa->len] = 'Z'; /* ``offensive programming'' */
+ return 1;
+}
diff --git a/src/stralloc_cats.c b/src/stralloc_cats.c
@@ -0,0 +1,10 @@
+/* Public domain. */
+
+#include "byte.h"
+#include "str.h"
+#include "stralloc.h"
+
+int stralloc_cats(stralloc *sa,const char *s)
+{
+ return stralloc_catb(sa,s,str_len(s));
+}
diff --git a/src/stralloc_eady.c b/src/stralloc_eady.c
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#include "alloc.h"
+#include "stralloc.h"
+#include "gen_allocdefs.h"
+
+GEN_ALLOC_ready(stralloc,char,s,len,a,i,n,x,30,stralloc_ready)
+GEN_ALLOC_readyplus(stralloc,char,s,len,a,i,n,x,30,stralloc_readyplus)
diff --git a/src/stralloc_opyb.c b/src/stralloc_opyb.c
@@ -0,0 +1,13 @@
+/* Public domain. */
+
+#include "stralloc.h"
+#include "byte.h"
+
+int stralloc_copyb(stralloc *sa,const char *s,unsigned int n)
+{
+ if (!stralloc_ready(sa,n + 1)) return 0;
+ byte_copy(sa->s,n,s);
+ sa->len = n;
+ sa->s[n] = 'Z'; /* ``offensive programming'' */
+ return 1;
+}
diff --git a/src/stralloc_opys.c b/src/stralloc_opys.c
@@ -0,0 +1,10 @@
+/* Public domain. */
+
+#include "byte.h"
+#include "str.h"
+#include "stralloc.h"
+
+int stralloc_copys(stralloc *sa,const char *s)
+{
+ return stralloc_copyb(sa,s,str_len(s));
+}
diff --git a/src/stralloc_pend.c b/src/stralloc_pend.c
@@ -0,0 +1,7 @@
+/* Public domain. */
+
+#include "alloc.h"
+#include "stralloc.h"
+#include "gen_allocdefs.h"
+
+GEN_ALLOC_append(stralloc,char,s,len,a,i,n,x,30,stralloc_readyplus,stralloc_append)
diff --git a/src/strerr.h b/src/strerr.h
@@ -0,0 +1,80 @@
+/* Public domain. */
+
+#ifndef STRERR_H
+#define STRERR_H
+
+struct strerr {
+ struct strerr *who;
+ const char *x;
+ const char *y;
+ const char *z;
+} ;
+
+extern struct strerr strerr_sys;
+extern void strerr_sysinit(void);
+
+extern const char *strerr(const struct strerr *);
+extern void strerr_warn(const char *,const char *,const char *,const char *,const char *,const char *,const struct strerr *);
+extern void strerr_die(int,const char *,const char *,const char *,const char *,const char *,const char *,const struct strerr *);
+
+#define STRERR(r,se,a) \
+{ se.who = 0; se.x = a; se.y = 0; se.z = 0; return r; }
+
+#define STRERR_SYS(r,se,a) \
+{ se.who = &strerr_sys; se.x = a; se.y = 0; se.z = 0; return r; }
+#define STRERR_SYS3(r,se,a,b,c) \
+{ se.who = &strerr_sys; se.x = a; se.y = b; se.z = c; return r; }
+
+#define strerr_warn6(x1,x2,x3,x4,x5,x6,se) \
+strerr_warn((x1),(x2),(x3),(x4),(x5),(x6),(se))
+#define strerr_warn5(x1,x2,x3,x4,x5,se) \
+strerr_warn((x1),(x2),(x3),(x4),(x5),0,(se))
+#define strerr_warn4(x1,x2,x3,x4,se) \
+strerr_warn((x1),(x2),(x3),(x4),0,0,(se))
+#define strerr_warn3(x1,x2,x3,se) \
+strerr_warn((x1),(x2),(x3),0,0,0,(se))
+#define strerr_warn2(x1,x2,se) \
+strerr_warn((x1),(x2),0,0,0,0,(se))
+#define strerr_warn1(x1,se) \
+strerr_warn((x1),0,0,0,0,0,(se))
+
+#define strerr_die6(e,x1,x2,x3,x4,x5,x6,se) \
+strerr_die((e),(x1),(x2),(x3),(x4),(x5),(x6),(se))
+#define strerr_die5(e,x1,x2,x3,x4,x5,se) \
+strerr_die((e),(x1),(x2),(x3),(x4),(x5),0,(se))
+#define strerr_die4(e,x1,x2,x3,x4,se) \
+strerr_die((e),(x1),(x2),(x3),(x4),0,0,(se))
+#define strerr_die3(e,x1,x2,x3,se) \
+strerr_die((e),(x1),(x2),(x3),0,0,0,(se))
+#define strerr_die2(e,x1,x2,se) \
+strerr_die((e),(x1),(x2),0,0,0,0,(se))
+#define strerr_die1(e,x1,se) \
+strerr_die((e),(x1),0,0,0,0,0,(se))
+
+#define strerr_die6sys(e,x1,x2,x3,x4,x5,x6) \
+strerr_die((e),(x1),(x2),(x3),(x4),(x5),(x6),&strerr_sys)
+#define strerr_die5sys(e,x1,x2,x3,x4,x5) \
+strerr_die((e),(x1),(x2),(x3),(x4),(x5),0,&strerr_sys)
+#define strerr_die4sys(e,x1,x2,x3,x4) \
+strerr_die((e),(x1),(x2),(x3),(x4),0,0,&strerr_sys)
+#define strerr_die3sys(e,x1,x2,x3) \
+strerr_die((e),(x1),(x2),(x3),0,0,0,&strerr_sys)
+#define strerr_die2sys(e,x1,x2) \
+strerr_die((e),(x1),(x2),0,0,0,0,&strerr_sys)
+#define strerr_die1sys(e,x1) \
+strerr_die((e),(x1),0,0,0,0,0,&strerr_sys)
+
+#define strerr_die6x(e,x1,x2,x3,x4,x5,x6) \
+strerr_die((e),(x1),(x2),(x3),(x4),(x5),(x6),0)
+#define strerr_die5x(e,x1,x2,x3,x4,x5) \
+strerr_die((e),(x1),(x2),(x3),(x4),(x5),0,0)
+#define strerr_die4x(e,x1,x2,x3,x4) \
+strerr_die((e),(x1),(x2),(x3),(x4),0,0,0)
+#define strerr_die3x(e,x1,x2,x3) \
+strerr_die((e),(x1),(x2),(x3),0,0,0,0)
+#define strerr_die2x(e,x1,x2) \
+strerr_die((e),(x1),(x2),0,0,0,0,0)
+#define strerr_die1x(e,x1) \
+strerr_die((e),(x1),0,0,0,0,0,0)
+
+#endif
diff --git a/src/strerr_die.c b/src/strerr_die.c
@@ -0,0 +1,33 @@
+/* Public domain. */
+
+#include <unistd.h>
+#include "buffer.h"
+#include "strerr.h"
+
+void strerr_warn(const char *x1,const char *x2,const char *x3,const char *x4,const char *x5,const char *x6,const struct strerr *se)
+{
+ strerr_sysinit();
+
+ if (x1) buffer_puts(buffer_2,x1);
+ if (x2) buffer_puts(buffer_2,x2);
+ if (x3) buffer_puts(buffer_2,x3);
+ if (x4) buffer_puts(buffer_2,x4);
+ if (x5) buffer_puts(buffer_2,x5);
+ if (x6) buffer_puts(buffer_2,x6);
+
+ while(se) {
+ if (se->x) buffer_puts(buffer_2,se->x);
+ if (se->y) buffer_puts(buffer_2,se->y);
+ if (se->z) buffer_puts(buffer_2,se->z);
+ se = se->who;
+ }
+
+ buffer_puts(buffer_2,"\n");
+ buffer_flush(buffer_2);
+}
+
+void strerr_die(int e,const char *x1,const char *x2,const char *x3,const char *x4,const char *x5,const char *x6,const struct strerr *se)
+{
+ strerr_warn(x1,x2,x3,x4,x5,x6,se);
+ _exit(e);
+}
diff --git a/src/strerr_sys.c b/src/strerr_sys.c
@@ -0,0 +1,14 @@
+/* Public domain. */
+
+#include "error.h"
+#include "strerr.h"
+
+struct strerr strerr_sys;
+
+void strerr_sysinit(void)
+{
+ strerr_sys.who = 0;
+ strerr_sys.x = error_str(errno);
+ strerr_sys.y = "";
+ strerr_sys.z = "";
+}
diff --git a/src/subgetopt.c b/src/subgetopt.c
@@ -0,0 +1,67 @@
+/* Public domain. */
+
+#define SUBGETOPTNOSHORT
+#include "subgetopt.h"
+
+#define sgopt subgetopt
+#define optind subgetoptind
+#define optpos subgetoptpos
+#define optarg subgetoptarg
+#define optproblem subgetoptproblem
+#define optdone subgetoptdone
+
+int optind = 1;
+int optpos = 0;
+const char *optarg = 0;
+int optproblem = 0;
+int optdone = SUBGETOPTDONE;
+
+int sgopt(int argc,const char *const *argv,const char *opts)
+{
+ int c;
+ const char *s;
+
+ optarg = 0;
+ if (!argv || (optind >= argc) || !argv[optind]) return optdone;
+ if (optpos && !argv[optind][optpos]) {
+ ++optind;
+ optpos = 0;
+ if ((optind >= argc) || !argv[optind]) return optdone;
+ }
+ if (!optpos) {
+ if (argv[optind][0] != '-') return optdone;
+ ++optpos;
+ c = argv[optind][1];
+ if ((c == '-') || (c == 0)) {
+ if (c) ++optind;
+ optpos = 0;
+ return optdone;
+ }
+ /* otherwise c is reassigned below */
+ }
+ c = argv[optind][optpos];
+ ++optpos;
+ s = opts;
+ while (*s) {
+ if (c == *s) {
+ if (s[1] == ':') {
+ optarg = argv[optind] + optpos;
+ ++optind;
+ optpos = 0;
+ if (!*optarg) {
+ optarg = argv[optind];
+ if ((optind >= argc) || !optarg) { /* argument past end */
+ optproblem = c;
+ return '?';
+ }
+ ++optind;
+ }
+ }
+ return c;
+ }
+ ++s;
+ if (*s == ':') ++s;
+ }
+ optproblem = c;
+ return '?';
+}
diff --git a/src/subgetopt.h b/src/subgetopt.h
@@ -0,0 +1,26 @@
+/* Public domain. */
+
+#ifndef SUBGETOPT_H
+#define SUBGETOPT_H
+
+#ifndef SUBGETOPTNOSHORT
+#define sgopt subgetopt
+#define sgoptarg subgetoptarg
+#define sgoptind subgetoptind
+#define sgoptpos subgetoptpos
+#define sgoptproblem subgetoptproblem
+#define sgoptprogname subgetoptprogname
+#define sgoptdone subgetoptdone
+#endif
+
+#define SUBGETOPTDONE -1
+
+extern int subgetopt(int,const char *const *,const char *);
+extern const char *subgetoptarg;
+extern int subgetoptind;
+extern int subgetoptpos;
+extern int subgetoptproblem;
+extern const char *subgetoptprogname;
+extern int subgetoptdone;
+
+#endif
diff --git a/src/tai.h b/src/tai.h
@@ -0,0 +1,28 @@
+/* Public domain. */
+
+#ifndef TAI_H
+#define TAI_H
+
+#include "uint64.h"
+
+struct tai {
+ uint64 x;
+} ;
+
+#define tai_unix(t,u) ((void) ((t)->x = 4611686018427387914ULL + (uint64) (u)))
+
+extern void tai_now(struct tai *);
+
+#define tai_approx(t) ((double) ((t)->x))
+
+extern void tai_add(struct tai *,const struct tai *,const struct tai *);
+extern void tai_sub(struct tai *,const struct tai *,const struct tai *);
+#define tai_less(t,u) ((t)->x < (u)->x)
+
+#define TAI_PACK 8
+extern void tai_pack(char *,const struct tai *);
+extern void tai_unpack(const char *,struct tai *);
+
+extern void tai_uint(struct tai *,unsigned int);
+
+#endif
diff --git a/src/tai_now.c b/src/tai_now.c
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+#include <time.h>
+#include "tai.h"
+
+void tai_now(struct tai *t)
+{
+ tai_unix(t,time((time_t *) 0));
+}
diff --git a/src/tai_pack.c b/src/tai_pack.c
@@ -0,0 +1,18 @@
+/* Public domain. */
+
+#include "tai.h"
+
+void tai_pack(char *s,const struct tai *t)
+{
+ uint64 x;
+
+ x = t->x;
+ s[7] = x & 255; x >>= 8;
+ s[6] = x & 255; x >>= 8;
+ s[5] = x & 255; x >>= 8;
+ s[4] = x & 255; x >>= 8;
+ s[3] = x & 255; x >>= 8;
+ s[2] = x & 255; x >>= 8;
+ s[1] = x & 255; x >>= 8;
+ s[0] = x;
+}
diff --git a/src/tai_sub.c b/src/tai_sub.c
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#include "tai.h"
+
+void tai_sub(struct tai *t,const struct tai *u,const struct tai *v)
+{
+ t->x = u->x - v->x;
+}
diff --git a/src/tai_unpack.c b/src/tai_unpack.c
@@ -0,0 +1,18 @@
+/* Public domain. */
+
+#include "tai.h"
+
+void tai_unpack(const char *s,struct tai *t)
+{
+ uint64 x;
+
+ x = (unsigned char) s[0];
+ x <<= 8; x += (unsigned char) s[1];
+ x <<= 8; x += (unsigned char) s[2];
+ x <<= 8; x += (unsigned char) s[3];
+ x <<= 8; x += (unsigned char) s[4];
+ x <<= 8; x += (unsigned char) s[5];
+ x <<= 8; x += (unsigned char) s[6];
+ x <<= 8; x += (unsigned char) s[7];
+ t->x = x;
+}
diff --git a/src/taia.h b/src/taia.h
@@ -0,0 +1,36 @@
+/* Public domain. */
+
+#ifndef TAIA_H
+#define TAIA_H
+
+#include "tai.h"
+
+struct taia {
+ struct tai sec;
+ unsigned long nano; /* 0...999999999 */
+ unsigned long atto; /* 0...999999999 */
+} ;
+
+extern void taia_tai(const struct taia *,struct tai *);
+
+extern void taia_now(struct taia *);
+
+extern double taia_approx(const struct taia *);
+extern double taia_frac(const struct taia *);
+
+extern void taia_add(struct taia *,const struct taia *,const struct taia *);
+extern void taia_addsec(struct taia *,const struct taia *,int);
+extern void taia_sub(struct taia *,const struct taia *,const struct taia *);
+extern void taia_half(struct taia *,const struct taia *);
+extern int taia_less(const struct taia *,const struct taia *);
+
+#define TAIA_PACK 16
+extern void taia_pack(char *,const struct taia *);
+extern void taia_unpack(const char *,struct taia *);
+
+#define TAIA_FMTFRAC 19
+extern unsigned int taia_fmtfrac(char *,const struct taia *);
+
+extern void taia_uint(struct taia *,unsigned int);
+
+#endif
diff --git a/src/taia_add.c b/src/taia_add.c
@@ -0,0 +1,20 @@
+/* Public domain. */
+
+#include "taia.h"
+
+/* XXX: breaks tai encapsulation */
+
+void taia_add(struct taia *t,const struct taia *u,const struct taia *v)
+{
+ t->sec.x = u->sec.x + v->sec.x;
+ t->nano = u->nano + v->nano;
+ t->atto = u->atto + v->atto;
+ if (t->atto > 999999999UL) {
+ t->atto -= 1000000000UL;
+ ++t->nano;
+ }
+ if (t->nano > 999999999UL) {
+ t->nano -= 1000000000UL;
+ ++t->sec.x;
+ }
+}
diff --git a/src/taia_approx.c b/src/taia_approx.c
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#include "taia.h"
+
+double taia_approx(const struct taia *t)
+{
+ return tai_approx(&t->sec) + taia_frac(t);
+}
diff --git a/src/taia_frac.c b/src/taia_frac.c
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#include "taia.h"
+
+double taia_frac(const struct taia *t)
+{
+ return (t->atto * 0.000000001 + t->nano) * 0.000000001;
+}
diff --git a/src/taia_less.c b/src/taia_less.c
@@ -0,0 +1,14 @@
+/* Public domain. */
+
+#include "taia.h"
+
+/* XXX: breaks tai encapsulation */
+
+int taia_less(const struct taia *t,const struct taia *u)
+{
+ if (t->sec.x < u->sec.x) return 1;
+ if (t->sec.x > u->sec.x) return 0;
+ if (t->nano < u->nano) return 1;
+ if (t->nano > u->nano) return 0;
+ return t->atto < u->atto;
+}
diff --git a/src/taia_now.c b/src/taia_now.c
@@ -0,0 +1,15 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include <time.h>
+#include <sys/time.h>
+#include "taia.h"
+
+void taia_now(struct taia *t)
+{
+ struct timeval now;
+ gettimeofday(&now,(struct timezone *) 0);
+ tai_unix(&t->sec,now.tv_sec);
+ t->nano = 1000 * now.tv_usec + 500;
+ t->atto = 0;
+}
diff --git a/src/taia_pack.c b/src/taia_pack.c
@@ -0,0 +1,22 @@
+/* Public domain. */
+
+#include "taia.h"
+
+void taia_pack(char *s,const struct taia *t)
+{
+ unsigned long x;
+
+ tai_pack(s,&t->sec);
+ s += 8;
+
+ x = t->atto;
+ s[7] = x & 255; x >>= 8;
+ s[6] = x & 255; x >>= 8;
+ s[5] = x & 255; x >>= 8;
+ s[4] = x;
+ x = t->nano;
+ s[3] = x & 255; x >>= 8;
+ s[2] = x & 255; x >>= 8;
+ s[1] = x & 255; x >>= 8;
+ s[0] = x;
+}
diff --git a/src/taia_sub.c b/src/taia_sub.c
@@ -0,0 +1,23 @@
+/* Public domain. */
+
+#include "taia.h"
+
+/* XXX: breaks tai encapsulation */
+
+void taia_sub(struct taia *t,const struct taia *u,const struct taia *v)
+{
+ unsigned long unano = u->nano;
+ unsigned long uatto = u->atto;
+
+ t->sec.x = u->sec.x - v->sec.x;
+ t->nano = unano - v->nano;
+ t->atto = uatto - v->atto;
+ if (t->atto > uatto) {
+ t->atto += 1000000000UL;
+ --t->nano;
+ }
+ if (t->nano > unano) {
+ t->nano += 1000000000UL;
+ --t->sec.x;
+ }
+}
diff --git a/src/taia_uint.c b/src/taia_uint.c
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#include "taia.h"
+
+/* XXX: breaks tai encapsulation */
+
+void taia_uint(struct taia *t,unsigned int s)
+{
+ t->sec.x = s;
+ t->nano = 0;
+ t->atto = 0;
+}
diff --git a/src/trycpp.c b/src/trycpp.c
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+int main()
+{
+#ifdef NeXT
+ printf("nextstep\n"); exit(0);
+#endif
+ printf("unknown\n"); exit(0);
+}
diff --git a/src/trydrent.c b/src/trydrent.c
@@ -0,0 +1,10 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include <dirent.h>
+
+void foo()
+{
+ DIR *dir;
+ struct dirent *d;
+}
diff --git a/src/tryflock.c b/src/tryflock.c
@@ -0,0 +1,10 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include <sys/file.h>
+#include <fcntl.h>
+
+main()
+{
+ flock(0,LOCK_EX | LOCK_UN | LOCK_NB);
+}
diff --git a/src/trymkffo.c b/src/trymkffo.c
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+void main()
+{
+ mkfifo("temp-trymkffo",0);
+}
diff --git a/src/trypoll.c b/src/trypoll.c
@@ -0,0 +1,20 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include <poll.h>
+
+int main()
+{
+ struct pollfd x;
+
+ x.fd = open("trypoll.c",O_RDONLY);
+ if (x.fd == -1) _exit(111);
+ x.events = POLLIN;
+ if (poll(&x,1,10) == -1) _exit(1);
+ if (x.revents != POLLIN) _exit(1);
+
+ /* XXX: try to detect and avoid poll() imitation libraries */
+
+ _exit(0);
+}
diff --git a/src/trysgact.c b/src/trysgact.c
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#include <signal.h>
+
+main()
+{
+ struct sigaction sa;
+ sa.sa_handler = 0;
+ sa.sa_flags = 0;
+ sigemptyset(&sa.sa_mask);
+ sigaction(0,&sa,(struct sigaction *) 0);
+}
diff --git a/src/trysgprm.c b/src/trysgprm.c
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#include <signal.h>
+
+main()
+{
+ sigset_t ss;
+
+ sigemptyset(&ss);
+ sigaddset(&ss,SIGCHLD);
+ sigprocmask(SIG_SETMASK,&ss,(sigset_t *) 0);
+}
diff --git a/src/tryshsgr.c b/src/tryshsgr.c
@@ -0,0 +1,16 @@
+/* Public domain. */
+
+int main()
+{
+ short x[4];
+
+ x[0] = x[1] = 1;
+ if (getgroups(1,x) == 0) if (setgroups(1,x) == -1) _exit(1);
+
+ if (getgroups(1,x) == -1) _exit(1);
+ if (x[1] != 1) _exit(1);
+ x[1] = 2;
+ if (getgroups(1,x) == -1) _exit(1);
+ if (x[1] != 2) _exit(1);
+ _exit(0);
+}
diff --git a/src/trysysel.c b/src/trysysel.c
@@ -0,0 +1,11 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/select.h> /* SVR4 silliness */
+
+void foo()
+{
+ ;
+}
diff --git a/src/tryulong64.c b/src/tryulong64.c
@@ -0,0 +1,13 @@
+/* Public domain. */
+
+int main()
+{
+ unsigned long u;
+ u = 1;
+ u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u;
+ u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u;
+ u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u;
+ u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u;
+ if (!u) _exit(1);
+ _exit(0);
+}
diff --git a/src/trywaitp.c b/src/trywaitp.c
@@ -0,0 +1,9 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+
+main()
+{
+ waitpid(0,0,0);
+}
diff --git a/src/uint64.h1 b/src/uint64.h1
@@ -0,0 +1,10 @@
+/* Public domain. */
+
+#ifndef UINT64_H
+#define UINT64_H
+
+/* sysdep: -ulong64 */
+
+typedef unsigned long long uint64;
+
+#endif
diff --git a/src/uint64.h2 b/src/uint64.h2
@@ -0,0 +1,10 @@
+/* Public domain. */
+
+#ifndef UINT64_H
+#define UINT64_H
+
+/* sysdep: +ulong64 */
+
+typedef unsigned long uint64;
+
+#endif
diff --git a/src/wait.h b/src/wait.h
@@ -0,0 +1,16 @@
+/* Public domain. */
+
+#ifndef WAIT_H
+#define WAIT_H
+
+extern int wait_pid();
+extern int wait_nohang();
+extern int wait_stop();
+extern int wait_stopnohang();
+
+#define wait_crashed(w) ((w) & 127)
+#define wait_exitcode(w) ((w) >> 8)
+#define wait_stopsig(w) ((w) >> 8)
+#define wait_stopped(w) (((w) & 127) == 127)
+
+#endif
diff --git a/src/wait_nohang.c b/src/wait_nohang.c
@@ -0,0 +1,14 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include "haswaitp.h"
+
+int wait_nohang(wstat) int *wstat;
+{
+#ifdef HASWAITPID
+ return waitpid(-1,wstat,WNOHANG);
+#else
+ return wait3(wstat,WNOHANG,(struct rusage *) 0);
+#endif
+}
diff --git a/src/wait_pid.c b/src/wait_pid.c
@@ -0,0 +1,41 @@
+/* Public domain. */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include "error.h"
+#include "haswaitp.h"
+
+#ifdef HASWAITPID
+
+int wait_pid(wstat,pid) int *wstat; int pid;
+{
+ int r;
+
+ do
+ r = waitpid(pid,wstat,0);
+ while ((r == -1) && (errno == error_intr));
+ return r;
+}
+
+#else
+
+/* XXX untested */
+/* XXX breaks down with more than two children */
+static int oldpid = 0;
+static int oldwstat; /* defined if(oldpid) */
+
+int wait_pid(wstat,pid) int *wstat; int pid;
+{
+ int r;
+
+ if (pid == oldpid) { *wstat = oldwstat; oldpid = 0; return pid; }
+
+ do {
+ r = wait(wstat);
+ if ((r != pid) && (r != -1)) { oldwstat = *wstat; oldpid = r; continue; }
+ }
+ while ((r == -1) && (errno == error_intr));
+ return r;
+}
+
+#endif
diff --git a/src/warn-auto.sh b/src/warn-auto.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+# WARNING: This file was auto-generated. Do not edit!
diff --git a/src/warn-shsgr b/src/warn-shsgr
@@ -0,0 +1,3 @@
+Oops. Your getgroups() returned 0, and setgroups() failed; this means
+that I can't reliably do my shsgr test. Please either ``make'' as root
+or ``make'' while you're in one or more supplementary groups.
diff --git a/src/x86cpuid.c b/src/x86cpuid.c
@@ -0,0 +1,40 @@
+/* Public domain. */
+
+#include <signal.h>
+
+void nope()
+{
+ exit(1);
+}
+
+int main()
+{
+ unsigned long x[4];
+ unsigned long y[4];
+ int i;
+ int j;
+ char c;
+
+ signal(SIGILL,nope);
+
+ x[0] = 0;
+ x[1] = 0;
+ x[2] = 0;
+ x[3] = 0;
+
+ asm volatile(".byte 15;.byte 162" : "=a"(x[0]),"=b"(x[1]),"=c"(x[3]),"=d"(x[2]) : "0"(0) );
+ if (!x[0]) return 0;
+ asm volatile(".byte 15;.byte 162" : "=a"(y[0]),"=b"(y[1]),"=c"(y[2]),"=d"(y[3]) : "0"(1) );
+
+ for (i = 1;i < 4;++i)
+ for (j = 0;j < 4;++j) {
+ c = x[i] >> (8 * j);
+ if (c < 32) c = 32;
+ if (c > 126) c = 126;
+ putchar(c);
+ }
+
+ printf("-%08x-%08x\n",y[0],y[3]);
+
+ return 0;
+}