diff options
-rw-r--r-- | Makefile | 4 | ||||
-rwxr-xr-x | configure | 338 | ||||
-rwxr-xr-x | patch-for-solaris | 2 | ||||
-rw-r--r-- | src/librandom/random_string.c | 11 | ||||
-rw-r--r-- | src/sysdeps/tryaccept4.c | 4 | ||||
-rw-r--r-- | src/sysdeps/trygetrandom.c | 18 | ||||
-rw-r--r-- | src/sysdeps/trypipe2.c | 3 | ||||
-rw-r--r-- | src/sysdeps/tryppoll.c | 11 | ||||
-rw-r--r-- | src/sysdeps/trysplice.c | 27 | ||||
-rwxr-xr-x | tools/gen-bits-internal.sh | 9 | ||||
-rwxr-xr-x | tools/gen-bits.sh | 6 | ||||
-rwxr-xr-x | tools/gen-sysdepsh.sh | 39 |
12 files changed, 274 insertions, 198 deletions
@@ -134,8 +134,8 @@ libskarnet.so.xyzzy: $(ALL_DOBJS) .DELETE_ON_ERROR: -src/include/$(package)/sysdeps.h: $(sysdeps)/sysdeps.h - exec cat < $< > $@ +src/include/$(package)/sysdeps.h: $(sysdeps)/sysdeps $(sysdeps)/target + exec tools/gen-sysdepsh.sh `cat $(sysdeps)/target` < $(sysdeps)/sysdeps > $@ src/include/$(package)/uint16.h: $(sysdeps)/sysdeps src/headers/bits-header src/headers/bits-footer src/headers/bits-lendian src/headers/bits-bendian src/headers/bits-template src/headers/uint64-include src/include/$(package)/uint64.h exec tools/gen-bits.sh $(sysdeps)/sysdeps 16 6 7 5 17 > $@ @@ -58,6 +58,11 @@ echo () { printf %s\\n "$*" } +echon () { + IFS=" " + printf %s "$*" +} + quote () { tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; } $1 @@ -116,12 +121,27 @@ tryldflag () { fi } + +# Sysdeps determination functions + +iscached () +{ + if test -n "$sysdepspre" && grep -qF "${1}: " "$sysdepspre" ; then + v=`grep -F "${1}: " "$sysdepspre" | tail -n 1 | awk '{print $2;}'` + echo "${1}: $v" >> "$sysdeps/sysdeps" + echo " ... user-provided: $v" + return 0 ; + else + return 1 ; + fi +} + choose () { what="$1" name="$2" - macro="$3" - echo "Checking whether system has $4..." - shift 4 + if iscached "$name" ; then return ; fi + echo "Checking whether system has $3..." + shift 3 libs="$*" r=true case "$what" in @@ -143,40 +163,122 @@ choose () { esac fi rm -f try$name.o try$name - echo "#undef ${package_macro_name}_HAS$macro" >> $sysdeps/sysdeps.h if $r ; then echo "$name: yes" >> $sysdeps/sysdeps - echo "#define ${package_macro_name}_HAS$macro" >> $sysdeps/sysdeps.h echo " ... yes" else echo "$name: no" >> $sysdeps/sysdeps echo " ... no" fi - echo >> $sysdeps/sysdeps.h +} + +trybasic () { + $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST -o "$tmpe" -c "$1" 2>/dev/null + r=$? + rm -f "$tmpe" + return $r +} + +tryendianness () { + echo "Checking endianness..." + if iscached endianness ; then return ; fi + for i in endian.h sys/endian.h machine/endian.h ; do + cat > "$tmpc" <<EOF +#include <$i> +int a = 1 ; +EOF + if trybasic "$tmpc" ; then + cat > "$tmpc" <<EOF +#ifndef _BSD_SOURCE +#define _BSD_SOURCE +#endif +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#ifndef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE +#endif +#include <$i> +int a = LITTLE_ENDIAN ; +int b = BIG_ENDIAN ; +int c = BYTE_ORDER ; +EOF + trybasic "$tmpc" || exit 5 + for j in little big pdp ; do + k=`echo $j | tr a-z A-Z` + cat > "$tmpc" <<EOF +#ifndef _BSD_SOURCE +#define _BSD_SOURCE +#endif +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#ifndef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE +#endif +#include <$i> +int a[BYTE_ORDER == ${k}_ENDIAN ? 1 : -1] ; +EOF + if trybasic "$tmpc" ; then + echo "endianness: $j" >> "$sysdeps/sysdeps" + echo " ... $j" + rm -f "$tmpc" + return + fi + done + rm -f "$tmpc" + echo "$0: error: unable to determine endianness according to $i" 1>&2 + exit 1 + fi + done + rm -f "$tmpc" + echo "$0: error: unable to determine endianness: no endian.h found" 1>&2 + exit 1 +} + +trysigned () { + cat > "$tmpc" <<EOF +#include <sys/types.h> +int a[($1)-1 < 0 ? 1 : -1] ; +EOF + trybasic "$tmpc" + r=$? + rm -f "$tmpc" + return $r +} + +trysizes () { + t="$1" ; shift + for arg ; do + cat > "$tmpc" <<EOF +#include <sys/types.h> +int a[sizeof($t) == $arg ? 1 : -1] ; +EOF + if trybasic "$tmpc" ; then + rm -f "$tmpc" + echo "$arg" + return + fi + done + rm -f "$tmpc" + echo "$0: error: unable to determine the size of $t on the target" 1>&2 + exit 1 +} + +trystdtype () { + t="$1" ; shift + iscached "sizeofu$t" || { echon "sizeofu${t}: " ; trysizes "$t" "$@" ; } >> "$sysdeps/sysdeps" } trytypes () { echo "Checking size and signedness of standard types..." - $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST $LDFLAGS_AUTO $LDFLAGS $LDFLAGS_POST -o output-types src/sysdeps/output-types.c - ./output-types >> $sysdeps/sysdeps - ./output-types | grep -F sizeof | while read key value ; do - caps=$(echo $key | sed s/:\$// | tr a-z A-Z) - echo "#undef ${package_macro_name}_${caps}" - echo "#define ${package_macro_name}_${caps} $value" - echo - done >> $sysdeps/sysdeps.h - ./output-types | grep -F signed | while read key value ; do - caps=$(echo $key | sed s/:\$// | tr a-z A-Z) - echo "#undef ${package_macro_name}_HASUN${caps}" - echo "#undef ${package_macro_name}_HAS${caps}" - if test $value = yes ; then - echo "#define ${package_macro_name}_HAS${caps}" - else - echo "#define ${package_macro_name}_HASUN${caps}" - fi - echo - done >> $sysdeps/sysdeps.h - rm -f output-types + trystdtype short 2 4 + trystdtype int 4 8 2 + trystdtype long 8 4 + for t in size uid gid pid time dev ino ; do + iscached "signed$t" || { echon "signed${t}: " ; if trysigned "${t}_t" ; then echo "yes" ; else echo "no" ; fi ; } >> "$sysdeps/sysdeps" + iscached "sizeof$t" || { echon "sizeof${t}: " ; trysizes "${t}_t" 4 8 2 ; } >> "$sysdeps/sysdeps" + done echo " ... done" } @@ -231,7 +333,7 @@ libdir='$prefix/lib/$package' includedir='$prefix/include' datadir='$prefix/etc' sysdepdir='$prefix/lib/$package/sysdeps' -sysdeps= +sysdepspre= shared=true static=true allpic=true @@ -261,7 +363,7 @@ for arg ; do --includedir=*) includedir=${arg#*=} ;; --datadir=*) datadir=${arg#*=} ;; --sysdepdir=*) sysdepdir=${arg#*=} ;; - --with-sysdeps=*) sysdeps=${arg#*=} ;; + --with-sysdeps=*) sysdepspre=${arg#*=} ;; --with-include=*) var=${arg#*=} ; stripdir var ; addincpath="$addincpath -I$var" ;; --with-lib=*) var=${arg#*=} ; stripdir var ; addlibspath="$addlibspath -L$var" ; vpaths="$vpaths $var" ;; --with-dynlib=*) var=${arg#*=} ; stripdir var ; addlibdpath="$addlibdpath -L$var" ; vpathd="$vpathd $var" ;; @@ -308,7 +410,7 @@ fi # Expand installation directories stripdir prefix -for i in exec_prefix dynlibdir libdir includedir datadir sysdepdir sysdeps sproot ; do +for i in exec_prefix dynlibdir libdir includedir datadir sysdepdir sysdepspre sproot ; do eval tmp=\${$i} eval $i=$tmp stripdir $i @@ -419,22 +521,21 @@ if $shared ; then tryldflag LDFLAGS -Wl,--hash-style=both fi -if test -n "$sysdeps" ; then - if test ! -d $sysdeps || test ! -f $sysdeps/target ; then - echo "$0: error: $sysdeps is not a valid sysdeps directory" +if test -n "$sysdepspre" ; then + if test ! -d "$sysdepspre" || test ! -f $sysdepspre/target ; then + echo "$0: error: $sysdepspre is not a valid sysdeps directory" exit 1 fi - if [ "x$target" != "x$(cat $sysdeps/target)" ] ; then - echo "$0: error: target $target does not match the contents of $sysdeps/target" + if [ "x$target" != "x$(cat $sysdepspre/target)" ] ; then + echo "$0: error: target $target does not match the contents of $sysdepspre/target" exit 1 fi - echo "Using pre-computed sysdeps in $sysdeps." - spawn_lib=$(cat $sysdeps/spawn.lib) - socket_lib=$(cat $sysdeps/socket.lib) - sysclock_lib=$(cat $sysdeps/sysclock.lib) - tainnow_lib=$(cat $sysdeps/tainnow.lib) - timer_lib=$(cat $sysdeps/timer.lib) - util_lib=$(cat $sysdeps/util.lib) + echo "Using pre-computed sysdeps in $sysdepspre." + spawn_lib=$(cat $sysdepspre/spawn.lib) + socket_lib=$(cat $sysdepspre/socket.lib) + sysclock_lib=$(cat $sysdepspre/sysclock.lib) + timer_lib=$(cat $sysdepspre/timer.lib) + util_lib=$(cat $sysdepspre/util.lib) else if test -n "$cross" ; then echo "$0: warning: possible cross-build attempt with a native compiler" 1>&2 @@ -442,17 +543,6 @@ else sysdeps=sysdeps.cfg mkdir -p $sysdeps echo "$target" > $sysdeps/target - echo "target: $target" > $sysdeps/sysdeps - cat <<EOF > $sysdeps/sysdeps.h -/* ISC license. */ - -#ifndef SYSDEPS_H -#define SYSDEPS_H - -#undef SKALIBS_TARGET -#define SKALIBS_TARGET "$target" - -EOF exec 3>&1 util_lib= @@ -461,105 +551,68 @@ EOF socket_lib=`trylibs lsock 'accessible socket functions' -lsocket -lnsl` || fail "$0: unable to determine socket.lib sysdep" echo "$socket_lib" > $sysdeps/socket.lib - hasclock=true - sysclock_lib=`trylibs clockrt 'clock_gettime()' -lrt` || hasclock=false - tainnow_lib=$sysclock_lib + hasclock=yes + sysclock_lib=`trylibs clockrt 'clock_gettime()' -lrt` || hasclock=no echo "$sysclock_lib" > $sysdeps/sysclock.lib - echo "$tainnow_lib" > $sysdeps/tainnow.lib - echo "#undef ${package_macro_name}_HASCLOCKRT" >> $sysdeps/sysdeps.h - if $hasclock ; then - echo 'clockrt: yes' >> $sysdeps/sysdeps - echo "#define ${package_macro_name}_HASCLOCKRT" >> $sysdeps/sysdeps.h - else - echo 'clockrt: no' >> $sysdeps/sysdeps - fi - echo >> $sysdeps/sysdeps.h - choose cl clockmon CLOCKMON CLOCK_MONOTONIC $sysclock_lib - choose cl clockboot CLOCKBOOT CLOCK_BOOTTIME $sysclock_lib + echo "clockrt: $hasclock" >> $sysdeps/sysdeps - hasspawn=true - spawn_lib=`trylibs posixspawn 'posix_spawn()' -lrt` || hasspawn=false + choose cl clockmon CLOCK_MONOTONIC $sysclock_lib + choose cl clockboot CLOCK_BOOTTIME $sysclock_lib + + hasspawn=yes + spawn_lib=`trylibs posixspawn 'posix_spawn()' -lrt` || hasspawn=no echo "$spawn_lib" > $sysdeps/spawn.lib - echo "#undef ${package_macro_name}_HASPOSIXSPAWN" >> $sysdeps/sysdeps.h - if $hasspawn ; then - echo 'posixspawn: yes' >> $sysdeps/sysdeps - echo "#define ${package_macro_name}_HASPOSIXSPAWN" >> $sysdeps/sysdeps.h - else - echo 'posixspawn: no' >> $sysdeps/sysdeps - fi - echo >> $sysdeps/sysdeps.h + echo "posixspawn: $hasspawn" >> $sysdeps/sysdeps - hastimer=true - timer_lib=`trylibs timer 'timer_create()' -lrt` || hastimer=false + hastimer=yes + timer_lib=`trylibs timer 'timer_create()' -lrt` || hastimer=no echo "$timer_lib" > $sysdeps/timer.lib - echo "#undef ${package_macro_name}_HASTIMER" >> $sysdeps/sysdeps.h - if $hastimer ; then - echo 'timer: yes' >> $sysdeps/sysdeps - echo "#define ${package_macro_name}_HASTIMER" >> $sysdeps/sysdeps.h - else - echo 'timer: no' >> $sysdeps/sysdeps - fi - echo >> $sysdeps/sysdeps.h + echo "timer: $hastimer" >> $sysdeps/sysdeps exec 3>&- - echo "Checking system endianness..." - $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST $LDFLAGS_AUTO $LDFLAGS $LDFLAGS_POST -o tryendianness src/sysdeps/tryendianness.c - endianness=$(./tryendianness) || fail "$0: unable to determine endianness" - echo "endianness: $endianness" >> $sysdeps/sysdeps - { - echo "#undef ${package_macro_name}_ENDIANNESS" - echo "#define ${package_macro_name}_ENDIANNESS \"$endianness\"" - echo - } >> $sysdeps/sysdeps.h - echo " ... $endianness" - rm -f tryendianness - + tryendianness trytypes - choose clr nullispointer NULLISPOINTER 'a pointer-typed NULL' - choose clr accept4 ACCEPT4 'accept4()' - choose c cmsgcloexec CMSGCLOEXEC 'MSG_CMSG_CLOEXEC' - choose clr devurandom DEVURANDOM '/dev/urandom' - choose cl dirfd DIRFD 'dirfd()' - choose cl eventfd EVENTFD 'eventfd()' - choose cl flock FLOCK 'flock()' - choose cl getpeereid GETPEEREID 'getpeereid()' - choose cl sopeercred SOPEERCRED 'SO_PEERCRED' - choose cl getpeerucred GETPEERUCRED 'getpeerucred()' - choose cl ipv6 IPV6 'IPv6 support' $socket_lib - choose clr malloc0 MALLOC0 'non-NULL malloc(0)' - choose c msgdontwait MSGDONTWAIT 'MSG_DONTWAIT' - choose c odirectory ODIRECTORY 'O_DIRECTORY' - choose cl openat OPENAT 'openat()' - choose cl linkat LINKAT 'linkat()' - choose cl memmem MEMMEM 'memmem()' - choose clr pipe2 PIPE2 'pipe2()' - choose clr ppoll PPOLL 'ppoll()' - choose cl revoke REVOKE 'revoke()' - choose cl sendfile SENDFILE 'sendfile()' - choose cl setgroups SETGROUPS 'setgroups()' - choose cl settimeofday SETTIMEOFDAY 'settimeofday()' - choose clr signalfd SIGNALFD 'signalfd()' - choose clr splice SPLICE 'splice()' - choose cl strcasestr STRCASESTR 'strcasestr()' - choose c strnlen STRNLEN 'strnlen()' - choose c uint64t UINT64T 'uint64_t' - choose cl futimens FUTIMENS 'futimens()' - choose cl futimes FUTIMES 'futimes()' - choose cl arc4random ARC4RANDOM 'arc4random()' - choose cl arc4random_addrandom ARC4RANDOM_ADDRANDOM 'arc4random_addrandom()' - choose clr getrandom GETRANDOM 'getrandom()' - choose cl itimer ITIMER 'setitimer()' - choose cl namespaces NAMESPACES 'namespaces' - choose cl nsgetparent NSGETPARENT 'NS_GET_PARENT' - choose cl explicit_bzero EXPLICIT_BZERO 'explicit_bzero()' - choose clr emptyregex EMPTYREGEX 'regcomp() accept empty regexes' - - echo '#endif' >> $sysdeps/sysdeps.h -fi + choose cl accept4 'accept4()' + choose c cmsgcloexec 'MSG_CMSG_CLOEXEC' + choose cl dirfd 'dirfd()' + choose cl eventfd 'eventfd()' + choose cl flock 'flock()' + choose cl getrandom 'getrandom()' + choose cl getpeereid 'getpeereid()' + choose cl sopeercred 'SO_PEERCRED' + choose cl getpeerucred 'getpeerucred()' + choose cl ipv6 'IPv6 support' $socket_lib + choose c msgdontwait 'MSG_DONTWAIT' + choose c odirectory 'O_DIRECTORY' + choose cl openat 'openat()' + choose cl linkat 'linkat()' + choose cl memmem 'memmem()' + choose cl pipe2 'pipe2()' + choose cl ppoll 'ppoll()' + choose cl revoke 'revoke()' + choose cl sendfile 'sendfile()' + choose cl setgroups 'setgroups()' + choose cl settimeofday 'settimeofday()' + choose cl signalfd 'signalfd()' + choose cl splice 'splice()' + choose cl strcasestr 'strcasestr()' + choose c strnlen 'strnlen()' + choose c uint64t 'uint64_t' + choose cl futimens 'futimens()' + choose cl futimes 'futimes()' + choose cl arc4random 'arc4random()' + choose cl arc4random_addrandom 'arc4random_addrandom()' + choose cl itimer 'setitimer()' + choose cl namespaces 'namespaces' + choose cl nsgetparent 'NS_GET_PARENT' + choose cl explicit_bzero 'explicit_bzero()' + + choose clr emptyregex 'regcomp() accept empty regexes' + choose clr nullispointer 'a pointer-typed NULL' + choose clr devurandom '/dev/urandom' + choose clr malloc0 'non-NULL malloc(0)' -echo "Copying $sysdeps/sysdeps.h to src/include/${package}/sysdeps.h ..." -cat < $sysdeps/sysdeps.h > src/include/${package}/sysdeps.h -echo " ... done" +fi echo "Creating config.mak..." cmdline=$(quote "$0") @@ -587,7 +640,6 @@ ipv6 := ${ipv6} SPAWN_LIB := ${spawn_lib} SOCKET_LIB := ${socket_lib} SYSCLOCK_LIB := ${sysclock_lib} -TAINNOW_LIB := ${tainnow_lib} TIMER_LIB := ${timer_lib} UTIL_LIB := ${util_lib} CC := ${CC_AUTO} diff --git a/patch-for-solaris b/patch-for-solaris index 4ca46ef..7e43e36 100755 --- a/patch-for-solaris +++ b/patch-for-solaris @@ -21,7 +21,7 @@ patchit ./tools/gen-deps.sh patchit ./tools/gen-types.sh patchit ./tools/gen-types-internal.sh patchit ./tools/gen-bits.sh -patchit ./tools/gen-bits-internal.sh +patchit ./tools/make-sysdepsh.sh echo 'SHELL := /usr/xpg4/bin/sh' > Makefile.tmp echo >> Makefile.tmp diff --git a/src/librandom/random_string.c b/src/librandom/random_string.c index f8cabc3..acdec69 100644 --- a/src/librandom/random_string.c +++ b/src/librandom/random_string.c @@ -16,21 +16,14 @@ void random_string (char *s, size_t n) #else #ifdef SKALIBS_HASGETRANDOM -#include <skalibs/nonposix.h> -#include <unistd.h> -#include <sys/syscall.h> +#include <sys/random.h> #include <skalibs/random.h> -static int getrandom (void *buf, size_t buflen, unsigned int flags) -{ - return syscall(SYS_getrandom, buf, buflen, flags) ; -} - void random_string (char *s, size_t n) { while (n) { - int r = getrandom(s, n, 0) ; + ssize_t r = getrandom(s, n, 0) ; if (r >= 0) { s += r ; diff --git a/src/sysdeps/tryaccept4.c b/src/sysdeps/tryaccept4.c index 98a75e6..ea3baaa 100644 --- a/src/sysdeps/tryaccept4.c +++ b/src/sysdeps/tryaccept4.c @@ -11,6 +11,10 @@ #define _GNU_SOURCE #endif +#ifndef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE +#endif + #include <sys/socket.h> #include <sys/stat.h> #include <fcntl.h> diff --git a/src/sysdeps/trygetrandom.c b/src/sysdeps/trygetrandom.c index 8abe3dd..cc2426b 100644 --- a/src/sysdeps/trygetrandom.c +++ b/src/sysdeps/trygetrandom.c @@ -1,24 +1,10 @@ /* ISC license. */ -#undef _POSIX_C_SOURCE -#undef _XOPEN_SOURCE - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include <sys/types.h> -#include <unistd.h> -#include <sys/syscall.h> - -static int getrandom (void *buf, size_t buflen, unsigned int flags) -{ - return syscall(SYS_getrandom, buf, buflen, flags) ; -} +#include <sys/random.h> int main (void) { char buf[4] ; - if (getrandom(buf, 4, 0) < 0) return 1 ; + if (getrandom(buf, 4, GRND_NONBLOCK) < 0) return 1 ; return 0 ; } diff --git a/src/sysdeps/trypipe2.c b/src/sysdeps/trypipe2.c index 0b8cb3c..173b815 100644 --- a/src/sysdeps/trypipe2.c +++ b/src/sysdeps/trypipe2.c @@ -12,6 +12,9 @@ #ifndef _BSD_SOURCE #define _BSD_SOURCE #endif +#ifndef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE +#endif #ifndef _NETBSD_SOURCE #define _NETBSD_SOURCE #endif diff --git a/src/sysdeps/tryppoll.c b/src/sysdeps/tryppoll.c index 1502f2c..18f7615 100644 --- a/src/sysdeps/tryppoll.c +++ b/src/sysdeps/tryppoll.c @@ -1,9 +1,20 @@ /* ISC license. */ +#undef _POSIX_C_SOURCE +#undef _XOPEN_SOURCE + +#ifndef _BSD_SOURCE +#define _BSD_SOURCE +#endif + #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif +#ifndef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE +#endif + #include <sys/stat.h> #include <fcntl.h> #include <time.h> diff --git a/src/sysdeps/trysplice.c b/src/sysdeps/trysplice.c index 8e8bd72..969c5ea 100644 --- a/src/sysdeps/trysplice.c +++ b/src/sysdeps/trysplice.c @@ -1,29 +1,22 @@ /* ISC license. */ +#undef _POSIX_C_SOURCE +#undef _XOPEN_SOURCE + #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif -#include <sys/stat.h> #include <fcntl.h> -#include <unistd.h> - -#define N 4096 +#include <sys/uio.h> int main (void) { - int p[2] ; - int fd ; - if (pipe(p) < 0) return 111 ; - fd = open("./src/sysdeps/trysplice.c", O_RDONLY) ; - if (fd < 0) return 111 ; - - for (;;) - { - ssize_t r = splice(fd, 0, p[1], 0, N, 0) ; - if (r < 0) return 1 ; - if (!r) break ; - if (splice(p[0], 0, 1, 0, r, 0) < r) return 2 ; - } + char s[2][2] ; + struct iovec v[2] = { { .iov_base = s[0], .iov_len = 2 }, { .iov_base = s[1], .iov_len = 2 } } ; + loff_t in, out ; + ssize_t r = splice(0, &in, 1, &out, 4096, SPLICE_F_MOVE) ; + r = tee(0, 1, 4096, SPLICE_F_NONBLOCK) ; + r = vmsplice(0, v, 2, 0) ; return 0 ; } diff --git a/tools/gen-bits-internal.sh b/tools/gen-bits-internal.sh deleted file mode 100755 index 93e64ab..0000000 --- a/tools/gen-bits-internal.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -e - -bits="$1" -dfmt="$2" -ofmt="$3" -xfmt="$4" -bfmt="$5" - -exec sed -e "s/@BITS@/$bits/g; s/@DFMT@/$dfmt/g; s/@OFMT@/$ofmt/g; s/@XFMT@/$xfmt/g; s/@BFMT@/$bfmt/g;" < src/headers/bits-template diff --git a/tools/gen-bits.sh b/tools/gen-bits.sh index 951a7d9..01aa9b8 100755 --- a/tools/gen-bits.sh +++ b/tools/gen-bits.sh @@ -7,6 +7,10 @@ ofmt="$4" xfmt="$5" bfmt="$6" +gen_bits() { + sed -e "s/@BITS@/$1/g; s/@DFMT@/$2/g; s/@OFMT@/$3/g; s/@XFMT@/$4/g; s/@BFMT@/$5/g;" < src/headers/bits-template +} + tools/gen-types-internal.sh "" "" "$bits" < src/headers/bits-header if test "$bits" = 64 ; then @@ -33,5 +37,5 @@ else fi tools/gen-types-internal.sh "" "" "$bits" < src/headers/bits-${endian}endian -tools/gen-bits-internal.sh "$bits" "$dfmt" "$ofmt" "$xfmt" "$bfmt" +gen_bits "$bits" "$dfmt" "$ofmt" "$xfmt" "$bfmt" exec tools/gen-types-internal.sh "" "" "$bits" < src/headers/bits-footer diff --git a/tools/gen-sysdepsh.sh b/tools/gen-sysdepsh.sh new file mode 100755 index 0000000..f6194f2 --- /dev/null +++ b/tools/gen-sysdepsh.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +cat <<EOF +/* ISC license. */ + +#ifndef SYSDEPS_H +#define SYSDEPS_H + +#undef SKALIBS_TARGET +#define SKALIBS_TARGET "$1" + +EOF + +while read k v ; do + k=$(echo "${k%%:}" | tr a-z A-Z) + if test ${k} != ${k##SIGNED} ; then + echo "#undef SKALIBS_HASUN$k" + echo "#undef SKALIBS_HAS$k" + if test $v = yes ; then + echo "#define SKALIBS_HAS$k" + else + echo "#define SKALIBS_HASUN$k" + fi + elif test ${k} != ${k##SIZEOF} ; then + echo "#undef SKALIBS_HAS$k" + echo "#define SKALIBS_HAS$k $v" + elif test ${k} = ENDIANNESS ; then + echo '#undef SKALIBS_ENDIANNESS' + echo "#define SKALIBS_ENDIANNESS $v" + else + echo "#undef SKALIBS_HAS$k" + if test $v = yes ; then + echo "#define SKALIBS_HAS$k" + fi + fi + echo +done + +echo '#endif' |