skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

commit 2990ce9b390ec1e2bfa1c043c406878e8aff86dd
parent 933e986a9207d2b61c5119e18603b44b924e7226
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Thu, 21 Dec 2017 11:18:28 +0000

 Big 2.6.3.0 reorganization

 - Add libposixplz, update headers
 - Add memmem and friends
 - Add textmessage to libunixonacid
 - Update some sysdeps tests

Diffstat:
MNEWS | 8+++++++-
Mconfigure | 1+
Mdoc/upgrade.html | 8+++++++-
Mpackage/deps.mak | 58++++++++++++++++++++++++++++++++++++++++++----------------
Msrc/include/skalibs/bytestr.h | 11+++--------
Msrc/include/skalibs/djbunix.h | 9+++------
Msrc/include/skalibs/environ.h | 7++-----
Msrc/include/skalibs/getpeereid.h | 9++-------
Msrc/include/skalibs/mininetstring.h | 5+++--
Asrc/include/skalibs/posixplz.h | 45+++++++++++++++++++++++++++++++++++++++++++++
Msrc/include/skalibs/setgroups.h | 12+++++++++++-
Msrc/include/skalibs/skalibs.h | 4++--
Msrc/include/skalibs/skamisc.h | 1+
Msrc/include/skalibs/stddjb.h | 4+---
Asrc/include/skalibs/textmessage.h | 96+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/include/skalibs/unixonacid.h | 1+
Msrc/include/skalibs/webipc.h | 2+-
Asrc/libposixplz/doublefork.c | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/libposixplz/execvep.c | 39+++++++++++++++++++++++++++++++++++++++
Asrc/libposixplz/getpeereid.c | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/libposixplz/memmem.c | 187+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/libstddjb/setgroups.c -> src/libposixplz/setgroups.c | 0
Asrc/libposixplz/strnlen.c | 16++++++++++++++++
Asrc/libposixplz/touch.c | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/libstddjb/byte_search.c | 11+++++++++++
Dsrc/libstddjb/doublefork.c | 50--------------------------------------------------
Msrc/libstddjb/env_get.c | 2+-
Dsrc/libstddjb/execvep.c | 39---------------------------------------
Dsrc/libstddjb/getpeereid.c | 66------------------------------------------------------------------
Msrc/libstddjb/pathexec.c | 2+-
Msrc/libstddjb/pathexec_run.c | 1+
Asrc/libstddjb/siovec_search.c | 30++++++++++++++++++++++++++++++
Asrc/libstddjb/skagetlnmaxsep.c | 29+++++++++++++++++++++++++++++
Dsrc/libstddjb/touch.c | 53-----------------------------------------------------
Msrc/libstddjb/xexecvep.c | 1+
Asrc/libunixonacid/textmessage_handle.c | 20++++++++++++++++++++
Asrc/libunixonacid/textmessage_put.c | 21+++++++++++++++++++++
Asrc/libunixonacid/textmessage_putv.c | 22++++++++++++++++++++++
Asrc/libunixonacid/textmessage_receive.c | 40++++++++++++++++++++++++++++++++++++++++
Asrc/libunixonacid/textmessage_receiver_0.c | 10++++++++++
Asrc/libunixonacid/textmessage_receiver_free.c | 10++++++++++
Asrc/libunixonacid/textmessage_receiver_hasmsginbuf.c | 21+++++++++++++++++++++
Asrc/libunixonacid/textmessage_receiver_init.c | 14++++++++++++++
Asrc/libunixonacid/textmessage_receiver_zero.c | 5+++++
Asrc/libunixonacid/textmessage_sender_1.c | 7+++++++
Asrc/libunixonacid/textmessage_sender_flush.c | 9+++++++++
Asrc/libunixonacid/textmessage_sender_getfd.c | 9+++++++++
Asrc/libunixonacid/textmessage_sender_timed_flush.c | 15+++++++++++++++
Asrc/libunixonacid/textmessage_sender_x.c | 7+++++++
Asrc/libunixonacid/textmessage_sender_zero.c | 5+++++
Asrc/libunixonacid/textmessage_timed_handle.c | 29+++++++++++++++++++++++++++++
Asrc/libunixonacid/textmessage_timed_receive.c | 29+++++++++++++++++++++++++++++
Msrc/sysdeps/tryarc4random.c | 16++++++++++++++++
Msrc/sysdeps/tryarc4random_addrandom.c | 16++++++++++++++++
Msrc/sysdeps/trygetpeereid.c | 20++++++++++++++++++--
Asrc/sysdeps/trymemmem.c | 28++++++++++++++++++++++++++++
Msrc/sysdeps/trynamespaces.c | 15+++++++++++++++
Msrc/sysdeps/trystrcasestr.c | 6++++++
Msrc/sysdeps/trystrnlen.c | 3+++
59 files changed, 1092 insertions(+), 265 deletions(-)

diff --git a/NEWS b/NEWS @@ -3,7 +3,13 @@ Changelog for skalibs. In 2.6.3.0 ---------- - - New function: atomic_symlink(). + - memmem implementation for platforms that don't provide it. + - memmem wrappers: byte_search, siovec_search. + - New functions: atomic_symlink, skagetlnmaxsep. + - New header: skalibs/posixplz.h, some header reorganization. + - New family of functions: skalibs/textmessage.h. + - skalibs/environ.h and skalibs/getpeereid.h are now obsolescent. + - mininetstring* functions are now obsolescent. In 2.6.2.0 diff --git a/configure b/configure @@ -520,6 +520,7 @@ EOF 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()' diff --git a/doc/upgrade.html b/doc/upgrade.html @@ -19,7 +19,13 @@ <h2> in 2.6.3.0 </h2> <ul> - <li> New function: atomic_symlink(). </li> + <li> memmem implementation for platforms that don't provide it. </li> + <li> memmem wrappers: byte_search, siovec_search. </li> + <li> New functions: atomic_symlink, skagetlnmaxsep. </li> + <li> New header: <tt>skalibs/posixplz.h</tt>. Some header reorganization. </li> + <li> New family of functions: <tt>skalibs/textmessage.h</tt>. </li> + <li> <tt>skalibs/environ.h</tt> and <tt>skalibs/getpeereid.h</tt> are now obsolescent. </li> + <li> <tt>skalibs/mininetstring.h</tt> and the functions are it declares now obsolescent. </li> </ul> <h2> in 2.6.2.0 </h2> diff --git a/package/deps.mak b/package/deps.mak @@ -12,45 +12,49 @@ src/include/skalibs/biguint.h: src/include/skalibs/gccattributes.h src/include/skalibs/bitarray.h: src/include/skalibs/gccattributes.h src/include/skalibs/bufalloc.h: src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h src/include/skalibs/buffer.h: src/include/skalibs/allreadwrite.h src/include/skalibs/cbuffer.h src/include/skalibs/functypes.h src/include/skalibs/gccattributes.h -src/include/skalibs/bytestr.h: src/include/skalibs/config.h src/include/skalibs/gccattributes.h src/include/skalibs/sysdeps.h +src/include/skalibs/bytestr.h: src/include/skalibs/gccattributes.h src/include/skalibs/posixplz.h src/include/skalibs/cbuffer.h: src/include/skalibs/gccattributes.h src/include/skalibs/cdb.h: src/include/skalibs/gccattributes.h src/include/skalibs/cdb_make.h: src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/diuint32.h src/include/skalibs/genalloc.h src/include/skalibs/datastruct.h: src/include/skalibs/avlnode.h src/include/skalibs/avltree.h src/include/skalibs/avltreen.h src/include/skalibs/genset.h src/include/skalibs/gensetdyn.h src/include/skalibs/djbtime.h: src/include/skalibs/tai.h src/include/skalibs/uint64.h -src/include/skalibs/djbunix.h: src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h +src/include/skalibs/djbunix.h: src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/gccattributes.h src/include/skalibs/posixplz.h src/include/skalibs/stralloc.h src/include/skalibs/env.h: src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h src/include/skalibs/envalloc.h: src/include/skalibs/genalloc.h +src/include/skalibs/environ.h: src/include/skalibs/posixplz.h src/include/skalibs/fmtscan.h: src/include/skalibs/gccattributes.h src/include/skalibs/genalloc.h: src/include/skalibs/functypes.h src/include/skalibs/stralloc.h src/include/skalibs/genset.h: src/include/skalibs/functypes.h src/include/skalibs/gensetdyn.h: src/include/skalibs/functypes.h src/include/skalibs/genalloc.h src/include/skalibs/stralloc.h +src/include/skalibs/getpeereid.h: src/include/skalibs/posixplz.h src/include/skalibs/iobuffer.h: src/include/skalibs/buffer.h src/include/skalibs/djbunix.h src/include/skalibs/iopause.h: src/include/skalibs/tai.h src/include/skalibs/kolbak.h: src/include/skalibs/unixmessage.h src/include/skalibs/lolstdio.h: src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/strerr2.h -src/include/skalibs/mininetstring.h: src/include/skalibs/stralloc.h +src/include/skalibs/mininetstring.h: src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h src/include/skalibs/netstring.h: src/include/skalibs/buffer.h src/include/skalibs/stralloc.h +src/include/skalibs/posixplz.h: src/include/skalibs/gccattributes.h src/include/skalibs/random.h: src/include/skalibs/stralloc.h src/include/skalibs/setgroups.h: src/include/skalibs/sysdeps.h src/include/skalibs/sha512.h: src/include/skalibs/uint64.h src/include/skalibs/sig.h: src/include/skalibs/gccattributes.h src/include/skalibs/siovec.h: src/include/skalibs/gccattributes.h src/include/skalibs/skaclient.h: src/include/skalibs/kolbak.h src/include/skalibs/tai.h src/include/skalibs/unixmessage.h -src/include/skalibs/skalibs.h: src/include/skalibs/biguint.h src/include/skalibs/datastruct.h src/include/skalibs/random.h src/include/skalibs/stdcrypto.h src/include/skalibs/stddjb.h src/include/skalibs/unixonacid.h +src/include/skalibs/skalibs.h: src/include/skalibs/biguint.h src/include/skalibs/datastruct.h src/include/skalibs/posixplz.h src/include/skalibs/random.h src/include/skalibs/stdcrypto.h src/include/skalibs/stddjb.h src/include/skalibs/unixonacid.h src/include/skalibs/skamisc.h: src/include/skalibs/buffer.h src/include/skalibs/stralloc.h src/include/skalibs/socket.h: src/include/skalibs/djbunix.h src/include/skalibs/gccattributes.h src/include/skalibs/tai.h src/include/skalibs/webipc.h src/include/skalibs/stdcrypto.h: src/include/skalibs/md5.h src/include/skalibs/rc4.h src/include/skalibs/sha1.h src/include/skalibs/sha256.h src/include/skalibs/sha512.h -src/include/skalibs/stddjb.h: src/include/skalibs/alarm.h src/include/skalibs/alloc.h src/include/skalibs/allreadwrite.h src/include/skalibs/bitarray.h src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/bytestr.h src/include/skalibs/cbuffer.h src/include/skalibs/cdb.h src/include/skalibs/cdb_make.h src/include/skalibs/config.h src/include/skalibs/direntry.h src/include/skalibs/disize.h src/include/skalibs/diuint.h src/include/skalibs/diuint32.h src/include/skalibs/djbtime.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/environ.h src/include/skalibs/error.h src/include/skalibs/fmtscan.h src/include/skalibs/functypes.h src/include/skalibs/gccattributes.h src/include/skalibs/genalloc.h src/include/skalibs/genwrite.h src/include/skalibs/getpeereid.h src/include/skalibs/iobuffer.h src/include/skalibs/iopause.h src/include/skalibs/ip46.h src/include/skalibs/lolstdio.h src/include/skalibs/mininetstring.h src/include/skalibs/netstring.h src/include/skalibs/nsig.h src/include/skalibs/segfault.h src/include/skalibs/selfpipe.h src/include/skalibs/setgroups.h src/include/skalibs/sgetopt.h src/include/skalibs/sig.h src/include/skalibs/siovec.h src/include/skalibs/skamisc.h src/include/skalibs/socket.h src/include/skalibs/stralloc.h src/include/skalibs/strerr.h src/include/skalibs/strerr2.h src/include/skalibs/tai.h src/include/skalibs/types.h src/include/skalibs/uint16.h src/include/skalibs/uint32.h src/include/skalibs/uint64.h src/include/skalibs/webipc.h +src/include/skalibs/stddjb.h: src/include/skalibs/alarm.h src/include/skalibs/alloc.h src/include/skalibs/allreadwrite.h src/include/skalibs/bitarray.h src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/bytestr.h src/include/skalibs/cbuffer.h src/include/skalibs/cdb.h src/include/skalibs/cdb_make.h src/include/skalibs/config.h src/include/skalibs/direntry.h src/include/skalibs/disize.h src/include/skalibs/diuint.h src/include/skalibs/diuint32.h src/include/skalibs/djbtime.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/error.h src/include/skalibs/fmtscan.h src/include/skalibs/functypes.h src/include/skalibs/gccattributes.h src/include/skalibs/genalloc.h src/include/skalibs/genwrite.h src/include/skalibs/iobuffer.h src/include/skalibs/iopause.h src/include/skalibs/ip46.h src/include/skalibs/lolstdio.h src/include/skalibs/mininetstring.h src/include/skalibs/netstring.h src/include/skalibs/nsig.h src/include/skalibs/segfault.h src/include/skalibs/selfpipe.h src/include/skalibs/setgroups.h src/include/skalibs/sgetopt.h src/include/skalibs/sig.h src/include/skalibs/siovec.h src/include/skalibs/skamisc.h src/include/skalibs/socket.h src/include/skalibs/stralloc.h src/include/skalibs/strerr.h src/include/skalibs/strerr2.h src/include/skalibs/tai.h src/include/skalibs/types.h src/include/skalibs/uint16.h src/include/skalibs/uint32.h src/include/skalibs/uint64.h src/include/skalibs/webipc.h src/include/skalibs/strerr.h: src/include/skalibs/gccattributes.h src/include/skalibs/strerr2.h: src/include/skalibs/strerr.h src/include/skalibs/tai.h: src/include/skalibs/gccattributes.h src/include/skalibs/uint64.h +src/include/skalibs/textmessage.h: src/include/skalibs/allreadwrite.h src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h src/include/skalibs/tai.h src/include/skalibs/unix-timed.h: src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/functypes.h src/include/skalibs/stralloc.h src/include/skalibs/tai.h src/include/skalibs/unix-transactional.h: src/include/skalibs/stralloc.h src/include/skalibs/uint64.h src/include/skalibs/unixconnection.h: src/include/skalibs/unixmessage.h src/include/skalibs/unixmessage.h: src/include/skalibs/buffer.h src/include/skalibs/cbuffer.h src/include/skalibs/gccattributes.h src/include/skalibs/genalloc.h src/include/skalibs/stralloc.h src/include/skalibs/tai.h -src/include/skalibs/unixonacid.h: src/include/skalibs/kolbak.h src/include/skalibs/skaclient.h src/include/skalibs/unix-timed.h src/include/skalibs/unix-transactional.h src/include/skalibs/unixconnection.h src/include/skalibs/unixmessage.h -src/include/skalibs/webipc.h: src/include/skalibs/djbunix.h src/include/skalibs/getpeereid.h src/include/skalibs/tai.h +src/include/skalibs/unixonacid.h: src/include/skalibs/kolbak.h src/include/skalibs/skaclient.h src/include/skalibs/textmessage.h src/include/skalibs/unix-timed.h src/include/skalibs/unix-transactional.h src/include/skalibs/unixconnection.h src/include/skalibs/unixmessage.h +src/include/skalibs/webipc.h: src/include/skalibs/djbunix.h src/include/skalibs/posixplz.h src/include/skalibs/tai.h src/libdatastruct/avlnode-internal.h: src/include/skalibs/avlnode.h src/librandom/random-internal.h: src/include/skalibs/surf.h src/libstdcrypto/md5-internal.h: src/include/skalibs/md5.h @@ -123,6 +127,13 @@ src/libdatastruct/gensetdyn_iter_withcancel.o src/libdatastruct/gensetdyn_iter_w src/libdatastruct/gensetdyn_new.o src/libdatastruct/gensetdyn_new.lo: src/libdatastruct/gensetdyn_new.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h src/libdatastruct/gensetdyn_ready.o src/libdatastruct/gensetdyn_ready.lo: src/libdatastruct/gensetdyn_ready.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h src/include/skalibs/stralloc.h src/libdatastruct/gensetdyn_zero.o src/libdatastruct/gensetdyn_zero.lo: src/libdatastruct/gensetdyn_zero.c src/include/skalibs/gensetdyn.h +src/libposixplz/doublefork.o src/libposixplz/doublefork.lo: src/libposixplz/doublefork.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/posixplz.h src/include/skalibs/uint64.h +src/libposixplz/execvep.o src/libposixplz/execvep.lo: src/libposixplz/execvep.c src/include/skalibs/bytestr.h src/include/skalibs/posixplz.h +src/libposixplz/getpeereid.o src/libposixplz/getpeereid.lo: src/libposixplz/getpeereid.c src/include/skalibs/nonposix.h src/include/skalibs/posixplz.h src/include/skalibs/sysdeps.h +src/libposixplz/memmem.o src/libposixplz/memmem.lo: src/libposixplz/memmem.c src/include/skalibs/posixplz.h src/include/skalibs/sysdeps.h +src/libposixplz/setgroups.o src/libposixplz/setgroups.lo: src/libposixplz/setgroups.c src/include/skalibs/nonposix.h src/include/skalibs/setgroups.h src/include/skalibs/sysdeps.h +src/libposixplz/strnlen.o src/libposixplz/strnlen.lo: src/libposixplz/strnlen.c src/include/skalibs/bytestr.h src/include/skalibs/posixplz.h src/include/skalibs/sysdeps.h +src/libposixplz/touch.o src/libposixplz/touch.lo: src/libposixplz/touch.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/posixplz.h src/include/skalibs/sysdeps.h src/librandom/random_char.o src/librandom/random_char.lo: src/librandom/random_char.c src/include/skalibs/random.h src/librandom/random_finish.o src/librandom/random_finish.lo: src/librandom/random_finish.c src/include/skalibs/djbunix.h src/librandom/random-internal.h src/include/skalibs/random.h src/include/skalibs/sysdeps.h src/librandom/random_init.o src/librandom/random_init.lo: src/librandom/random_init.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/librandom/random-internal.h src/include/skalibs/random.h src/include/skalibs/surf.h src/include/skalibs/sysdeps.h @@ -222,6 +233,7 @@ src/libstddjb/byte_chr.o src/libstddjb/byte_chr.lo: src/libstddjb/byte_chr.c src src/libstddjb/byte_count.o src/libstddjb/byte_count.lo: src/libstddjb/byte_count.c src/include/skalibs/bytestr.h src/libstddjb/byte_in.o src/libstddjb/byte_in.lo: src/libstddjb/byte_in.c src/include/skalibs/bytestr.h src/libstddjb/byte_rchr.o src/libstddjb/byte_rchr.lo: src/libstddjb/byte_rchr.c src/include/skalibs/bytestr.h +src/libstddjb/byte_search.o src/libstddjb/byte_search.lo: src/libstddjb/byte_search.c src/include/skalibs/bytestr.h src/include/skalibs/posixplz.h src/libstddjb/case_lowerb.o src/libstddjb/case_lowerb.lo: src/libstddjb/case_lowerb.c src/include/skalibs/bytestr.h src/libstddjb/case_lowers.o src/libstddjb/case_lowers.lo: src/libstddjb/case_lowers.c src/include/skalibs/bytestr.h src/libstddjb/case_startb.o src/libstddjb/case_startb.lo: src/libstddjb/case_startb.c src/include/skalibs/bytestr.h @@ -258,9 +270,8 @@ src/libstddjb/child_spawn2.o src/libstddjb/child_spawn2.lo: src/libstddjb/child_ src/libstddjb/coe.o src/libstddjb/coe.lo: src/libstddjb/coe.c src/include/skalibs/djbunix.h src/libstddjb/deepsleepuntil.o src/libstddjb/deepsleepuntil.lo: src/libstddjb/deepsleepuntil.c src/include/skalibs/iopause.h src/include/skalibs/tai.h src/libstddjb/dir_close.o src/libstddjb/dir_close.lo: src/libstddjb/dir_close.c src/include/skalibs/direntry.h -src/libstddjb/doublefork.o src/libstddjb/doublefork.lo: src/libstddjb/doublefork.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/uint64.h src/libstddjb/env_addmodif.o src/libstddjb/env_addmodif.lo: src/libstddjb/env_addmodif.c src/include/skalibs/env.h src/include/skalibs/stralloc.h -src/libstddjb/env_get.o src/libstddjb/env_get.lo: src/libstddjb/env_get.c src/include/skalibs/env.h src/include/skalibs/environ.h +src/libstddjb/env_get.o src/libstddjb/env_get.lo: src/libstddjb/env_get.c src/include/skalibs/env.h src/include/skalibs/posixplz.h src/libstddjb/env_get2.o src/libstddjb/env_get2.lo: src/libstddjb/env_get2.c src/include/skalibs/bytestr.h src/include/skalibs/env.h src/libstddjb/env_len.o src/libstddjb/env_len.lo: src/libstddjb/env_len.c src/include/skalibs/env.h src/libstddjb/env_make.o src/libstddjb/env_make.lo: src/libstddjb/env_make.c src/include/skalibs/env.h @@ -272,7 +283,6 @@ src/libstddjb/envalloc_merge.o src/libstddjb/envalloc_merge.lo: src/libstddjb/en src/libstddjb/envalloc_uniq.o src/libstddjb/envalloc_uniq.lo: src/libstddjb/envalloc_uniq.c src/include/skalibs/bytestr.h src/include/skalibs/envalloc.h src/include/skalibs/genalloc.h src/libstddjb/envdir.o src/libstddjb/envdir.lo: src/libstddjb/envdir.c src/include/skalibs/bytestr.h src/include/skalibs/direntry.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/stralloc.h src/libstddjb/error_temp.o src/libstddjb/error_temp.lo: src/libstddjb/error_temp.c src/include/skalibs/error.h -src/libstddjb/execvep.o src/libstddjb/execvep.lo: src/libstddjb/execvep.c src/include/skalibs/bytestr.h src/include/skalibs/djbunix.h src/libstddjb/fd_cat.o src/libstddjb/fd_cat.lo: src/libstddjb/fd_cat.c src/include/skalibs/djbunix.h src/include/skalibs/iobuffer.h src/libstddjb/fd_catn.o src/libstddjb/fd_catn.lo: src/libstddjb/fd_catn.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/iobuffer.h src/libstddjb/fd_chdir.o src/libstddjb/fd_chdir.lo: src/libstddjb/fd_chdir.c src/include/skalibs/djbunix.h @@ -306,7 +316,6 @@ src/libstddjb/genwrite_stderr.o src/libstddjb/genwrite_stderr.lo: src/libstddjb/ src/libstddjb/genwrite_stdout.o src/libstddjb/genwrite_stdout.lo: src/libstddjb/genwrite_stdout.c src/include/skalibs/buffer.h src/include/skalibs/genwrite.h src/libstddjb/getlnmax.o src/libstddjb/getlnmax.lo: src/libstddjb/getlnmax.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/include/skalibs/skamisc.h src/libstddjb/getlnmaxsep.o src/libstddjb/getlnmaxsep.lo: src/libstddjb/getlnmaxsep.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/include/skalibs/skamisc.h -src/libstddjb/getpeereid.o src/libstddjb/getpeereid.lo: src/libstddjb/getpeereid.c src/include/skalibs/getpeereid.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/hiercopy.o src/libstddjb/hiercopy.lo: src/libstddjb/hiercopy.c src/include/skalibs/djbunix.h src/include/skalibs/skamisc.h src/libstddjb/hiercopy_tmp.o src/libstddjb/hiercopy_tmp.lo: src/libstddjb/hiercopy_tmp.c src/include/skalibs/direntry.h src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/include/skalibs/strerr2.h src/libstddjb/int160_scan.o src/libstddjb/int160_scan.lo: src/libstddjb/int160_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h @@ -421,13 +430,13 @@ src/libstddjb/openwritenclose_unsafe.o src/libstddjb/openwritenclose_unsafe.lo: src/libstddjb/openwritevnclose.o src/libstddjb/openwritevnclose.lo: src/libstddjb/openwritevnclose.c src/include/skalibs/djbunix.h src/libstddjb/openwritevnclose_suffix.o src/libstddjb/openwritevnclose_suffix.lo: src/libstddjb/openwritevnclose_suffix.c src/include/skalibs/djbunix.h src/libstddjb/openwritevnclose_unsafe.o src/libstddjb/openwritevnclose_unsafe.lo: src/libstddjb/openwritevnclose_unsafe.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h -src/libstddjb/pathexec.o src/libstddjb/pathexec.lo: src/libstddjb/pathexec.c src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/environ.h +src/libstddjb/pathexec.o src/libstddjb/pathexec.lo: src/libstddjb/pathexec.c src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/posixplz.h src/libstddjb/pathexec0.o src/libstddjb/pathexec0.lo: src/libstddjb/pathexec0.c src/include/skalibs/djbunix.h src/libstddjb/pathexec0_run.o src/libstddjb/pathexec0_run.lo: src/libstddjb/pathexec0_run.c src/include/skalibs/djbunix.h src/libstddjb/pathexec_fromenv.o src/libstddjb/pathexec_fromenv.lo: src/libstddjb/pathexec_fromenv.c src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/stralloc.h src/libstddjb/pathexec_r.o src/libstddjb/pathexec_r.lo: src/libstddjb/pathexec_r.c src/include/skalibs/djbunix.h src/libstddjb/pathexec_r_name.o src/libstddjb/pathexec_r_name.lo: src/libstddjb/pathexec_r_name.c src/include/skalibs/bytestr.h src/include/skalibs/djbunix.h src/include/skalibs/env.h -src/libstddjb/pathexec_run.o src/libstddjb/pathexec_run.lo: src/libstddjb/pathexec_run.c src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/env.h +src/libstddjb/pathexec_run.o src/libstddjb/pathexec_run.lo: src/libstddjb/pathexec_run.c src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/posixplz.h src/libstddjb/pipe_internal.o src/libstddjb/pipe_internal.lo: src/libstddjb/pipe_internal.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/prog.o src/libstddjb/prog.lo: src/libstddjb/prog.c src/include/skalibs/strerr2.h src/libstddjb/prot.o src/libstddjb/prot.lo: src/libstddjb/prot.c src/include/skalibs/djbunix.h @@ -454,7 +463,6 @@ src/libstddjb/selfpipe_read.o src/libstddjb/selfpipe_read.lo: src/libstddjb/self src/libstddjb/selfpipe_trap.o src/libstddjb/selfpipe_trap.lo: src/libstddjb/selfpipe_trap.c src/libstddjb/selfpipe-internal.h src/include/skalibs/selfpipe.h src/include/skalibs/sig.h src/include/skalibs/sysdeps.h src/libstddjb/selfpipe_trapset.o src/libstddjb/selfpipe_trapset.lo: src/libstddjb/selfpipe_trapset.c src/include/skalibs/nonposix.h src/include/skalibs/nsig.h src/libstddjb/selfpipe-internal.h src/include/skalibs/selfpipe.h src/include/skalibs/sig.h src/include/skalibs/sysdeps.h src/libstddjb/selfpipe_untrap.o src/libstddjb/selfpipe_untrap.lo: src/libstddjb/selfpipe_untrap.c src/libstddjb/selfpipe-internal.h src/include/skalibs/selfpipe.h src/include/skalibs/sig.h src/include/skalibs/sysdeps.h -src/libstddjb/setgroups.o src/libstddjb/setgroups.lo: src/libstddjb/setgroups.c src/include/skalibs/nonposix.h src/include/skalibs/setgroups.h src/include/skalibs/sysdeps.h src/libstddjb/sgetopt.o src/libstddjb/sgetopt.lo: src/libstddjb/sgetopt.c src/include/skalibs/buffer.h src/include/skalibs/sgetopt.h src/libstddjb/sig_block.o src/libstddjb/sig_block.lo: src/libstddjb/sig_block.c src/include/skalibs/sig.h src/libstddjb/sig_blocknone.o src/libstddjb/sig_blocknone.lo: src/libstddjb/sig_blocknone.c src/include/skalibs/sig.h @@ -478,10 +486,12 @@ src/libstddjb/siovec_deal.o src/libstddjb/siovec_deal.lo: src/libstddjb/siovec_d src/libstddjb/siovec_gather.o src/libstddjb/siovec_gather.lo: src/libstddjb/siovec_gather.c src/include/skalibs/siovec.h src/libstddjb/siovec_len.o src/libstddjb/siovec_len.lo: src/libstddjb/siovec_len.c src/include/skalibs/siovec.h src/libstddjb/siovec_scatter.o src/libstddjb/siovec_scatter.lo: src/libstddjb/siovec_scatter.c src/include/skalibs/siovec.h +src/libstddjb/siovec_search.o src/libstddjb/siovec_search.lo: src/libstddjb/siovec_search.c src/include/skalibs/posixplz.h src/include/skalibs/siovec.h src/libstddjb/siovec_seek.o src/libstddjb/siovec_seek.lo: src/libstddjb/siovec_seek.c src/include/skalibs/bytestr.h src/include/skalibs/siovec.h src/libstddjb/siovec_trunc.o src/libstddjb/siovec_trunc.lo: src/libstddjb/siovec_trunc.c src/include/skalibs/siovec.h src/libstddjb/skagetln.o src/libstddjb/skagetln.lo: src/libstddjb/skagetln.c src/include/skalibs/buffer.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h src/libstddjb/skagetln_nofill.o src/libstddjb/skagetln_nofill.lo: src/libstddjb/skagetln_nofill.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h +src/libstddjb/skagetlnmaxsep.o src/libstddjb/skagetlnmaxsep.lo: src/libstddjb/skagetlnmaxsep.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h src/libstddjb/skagetlnsep.o src/libstddjb/skagetlnsep.lo: src/libstddjb/skagetlnsep.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h src/libstddjb/skalibs_tzisright.o src/libstddjb/skalibs_tzisright.lo: src/libstddjb/skalibs_tzisright.c src/libstddjb/djbtime-internal.h src/libstddjb/skasig_dfl.o src/libstddjb/skasig_dfl.lo: src/libstddjb/skasig_dfl.c src/include/skalibs/sig.h @@ -619,7 +629,6 @@ src/libstddjb/timestamp_scan.o src/libstddjb/timestamp_scan.lo: src/libstddjb/ti src/libstddjb/timeval_from_tain.o src/libstddjb/timeval_from_tain.lo: src/libstddjb/timeval_from_tain.c src/include/skalibs/tai.h src/libstddjb/timeval_from_tain_relative.o src/libstddjb/timeval_from_tain_relative.lo: src/libstddjb/timeval_from_tain_relative.c src/include/skalibs/tai.h src/libstddjb/timeval_sysclock_from_tain.o src/libstddjb/timeval_sysclock_from_tain.lo: src/libstddjb/timeval_sysclock_from_tain.c src/include/skalibs/tai.h -src/libstddjb/touch.o src/libstddjb/touch.lo: src/libstddjb/touch.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/ucharn_findlen.o src/libstddjb/ucharn_findlen.lo: src/libstddjb/ucharn_findlen.c src/include/skalibs/fmtscan.h src/libstddjb/ucharn_fmt.o src/libstddjb/ucharn_fmt.lo: src/libstddjb/ucharn_fmt.c src/include/skalibs/fmtscan.h src/libstddjb/ucharn_fmt_little.o src/libstddjb/ucharn_fmt_little.lo: src/libstddjb/ucharn_fmt_little.c src/include/skalibs/fmtscan.h @@ -679,7 +688,7 @@ src/libstddjb/waitn_reap.o src/libstddjb/waitn_reap.lo: src/libstddjb/waitn_reap src/libstddjb/waitpid_nointr.o src/libstddjb/waitpid_nointr.lo: src/libstddjb/waitpid_nointr.c src/include/skalibs/djbunix.h src/libstddjb/writenclose_unsafe.o src/libstddjb/writenclose_unsafe.lo: src/libstddjb/writenclose_unsafe.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/libstddjb/writevnclose_unsafe.o src/libstddjb/writevnclose_unsafe.lo: src/libstddjb/writevnclose_unsafe.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/siovec.h -src/libstddjb/xexecvep.o src/libstddjb/xexecvep.lo: src/libstddjb/xexecvep.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h +src/libstddjb/xexecvep.o src/libstddjb/xexecvep.lo: src/libstddjb/xexecvep.c src/include/skalibs/djbunix.h src/include/skalibs/posixplz.h src/include/skalibs/strerr2.h src/libstddjb/xpathexec.o src/libstddjb/xpathexec.lo: src/libstddjb/xpathexec.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h src/libstddjb/xpathexec0.o src/libstddjb/xpathexec0.lo: src/libstddjb/xpathexec0.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h src/libstddjb/xpathexec0_run.o src/libstddjb/xpathexec0_run.lo: src/libstddjb/xpathexec0_run.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h @@ -747,6 +756,23 @@ src/libunixonacid/skaclient_startf_async.o src/libunixonacid/skaclient_startf_as src/libunixonacid/skaclient_syncify.o src/libunixonacid/skaclient_syncify.lo: src/libunixonacid/skaclient_syncify.c src/include/skalibs/skaclient.h src/libunixonacid/skaclient_zero.o src/libunixonacid/skaclient_zero.lo: src/libunixonacid/skaclient_zero.c src/include/skalibs/skaclient.h src/libunixonacid/stat_at.o src/libunixonacid/stat_at.lo: src/libunixonacid/stat_at.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/include/skalibs/unix-transactional.h +src/libunixonacid/textmessage_handle.o src/libunixonacid/textmessage_handle.lo: src/libunixonacid/textmessage_handle.c src/include/skalibs/textmessage.h +src/libunixonacid/textmessage_put.o src/libunixonacid/textmessage_put.lo: src/libunixonacid/textmessage_put.c src/include/skalibs/bufalloc.h src/include/skalibs/textmessage.h src/include/skalibs/uint32.h +src/libunixonacid/textmessage_putv.o src/libunixonacid/textmessage_putv.lo: src/libunixonacid/textmessage_putv.c src/include/skalibs/bufalloc.h src/include/skalibs/siovec.h src/include/skalibs/textmessage.h src/include/skalibs/uint32.h +src/libunixonacid/textmessage_receive.o src/libunixonacid/textmessage_receive.lo: src/libunixonacid/textmessage_receive.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/stralloc.h src/include/skalibs/textmessage.h src/include/skalibs/uint32.h +src/libunixonacid/textmessage_receiver_0.o src/libunixonacid/textmessage_receiver_0.lo: src/libunixonacid/textmessage_receiver_0.c src/include/skalibs/buffer.h src/include/skalibs/textmessage.h +src/libunixonacid/textmessage_receiver_free.o src/libunixonacid/textmessage_receiver_free.lo: src/libunixonacid/textmessage_receiver_free.c src/include/skalibs/stralloc.h src/include/skalibs/textmessage.h +src/libunixonacid/textmessage_receiver_hasmsginbuf.o src/libunixonacid/textmessage_receiver_hasmsginbuf.lo: src/libunixonacid/textmessage_receiver_hasmsginbuf.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/include/skalibs/textmessage.h src/include/skalibs/uint32.h +src/libunixonacid/textmessage_receiver_init.o src/libunixonacid/textmessage_receiver_init.lo: src/libunixonacid/textmessage_receiver_init.c src/include/skalibs/buffer.h src/include/skalibs/stralloc.h src/include/skalibs/textmessage.h +src/libunixonacid/textmessage_receiver_zero.o src/libunixonacid/textmessage_receiver_zero.lo: src/libunixonacid/textmessage_receiver_zero.c src/include/skalibs/textmessage.h +src/libunixonacid/textmessage_sender_1.o src/libunixonacid/textmessage_sender_1.lo: src/libunixonacid/textmessage_sender_1.c src/include/skalibs/textmessage.h +src/libunixonacid/textmessage_sender_flush.o src/libunixonacid/textmessage_sender_flush.lo: src/libunixonacid/textmessage_sender_flush.c src/include/skalibs/bufalloc.h src/include/skalibs/textmessage.h +src/libunixonacid/textmessage_sender_getfd.o src/libunixonacid/textmessage_sender_getfd.lo: src/libunixonacid/textmessage_sender_getfd.c src/include/skalibs/bufalloc.h src/include/skalibs/textmessage.h +src/libunixonacid/textmessage_sender_timed_flush.o src/libunixonacid/textmessage_sender_timed_flush.lo: src/libunixonacid/textmessage_sender_timed_flush.c src/include/skalibs/functypes.h src/include/skalibs/textmessage.h src/include/skalibs/unix-timed.h +src/libunixonacid/textmessage_sender_x.o src/libunixonacid/textmessage_sender_x.lo: src/libunixonacid/textmessage_sender_x.c src/include/skalibs/textmessage.h +src/libunixonacid/textmessage_sender_zero.o src/libunixonacid/textmessage_sender_zero.lo: src/libunixonacid/textmessage_sender_zero.c src/include/skalibs/textmessage.h +src/libunixonacid/textmessage_timed_handle.o src/libunixonacid/textmessage_timed_handle.lo: src/libunixonacid/textmessage_timed_handle.c src/include/skalibs/functypes.h src/include/skalibs/textmessage.h src/include/skalibs/unix-timed.h +src/libunixonacid/textmessage_timed_receive.o src/libunixonacid/textmessage_timed_receive.lo: src/libunixonacid/textmessage_timed_receive.c src/include/skalibs/functypes.h src/include/skalibs/textmessage.h src/include/skalibs/unix-timed.h src/libunixonacid/timed_flush.o src/libunixonacid/timed_flush.lo: src/libunixonacid/timed_flush.c src/include/skalibs/error.h src/include/skalibs/iopause.h src/include/skalibs/unix-timed.h src/libunixonacid/timed_get.o src/libunixonacid/timed_get.lo: src/libunixonacid/timed_get.c src/include/skalibs/allreadwrite.h src/include/skalibs/iopause.h src/include/skalibs/unix-timed.h src/libunixonacid/timed_getln.o src/libunixonacid/timed_getln.lo: src/libunixonacid/timed_getln.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/functypes.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h src/include/skalibs/unix-timed.h diff --git a/src/include/skalibs/bytestr.h b/src/include/skalibs/bytestr.h @@ -3,27 +3,21 @@ #ifndef BYTESTR_H #define BYTESTR_H -#include <skalibs/config.h> #include <skalibs/gccattributes.h> /* for Alphas and other archs where char != 8bit */ #define T8(x) ((x) & 0xffU) -#include <skalibs/sysdeps.h> #include <string.h> #include <strings.h> +#include <skalibs/posixplz.h> #define byte_copy(to, n, from) memmove(to, (from), n) #define byte_copyr(to, n, from) memmove(to, (from), n) #define byte_diff(a, n, b) memcmp(a, (b), n) #define byte_zero(p, n) memset(p, 0, n) #define str_len strlen - -#ifdef SKALIBS_HASSTRNLEN -# define str_nlen strnlen -#else -# define str_nlen(s, max) byte_chr(s, (max), 0) -#endif +#define str_nlen strnlen #define str_diff strcmp #define str_diffn strncmp @@ -36,6 +30,7 @@ extern size_t byte_rchr (char const *, size_t, int) gccattr_pure ; extern size_t byte_in (char const *, size_t, char const *, size_t) gccattr_pure ; #define byte_equal(s, n, t) (!memcmp(s, (t), n)) extern size_t byte_count (char const *, size_t, char) gccattr_pure ; +extern size_t byte_search (char const *, size_t, char const *, size_t) ; #define str_diffb(a, n, b) strncmp(a, (b), n) extern size_t str_chr (char const *, int) gccattr_pure ; diff --git a/src/include/skalibs/djbunix.h b/src/include/skalibs/djbunix.h @@ -9,7 +9,8 @@ #include <skalibs/gccattributes.h> #include <skalibs/stralloc.h> #include <skalibs/envalloc.h> -#include <skalibs/env.h> /* compatibility */ +#include <skalibs/env.h> /* will disappear */ +#include <skalibs/posixplz.h> #define DJBUNIX_FLAG_NB 0x01U #define DJBUNIX_FLAG_COE 0x02U @@ -56,7 +57,6 @@ extern int pathexec_env (char const *, char const *) ; extern void pathexec_r (char const *const *, char const *const *, size_t, char const *, size_t) ; extern void pathexec_r_name (char const *, char const *const *, char const *const *, size_t, char const *, size_t) ; extern void pathexec_fromenv (char const *const *, char const *const *, size_t) ; -extern void execvep (char const *, char const *const *, char const *const *, char const *) ; extern void pathexec_run (char const *, char const *const *, char const *const *) ; extern void pathexec0_run (char const *const *, char const *const *) ; extern void pathexec (char const *const *) ; @@ -89,11 +89,9 @@ extern unsigned int wait_reap (void) ; extern int waitn (pid_t *, unsigned int) ; extern int waitn_reap (pid_t *, unsigned int) ; -extern pid_t doublefork (void) ; - extern int fd_chdir (int) ; -#define absolutepath(sa, s) sarealpath(sa, s) +#define absolutepath(sa, s) sarealpath(sa, s) /* will disappear */ extern int sarealpath (stralloc *, char const *) ; extern int sarealpath_tmp (stralloc *, char const *, stralloc *) ; extern int sabasename (stralloc *, char const *, size_t) ; @@ -162,7 +160,6 @@ extern int rm_rf_in_tmp (stralloc *, size_t) ; /* caution ! */ extern int rmstar (char const *) ; extern int rmstar_tmp (char const *, stralloc *) ; -extern int touch (char const *) ; extern int filecopy_unsafe (char const *, char const *, unsigned int) ; extern int filecopy_suffix (char const *, char const *, unsigned int, char const *) ; extern int hiercopy (char const *, char const *) ; diff --git a/src/include/skalibs/environ.h b/src/include/skalibs/environ.h @@ -1,8 +1,5 @@ /* ISC license. */ -#ifndef ENVIRON_H -#define ENVIRON_H +/* This header is being deprecated */ -extern char **environ ; - -#endif +#include <skalibs/posixplz.h> diff --git a/src/include/skalibs/getpeereid.h b/src/include/skalibs/getpeereid.h @@ -1,10 +1,5 @@ /* ISC license. */ -#ifndef GETPEEREID_H -#define GETPEEREID_H +/* This header is being deprecated */ -#include <sys/types.h> - -extern int getpeereid (int, uid_t *, gid_t *) ; - -#endif +#include <skalibs/posixplz.h> diff --git a/src/include/skalibs/mininetstring.h b/src/include/skalibs/mininetstring.h @@ -4,9 +4,10 @@ #define MININETSTRING_H #include <stdint.h> +#include <skalibs/gccattributes.h> #include <skalibs/stralloc.h> -extern int mininetstring_read (int, stralloc *, uint32_t *) ; -extern int mininetstring_write (int, char const *, uint16_t, uint32_t *) ; +extern int mininetstring_read (int, stralloc *, uint32_t *) gccattr_deprecated ; +extern int mininetstring_write (int, char const *, uint16_t, uint32_t *) gccattr_deprecated ; #endif diff --git a/src/include/skalibs/posixplz.h b/src/include/skalibs/posixplz.h @@ -0,0 +1,45 @@ +/* ISC license. */ + +#ifndef SKALIBS_POSIXPLZ_H +#define SKALIBS_POSIXPLZ_H + +#include <sys/types.h> +#include <skalibs/gccattributes.h> + + + /* + Stuff that doesn't have its own POSIX header for some reason. + */ + +extern char **environ ; + + + /* + Stuff that _is_ POSIX, but some OSes still don't have it. + openat() et al. should be here, but they're impossible to + emulate correctly, and I don't want an app using openat() + to think it has safe POSIX semantics when it doesn't :/ + EPROTO et al. should be here, but ugh ifdef forests. + */ + +extern size_t strnlen (char const *, size_t) gccattr_pure ; + + + /* + Non-POSIX functions that some OSes provide and others don't. + setgroups() isn't included because it's its own kind of broken. + */ + +extern void *memmem (void const *, size_t, void const *, size_t) gccattr_pure ; +extern int getpeereid (int, uid_t *, gid_t *) ; + + + /* + Functions that aren't standard at all, but honestly could be. :P + */ + +extern void execvep (char const *, char const *const *, char const *const *, char const *) ; +extern pid_t doublefork (void) ; +extern int touch (char const *) ; + +#endif diff --git a/src/include/skalibs/setgroups.h b/src/include/skalibs/setgroups.h @@ -7,6 +7,13 @@ #ifdef SKALIBS_HASSETGROUPS + /* + setgroups() is defined by a lot of OSes. + However, they don't agree on what it should do: + some change the primary gid, others don't, etc. It's a mess. + Never use setgroups(). Use the functions below instead. + */ + #include <unistd.h> extern int setgroups_and_gid (gid_t, size_t, gid_t const *) ; @@ -15,8 +22,11 @@ extern int skalibs_setgroups (size_t, gid_t const *) ; #else + /* No setgroups() at all? not much we can do. */ + #include <errno.h> -#define setgroups(n, tab) (errno = ENOSYS, -1) + +#define setgroups_and_gid(g, n, tab) (errno = ENOSYS, -1) #define setgroups_with_egid(n, tab) (errno = ENOSYS, -1) #define skalibs_setgroups(n, tab) (errno = ENOSYS, -1) diff --git a/src/include/skalibs/skalibs.h b/src/include/skalibs/skalibs.h @@ -4,11 +4,11 @@ #define SKALIBS_H /* - This header includes everything in skalibs, - except skalibs/config.h and skalibs/sysdeps.h + This header includes everything in skalibs except skalibs/config.h It's heavy! */ +#include <skalibs/posixplz.h> #include <skalibs/stddjb.h> #include <skalibs/stdcrypto.h> #include <skalibs/random.h> diff --git a/src/include/skalibs/skamisc.h b/src/include/skalibs/skamisc.h @@ -12,6 +12,7 @@ extern stralloc satmp ; extern int skagetln (buffer *, stralloc *, char) ; extern int skagetln_nofill (buffer *, stralloc *, char) ; extern int skagetlnsep (buffer *, stralloc *, char const *, size_t) ; +extern int skagetlnmaxsep (buffer *, stralloc *, size_t, char const *, size_t) ; extern int getlnmax (buffer *, char *, size_t, size_t *, char) ; extern int getlnmaxsep (buffer *, char *, size_t, size_t *, char const *, size_t) ; diff --git a/src/include/skalibs/stddjb.h b/src/include/skalibs/stddjb.h @@ -29,17 +29,15 @@ #include <skalibs/djbunix.h> #include <skalibs/envalloc.h> #include <skalibs/env.h> -#include <skalibs/environ.h> #include <skalibs/fmtscan.h> #include <skalibs/functypes.h> #include <skalibs/gccattributes.h> #include <skalibs/genalloc.h> #include <skalibs/genwrite.h> -#include <skalibs/getpeereid.h> #include <skalibs/iobuffer.h> #include <skalibs/iopause.h> #include <skalibs/lolstdio.h> -#include <skalibs/mininetstring.h> +#include <skalibs/mininetstring.h> /* will disappear */ #include <skalibs/netstring.h> #include <skalibs/nsig.h> #include <skalibs/segfault.h> diff --git a/src/include/skalibs/textmessage.h b/src/include/skalibs/textmessage.h @@ -0,0 +1,96 @@ +/* ISC license. */ + +#ifndef SKALIBS_TEXTMESSAGE_H +#define SKALIBS_TEXTMESSAGE_H + +#include <sys/uio.h> +#include <stdint.h> +#include <skalibs/gccattributes.h> +#include <skalibs/allreadwrite.h> +#include <skalibs/bufalloc.h> +#include <skalibs/buffer.h> +#include <skalibs/stralloc.h> +#include <skalibs/tai.h> + +#define TEXTMESSAGE_MAXREADS 128 + + + /* Sender */ + +typedef struct textmessage_sender_s textmessage_sender_t, *textmessage_sender_t_ref ; +struct textmessage_sender_s +{ + bufalloc out ; +} ; +#define TEXTMESSAGE_SENDER_ZERO { .out = BUFALLOC_ZERO } +extern textmessage_sender_t const textmessage_sender_zero ; +#define TEXTMESSAGE_SENDER_INIT(fd) { .out = BUFALLOC_INIT(&fd_write, (fd)) } + +#define textmessage_sender_init(ts, fd) bufalloc_init(&(ts)->out, &fd_write, fd) +#define textmessage_sender_free(ts) bufalloc_free(&(ts)->out) +#define textmessage_sender_fd(ts) bufalloc_fd(&(ts)->out) +extern int textmessage_sender_getfd (textmessage_sender_t const *) gccattr_pure ; +#define textmessage_sender_isempty(ts) bufalloc_isempty(&(ts)->out) + +extern int textmessage_put (textmessage_sender_t *, char const *, size_t) ; +extern int textmessage_putv (textmessage_sender_t *, struct iovec const *, unsigned int) ; + +extern int textmessage_sender_flush (textmessage_sender_t *) ; +extern int unixmessage_sender_timed_flush (textmessage_sender_t *, tain_t const *, tain_t *) ; +#define textmessage_sender_timed_flush_g(ts, deadline) textmessage_sender_timed_flush(ts, (deadline), &STAMP) + +#define textmessage_send(ts, s, len) (textmessage_put(ts, s, len) && textmessage_sender_flush(ts)) +#define textmessage_sendv(ts, v, n) (textmessage_putv(ts, v, n) && textmessage_sender_flush(ts)) +#define textmessage_timed_send(ts, s, len, deadline, stamp) (textmessage_put(ts, s, len) && texxtmessage_sender_timed_flush(ts, deadline, stamp)) +#define textmessage_timed_sendv(ts, v, n, deadline, stamp) (textmessage_putv(ts, v, n) && texxtmessage_sender_timed_flush(ts, deadline, stamp)) +#define textmessage_timed_send_g(ts, s, len, deadline) textmessage_timed_send(ts, s, len, (deadline), &STAMP) +#define textmessage_timed_sendv_g(ts, v, n, deadline) textmessage_timed_sendv(ts, v, n, (deadline), &STAMP) + + + /* Receiver */ + +typedef struct textmessage_receiver_s textmessage_receiver_t, *textmessage_receiver_t_ref ; +struct textmessage_receiver_s +{ + buffer in ; + stralloc indata ; + uint32_t wanted ; + uint32_t max ; +} ; +#define TEXTMESSAGE_RECEIVER_ZERO { .in = BUFFER_ZERO, .indata = STRALLOC_ZERO, .wanted = 0, .max = 0 } +extern textmessage_receiver_t const textmessage_receiver_zero ; +#define TEXTMESSAGE_RECEIVER_INIT(fd, buf, len, n) { .in = BUFFER_INIT(&buffer_read, (fd), buf, len), .indata = STRALLOC_ZERO, .wanted = 0, .max = n } + +extern int textmessage_receiver_init (textmessage_receiver_t *, int, char *, size_t, uint32_t) ; +extern void textmessage_receiver_free (textmessage_receiver_t *) ; +#define textmessage_receiver_fd(tr) buffer_fd(&(tr)->in) +#define textmessage_receiver_isempty(tr) buffer_isempty(&(tr)->in) +#define textmessage_receiver_isfull(tr) buffer_isfull(&(tr)->in) + +extern int textmessage_receiver_hasmsginbuf (textmessage_receiver_t const *) gccattr_pure ; + +extern int textmessage_receive (textmessage_receiver_t *, struct iovec *) ; +extern int textmessage_timed_receive (textmessage_receiver_t *, struct iovec *, tain_t const *, tain_t *) ; +#define textmessage_timed_receive_g(tr, s, max, deadline) textmessage_timed_receive(tr, s, max, (deadline), &STAMP) + +typedef int textmessage_handler_func_t (struct iovec const *, void *) ; +typedef textmessage_handler_func_t *textmessage_handler_func_t_ref ; + +extern int textmessage_handle (textmessage_receiver_t *, textmessage_handler_func_t_ref, void *) ; +extern int textmessage_timed_handle (textmessage_receiver_t *, textmessage_handler_func_t_ref, void *, tain_t const *, tain_t *) ; +#define textmessage_timed_handle_g(tr, f, p, deadline) unixmessage_timed_handle(tr, f, p, (deadline), &STAMP) + + + + /* Globals */ + +extern textmessage_receiver_t textmessage_receiver_0_ ; +#define textmessage_receiver_0 (&textmessage_receiver_0_) + +extern textmessage_sender_t textmessage_sender_1_ ; +#define textmessage_sender_1 (&textmessage_sender_1_) + +extern textmessage_sender_t textmessage_sender_x_ ; +#define textmessage_sender_x (&textmessage_sender_x_) + +#endif diff --git a/src/include/skalibs/unixonacid.h b/src/include/skalibs/unixonacid.h @@ -5,6 +5,7 @@ #include <skalibs/unix-transactional.h> #include <skalibs/unix-timed.h> +#include <skalibs/textmessage.h> #include <skalibs/unixmessage.h> #include <skalibs/unixconnection.h> #include <skalibs/kolbak.h> diff --git a/src/include/skalibs/webipc.h b/src/include/skalibs/webipc.h @@ -13,7 +13,7 @@ #define IPCPATH_MAX 107 #include <sys/types.h> -#include <skalibs/getpeereid.h> +#include <skalibs/posixplz.h> #include <skalibs/tai.h> #include <skalibs/djbunix.h> diff --git a/src/libposixplz/doublefork.c b/src/libposixplz/doublefork.c @@ -0,0 +1,51 @@ +/* ISC license. */ + +#include <sys/wait.h> +#include <unistd.h> +#include <errno.h> +#include <skalibs/uint64.h> +#include <skalibs/allreadwrite.h> +#include <skalibs/djbunix.h> +#include <skalibs/posixplz.h> + +pid_t doublefork () +{ + char pack[8] ; + int fd[2] ; + pid_t child ; + if (pipe(fd) == -1) return -1 ; + child = fork() ; + switch (child) + { + case -1: + { + fd_close(fd[1]) ; + fd_close(fd[0]) ; + return -1 ; + } + case 0: + { + pid_t pid ; + fd_close(fd[0]) ; + pid = fork() ; + switch (pid) + { + case -1: _exit(errno) ; + case 0: fd_close(fd[1]) ; return 0 ; + } + uint64_pack_big(pack, pid) ; + _exit((allwrite(fd[1], pack, 8) < 8) ? errno : 0) ; + } + } + fd_close(fd[1]) ; + { + uint64_t grandchild = 0 ; + int wstat ; + if (allread(fd[0], pack, 8) < 8) grandchild = 1 ; + fd_close(fd[0]) ; + wait_pid(child, &wstat) ; + if (grandchild) return (errno = WIFSIGNALED(wstat) ? EINTR : WEXITSTATUS(wstat), -1) ; + uint64_unpack_big(pack, &grandchild) ; + return (pid_t)grandchild ; + } +} diff --git a/src/libposixplz/execvep.c b/src/libposixplz/execvep.c @@ -0,0 +1,39 @@ +/* ISC license. */ + +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <skalibs/bytestr.h> +#include <skalibs/posixplz.h> + +void execvep (char const *file, char const *const *argv, char const *const *envp, char const *path) +{ + if (!path) errno = EINVAL ; + else if (file[str_chr(file, '/')]) + execve(file, (char *const *)argv, (char *const *)envp) ; /* execve prototype sucks */ + else + { + size_t pathlen = strlen(path) + 1 ; + size_t filelen = strlen(file) ; + int savederrno = 0 ; + while (pathlen) + { + size_t split = byte_chr(path, pathlen - 1, ':') ; + if (split) + { + char tmp[split + 2 + filelen] ; + memcpy(tmp, path, split) ; + tmp[split] = '/' ; + memcpy(tmp + split + 1, file, filelen + 1) ; + execve(tmp, (char *const *)argv, (char *const *)envp) ; + if (errno != ENOENT) + { + savederrno = errno ; + if ((errno != EACCES) && (errno != EPERM) && (errno != EISDIR)) break ; + } + } + path += split+1 ; pathlen -= split+1 ; + } + if (savederrno) errno = savederrno ; + } +} diff --git a/src/libposixplz/getpeereid.c b/src/libposixplz/getpeereid.c @@ -0,0 +1,66 @@ +/* ISC license. */ + +#include <skalibs/sysdeps.h> + +#ifdef SKALIBS_HASGETPEEREID +/* syscall exists - do nothing */ + +#else + +#ifdef SKALIBS_HASSOPEERCRED +/* implementation with SO_PEERCRED */ + +#include <skalibs/nonposix.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <skalibs/posixplz.h> + +int getpeereid (int s, uid_t *u, gid_t *g) +{ + struct ucred blah ; + socklen_t len = sizeof(blah) ; + + if (getsockopt(s, SOL_SOCKET, SO_PEERCRED, &blah, &len) == -1) + return -1 ; + *u = blah.uid ; + *g = blah.gid ; + return 0 ; +} + +#else + +#ifdef SKALIBS_HASGETPEERUCRED +/* implementation with getpeerucred() */ + +#include <skalibs/nonposix.h> +#include <ucred.h> +#include <skalibs/posixplz.h> + +int getpeereid (int s, uid_t *u, gid_t *g) +{ + ucred_t *cred ; + if (getpeerucred(s, &cred) == -1) return -1 ; + *u = ucred_geteuid(cred) ; + *g = ucred_getegid(cred) ; + ucred_free(cred) ; + return 0 ; +} + +#else + +/* can't find a real implementation, make a stub */ + +#include <errno.h> +#include <skalibs/posixplz.h> + +int getpeereid (int s, uid_t *uid, gid_t *gid) +{ + (void)s ; + *uid = *gid = -1 ; + errno = ENOSYS ; + return -1 ; +} + +#endif +#endif +#endif diff --git a/src/libposixplz/memmem.c b/src/libposixplz/memmem.c @@ -0,0 +1,187 @@ +/* MIT license. See below. */ + +#include <skalibs/sysdeps.h> + +#ifndef SKALIBS_HASMEMMEM + +/* + If the underlying platform does not provide memmem(), then the + following implementation is used. It comes from the musl libc, + which is MIT-licensed: + +---------------------------------------------------------------------- +Copyright © 2005-2017 Rich Felker, Szabolcs Nagy, Timo Teräs, Alexander Monakov + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +---------------------------------------------------------------------- + +*/ + +#include <string.h> +#include <stdint.h> +#include <skalibs/posixplz.h> + +static char *twobyte_memmem(const unsigned char *h, size_t k, const unsigned char *n) +{ + uint16_t nw = n[0]<<8 | n[1], hw = h[0]<<8 | h[1]; + for (h+=2, k-=2; k; k--, hw = hw<<8 | *h++) + if (hw == nw) return (char *)h-2; + return hw == nw ? (char *)h-2 : 0; +} + +static char *threebyte_memmem(const unsigned char *h, size_t k, const unsigned char *n) +{ + uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8; + uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8; + for (h+=3, k-=3; k; k--, hw = (hw|*h++)<<8) + if (hw == nw) return (char *)h-3; + return hw == nw ? (char *)h-3 : 0; +} + +static char *fourbyte_memmem(const unsigned char *h, size_t k, const unsigned char *n) +{ + uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8 | n[3]; + uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8 | h[3]; + for (h+=4, k-=4; k; k--, hw = hw<<8 | *h++) + if (hw == nw) return (char *)h-4; + return hw == nw ? (char *)h-4 : 0; +} + +#define MAX(a,b) ((a)>(b)?(a):(b)) +#define MIN(a,b) ((a)<(b)?(a):(b)) + +#define BITOP(a,b,op) \ + ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) + +static char *twoway_memmem(const unsigned char *h, const unsigned char *z, const unsigned char *n, size_t l) +{ + size_t i, ip, jp, k, p, ms, p0, mem, mem0; + size_t byteset[32 / sizeof(size_t)] = { 0 }; + size_t shift[256]; + + /* Computing length of needle and fill shift table */ + for (i=0; i<l; i++) + BITOP(byteset, n[i], |=), shift[n[i]] = i+1; + + /* Compute maximal suffix */ + ip = -1; jp = 0; k = p = 1; + while (jp+k<l) { + if (n[ip+k] == n[jp+k]) { + if (k == p) { + jp += p; + k = 1; + } else k++; + } else if (n[ip+k] > n[jp+k]) { + jp += k; + k = 1; + p = jp - ip; + } else { + ip = jp++; + k = p = 1; + } + } + ms = ip; + p0 = p; + + /* And with the opposite comparison */ + ip = -1; jp = 0; k = p = 1; + while (jp+k<l) { + if (n[ip+k] == n[jp+k]) { + if (k == p) { + jp += p; + k = 1; + } else k++; + } else if (n[ip+k] < n[jp+k]) { + jp += k; + k = 1; + p = jp - ip; + } else { + ip = jp++; + k = p = 1; + } + } + if (ip+1 > ms+1) ms = ip; + else p = p0; + + /* Periodic needle? */ + if (memcmp(n, n+p, ms+1)) { + mem0 = 0; + p = MAX(ms, l-ms-1) + 1; + } else mem0 = l-p; + mem = 0; + + /* Search loop */ + for (;;) { + /* If remainder of haystack is shorter than needle, done */ + if (z-h < l) return 0; + + /* Check last byte first; advance by shift on mismatch */ + if (BITOP(byteset, h[l-1], &)) { + k = l-shift[h[l-1]]; + if (k) { + if (mem0 && mem && k < p) k = l-p; + h += k; + mem = 0; + continue; + } + } else { + h += l; + mem = 0; + continue; + } + + /* Compare right half */ + for (k=MAX(ms+1,mem); k<l && n[k] == h[k]; k++); + if (k < l) { + h += k-ms; + mem = 0; + continue; + } + /* Compare left half */ + for (k=ms+1; k>mem && n[k-1] == h[k-1]; k--); + if (k <= mem) return (char *)h; + h += p; + mem = mem0; + } +} + +void *memmem(const void *h0, size_t k, const void *n0, size_t l) +{ + const unsigned char *h = h0, *n = n0; + + /* Return immediately on empty needle */ + if (!l) return (void *)h; + + /* Return immediately when needle is longer than haystack */ + if (k<l) return 0; + + /* Use faster algorithms for short needles */ + h = memchr(h0, *n, k); + if (!h || l==1) return (void *)h; + k -= h - (const unsigned char *)h0; + if (k<l) return 0; + if (l==2) return twobyte_memmem(h, k, n); + if (l==3) return threebyte_memmem(h, k, n); + if (l==4) return fourbyte_memmem(h, k, n); + + return twoway_memmem(h, h+k, n, l); +} + +#endif diff --git a/src/libstddjb/setgroups.c b/src/libposixplz/setgroups.c diff --git a/src/libposixplz/strnlen.c b/src/libposixplz/strnlen.c @@ -0,0 +1,16 @@ +/* ISC license. */ + +#include <skalibs/sysdeps.h> + +#ifndef SKALIBS_HASSTRNLEN + +#include <string.h> +#include <skalibs/bytestr.h> +#include <skalibs/posixplz.h> + +size_t strnlen (char const *s, size_t max) +{ + return byte_chr(s, max, 0) ; +} + +#endif diff --git a/src/libposixplz/touch.c b/src/libposixplz/touch.c @@ -0,0 +1,56 @@ +/* ISC license. */ + +#include <skalibs/sysdeps.h> + +#ifdef SKALIBS_HASFUTIMENS + +#include <skalibs/nonposix.h> +#include <time.h> +#include <sys/stat.h> +#include <skalibs/djbunix.h> +#include <skalibs/posixplz.h> + +int touch (char const *file) +{ + int r ; + int fd = open_create(file) ; + if (fd < 0) return 0 ; + r = futimens(fd, 0) >= 0 ; + fd_close(fd) ; + return r ; +} + +#else +#ifdef SKALIBS_HASFUTIMES + +#include <skalibs/nonposix.h> +#include <sys/time.h> +#include <skalibs/djbunix.h> +#include <skalibs/posixplz.h> + +int touch (char const *file) +{ + int r ; + int fd = open_create(file) ; + if (fd < 0) return 0 ; + r = futimes(fd, 0) >= 0 ; + fd_close(fd) ; + return r ; +} + +#else + +#include <sys/time.h> +#include <skalibs/djbunix.h> +#include <skalibs/posixplz.h> + +int touch (char const *file) +{ + int fd = open_create(file) ; + if (fd < 0) return 0 ; + fd_close(fd) ; + return utimes(file, 0) >= 0 ; +} + +#endif +#endif diff --git a/src/libstddjb/byte_search.c b/src/libstddjb/byte_search.c @@ -0,0 +1,11 @@ +/* ISC license. */ + +#include <string.h> +#include <skalibs/posixplz.h> +#include <skalibs/bytestr.h> + +size_t byte_search (char const *haystack, size_t hlen, char const *needle, size_t nlen) +{ + char *p = memmem(haystack, hlen, needle, nlen) ; + return p ? p - haystack : hlen + 1 - nlen ; +} diff --git a/src/libstddjb/doublefork.c b/src/libstddjb/doublefork.c @@ -1,50 +0,0 @@ -/* ISC license. */ - -#include <sys/wait.h> -#include <unistd.h> -#include <errno.h> -#include <skalibs/uint64.h> -#include <skalibs/allreadwrite.h> -#include <skalibs/djbunix.h> - -pid_t doublefork () -{ - char pack[8] ; - int fd[2] ; - pid_t child ; - if (pipe(fd) == -1) return -1 ; - child = fork() ; - switch (child) - { - case -1: - { - fd_close(fd[1]) ; - fd_close(fd[0]) ; - return -1 ; - } - case 0: - { - pid_t pid ; - fd_close(fd[0]) ; - pid = fork() ; - switch (pid) - { - case -1: _exit(errno) ; - case 0: fd_close(fd[1]) ; return 0 ; - } - uint64_pack_big(pack, pid) ; - _exit((allwrite(fd[1], pack, 8) < 8) ? errno : 0) ; - } - } - fd_close(fd[1]) ; - { - uint64_t grandchild = 0 ; - int wstat ; - if (allread(fd[0], pack, 8) < 8) grandchild = 1 ; - fd_close(fd[0]) ; - wait_pid(child, &wstat) ; - if (grandchild) return (errno = WIFSIGNALED(wstat) ? EINTR : WEXITSTATUS(wstat), -1) ; - uint64_unpack_big(pack, &grandchild) ; - return (pid_t)grandchild ; - } -} diff --git a/src/libstddjb/env_get.c b/src/libstddjb/env_get.c @@ -1,7 +1,7 @@ /* ISC license. */ #include <skalibs/env.h> -#include <skalibs/environ.h> +#include <skalibs/posixplz.h> char const *env_get (char const *s) { diff --git a/src/libstddjb/execvep.c b/src/libstddjb/execvep.c @@ -1,39 +0,0 @@ -/* ISC license. */ - -#include <unistd.h> -#include <string.h> -#include <errno.h> -#include <skalibs/bytestr.h> -#include <skalibs/djbunix.h> - -void execvep (char const *file, char const *const *argv, char const *const *envp, char const *path) -{ - if (!path) errno = EINVAL ; - else if (file[str_chr(file, '/')]) - execve(file, (char *const *)argv, (char *const *)envp) ; /* execve prototype sucks */ - else - { - size_t pathlen = strlen(path) + 1 ; - size_t filelen = strlen(file) ; - int savederrno = 0 ; - while (pathlen) - { - size_t split = byte_chr(path, pathlen - 1, ':') ; - if (split) - { - char tmp[split + 2 + filelen] ; - memcpy(tmp, path, split) ; - tmp[split] = '/' ; - memcpy(tmp + split + 1, file, filelen + 1) ; - execve(tmp, (char *const *)argv, (char *const *)envp) ; - if (errno != ENOENT) - { - savederrno = errno ; - if ((errno != EACCES) && (errno != EPERM) && (errno != EISDIR)) break ; - } - } - path += split+1 ; pathlen -= split+1 ; - } - if (savederrno) errno = savederrno ; - } -} diff --git a/src/libstddjb/getpeereid.c b/src/libstddjb/getpeereid.c @@ -1,66 +0,0 @@ -/* ISC license. */ - -#include <skalibs/sysdeps.h> - -#ifdef SKALIBS_HASGETPEEREID -/* syscall exists - do nothing */ - -#else - -#ifdef SKALIBS_HASSOPEERCRED -/* implementation with SO_PEERCRED */ - -#include <skalibs/nonposix.h> -#include <sys/socket.h> -#include <sys/un.h> -#include <skalibs/getpeereid.h> - -int getpeereid (int s, uid_t *u, gid_t *g) -{ - struct ucred blah ; - socklen_t len = sizeof(blah) ; - - if (getsockopt(s, SOL_SOCKET, SO_PEERCRED, &blah, &len) == -1) - return -1 ; - *u = blah.uid ; - *g = blah.gid ; - return 0 ; -} - -#else - -#ifdef SKALIBS_HASGETPEERUCRED -/* implementation with getpeerucred() */ - -#include <skalibs/nonposix.h> -#include <ucred.h> -#include <skalibs/getpeereid.h> - -int getpeereid (int s, uid_t *u, gid_t *g) -{ - ucred_t *cred ; - if (getpeerucred(s, &cred) == -1) return -1 ; - *u = ucred_geteuid(cred) ; - *g = ucred_getegid(cred) ; - ucred_free(cred) ; - return 0 ; -} - -#else - -/* can't find a real implementation, make a stub */ - -#include <errno.h> -#include <skalibs/getpeereid.h> - -int getpeereid (int s, uid_t *uid, gid_t *gid) -{ - (void)s ; - *uid = *gid = -1 ; - errno = ENOSYS ; - return -1 ; -} - -#endif -#endif -#endif diff --git a/src/libstddjb/pathexec.c b/src/libstddjb/pathexec.c @@ -4,7 +4,7 @@ #include <skalibs/env.h> #include <skalibs/djbunix.h> -#include <skalibs/environ.h> +#include <skalibs/posixplz.h> void pathexec (char const *const *argv) { diff --git a/src/libstddjb/pathexec_run.c b/src/libstddjb/pathexec_run.c @@ -2,6 +2,7 @@ #include <skalibs/config.h> #include <skalibs/env.h> +#include <skalibs/posixplz.h> #include <skalibs/djbunix.h> void pathexec_run (char const *file, char const *const *argv, char const *const *envp) diff --git a/src/libstddjb/siovec_search.c b/src/libstddjb/siovec_search.c @@ -0,0 +1,30 @@ +/* ISC license. */ + +#include <string.h> +#include <sys/uio.h> +#include <skalibs/posixplz.h> +#include <skalibs/siovec.h> + +size_t siovec_search (struct iovec const *v, unsigned int n, char const *needle, size_t nlen) +{ + size_t vlen = siovec_len(v, n) ; + size_t w = 0 ; + unsigned int i = 0 ; + for (; i < n ; i++) + { + char *p = memmem(v[i].iov_base, v[i].iov_len, needle, nlen) ; + if (p) return w + (p - (char *)v[i].iov_base) ; + if (i < n-1 && nlen > 1 && v[i].iov_len) + { + size_t prelen = v[i].iov_len < nlen ? v[i].iov_len : nlen ; + size_t postlen = vlen - w - v[i].iov_len < nlen ? vlen - w - v[i].iov_len : nlen ; + char buf[prelen + postlen - 2] ; + memcpy(buf, (char *)v[i].iov_base + v[i].iov_len - prelen + 1, prelen - 1) ; + siovec_gather(v + i + 1, n - 1 - i, buf + prelen - 1, postlen - 1) ; + p = memmem(buf, prelen + postlen - 2, needle, nlen) ; + if (p) return w + v[i].iov_len - prelen + 1 + (p - buf) ; + } + w += v[i].iov_len ; + } + return w ; +} diff --git a/src/libstddjb/skagetlnmaxsep.c b/src/libstddjb/skagetlnmaxsep.c @@ -0,0 +1,29 @@ +/* ISC license. */ + +#include <sys/uio.h> +#include <errno.h> +#include <skalibs/buffer.h> +#include <skalibs/siovec.h> +#include <skalibs/stralloc.h> +#include <skalibs/skamisc.h> + +int skagetlnmaxsep (buffer *b, stralloc *sa, size_t max, char const *sep, size_t seplen) +{ + size_t start = sa->len ; + for (;;) + { + struct iovec v[2] ; + size_t pos ; + int r ; + buffer_rpeek(b, v) ; + pos = siovec_bytein(v, 2, sep, seplen) ; + r = pos < buffer_len(b) ; pos += r ; + if (!stralloc_readyplus(sa, pos)) return -1 ; + buffer_getnofill(b, sa->s + sa->len, pos) ; sa->len += pos ; + if (r) return 1 ; + if (sa->len - start >= max) return (errno = EMSGSIZE, -1) ; + r = buffer_fill(b) ; + if (r < 0) return r ; + if (!r) return (sa->s && (sa->len > start)) ? (errno = EPIPE, -1) : 0 ; + } +} diff --git a/src/libstddjb/touch.c b/src/libstddjb/touch.c @@ -1,53 +0,0 @@ -/* ISC license. */ - -#include <skalibs/sysdeps.h> - -#ifdef SKALIBS_HASFUTIMENS - -#include <skalibs/nonposix.h> -#include <time.h> -#include <sys/stat.h> -#include <skalibs/djbunix.h> - -int touch (char const *file) -{ - int r ; - int fd = open_create(file) ; - if (fd < 0) return 0 ; - r = futimens(fd, 0) >= 0 ; - fd_close(fd) ; - return r ; -} - -#else -#ifdef SKALIBS_HASFUTIMES - -#include <skalibs/nonposix.h> -#include <sys/time.h> -#include <skalibs/djbunix.h> - -int touch (char const *file) -{ - int r ; - int fd = open_create(file) ; - if (fd < 0) return 0 ; - r = futimes(fd, 0) >= 0 ; - fd_close(fd) ; - return r ; -} - -#else - -#include <sys/time.h> -#include <skalibs/djbunix.h> - -int touch (char const *file) -{ - int fd = open_create(file) ; - if (fd < 0) return 0 ; - fd_close(fd) ; - return utimes(file, 0) >= 0 ; -} - -#endif -#endif diff --git a/src/libstddjb/xexecvep.c b/src/libstddjb/xexecvep.c @@ -1,6 +1,7 @@ /* ISC license. */ #include <errno.h> +#include <skalibs/posixplz.h> #include <skalibs/djbunix.h> #include <skalibs/strerr2.h> diff --git a/src/libunixonacid/textmessage_handle.c b/src/libunixonacid/textmessage_handle.c @@ -0,0 +1,20 @@ +/* ISC license. */ + +#include <sys/uio.h> +#include <skalibs/textmessage.h> + +int textmessage_handle (textmessage_receiver_t *tr, textmessage_handler_func_t_ref f, void *p) +{ + unsigned int count = 0 ; + while (count < TEXTMESSAGE_MAXREADS || textmessage_receiver_hasmsginbuf(tr)) + { + struct iovec v ; + int r = textmessage_receive(tr, &v) ; + if (r < 0) return -1 ; + if (!r) break ; + r = (*f)(&v, p) ; + if (r <= 0) return r-2 ; + count++ ; + } + return (int)count ; +} diff --git a/src/libunixonacid/textmessage_put.c b/src/libunixonacid/textmessage_put.c @@ -0,0 +1,21 @@ +/* ISC license. */ + +#include <sys/uio.h> +#include <errno.h> +#include <stdint.h> +#include <skalibs/uint32.h> +#include <skalibs/bufalloc.h> +#include <skalibs/textmessage.h> + +int textmessage_put (textmessage_sender_t *ts, char const *s, size_t len) +{ + char pack[4] ; + struct iovec v[2] = + { + { .iov_base = pack, .iov_len = 4 }, + { .iov_base = (char *)s, .iov_len = len } + } ; + if (len > UINT32_MAX) return (errno = EINVAL, 0) ; + uint32_pack_big(pack, (uint32_t)len) ; + return bufalloc_putv(&ts->out, v, 2) ; +} diff --git a/src/libunixonacid/textmessage_putv.c b/src/libunixonacid/textmessage_putv.c @@ -0,0 +1,22 @@ +/* ISC license. */ + +#include <sys/uio.h> +#include <errno.h> +#include <stdint.h> +#include <skalibs/uint32.h> +#include <skalibs/bufalloc.h> +#include <skalibs/siovec.h> +#include <skalibs/textmessage.h> + +int textmessage_putv (textmessage_sender_t *ts, struct iovec const *v, unsigned int n) +{ + size_t len = siovec_len(v, n) ; + char pack[4] ; + struct iovec vv[n+1] ; + if (len > UINT32_MAX) return (errno = EINVAL, 0) ; + vv[0].iov_base = pack ; + vv[0].iov_len = 4 ; + for (unsigned int i = 0 ; i < n ; i++) vv[i+1] = v[i] ; + uint32_pack_big(pack, (uint32_t)len) ; + return bufalloc_putv(&ts->out, vv, n+1) ; +} diff --git a/src/libunixonacid/textmessage_receive.c b/src/libunixonacid/textmessage_receive.c @@ -0,0 +1,40 @@ +/* ISC license. */ + +#include <sys/uio.h> +#include <stdint.h> +#include <errno.h> +#include <skalibs/uint32.h> +#include <skalibs/allreadwrite.h> +#include <skalibs/buffer.h> +#include <skalibs/stralloc.h> +#include <skalibs/textmessage.h> + +int textmessage_receive (textmessage_receiver_t *tr, struct iovec *v) +{ + if (tr->indata.len == tr->wanted) + { + uint32_t u ; + char pack[4] ; + if (buffer_len(&tr->in) < 4) + { + ssize_t r = sanitize_read(buffer_fill(&tr->in)) ; + if (r <= 0) return r ; + if (buffer_len(&tr->in) < 4) return (errno = EWOULDBLOCK, 0) ; + } + buffer_getnofill(&tr->in, pack, 4) ; + uint32_unpack_big(pack, &u) ; + if (u > tr->max) return (errno = EMSGSIZE, -1) ; + if (!stralloc_ready(&tr->indata, u)) return -1 ; + tr->wanted = u ; + tr->indata.len = 0 ; + } + + { + int r = buffer_getall(&tr->in, tr->indata.s, tr->wanted, &tr->indata.len) ; + if (r <= 0) return r ; + } + + v->iov_base = tr->indata.s ; + v->iov_len = tr->indata.len ; + return 1 ; +} diff --git a/src/libunixonacid/textmessage_receiver_0.c b/src/libunixonacid/textmessage_receiver_0.c @@ -0,0 +1,10 @@ +/* ISC license. */ + +/* MT-unsafe */ + +#include <stdint.h> +#include <skalibs/buffer.h> +#include <skalibs/textmessage.h> + +static char buf[BUFFER_INSIZE] ; +textmessage_receiver_t textmessage_receiver_0_ = TEXTMESSAGE_RECEIVER_INIT(0, buf, BUFFER_INSIZE, UINT32_MAX) ; diff --git a/src/libunixonacid/textmessage_receiver_free.c b/src/libunixonacid/textmessage_receiver_free.c @@ -0,0 +1,10 @@ +/* ISC license. */ + +#include <skalibs/stralloc.h> +#include <skalibs/textmessage.h> + +void textmessage_receiver_free (textmessage_receiver_t *ts) +{ + stralloc_free(&ts->indata) ; + *ts = textmessage_receiver_zero ; +} diff --git a/src/libunixonacid/textmessage_receiver_hasmsginbuf.c b/src/libunixonacid/textmessage_receiver_hasmsginbuf.c @@ -0,0 +1,21 @@ +/* ISC license. */ + +#include <stdint.h> +#include <sys/uio.h> +#include <skalibs/uint32.h> +#include <skalibs/siovec.h> +#include <skalibs/buffer.h> +#include <skalibs/textmessage.h> + +int textmessage_receiver_hasmsginbuf (textmessage_receiver_t const *tr) +{ + size_t len = buffer_len(&tr->in) ; + uint32_t n ; + char pack[4] ; + struct iovec v[2] ; + if (len < 4) return 0 ; + buffer_rpeek(&tr->in, v) ; + siovec_gather(v, 2, pack, 4) ; + uint32_unpack_big(pack, &n) ; + return len - 4 >= n ; +} diff --git a/src/libunixonacid/textmessage_receiver_init.c b/src/libunixonacid/textmessage_receiver_init.c @@ -0,0 +1,14 @@ +/* ISC license. */ + +#include <skalibs/buffer.h> +#include <skalibs/stralloc.h> +#include <skalibs/textmessage.h> + +int textmessage_receiver_init (textmessage_receiver_t *tr, int fd, char *buf, size_t buflen, uint32_t max) +{ + if (!buffer_init(&tr->in, &buffer_read, fd, buf, buflen)) return 0 ; + tr->indata = stralloc_zero ; + tr->wanted = 0 ; + tr->max = max ; + return 1 ; +} diff --git a/src/libunixonacid/textmessage_receiver_zero.c b/src/libunixonacid/textmessage_receiver_zero.c @@ -0,0 +1,5 @@ +/* ISC license. */ + +#include <skalibs/textmessage.h> + +textmessage_receiver_t const textmessage_receiver_zero = TEXTMESSAGE_RECEIVER_ZERO ; diff --git a/src/libunixonacid/textmessage_sender_1.c b/src/libunixonacid/textmessage_sender_1.c @@ -0,0 +1,7 @@ +/* ISC license. */ + +/* MT-unsafe */ + +#include <skalibs/textmessage.h> + +textmessage_sender_t textmessage_sender_1_ = TEXTMESSAGE_SENDER_INIT(1) ; diff --git a/src/libunixonacid/textmessage_sender_flush.c b/src/libunixonacid/textmessage_sender_flush.c @@ -0,0 +1,9 @@ +/* ISC license. */ + +#include <skalibs/bufalloc.h> +#include <skalibs/textmessage.h> + +int textmessage_sender_flush (textmessage_sender_t *ts) +{ + return bufalloc_flush(&ts->out) ; +} diff --git a/src/libunixonacid/textmessage_sender_getfd.c b/src/libunixonacid/textmessage_sender_getfd.c @@ -0,0 +1,9 @@ +/* ISC license. */ + +#include <skalibs/bufalloc.h> +#include <skalibs/textmessage.h> + +int textmessage_sender_getfd (textmessage_sender_t const *ts) +{ + return bufalloc_fd(&ts->out) ; +} diff --git a/src/libunixonacid/textmessage_sender_timed_flush.c b/src/libunixonacid/textmessage_sender_timed_flush.c @@ -0,0 +1,15 @@ +/* ISC license. */ + +#include <skalibs/functypes.h> +#include <skalibs/unix-timed.h> +#include <skalibs/textmessage.h> + +static int textmessage_sender_isnonempty (textmessage_sender_t *ts) +{ + return !textmessage_sender_isempty(ts) ; +} + +int textmessage_sender_timed_flush (textmessage_sender_t *ts, tain_t const *deadline, tain_t *stamp) +{ + return timed_flush(ts, (initfunc_t_ref)&textmessage_sender_getfd, (initfunc_t_ref)&textmessage_sender_isnonempty, (initfunc_t_ref)&textmessage_sender_flush, deadline, stamp) ; +} diff --git a/src/libunixonacid/textmessage_sender_x.c b/src/libunixonacid/textmessage_sender_x.c @@ -0,0 +1,7 @@ +/* ISC license. */ + +/* MT-unsafe */ + +#include <skalibs/textmessage.h> + +textmessage_sender_t textmessage_sender_x_ = TEXTMESSAGE_SENDER_ZERO ; diff --git a/src/libunixonacid/textmessage_sender_zero.c b/src/libunixonacid/textmessage_sender_zero.c @@ -0,0 +1,5 @@ +/* ISC license. */ + +#include <skalibs/textmessage.h> + +textmessage_sender_t const textmessage_sender_zero = TEXTMESSAGE_SENDER_ZERO ; diff --git a/src/libunixonacid/textmessage_timed_handle.c b/src/libunixonacid/textmessage_timed_handle.c @@ -0,0 +1,29 @@ +/* ISC license. */ + +#include <skalibs/functypes.h> +#include <skalibs/unix-timed.h> +#include <skalibs/textmessage.h> + +typedef struct textmessage_handler_blah_s textmessage_handler_blah_t, *textmessage_handler_blah_t_ref ; +struct textmessage_handler_blah_s +{ + textmessage_receiver_t *tr ; + textmessage_handler_func_t_ref f ; + void *p ; +} ; + +static int getfd (textmessage_handler_blah_t *blah) +{ + return textmessage_receiver_fd(blah->tr) ; +} + +static ssize_t get (textmessage_handler_blah_t *blah) +{ + return textmessage_handle(blah->tr, blah->f, blah->p) ; +} + +int textmessage_timed_handle (textmessage_receiver_t *tr, textmessage_handler_func_t_ref f, void *p, tain_t const *deadline, tain_t *stamp) +{ + textmessage_handler_blah_t blah = { .tr = tr, .f = f, .p = p } ; + return timed_get(&blah, (initfunc_t_ref)&getfd, (getfunc_t_ref)&get, deadline, stamp) ; +} diff --git a/src/libunixonacid/textmessage_timed_receive.c b/src/libunixonacid/textmessage_timed_receive.c @@ -0,0 +1,29 @@ +/* ISC license. */ + +#include <sys/uio.h> +#include <skalibs/functypes.h> +#include <skalibs/unix-timed.h> +#include <skalibs/textmessage.h> + +typedef struct textmessage_get_s textmessage_get_t, *textmessage_get_t_ref ; +struct textmessage_get_s +{ + textmessage_receiver_t *tr ; + struct iovec *v ; +} ; + +static int getfd (textmessage_get_t *g) +{ + return textmessage_receiver_fd(g->tr) ; +} + +static ssize_t get (textmessage_get_t *g) +{ + return textmessage_receive(g->tr, g->v) ; +} + +int textmessage_timed_receive (textmessage_receiver_t *tr, struct iovec *v, tain_t const *deadline, tain_t *stamp) +{ + textmessage_get_t g = { .tr = tr, .v = v } ; + return timed_get(&g, (initfunc_t_ref)&getfd, (getfunc_t_ref)&get, deadline, stamp) ; +} diff --git a/src/sysdeps/tryarc4random.c b/src/sysdeps/tryarc4random.c @@ -3,6 +3,22 @@ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE +#ifndef __EXTENSIONS__ +#define __EXTENSIONS__ +#endif +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#ifndef _BSD_SOURCE +#define _BSD_SOURCE +#endif +#ifndef _NETBSD_SOURCE +#define _NETBSD_SOURCE +#endif +#ifndef _INCOMPLETE_XOPEN_C063 +#define _INCOMPLETE_XOPEN_C063 +#endif + #include <stdlib.h> int main (void) diff --git a/src/sysdeps/tryarc4random_addrandom.c b/src/sysdeps/tryarc4random_addrandom.c @@ -3,6 +3,22 @@ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE +#ifndef __EXTENSIONS__ +#define __EXTENSIONS__ +#endif +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#ifndef _BSD_SOURCE +#define _BSD_SOURCE +#endif +#ifndef _NETBSD_SOURCE +#define _NETBSD_SOURCE +#endif +#ifndef _INCOMPLETE_XOPEN_C063 +#define _INCOMPLETE_XOPEN_C063 +#endif + #include <stdlib.h> int main (void) diff --git a/src/sysdeps/trygetpeereid.c b/src/sysdeps/trygetpeereid.c @@ -3,6 +3,22 @@ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE +#ifndef __EXTENSIONS__ +#define __EXTENSIONS__ +#endif +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#ifndef _BSD_SOURCE +#define _BSD_SOURCE +#endif +#ifndef _NETBSD_SOURCE +#define _NETBSD_SOURCE +#endif +#ifndef _INCOMPLETE_XOPEN_C063 +#define _INCOMPLETE_XOPEN_C063 +#endif + #include <sys/types.h> #include <unistd.h> @@ -10,6 +26,6 @@ int main (void) { uid_t uid ; gid_t gid ; - int s = 0 ; - return getpeereid(s, &uid, &gid) ; + int fd = 0 ; + return getpeereid(fd, &uid, &gid) ; } diff --git a/src/sysdeps/trymemmem.c b/src/sysdeps/trymemmem.c @@ -0,0 +1,28 @@ +/* ISC license. */ + +#undef _POSIX_C_SOURCE +#undef _XOPEN_SOURCE + +#ifndef __EXTENSIONS__ +#define __EXTENSIONS__ +#endif +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#ifndef _BSD_SOURCE +#define _BSD_SOURCE +#endif +#ifndef _NETBSD_SOURCE +#define _NETBSD_SOURCE +#endif +#ifndef _INCOMPLETE_XOPEN_C063 +#define _INCOMPLETE_XOPEN_C063 +#endif + +#include <string.h> + +int main (void) +{ + memmem("blah", 4, "la", 2) ; + return 0 ; +} diff --git a/src/sysdeps/trynamespaces.c b/src/sysdeps/trynamespaces.c @@ -1,8 +1,23 @@ /* ISC license. */ +#undef _POSIX_C_SOURCE +#undef _XOPEN_SOURCE + +#ifndef __EXTENSIONS__ +#define __EXTENSIONS__ +#endif #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif +#ifndef _BSD_SOURCE +#define _BSD_SOURCE +#endif +#ifndef _NETBSD_SOURCE +#define _NETBSD_SOURCE +#endif +#ifndef _INCOMPLETE_XOPEN_C063 +#define _INCOMPLETE_XOPEN_C063 +#endif #include <sched.h> diff --git a/src/sysdeps/trystrcasestr.c b/src/sysdeps/trystrcasestr.c @@ -3,6 +3,9 @@ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE +#ifndef __EXTENSIONS__ +#define __EXTENSIONS__ +#endif #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif @@ -12,6 +15,9 @@ #ifndef _NETBSD_SOURCE #define _NETBSD_SOURCE #endif +#ifndef _INCOMPLETE_XOPEN_C063 +#define _INCOMPLETE_XOPEN_C063 +#endif #include <string.h> diff --git a/src/sysdeps/trystrnlen.c b/src/sysdeps/trystrnlen.c @@ -1,5 +1,8 @@ /* ISC license. */ +#undef _POSIX_C_SOURCE +#undef _XOPEN_SOURCE + #include <string.h> int main (void)