pax_global_header00006660000000000000000000000064135533511540014517gustar00rootroot0000000000000052 comment=a1cc5ca8aa7b72eedd88d57e8e9b09a68f7c63a1 skalibs-2.9.1.0/000077500000000000000000000000001355335115400133165ustar00rootroot00000000000000skalibs-2.9.1.0/.gitignore000066400000000000000000000004121355335115400153030ustar00rootroot00000000000000*.o /*.a.xyzzy *.lo /*.so.xyzzy /config.mak /src/include/skalibs/config.h /src/include/skalibs/ip46.h /src/include/skalibs/sysdeps.h /src/include/skalibs/types.h /src/include/skalibs/uint16.h /src/include/skalibs/uint32.h /src/include/skalibs/uint64.h /sysdeps.cfg/ skalibs-2.9.1.0/AUTHORS000066400000000000000000000024331355335115400143700ustar00rootroot00000000000000Main author: Laurent Bercot Contributors: Dan J. Bernstein William E. Baxter Olivier Brunel Lionel Van Bemten Rasmus Villemoes Jesse Young 7heo <7heo@mail.com> John Regan Shengjing Zhu Thanks to: Jean Marot Paul Jarc Nicolas George David Madore Taj Khattra Dan Kegel Stefan Karrmann Matthew R. Dempsky Lasse Kliemann Robert Ransom Frans Haarman Vincent De Ribou Jorge Almeida Roman I Khimov Yannick Duchêne Michael Zuo Éric Le Bihan Samuel Holland Jan Bramkamp Johannes Nixdorf Casper Ti. Vector Guillermo skalibs-2.9.1.0/COPYING000066400000000000000000000013701355335115400143520ustar00rootroot00000000000000Copyright (c) 2011-2019 Laurent Bercot Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. skalibs-2.9.1.0/INSTALL000066400000000000000000000154131355335115400143530ustar00rootroot00000000000000Build Instructions ------------------ * Requirements ------------ - A POSIX-compliant C development environment - GNU make version 3.81 or later - If cross-compiling: the sysdeps for your target architecture (see the "Cross-compilation" section below) This software will install on any operating system that implements POSIX.1-2008, available at: http://pubs.opengroup.org/onlinepubs/9699919799/ * Standard usage -------------- ./configure && make && sudo make install will work for most users. It will install the static libraries in /usr/lib/skalibs, the shared libraries in /lib, and the sysdeps in /usr/lib/skalibs/sysdeps. Please note that static libraries in /usr/lib/skalibs *will not* be found by a default linker invocation: you need -L/usr/lib/skalibs. Other skarnet.org software automatically handles that case if the default configuration is used, but if you change the configuration, remember to use the appropriate --with-lib configure option. You can strip the libraries of their extra symbols via "make strip" before the "make install" phase. It will shave a few bytes off them. * Customization ------------- You can customize the installation process via flags given to configure. See ./configure --help for a list of all available configure options. * Environment variables --------------------- Controlling a build process via environment variables is a big and dangerous hammer. You should try and pass flags to configure instead; nevertheless, a few standard environment variables are recognized. If the CC environment variable is set, its value will override compiler detection by configure. The --host=HOST option will still add a HOST- prefix to the value of CC. The values of CFLAGS, CPPFLAGS and LDFLAGS will be appended to the default flags set by configure. To override those defaults instead of appending to them, use the CPPFLAGS, CFLAGS and LDFLAGS _make variables_ instead of environment variables. * Make variables -------------- You can invoke make with a few variables for more configuration. CC, CFLAGS, CPPFLAGS, LDFLAGS, LDLIBS, AR, RANLIB, STRIP, INSTALL and CROSS_COMPILE can all be overridden on the make command line. This is an even bigger hammer than running ./configure with environment variables, so it is advised to only do this when it is the only way of obtaining the behaviour you want. DESTDIR can be given on the "make install" command line in order to install to a staging directory. * Shared libraries ---------------- Software from skarnet.org is small enough that shared libraries are generally not worth using. Static linking is simpler and incurs less runtime overhead and less points of failure: but since skalibs only provides libraries, both versions are built by default. Nevertheless, you can: * avoid building shared libraries: --disable-shared * avoid building static libraries: --disable-static If you are using a GNU/Linux system, be aware that the GNU libc behaves badly with static linking and produces huge executables, so if you plan on making static executables, you should consider using another libc, which you also need to use when compiling skalibs. musl is recommended: http://musl-libc.org/ * Cross-compilation ----------------- skarnet.org centralizes all the difficulty of cross-compilation in skalibs. The native skalibs build process runs some tests to gather "sysdeps", i.e. system-dependent properties of the target, and stores those into a sysdeps directory; software depending on skalibs is provided the name of the sysdeps directory at build time, and can depend on its contents - that's how skarnet.org packages are easily made portable. However, when the host differs from the target - the cross-compilation case - some of those build-time tests, i.e. the ones that require code execution on the target, are invalid. So you must manually provide configure with appropriate values for the list of sysdeps that cannot be autodetected. For a sysdep named K with a value V, the correct option to give to configure is: --with-sysdep-K=V Most of the time, sysdeps have a boolean value, so the correct V is "yes" or "no". For instance, to say that the target has a working pseudorandom number generator in /dev/urandom, you would give the following option to configure: --with-sysdep-devurandom=yes ./configure --help lists all the sysdeps you need to manually provide a value for when cross-compiling. Note that you can provide manual sysdeps values at any time, for any existing sysdep, to bypass autodetection - and you can even do it when building natively. It's just not recommended (you should let skalibs autodetect everything it can), and and it's only mandatory for a small subset of sysdeps in the cross-compilation case. * The slashpackage convention --------------------------- The slashpackage convention (http://cr.yp.to/slashpackage.html) is a package installation scheme that provides a few guarantees over other conventions such as the FHS, for instance fixed absolute pathnames. skarnet.org packages support it: use the --enable-slashpackage option to configure, or --enable-slashpackage=DIR for a prefixed DIR/package tree. This option will activate slashpackage support during the build and set slashpackage-compatible installation directories. If $version is the current skalibs version number: --bindir will be set to /package/prog/skalibs-$version/command --includedir will be set to /package/prog/skalibs-$version/include --libdir will be set to /package/prog/skalibs-$version/library --dynlibdir will be set to /package/prog/skalibs-$version/library.so --sysdepdir will be set to /package/prog/skalibs-$version/sysdeps Note that --datadir will be unchanged, because the data exported by skalibs, i.e. the leap second table, is system-wide. You should manually specify --datadir=... if you want to deviate from the default. --prefix is pretty much ignored when you use --enable-slashpackage: it will only impact --datadir. You should probably not use both --enable-slashpackage and --prefix. When using slashpackage, two additional Makefile targets are available after "make install": - "make -L update" changes the default version of the software to the freshly installed one. (This is useful when you have several installed versions of the same software, which slashpackage supports.) - "make -L global-links" adds links from DIR/command and DIR/library.so to the default version of the binaries and shared libraries. The "-L" option to make is necessary because targets are symbolic links, and the default make behaviour is to check the pointed file's timestamp and not the symlink's timestamp. * Out-of-tree builds ------------------ skarnet.org packages do not support out-of-tree builds. They are small, so it does not cost much to duplicate the entire source tree if parallel builds are needed. skalibs-2.9.1.0/Makefile000066400000000000000000000140671355335115400147660ustar00rootroot00000000000000# # This Makefile requires GNU make. # # Do not make changes here. # Use the included .mak files. # it: all make_need := 3.81 ifeq "" "$(strip $(filter $(make_need), $(firstword $(sort $(make_need) $(MAKE_VERSION)))))" fail := $(error Your make ($(MAKE_VERSION)) is too old. You need $(make_need) or newer) endif CC = $(error Please use ./configure first) -include config.mak include package/deps.mak version_m := $(basename $(version)) version_M := $(basename $(version_m)) version_l := $(basename $(version_M)) CPPFLAGS_ALL := $(CPPFLAGS_AUTO) $(CPPFLAGS) CFLAGS_ALL := $(CFLAGS_AUTO) $(CFLAGS) LDFLAGS_ALL := $(LDFLAGS_AUTO) $(LDFLAGS) LDLIBS_ALL := $(LDLIBS_AUTO) $(LDLIBS) AR := $(CROSS_COMPILE)ar RANLIB := $(CROSS_COMPILE)ranlib STRIP := $(CROSS_COMPILE)strip INSTALL := ./tools/install.sh TYPES := size uid gid pid time dev ino ALL_SRCS := $(sort $(wildcard src/lib*/*.c)) ALL_DOBJS := $(ALL_SRCS:%.c=%.lo) ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),) ALL_SOBJS := $(ALL_SRCS:%.c=%.o) CFLAGS_SHARED := -fPIC else ALL_SOBJS := $(ALL_DOBJS) CFLAGS_SHARED := endif ALL_LIBS := $(SHARED_LIBS) $(STATIC_LIBS) BUILT_INCLUDES := \ src/include/$(package)/sysdeps.h \ src/include/$(package)/uint16.h \ src/include/$(package)/uint32.h \ src/include/$(package)/uint64.h \ src/include/$(package)/types.h \ src/include/$(package)/ip46.h ALL_INCLUDES := $(sort $(BUILT_INCLUDES) $(wildcard src/include/$(package)/*.h)) ALL_SYSDEPS := $(wildcard $(sysdeps)/*) ALL_DATA := $(wildcard src/etc/*) all: $(ALL_LIBS) $(ALL_INCLUDES) $(ALL_SYSDEPS) $(ALL_DATA) clean: @exec rm -f $(ALL_LIBS) $(ALL_BINS) $(ALL_SOBJS) $(ALL_DOBJS) $(BUILT_INCLUDES) distclean: clean @exec rm -rf config.mak src/include/$(package)/config.h sysdeps.cfg tgz: distclean @. package/info && \ rm -rf /tmp/$$package-$$version && \ cp -a . /tmp/$$package-$$version && \ cd /tmp && \ tar -zpcv --owner=0 --group=0 --numeric-owner --exclude=.git* -f /tmp/$$package-$$version.tar.gz $$package-$$version && \ exec rm -rf /tmp/$$package-$$version strip: $(ALL_LIBS) ifneq ($(strip $(STATIC_LIBS)),) exec $(STRIP) -x -R .note -R .comment -R .note.GNU-stack $(STATIC_LIBS) endif ifneq ($(strip $(SHARED_LIBS)),) exec $(STRIP) -R .note -R .comment -R .note.GNU-stack $(SHARED_LIBS) endif install: install-data install-sysdeps install-dynlib install-lib install-include install-data: $(ALL_DATA:src/etc/%=$(DESTDIR)$(datadir)/%) install-sysdeps: $(ALL_SYSDEPS:$(sysdeps)/%=$(DESTDIR)$(sysdepdir)/%) install-dynlib: $(SHARED_LIBS:lib%.so.xyzzy=$(DESTDIR)$(dynlibdir)/lib%.so) install-lib: $(STATIC_LIBS:lib%.a.xyzzy=$(DESTDIR)$(libdir)/lib%.a) install-include: $(ALL_INCLUDES:src/include/$(package)/%.h=$(DESTDIR)$(includedir)/$(package)/%.h) ifneq ($(exthome),) $(DESTDIR)$(exthome): $(DESTDIR)$(home) exec $(INSTALL) -l $(notdir $(home)) $(DESTDIR)$(exthome) update: $(DESTDIR)$(exthome) global-links: $(DESTDIR)$(exthome) $(SHARED_LIBS:lib%.so.xyzzy=$(DESTDIR)$(sproot)/library.so/lib%.so.$(version_M)) $(DESTDIR)$(sproot)/library.so/lib%.so.$(version_M): $(DESTDIR)$(home)/library.so/lib%.so.$(version_M) exec $(INSTALL) -D -l ..$(subst $(sproot),,$(exthome))/library.so/$( $@ 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 > $@ src/include/$(package)/uint32.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 32 11 13 9 33 > $@ src/include/$(package)/uint64.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-ulong64 src/headers/uint64-noulong64 src/headers/uint64-defs src/headers/uint64-macros exec tools/gen-bits.sh $(sysdeps)/sysdeps 64 21 25 17 65 > $@ src/include/$(package)/types.h: src/include/$(package)/uint16.h src/include/$(package)/uint32.h src/include/$(package)/uint64.h $(sysdeps)/sysdeps src/headers/types-header src/headers/types-footer src/headers/unsigned-template src/headers/signed-template exec tools/gen-types.sh $(sysdeps)/sysdeps $(TYPES) > $@ src/include/$(package)/ip46.h: src/include/$(package)/fmtscan.h src/include/$(package)/socket.h $(sysdeps)/sysdeps src/headers/ip46-header src/headers/ip46-footer src/headers/ip46-with src/headers/ip46-without @{ \ cat src/headers/ip46-header ; \ if $(ipv6) && grep -qF 'ipv6: yes' $(sysdeps)/sysdeps ; then cat src/headers/ip46-with ; \ else cat src/headers/ip46-without ; \ fi ; \ exec cat src/headers/ip46-footer ; \ } > $@ skalibs-2.9.1.0/NEWS000066400000000000000000000113471355335115400140230ustar00rootroot00000000000000Changelog for skalibs. In 2.9.1.0 ---------- - Bugfixes. - Better support for GNU Hurd. - Added path_canonicalize(). In 2.9.0.0 ---------- - Bugfixes. - Better support of out-of-path toolchains (among other things, that means better autotools emulation). - Build more friendly to recent glibc. - Refactoring and optimization of scanning and formatting functions. - Refactoring of stopwatch/wallclock functions. The --enable-clock and --enable-monotonic configure switches have been removed. tain_now() can now be set at run time to use a wall clock (default, or via tain_now_set_wallclock()) or a stopwatch (via tain_now_set_stopwatch()), instead of it being fixed at build time. - Easy cross-compilation: no need to provide a whole sysdeps directory anymore. Only a few sysdeps have to be provided manually, via a --with-sysdep-K=V option to configure. Currently, that means one: --with-sysdep-devurandom=yes|no In 2.8.1.0 ---------- - Added skalibs_regcomp(), accepting empty regexes on BSDs. In 2.8.0.1 ---------- - Bugfixes. - Better reporting in utc_from_tai() and localtm_from_*() In 2.8.0.0 ---------- - Bugfixes. - avltreeb removed. (It used VLAs inside of structures, which is GNU C, not C99.) The AVLTREEN_DECLARE_AND_INIT() macro should be used instead. - New functions: env_dump(), mk?temp(), autosurf(), autosurf_name() - mkdir_unique() removed. (Duplicate functionality with mkdtemp.) - ancilautoclose and nbwaitall sysdeps removed. - New header: skalibs/posixishard.h - Static libraries are now PIC by default. In 2.7.0.0 ---------- - Bugfixes. - New functions: ipc_timed_sendv(), unlink_void(), genset_deepfree(), gensetdyn_deepfree(), skagetln_loose(), skagetlnsep_loose() - dir_close() now returns void and leaves errno unchanged - absolutepath(), sarealpath_tmp(), avl*_deletnode(), mininetstring, prot functions removed - djbunix.h doesn't include env.h anymore In 2.6.4.0 ---------- - Bugfixes. - New functions: execvep_loose(), byte_zzero(), openb_read(), sig0_scan() - New function family: skalibs/genqdyn.h In 2.6.3.1 ---------- - Bugfixes. In 2.6.3.0 ---------- - New dir_fd function wrapping dirfd() (Solaris doesn't have dirfd()) - memmem implementation for platforms that don't provide it. - memmem wrappers: byte_search, siovec_search. - New functions: atomic_symlink, skagetlnmaxsep, child_spawn3 - New header: skalibs/posixplz.h, some header reorganization. - New family of functions: textmessage and textclient - skalibs/environ.h and skalibs/getpeereid.h are now obsolescent. - Bugfixes. In 2.6.2.0 ---------- - New functions: access_at() (MacOS and Solaris don't support faccessat), skaclient_timed_aflush(). - stralloc.h and tai.h are suitable for inclusion in C++ headers. - New sysdep: SKALIBS_HASODIRECTORY. (MacOS doesn't support O_DIRECTORY.) In 2.6.1.0 ---------- - New function: lock_unx(). In 2.6.0.2 ---------- - Bugfixes. - Optimized packing/unpacking routines. In 2.6.0.1 ---------- - Better CPPFLAGS/CFLAGS/LDFLAGS management. - openwritenclose() and openwritevnclose() now use mkstemp. In 2.6.0.0 ---------- - Bugfixes. - New unixmessage_receiver_hasmsginbuf() function to address an issue in unixmessage_handle(). - fd_close() now returns void. This mandates a major version bump. - new skalibs_setgroups(), setgroups_with_egid() and setgroups_and_gid() functions to work around supplementary group mismanagement in... can you guess what operating system? (You get 3 tries. One for each BSD.) In 2.5.1.1 ---------- - Bugfixes. In 2.5.1.0 ---------- - Bugfixes. - More workarounds for OpenBSD (who else). - More workarounds for sysdeps detection by broken toolchains. - Added the xpathexec_* family of functions (in djbunix.h). In 2.5.0.0 ---------- - Added this NEWS file. :) - Dropped support for old versions of OpenBSD (at least 4.9 isn't working anymore). Newer versions are still supported: 5.7 and up are working. - --enable-replace-libc flag dropped. All supported systems now have a compliant-enough libc for skalibs' purposes. - Major types overhaul to be more POSIXly correct. 64-bit operations are now supported on 64-bit archs where int is 32-bit. Use of POSIX types wherever important, e.g. where pointers are used: datastruct.h indices, for instance, are uint32_t. stralloc et al. lengths are size_t. - Related API changes: skalibs/ushort.h, skalibs/uint.h and skalibs/ulong.h have disappeared - replaced with skalibs/types.h that also includes basic fmtscan support for common POSIX types. The uint16, uint32 and uint64 integer types have disappeared - replaced with stdint.h types. uint64_t is defined by skalibs/uint64.h when stdint.h omits it. - Lots of minor bugfixes and cleanups related to the types system. - Better support for getrandom() and arc4random(). skalibs-2.9.1.0/README000066400000000000000000000012071355335115400141760ustar00rootroot00000000000000skalibs - a general-purpose low-level C library ----------------------------------------------- skalibs is a C library used by all the skarnet.org packages. It provides APIs more suited to secure and efficient system programming than the libc, especially where network programming and IPCs are concerned. See the enclosed doc/ subdirectory for the documentation, or https://skarnet.org/software/skalibs/ * Installation ------------ See the INSTALL file. * Contact information ------------------- Laurent Bercot Please use the mailing-list for questions about skalibs. skalibs-2.9.1.0/README.macos000066400000000000000000000002431355335115400152760ustar00rootroot00000000000000 This package will compile on Darwin (MacOS), but the building of shared libraries is not supported. Make sure you use the --disable-shared option to configure. skalibs-2.9.1.0/README.solaris000066400000000000000000000006531355335115400156550ustar00rootroot00000000000000 This package assumes the existence of a POSIX shell in /bin/sh. On Solaris, /bin/sh is not POSIX. Most versions of Solaris provide a POSIX shell in /usr/xpg4/bin/sh. To compile this package on Solaris, you will need to run ./patch-for-solaris before you run ./configure. This script will change the #! invocation of the configure script and various tools so that a POSIX shell is used for the compilation process. skalibs-2.9.1.0/configure000077500000000000000000000471101355335115400152300ustar00rootroot00000000000000#!/bin/sh cd `dirname "$0"` . package/info usage () { cat </dev/null 2>&1 && { echo "$1" ; return 0 ; } $1 EOF echo "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#" -e "s|\*/|* /|g" } fail () { echo "$*" 1>&2 exit 1 } fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" } cmdexists () { type "$1" >/dev/null 2>&1 } trycc () { test -z "$CC_AUTO" && cmdexists "$1" && CC_AUTO="$*" } stripdir () { while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" done } tryflag () { echo "Checking whether compiler accepts $2 ..." echo "typedef int x;" > "$tmpc" if $CC_AUTO "$2" -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then echo " ... yes" eval "$1=\"\${$1} \$2\"" eval "$1=\${$1# }" return 0 else echo " ... no" return 1 fi } tryldflag () { echo "Checking whether linker accepts $2 ..." echo "typedef int x;" > "$tmpc" if $CC_AUTO -nostdlib "$2" -o /dev/null "$tmpc" >/dev/null 2>&1 ; then echo " ... yes" eval "$1=\"\${$1} \$2\"" eval "$1=\${$1# }" return 0 else echo " ... no" return 1 fi } # Sysdeps determination functions iscached () { if test -r "$tmps" && grep -qF "${1}: " "$tmps" ; then v=`grep -F "${1}: " "$tmps" | 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" echo "Checking whether system has $3..." if iscached "$name" ; then return ; fi shift 3 libs="$*" r=true case "$what" in *c*) $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST -o try$name.o -c src/sysdeps/try$name.c 2>/dev/null || r=false ;; esac if $r ; then case "$what" in *l*) $CC_AUTO $CFLAGS_AUTO $CFLAGS $CFLAGS_POST $LDFLAGS_AUTO $LDFLAGS $LDFLAGS_POST -o try$name try$name.o $libs 2>/dev/null || r=false ;; esac fi if $r ; then case "$what" in *r*) if test -n "$cross" ; then rm -f try$name.o try$name fail "$0: sysdep $name cannot be autodetected when cross-compiling. Please manually provide a value with the --with-sysdep-${name}=yes|no|... option." fi ./try$name >/dev/null 2>&1 ; r=$? case "$r" in 111) fail "$0: test crashed, aborting." ;; 0) r=true ;; *) r=false ;; esac esac fi rm -f try$name.o try$name if $r ; then echo "$name: yes" >> $sysdeps/sysdeps echo " ... yes" else echo "$name: no" >> $sysdeps/sysdeps echo " ... no" fi } 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" < int a = 1 ; EOF if trybasic "$tmpc" ; then cat > "$tmpc" < int a = LITTLE_ENDIAN ; int b = BIG_ENDIAN ; int c = BYTE_ORDER ; EOF trybasic "$tmpc" || continue for j in little big pdp ; do k=`echo $j | tr a-z A-Z` cat > "$tmpc" < 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" fail "$0: error: unable to determine endianness according to $i" fi done rm -f "$tmpc" fail "$0: error: unable to determine endianness: no endian.h found" } trysigned () { cat > "$tmpc" < 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" < int a[sizeof($t) == $arg ? 1 : -1] ; EOF if trybasic "$tmpc" ; then rm -f "$tmpc" echo "$arg" return fi done rm -f "$tmpc" fail "$0: error: unable to determine the size of $t on the target" } trystdtype () { t="$1" ; shift iscached "sizeofu$t" || { echon "sizeofu${t}: " ; trysizes "$t" "$@" ; } >> "$sysdeps/sysdeps" } trytypes () { echo "Checking size and signedness of standard 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" } trylibs () { args= name=$1 echo "Checking whether system has $2..." >&3 shift 2 if $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST -c -o try$name.o src/sysdeps/try$name.c 2>/dev/null ; then until $CC_AUTO $CFLAGS_AUTO $CFLAGS $CFLAGS_POST $LDFLAGS_AUTO $LDFLAGS $LDFLAGS_POST -o /dev/null try$name.o $args 2>/dev/null ; do if test -z "$*" ; then rm -f try$name.o echo echo " ... no" >&3 return 1 fi args="$args $1" shift done echo ${args# } if test -z "$args" ; then echo " ... yes" >&3 else echo " ... yes, with$args" >&3 fi rm -f try$name.o return 0 else echo echo " ... no" >&3 return 1 fi } # Actual script CC_AUTO= CPPFLAGS_AUTO="-D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -Isrc/include" CPPFLAGS_POST="$CPPFLAGS" CPPFLAGS= CFLAGS_AUTO="-pipe -Wall" CFLAGS_POST="$CFLAGS" CFLAGS="-O2" LDFLAGS_AUTO= LDFLAGS_POST="$LDFLAGS" LDFLAGS= LDFLAGS_NOSHARED= LDFLAGS_SHARED=-shared prefix= dynlibdir='$prefix/lib' libdir='$prefix/lib/$package' includedir='$prefix/include' datadir='$prefix/etc' sysdepdir='$prefix/lib/$package/sysdeps' sysdeplist= shared=true static=true allpic=true slashpackage=false ipv6=true select=false taiclock=false ddefaultpath=/usr/bin:/bin defaultpath=$ddefaultpath dpathorig=true sproot= home= exthome= addincpath='' addlibspath='' addlibdpath='' vpaths='' vpathd='' build= for arg ; do case "$arg" in --help) usage ;; --prefix=*) prefix=${arg#*=} ;; --dynlibdir=*) dynlibdir=${arg#*=} ;; --libdir=*) libdir=${arg#*=} ;; --includedir=*) includedir=${arg#*=} ;; --datadir=*) datadir=${arg#*=} ;; --sysdepdir=*) sysdepdir=${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" ;; --enable-shared|--enable-shared=yes) shared=true ;; --disable-shared|--enable-shared=no) shared=false ;; --enable-static|--enable-static=yes) static=true ;; --disable-static|--enable-static=no) static=false ;; --enable-all-pic|--enable-all-pic=yes) allpic=true ;; --disable-all-pic|--enable-all-pic=no) allpic=false ;; --enable-slashpackage=*) sproot=${arg#*=} ; slashpackage=true ; ;; --enable-slashpackage) sproot= ; slashpackage=true ;; --disable-slashpackage) sproot= ; slashpackage=false ;; --enable-ipv6|--enable-ipv6=yes) ipv6=true ;; --disable-ipv6|--enable-ipv6=no) ipv6=false ;; --enable-iopause-select|--enable-iopause-select=yes) select=true ;; --disable-iopause-select|--enable-iopause-select=no) select=false ;; --enable-tai-clock|--enable-tai-clock=yes) taiclock=true ;; --disable-tai-clock|--enable-tai-clock=no) taiclock=false ;; --enable-monotonic|--enable-monotonic=yes) echo "$0: warning: --enable-monotonic is now obsolete" 1>&2 ;; --disable-monotonic|--enable-monotonic=no) ;; --with-default-path=*) defaultpath=${arg#*=} ; dpathorig=false ;; --without-default-path) defaultpath=$ddefaultpath ; dpathorig=true ;; --with-sysdep-*=*) sysdeplist="$sysdeplist ${arg#--with-sysdep-}" ;; --without-sysdep-*) sysdeplist="$sysdeplist ${arg#--with-sysdep-}=no" ;; --enable-*|--disable-*|--with-*|--without-*|--*dir=*) ;; --host=*|--target=*) target=${arg#*=} ;; --build=*) build=${arg#*=} ;; -* ) echo "$0: unknown option $arg" ;; *=*) ;; *) target=$arg ;; esac done # Add /usr in the default default case if test -z "$prefix" ; then if test "$libdir" = '$prefix/lib/$package' ; then libdir=/usr/lib/$package fi if test "$includedir" = '$prefix/include' ; then includedir=/usr/include fi if test "$sysdepdir" = '$prefix/lib/$package/sysdeps' ; then sysdepdir=/usr/lib/$package/sysdeps fi fi # Expand installation directories stripdir prefix for i in exec_prefix dynlibdir libdir includedir datadir sysdepdir sysdepspre sproot ; do eval tmp=\${$i} eval $i=$tmp stripdir $i done # Get usable temp filenames i=0 set -C while : ; do i=$(($i+1)) tmpc="./tmp-configure-$$-$PPID-$i.c" tmpe="./tmp-configure-$$-$PPID-$i.tmp" tmps="./tmp-configure-$$-$PPID-$i.sysdeps" 2>|/dev/null > "$tmpc" && break 2>|/dev/null > "$tmpe" && break test "$i" -gt 50 && fail "$0: cannot create temporary files" done set +C trap 'rm -f "$tmpc" "$tmpe" "$tmps"' EXIT ABRT INT QUIT TERM HUP # Set slashpackage values if $slashpackage ; then home=${sproot}/package/${category}/${package}-${version} exthome=${sproot}/package/${category}/${package} sysdepdir=${home}/sysdeps binprefix=${home}/command extbinprefix=${exthome}/command dynlibdir=${home}/library.so libdir=${home}/library includedir=${home}/include if $dpathorig ; then if echo $defaultpath | tr : '\n' | grep -q '^/command$' ; then : ; else defaultpath="/command:$defaultpath" fi fi fi # Find a C compiler to use if test -n "$target" && test x${build} != x${target} ; then cross=${target}- else cross= fi echo "Checking for C compiler..." trycc ${CC} if test -n "$CC_AUTO" ; then b=`basename "$CC"` adjust_cross=false if test "$b" != "$CC" ; then adjust_cross=true echo "$0: warning: compiler $CC is declared with its own path. If it's not accessible via PATH, you will need to pass AR, RANLIB and STRIP make variables to the make invocation." 1>&2 fi if test -n "$cross" ; then if test "$b" = "${b##$cross}" ; then echo "$0: warning: compiler $CC is declared as a cross-compiler for target $target but does not start with prefix ${cross}" 1>&2 elif $adjust_cross ; then cross=`dirname "$CC"`/"$cross" fi fi fi trycc ${cross}gcc trycc ${cross}clang trycc ${cross}cc test -n "$CC_AUTO" || fail "$0: cannot find a C compiler" echo " ... $CC_AUTO" echo "Checking whether C compiler works... " echo "typedef int x;" > "$tmpc" if $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST -c -o /dev/null "$tmpc" 2>"$tmpe" ; then echo " ... yes" else echo " ... no. Compiler output follows:" cat < "$tmpe" exit 1 fi echo "Checking target system type..." if test -z "$target" ; then if test -n "$build" ; then target=$build ; else target=$($CC_AUTO -dumpmachine 2>/dev/null) || target=unknown fi fi echo " ... $target" if $allpic ; then tryflag CPPFLAGS_AUTO -fPIC fi tryflag CFLAGS_AUTO -std=c99 tryflag CFLAGS -fomit-frame-pointer tryflag CFLAGS_AUTO -fno-exceptions tryflag CFLAGS_AUTO -fno-unwind-tables tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables tryflag CFLAGS_AUTO -Wa,--noexecstack tryflag CFLAGS -fno-stack-protector tryflag CPPFLAGS_AUTO -Werror=implicit-function-declaration tryflag CPPFLAGS_AUTO -Werror=implicit-int tryflag CPPFLAGS_AUTO -Werror=pointer-sign tryflag CPPFLAGS_AUTO -Werror=pointer-arith tryflag CPPFLAGS_AUTO -Wno-unused-value tryflag CPPFLAGS_AUTO -Wno-parentheses tryflag CFLAGS_AUTO -ffunction-sections tryflag CFLAGS_AUTO -fdata-sections tryldflag LDFLAGS_AUTO -Wl,--sort-section=alignment tryldflag LDFLAGS_AUTO -Wl,--sort-common if $shared ; then tryldflag LDFLAGS -Wl,--hash-style=both fi rm -f "$tmps" if test -n "$sysdeplist" ; then :> "$tmps" for i in $sysdeplist ; do k=${i%%=*} v=${i#*=} if test "$v" = "true" ; then v=yes elif test "$v" = "false" ; then v=no fi if grep -qF -e "${k}: " "$tmps" ; then grep -vF -e "${k}: " "$tmps" > "$tmpe" mv -f "$tmpe" "$tmps" fi echo "${k}: $v" >> "$tmps" done fi sysdeps=sysdeps.cfg mkdir -p $sysdeps echo "$target" > $sysdeps/target :> "$sysdeps/sysdeps" exec 3>&1 util_lib= echo > $sysdeps/util.lib socket_lib=`trylibs lsock 'accessible socket functions' -lsocket -lnsl` || fail "$0: unable to determine socket.lib sysdep" echo "$socket_lib" > $sysdeps/socket.lib hasclock=yes sysclock_lib=`trylibs clockrt 'clock_gettime()' -lrt` || hasclock=no echo "$sysclock_lib" > $sysdeps/sysclock.lib echo "clockrt: $hasclock" >> $sysdeps/sysdeps 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 "posixspawn: $hasspawn" >> $sysdeps/sysdeps hastimer=yes timer_lib=`trylibs timer 'timer_create()' -lrt` || hastimer=no echo "$timer_lib" > $sysdeps/timer.lib echo "timer: $hastimer" >> $sysdeps/sysdeps exec 3>&- tryendianness trytypes 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()' # And here are the evil irreducible sysdeps. choose clr devurandom '/dev/urandom' rm -f "$tmps" echo "Creating config.mak..." cmdline=$(quote "$0") for i ; do cmdline="$cmdline $(quote "$i")" ; done exec 3>&1 1>config.mak cat << EOF # This file was generated by: # $cmdline # Any changes made here will be lost if configure is re-run. target := $target package := $package prefix := $prefix datadir := $datadir sysdepdir := $sysdepdir dynlibdir := $dynlibdir libdir := $libdir includedir := $includedir sysdeps := $sysdeps version := $version sproot := $sproot home := $home exthome := ${exthome} ipv6 := ${ipv6} SPAWN_LIB := ${spawn_lib} SOCKET_LIB := ${socket_lib} SYSCLOCK_LIB := ${sysclock_lib} TIMER_LIB := ${timer_lib} UTIL_LIB := ${util_lib} CC := ${CC_AUTO} CPPFLAGS_AUTO := $CPPFLAGS_AUTO CPPFLAGS := $CPPFLAGS $CPPFLAGS_POST CFLAGS_AUTO := $CFLAGS_AUTO CFLAGS := $CFLAGS $CFLAGS_POST LDFLAGS_AUTO := $LDFLAGS_AUTO LDFLAGS := $LDFLAGS $LDFLAGS_POST LDFLAGS_NOSHARED := $LDFLAGS_NOSHARED LDFLAGS_SHARED := $LDFLAGS_SHARED CROSS_COMPILE := ${cross} EOF if test -n "$vpaths" ; then echo "vpath lib%a$vpaths" fi if test -n "$vpathd" ; then echo "vpath lib%.so$vpathd" fi if $static ; then echo "STATIC_LIBS := libskarnet.a.xyzzy" else echo "STATIC_LIBS :=" fi if $shared ; then echo "SHARED_LIBS := libskarnet.so.xyzzy" else echo "SHARED_LIBS :=" fi if $allpic ; then echo "STATIC_LIBS_ARE_PIC := 1" else echo "STATIC_LIBS_ARE_PIC :=" fi exec 1>&3 3>&- echo " ... done." echo "Creating src/include/${package}/config.h..." mkdir -p -m 0755 src/include/${package} exec 3>&1 1> src/include/${package}/config.h cat <&3 3>&- echo " ... done." skalibs-2.9.1.0/doc/000077500000000000000000000000001355335115400140635ustar00rootroot00000000000000skalibs-2.9.1.0/doc/crosscompile.html000066400000000000000000000066361355335115400174660ustar00rootroot00000000000000 How to cross-compile skalibs

skalibs
Software
skarnet.org

How to cross-compile skalibs

There are three issues in the world of cross-compilation:

  • support for parallel builds: the source directory must be read-only and each build process must have its own build tree.
  • support for compiler options: to specify the target architecture, the header and library files that should be used, etc.
  • build-time tests performed on the build architecture are invalid if the target architecture is different.

Support for parallel builds

skalibs does not support out-of-tree builds at the moment, but since the source code tree is small, it's not costly to duplicate it to perform parallel builds. If the source code tree grows significantly larger, out-of-tree build support will be considered.

Support for staging

The skalibs Makefile, as well as every other skarnet.org package's Makefile, supports the DESTDIR convention for staging. To install skalibs under a stage fake root:

  • Give the options you need to ./configure. The arguments to the --prefix, --libdir and similar options must be the valid paths for run-time.
  • To install the software, run make install DESTDIR=stage.

Support for build-time options and bypassing target execution tests

skalibs uses a standard ./configure && make && make install process, and cross-compiling build-time options can be given on the ./configure command line.

skalibs performs a certain number of build-time tests, to collect behaviour information on the target architecture. Most of these tests work when cross-compiling, because they only involve characteristics of the target that the cross-toolchain knows at build time; but some actually require code execution on the target, and so they cannot be performed when cross-compiling. For those, you have to manually give a special option to configure, to tell the build system what the behaviour of the target architecture is. The option is of the form --with-sysdep-key=value, where key is the name of the sysdep (i.e. the element of target behaviour that is being tested), and value the associated value, most of the time yes or no.

At all times, ./configure --help provides the list of sysdeps you need to provide a --with-sysdep-* option for. As of skalibs-2.9.0.0, there is only one such sysdep, named devurandom, and the value should be yes if the target has a valid pseudorandom generation device in /dev/urandom, and no otherwise.

skalibs-2.9.1.0/doc/djblegacy.html000066400000000000000000000127521355335115400167040ustar00rootroot00000000000000 skalibs: the djb legacy

skalibs
Software
skarnet.org

The DJB legacy

Who is this DJB guy, and why is he so special anyway ?

Dan J. Bernstein is a cryptologist and a mathematician; he's also the author of a widely known and used MTA, qmail, as well as a few lesser known pieces of software.

For some time he was quite active in some Unix software-related Internet newsgroups and mailing-lists; he quickly became a controversial figure of the Unix programming community, mostly by being extremely vocal against well-known authors of "mainstream" Unix software and by suggesting designs so removed from traditional software design that a normal human reaction is to first view him as a complete nut.

I do not care for controversy. I am interested in the code. I was a sysadmin at the time, and still learning to program in C beyond what they teach you in school (i.e. not much). I had heard enough horror stories with sendmail; so I gave a shot at qmail, trying to understand its design principles and the way it was made. And then I fell down the rabbit hole.

Look, I don't care what you think of the guy, I don't know him anyway, and this is totally beside the point. The only thing that matters is that DJB's software is right in so many ways. This software works. DJB's design principles are sound and elegant; they are sound foundations to build reliable, secure, and low resource-consuming software. And the design, when you get used to it, feels so unix-ish: it's Unix the way it should have been from the start.

Studying DJB's software was the best course in C/Unix programming I ever had. Now I teach C/Unix; and I am really glad I learned from the best.

Building beyond DJB's works.

There's already a lot you can do with pristine DJB software and some brains.

However, I mostly see DJB as a pioneer. He showed it was possible to think Unix differently and build secure, reliable and efficient software without investing millions of dollars into it; now it is up to software architects and programmers to use the breakthrough and build upon it. There's a real demand for quality Unix software out there; it's time to supply. And I am not the only one thinking this way.

So, skalibs.

One of the "DJB philosophy" key points is to question the interfaces. You have a task to do; you have existing interfaces. What do you do?

  • Most people don't even think about it and use the existing interfaces, even if it amounts to cramming a square peg into a round hole. This is why buffer overflows exist. This is why people use abominations such as gets(), which is still in the Single Unix Specification as of version 4, in freaking June 2011. This is why the System V initialization scheme is still prevalent in Linux distributions, despite being one of the slowest and most unreliable of all initialization schemes. This is why people still use the atrocious "libresolv" DNS client library.
  • An alternative way of thinking is to ask yourself: "Is the interface I have adequate for the task at hand?"
    • If yes: perfect, use that interface.
    • If no: then do not use that interface, duh. Design a better one and use it: so the complexity will be split and the code will be easier to maintain.

Interfaces should be questioned right down to the libc. You cannot build strong software on flakey foundations. And from a system and network programmer's point of view, one thing is clear: most standard libc interfaces suck. There is no buffered asynchronous I/O. There is no timed I/O. There is no heap management helper. Even simple system calls are not always guaranteed to succeed!

That is where skalibs comes from. skalibs results from questioning the libc interfaces, and providing replacements or additions where the existing interfaces do not make it easy to write reliable, secure and efficient software. It is inspired by DJB's work. It is not a shrine or anything of the kind.

Conclusion

So, in short, DJB is not a guru, I'm not a mindless brainwashed fan, and the "DJB advocates" are not a cult. We just think DJB brought something to Unix and more generally to the software programming world; we learned from him, we write software following sound principles that he was one of the first to really apply, and we give credit where credit is due.

Use our software. You will never want to go back.

skalibs-2.9.1.0/doc/flags.html000066400000000000000000000204111355335115400160430ustar00rootroot00000000000000 skalibs: configuration flags

skalibs
Software
skarnet.org

skalibs configuration flags

The skalibs ./configure script comes with a few uncommon options; this page explains what they are for.

--enable-slashpackage[=sproot]

This flag tells configure that you want to install skalibs according to the slashpackage convention. If you enable it, and $v is the version of skalibs you're compiling, make install will install the skalibs header files in /package/prog/skalibs-$v/include, the static libraries in /package/prog/skalibs-$v/library, the dynamic libraries in /package/prog/skalibs-$v/library.so and the data files in /package/prog/skalibs-$v/etc, all prefixed by sproot if present.

It will also prepend the default path with /command, unless an explicit default path has been given via the --with-default-path option.

Additionally, it will add two more "make" targets:

  • make update will update the /package/prog/skalibs symbolic link to point to skalibs-$v
  • make -L global-links will make links from /library.so to the installed skalibs shared libraries.

If this option is not given, no slashpackage support will be provided.

--enable-tai-clock

To understand what this flag is about - and the next two flags too - you should start by reading this page about Unix time, which David Madore wrote after a long and fairly complete discussion we had on the subject. You can also read what DJB says about Unix time. Unfortunately, when he says "the POSIX rules are so outrageously dumb (...) that no self-respecting engineer would obey them", DJB is wrong: a lot of people follow the POSIX rules. Or maybe he's right... and there are very, very few self-respecting engineers.

Basically, when you configure a Unix system, there are essentially two ways to deal with your system clock.

  1. You can set your system clock to TAI-10, which is the "right", but uncommon, thing to do:
    • ↑ The main advantage of this setup is that it makes your system clock linear. In other words, gettimeofday() becomes suitable for both timestamping (which needs absolute time) and timeout computations (which need reliable interval measurements); if your clock is accurate enough, it can function as both a wall clock and a stopwatch. This simplifies keeping track of the current time considerably, and makes event loop handling (with functions such as iopause()) trivial.
    • ↑ skalibs uses TAI internally; setting your system clock to TAI-10 saves a lot of conversions and makes time computations with skalibs more efficient.
    • → skalibs-aware software will display GMT or local time properly in every case, but you have to use the right/ timezones, from Arthur David Olson's timezone library, to prevent your other software from being confused by a TAI-10 system clock. If you do not use right/ timezones, utilities such as date will not compute the proper time - they will have an offset of 24 seconds or so.
    • ↓ This setup is arguably not SUSv4 conformant (a strict interpretation of Single Unix requires the system clock to be set to UTC).
    • ↓ This setup is not compatible with ntpd. ntpd's design is flawed: it makes the mistake of setting the system clock itself - instead of simply making the computed time available to other programs, one of which could set the system clock - and it always sets it to UTC. (The s6-networking package provides alternate ways to synchronize your clock, though.)
  2. You can set your system clock to UTC, which is the common, strictly POSIX setup:
    • ↑ This is strictly SUSv4-compliant. Most Unix machines all over the world are set up like this.
    • ↑ This is compatible with ntpd.
    • → You should use posix/ time zones in that case, not right/ time zones.
    • ↓ skalibs time computations will take a bit more processing power.
    • ↓ Most importantly, you forsake all linearity - and even monotonicity - on your system clock, which can now only be used as a wall clock, not as a stopwatch. skalibs will try its best to do accurate time computations, but there's no way gettimeofday() can be relied on when a leap second is nearby; you have to use CLOCK_MONOTONIC as a stopwatch for accurate interval measurement.

Use --enable-tai-clock if your system clock is set to TAI-10. I generally recommend this setup for computers you have full control on, on which you install and tweak the software your way, like manually administered servers or embedded boxes. If you do not run ntpd and do not mind breaking POSIX, it is the sensible choice.

Do not use this option if your system clock is set to UTC, i.e. if you're in none of the above cases: you are a POSIX freak, or your Unix distribution is running ntpd for you, or other software is assuming you're on UTC. This is the default.

--enable-clock

The Open Group Base Specifications, issue 7, describes gettimeofday() as obsolescent, and recommends the use of clock_gettime() with the CLOCK_REALTIME option instead. However:

  • clock_gettime() is not as portable; for instance, Darwin does not have it.
  • On most systems, using the clock_ functions requires linking with librt, which is slightly inconvenient - and silly if all you want is timestamping.

If --enable-clock is set, the tain_now() and tain_setnow() functions for getting and setting time will be based on the clock_gettime() and clock_settime() functions.

Otherwise, the old-school gettimeofday() and settimeofday() interfaces will be used. This is the default, and it's usually safe.

--disable-ipv6

If you set this option, then skalibs will be compiled without IPv6 support, even if your target architecture supports it. This can significantly reduce the size of your networking applications if they don't need IPv6 support.

If you don't set this option, then skalibs will include IPv6 support in the relevant networking functions if and only if the target architecture supports it. This is the default, and it is safe.

--with-default-path=path

The execvep() function uses the value of the PATH environment variable as its executable search path. Specifying this option to configure tells execvep() what executable search path to use when PATH is undefined (which should not happen often anyway). The default is /usr/bin:/usr/sbin:/bin:/sbin, which is usually safe.

skalibs-2.9.1.0/doc/index.html000066400000000000000000000102771355335115400160670ustar00rootroot00000000000000 skalibs: a C library for system programming

Software
skarnet.org

skalibs

What is it ?

skalibs is a package centralizing the free software / open source C development files used for building all software at skarnet.org: it contains essentially general-purpose libraries. You will need to install skalibs if you plan to build skarnet.org software. The point is that you won't have to download and compile big libraries, and care about portability issues, everytime you need to build a package: do it only once.

skalibs can also be used as a sound basic start for C development. There are a lot of general-purpose libraries out there; but if your main goal is to produce small and secure C code with a focus on system programming, skalibs might be for you.


Installation

Requirements

Licensing

skalibs is free software. It is available under the ISC license.

Download

  • The current released version of skalibs is 2.9.1.0.
  • Alternatively, you can checkout a copy of the skalibs git repository:
     git clone git://git.skarnet.org/skalibs 
  • There's also a GitHub mirror of the skalibs git repository.

Compilation

  • See the enclosed INSTALL file for installation details.
  • skalibs sports a few uncommon options to its ./configure script. This page documents them in detail.

Upgrade notes

  • This page lists the differences to be aware of between the previous versions of skalibs and the current one.

Cross-compilation

Cross-compilation is tricky. skalibs provides system-agnostic interfaces, so all the other skarnet.org packages cross-compile easily; but some effort needs to be made to cross-compile skalibs, see this page.


Reference

Libraries


Similar work

Here are a few other libraries originating from the same place as skalibs, i.e. people start to reuse and package, or rewrite, code from Dan J. Bernstein, and then patch after patch, addition after addition, the code evolves into a project of its own:

Related resources

  • skalibs is discussed on the skaware mailing-list.
skalibs-2.9.1.0/doc/libbiguint/000077500000000000000000000000001355335115400162135ustar00rootroot00000000000000skalibs-2.9.1.0/doc/libbiguint/index.html000066400000000000000000000236451355335115400202220ustar00rootroot00000000000000 skalibs: the biguint library interface

libskarnet
skalibs
Software
www.skarnet.org

The biguint library interface

biguint is set of simple primitives performing arithmetical operations on (unsigned) integers of arbitrary length. It is nowhere near as powerful or efficient as specialized, assembly language-optimized libraries such as GMP, but it has the advantages of smallness and simplicity.

Compiling

  • Use #include <skalibs/biguint.h>

Programming

You should refer to the skalibs/biguint.h header for the exact function prototypes.

Definitions

  • A biguint x is a pointer to an array u of uint32_t, together with an unsigned integer n called its length.
    x = (2^32)^0 * u[0] + (2^32)^1 * u[1] + ... + (2^32)^(n-1) * u[n-1].
  • Every u[i] is called a limb.
  • The greatest integer i lesser than n for which u[i] is non-zero is called the order of x. The order of zero is 0.

Basic operations

Creating a biguint

Just declare uint32_t x[n] ; - n being the length of the biguint. You could also allocate x in the heap, possibly using a uint32_t genalloc. In the following, a biguint is always referred to as a uint32_t * with its unsigned int length ; it must always be pre-allocated.

If an operation fails because a biguint's length n is too small to accommodate the result, the function will write the first (i.e. least significant) n limbs of the result, truncating it, then return 0 with errno set to EOVERFLOW.

Setting it to zero

uint32_t *x ;
unsigned int n ;

 bu_zero(x, n) ;

bu_zero() sets the first n limbs of x to zero.

Copying a biguint

uint32_t const *x ;
unsigned int xn ;
uint32_t *y ;
unsigned int yn ;

  bu_copy(y, yn, x, xn) ;

bu_copy() copies x to y, setting higher limbs of y to zero if needed. It then returns 1. If y is too small to contain x, the function returns 0 EOVERFLOW.

Calculating the order

uint32_t const *x ;
unsigned int n ;
unsigned int r ;

  r = bu_len(x, n) ;

bu_len() outputs the order of x of length n. 0 <= r <= n.

Comparing two biguints

uint32_t const *a ;
unsigned int an ;
uint32_t const *b ;
unsigned int bn ;
int r ;

  r = bu_cmp(a, an, b, bn) ;

bu_cmp() returns -1 if a < b, 1 if a > b, and 0 if a = b.

I/O operations

Writing a biguint as an array of bytes

char *s ;
uint32_t const *x ;
unsigned int n ;

  bu_pack(s, x, n) ;
  bu_pack_big(s, x, n) ;

bu_pack() writes 4*n bytes to s. The bytes are a little-endian representation of x.
bu_pack_big() is the same, with a big-endian representation.

Reading a biguint from an array of bytes

char const *s ;
uint32_t *x ;
unsigned int n ;

  bu_unpack(s, x, n) ;
  bu_unpack_big(s, x, n) ;

bu_unpack() reads 4*n little-endian bytes from s and writes them into the corresponding biguint x.
bu_unpack_big() is the same, but the bytes are interpreted as big-endian.

Formatting a biguint for readable output

char *s ;
uint32_t const *x ;
unsigned int n ;

  bu_fmt(s, x, n) ;

bu_fmt() writes x in s as a standard big-endian hexadecimal number. x is considered of length n, so 8*n bytes will be written to s, even if it x starts with zeros. bu_fmt returns the number of bytes written.

Reading a biguint from readable format

char const *s ;
uint32_t *x ;
unsigned int xn ;
unsigned int z ;
unsigned int len ;

  len = bu_scanlen(s, &z) ;
  bu_scan(s, len, x, xn, z) ;

bu_scanlen() scans s for a biguint written as a hexadecimal number and returns the number of bytes read. The reading stops at the first byte encountered that is not in the 0-9, A-F or a-f range. The z integer then contains the number of bytes excluding leading zeros.

If x has not been allocated yet, you can use xn = bitarray_div8(z) (if you have included the bitarray.h header) and allocate x with length xn.

bu_scan() then reads len bytes from s, assuming there are z significant bytes (i.e. not leading zeros); it writes the resulting biguint into x of length xn. It returns 1, except if xn is too small, in which case it returns 0 EOVERFLOW.

Arithmetic operations

Addition

uint32_t const *a ;
unsigned int an ;
uint32_t const *b ;
unsigned int bn ;
uint32_t *c ;
unsigned int cn ;
unsigned char carrybefore ;
unsigned char carryafter ;

  bu_add(c, cn, a, an, b, bn) ;
  bu_sub(c, cn, a, an, b, bn) ;

bu_add() adds a and b, and puts the result into c. It returns 1 unless it has to truncate it.

bu_sub() substracts b from a, and puts the result into c. If the result should be negative, then it is written as (2^32)^cn - c and the function returns 0 EOVERFLOW.

Multiplication

uint32_t const *a ;
unsigned int an ;
uint32_t const *b ;
unsigned int bn ;
uint32_t *c ;
unsigned int cn ;

 bu_mul(c, cn, a, an, b, bn) ;

bu_mul() computes c=a*b. Make sure that cnbu_len(a, an) + bu_len(b, bn). If it is not the case, the result will be truncated and bu_mul will return 0 EOVERFLOW.

Division

uint32_t const *a ;
unsigned int an ;
uint32_t const *b ;
unsigned int bn ;
uint32_t *q ;
unsigned int qn ;
uint32_t *r ;
unsigned int rn ;

 bu_div(a, an, b, bn, q, qn, r, rn) ;
 bu_mod(r, rn, b, bn) ;

bu_div() computes q, the quotient, and r, the remainder, of a divided by b. If b is zero, it returns 0 EDOM. If qn or rn is to small to store the quotient or the remainder, it returns 0 EOVERFLOW. bu_mod() computes only the remainder, and stores it in-place.

GCD

uint32_t *r ;
unsigned int rn ;
uint32_t const *a ;
unsigned int an ;
uint32_t const *b ;
unsigned int bn ;

 bu_gcd(r, rn, a, an, b, bn) ;

bu_gcd() computes the greatest common divisor between a and b, and stores it into r. It returns 1 if all went well.

Note that this function iterates on divisions, so it might use a non totally negligible amount of CPU time.

Left-shifts and right-shifts

uint32_t *x ;
unsigned int xn ;
unsigned char carryafter ;
unsigned char carrybefore ;

 carryafter = bu_slbc(x, xn, carrybefore) ;
 carryafter = bu_srbc(x, xn, carrybefore) ;

bu_slbc() computes x <<= 1. The least significant bit of x is then set to carrybefore. bu_slbc() returns the previous value of x's most significant bit.
bu_srbc() computes x >>= 1. The most significant bit of x is then set to carrybefore. bu_slbc() returns the previous value of x's least significant bit.
bu_slb(x, n) and bu_srb(x, n) are macros for respectively bu_slbc(x, n, 0) and bu_srbc(x, n, 0).

Modular operations

uint32_t const *a ;
unsigned int an ;
uint32_t const *b ;
unsigned int bn ;
uint32_t *c ;
unsigned int cn ;
uint32_t const *m ;
unsigned int mn ;

 bu_addmod(c, cn, a, an, b, bn, m, mn) ;
 bu_submod(c, cn, a, an, b, bn, m, mn) ;
 bu_mulmod(c, cn, a, an, b, bn, m, mn) ;
 bu_divmod(c, cn, a, an, b, bn, m, mn) ;
 bu_invmod(c, cn, m, mn) ;

bu_addmod() computes c = (a+b) mod m.
bu_submod() computes c = (a-b) mod m.
bu_mulmod() computes c = (a*b) mod m.
a and b must already be numbers modulo m.
The functions return 1 if all went well.

bu_divmod() computes a divided by b modulo m and stores it into c.
bu_invmod() computes the inverse of c modulo m and stores it into c.
The divisor and m must be relatively prime, else those functions return 0 EDOM.
The algorithm for modular division and inversion is due to
Sheueling Chang Shantz.

skalibs-2.9.1.0/doc/libdatastruct/000077500000000000000000000000001355335115400167305ustar00rootroot00000000000000skalibs-2.9.1.0/doc/libdatastruct/genqdyn.html000066400000000000000000000112521355335115400212640ustar00rootroot00000000000000 skalibs: the genqdyn library interface

libdatastruct
libskarnet
skalibs
Software
skarnet.org

The genqdyn library interface

The following functions are declared in the skalibs/genqdyn.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

genqdyn is a set of functions implementing simple queues on generic objects. The dyn prefix means the queues are dynamically allocated (and live in heap memory): it is possible to enqueue an arbitrary number of objects, up to the available memory.

Data structures

A genqdyn structure holds the information necessary to implement a queue. It can be declared anywhere (including in the stack). All genqdyn functions take a pointer to this structure as an argument.

Macros

genqdyn GENQDYN_INIT(type, num, den)
Returns an anonymous genqdyn structure suitable for holding objects of type type. The num and den arguments are integers, used to tune the amount of memory needed / management overhead balance. num/den must be a fractional value between 0 and 1. The closer to 0, the longer genqdyn will wait before performing a cleanup (and the more memory it can consume). At 0, genqdyn can only recycle memory when the queue becomes totally empty. The closer to 1, the more genqdyn optimizes its memory usage (and the more often it performs maintenance on its queue). At 1, it performs maintenance every time an object is popped. Anything between 1/4 and 3/4 is a reasonable value for num/den.

size_t genqdyn_n (genqdyn *g)
Returns the number of elements in the genqdyn *g, which must have been initialized.

void *genqdyn_peek (genqdyn *g)
Peeks at the next object in the queue, i.e. the object that has been pushed the earliest and that hasn't been popped yet. You can use the GENQDYN_PEEK(type, g) macro to get a type * pointer instead of a void * one.

Functions

void genqdyn_init (genqdyn *g, size_t esize, unsigned int den, unsigned int den)
Initializes the genqdyn *g to hold objects of size esize. g must be unused, or have been freed. The num and den arguments tune g's behaviour as described above in the GENQDYN_INIT description. This function is similar to the GENQDYN_INIT macro, except that it can be used dynamically and works on a pre-declared genqdyn, whereas the macro can only be used as a static initializer.

void genqdyn_init (genqdyn *g, size_t esize, unsigned int den, unsigned int den)
Initializes the genqdyn *g to hold objects of size esize. g must be unused, or have been freed. The num and den arguments tune g's behaviour as described above in the GENQDYN_INIT description.

void genqdyn_free (genqdyn *g)
Frees the resources used by *g, which is then considered uninitialized.

int genqdyn_push (genqdyn *g, void const *p)
Pushes the object pointed to by p onto the queue. This object must have the same size that has been given to the genqdyn_init() invocation, or be of the same type that has been given to the GENQDYN_INIT() invocation. The function returns 1 if it succeeds and 0 (and sets errno) if it fails.

int genqdyn_unpush (genqdyn *g)
Undoes the last push. Returns 1, except if the queue is empty, in which case it returns 0 and sets errno to EINVAL.

int genqdyn_pop (genqdyn *g)
Pops an object from the queue, and possibly performs maintenance to reuse some memory. Returns 1, unless the queue is empty, in which case it returns 0 and sets errno to EINVAL.

skalibs-2.9.1.0/doc/libdatastruct/index.html000066400000000000000000000027721355335115400207350ustar00rootroot00000000000000 skalibs: the datastruct library interface

libskarnet
skalibs
Software
skarnet.org

The datastruct library interface

libdatastruct implements generic data structures like chained lists and AVL trees, in a memory-efficient and CPU-efficient way.

Compiling

  • Use #include <skalibs/datastruct.h>
  • You can also use the lower-level headers included by skalibs/datastruct.h instead.

Programming

skalibs/datastruct.h is a collection of several headers, each one defining a specific data structure and providing functions to work on it.

  • skalibs/genqdyn.h: dynamically allocated queues for generic objects
  • FIXME: To be completed
skalibs-2.9.1.0/doc/libposixplz/000077500000000000000000000000001355335115400164425ustar00rootroot00000000000000skalibs-2.9.1.0/doc/libposixplz/index.html000066400000000000000000000021601355335115400204360ustar00rootroot00000000000000 skalibs: the posixplz library interface

libskarnet
skalibs
Software
www.skarnet.org

The posixplz library interface

libposixplz is a thin layer of APIs addressing deficencies in POSIX itself.

Compiling

  • The libposixplz functions are available under the skalibs/posixplz.h header.

Programming

  • TODO: describe the functions.
skalibs-2.9.1.0/doc/librandom/000077500000000000000000000000001355335115400160325ustar00rootroot00000000000000skalibs-2.9.1.0/doc/librandom/index.html000066400000000000000000000075451355335115400200420ustar00rootroot00000000000000 skalibs: the random library interface

libskarnet
skalibs
Software
skarnet.org

The random library interface

librandom is a small library designed to provide an interface to some reasonable-quality pseudorandom number generation. librandom uses arc4random when available, or getrandom - else it defaults to /dev/urandom and a a SURF PRNG.

Compiling

  • Use #include <skalibs/random.h>

Programming

You should refer to the skalibs/random.h header for the exact function prototypes.

Basic functions

  unsigned char c ;
  uint32_t max ;
  uint32_t n ;
  size_t b ;
  char data[at least b] ;
  int r ;

  r = random_init() ;
  c = random_char() ;
  n = random_uint32(max) ;
  random_string(data, b) ;
  random_finish() ;

random_init() must be called before any other function in the random library. It returns 0 (and sets errno) on failure, and nonzero on success.

It is recommended that you let the library perform cleanups after you are done using it, by calling random_finish() - unless your process exits right away.

  • random_char() returns a random character.
  • random_uint32(max) returns a random integer between 0 and max-1.
  • random_string(data, b) fills b bytes in data (which must be preallocated) with random data.

Advanced functions

void random_unsort (char *s, unsigned int n, unsigned int chunksize)
Shuffles the array s (of size at least n*chunksize) by performing a random permutation of the n blocks of chunksize bytes. Bytes are not permuted inside chunks.

void random_name (char *s, size_t n)
Writes n random readable ASCII characters into s: letters, numbers, hyphens or underscores. Does not terminate with a null character.

int random_sauniquename (stralloc *sa, unsigned int n)
Appends a (non-null-terminated) unique, unpredictable ASCII name to the stralloc *sa. That name includes n randomly generated ASCII characters.

Notes

  • The random library is a thin wrapper around the best available random generator provided by the underlying system. By decreasing order of preference, it will use the following implementations if available:
  • The random_init() function tries to automatically add some reasonably random data to the underlying random generator's entropy pool. However, that pseudorandom data is not 100% unpredictable, so it will not replace proper seeding of the random generator at boot time.
skalibs-2.9.1.0/doc/libskarnet.html000066400000000000000000000113741355335115400171150ustar00rootroot00000000000000 skalibs: the skarnet library interface

skalibs
Software
skarnet.org

The skarnet library interface

libskarnet is the library exported by skalibs; both a static library and a shared library (if they are supported on your system) are available. Every skarnet.org binary needs this library.

Compiling

  • Make sure the place you installed the skalibs header files in is in your header directory list; the default is /usr/include, which is normally browsed by default by your C preprocessor.
  • Use #include <skalibs/foobar.h> where foobar.h is the header you need.
    • The skalibs/skalibs.h header is the general entry point that will declare the near-entirety of the functions, variables and constants in skalibs. Including this header in your source files whenever you need a skalibs function will work; however, it is rather heavy, and you might want to include lower-level headers instead to reduce compilation time.

Linking

  • For static linking: add /usr/lib/skalibs, or wherever you installed your .a files, to your library directory list.
  • For dynamic linking: make sure the place you installed the libskarnet.so shared library in is in your shared library directory list; the default is /lib, which is normally browsed by default by your build-time and run-time linker. If you are using another place than the default (for instance, if you are using the slashpackage convention), make sure to edit your ld.so.conf file so your linker can find this place, and to run ldconfig if needed.
  • Take note of the place where your sysdeps directory has been installed: by default, it's /usr/lib/skalibs/sysdeps. Let's call it $sysdeps.
  • Link with -lskarnet. If you are using socket functions, you will also need to link with `cat $sysdeps/socket.lib`. If you are using time functions such as tain_now(), you will also need to link with `cat $sysdeps/sysclock.lib`. Also `cat $sysdeps/spawn.lib`` for posix_spawn() functions, timer.lib for timer_create functions, and so on. This is, unfortunately, the only way to work with all the idiosyncrasies and whimsies of various libcs; only musl does the sensible thing and exports all its functions from libc.a and libc.so, without requiring any additional linker command line flags.

The skarnet library as a whole is big (945k for libskarnet.a and 179k for libskarnet.so.2.4.0.0 on x86_64-linux), but the utmost care has been given to separate functions so that linkers never pull in any more than they need. Linking against the static version of libskarnet actually produces very small executables, and if your libc is suited for that, since skalibs only uses very basic libc interfaces, it is very possible to produce small static binaries - in many cases, a static program written with skalibs APIs will be an order of magnitude smaller than the equivalent program written using libc's or other utility libraries' APIs.

Programming

The skalibs source code is divided into several subdirectories, each containing a logical unit of code implementing independent functions.

  • libposixplz: workarounds for some POSIX deficiencies and for systems that don't quite implement POSIX
  • libstddjb: basic C API for system programming
  • libdatastruct: efficient C implementation of basic data structures like sets or trees
  • libstdcrypto: a few crypto primitives
  • librandom: cryptographically secure random or pseudorandom number generation
  • libunixonacid: more advanced C/Unix APIs, mainly for safe asynchronous interprocess communication
  • libbiguint: large integer arithmetic
skalibs-2.9.1.0/doc/libstdcrypto/000077500000000000000000000000001355335115400166055ustar00rootroot00000000000000skalibs-2.9.1.0/doc/libstdcrypto/index.html000066400000000000000000000077061355335115400206140ustar00rootroot00000000000000 skalibs: the stdcrypto library interface

libskarnet
skalibs
Software
skarnet.org

The stdcrypto library interface

stdcrypto is a small collection of standard, public-domain cryptographic primitives. Currently, the following operations are provided:

  • rc4
  • md5
  • sha1
  • sha256
  • sha512

Please bear in mind that rc4 and md5 are broken, and that sha1 is about to be. Do not use them in security-critical applications.

Compiling

  • Use #include <skalibs/stdcrypto.h>

Programming

You should refer to the skalibs/stdcrypto.h header and included headers for the exact function prototypes.

RC4

  RC4Schedule ctx ;
  unsigned char const *key ;
  size_t keylen ;
  unsigned char const *in ;
  unsigned char *out ;
  size_t len ;

  rc4_init(&ctx, key, keylen) ;
  rc4(&ctx, in, out, len) ;
  • rc4_init() initializes a RC4Schedule structure with a key key, of length keylen. It then computes and throws away the first RC4_THROWAWAY bytes, usually 100
  • rc4() encrypts len bytes of in with the RC4 flow, and stores the results into out

MD5

  MD5Schedule ctx ;
  char const *message ;
  size_t messagelen ;
  char digest[16] ;

  md5_init(&ctx) ;
  md5_update(&ctx, message, messagelen) ;
  md5_final(&ctx, digest) ;
  • md5_init() prepares a MD5Schedule structure for computation
  • md5_update() adds message to the message to be digested
  • md5_final() computes the digest

SHA1

  SHA1Schedule ctx ;
  char const *message ;
  size_t messagelen ;
  unsigned char digest[20] ;

  sha1_init(&ctx) ;
  sha1_update(&ctx, message, messagelen) ;
  sha1_final(&ctx, digest) ;
  • sha1_init() prepares a SHA1Schedule structure for computation
  • sha1_update() adds message to the message to be digested
  • sha1_final() computes the digest

SHA256

  SHA256Schedule ctx ;
  char const *message ;
  size_t messagelen ;
  char digest[32] ;

  sha256_init(&ctx) ;
  sha256_update(&ctx, message, messagelen) ;
  sha256_final(&ctx, digest) ;
  • sha256_init() prepares a SHA256Schedule structure for computation
  • sha256_update() adds message to the message to be digested
  • sha256_final() computes the digest

SHA512

  SHA512Schedule ctx ;
  char const *message ;
  size_t messagelen ;
  char digest[64] ;

  sha512_init(&ctx) ;
  sha512_update(&ctx, message, messagelen) ;
  sha512_final(&ctx, digest) ;
  • sha512_init() prepares a SHA512Schedule structure for computation
  • sha512_update() adds message to the message to be digested
  • sha512_final() computes the digest
skalibs-2.9.1.0/doc/libstddjb/000077500000000000000000000000001355335115400160245ustar00rootroot00000000000000skalibs-2.9.1.0/doc/libstddjb/alarm.html000066400000000000000000000066041355335115400200140ustar00rootroot00000000000000 skalibs: the alarm library interface

libstddjb
libskarnet
skalibs
Software
skarnet.org

The alarm library interface

The following functions are declared in the skalibs/alarm.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

alarm is a set of primitives to provide the same functionality as alarm(), but with sub-second precision.

Depending on the functionality the underlying system provides, the precision can be 1 nanosecond (implementation via timer_settime(), 1 microsecond (implementation via setitimer(), or 1 second (fallback implementation with alarm() when nothing better can be found).

Functions

int alarm_milliseconds (unsigned int n)
Sets a fuse that will raise a SIGALRM after n milliseconds. If n is 0, the SIGALRM will be raised instantly. Returns 1 on success and 0 (and sets errno) on failure.

int alarm_timeout (tain_t const *tto)
Sets a fuse that will raise a SIGALRM after some amount of time has passed. The amount of time is described in *tto, which is a relative tain_t, i.e. a structure containing a relative TAIN64 time. Returns 1 on success and 0 (and sets errno) on failure.

int alarm_deadline (tain_t const *deadline)
Sets a fuse that will raise a SIGALRM when the clock reaches *deadline, which is an absolute time expressed in TAI64N format. Returns 1 on success and 0 (and sets errno) on failure.

void alarm_disable (void)
Cancels a previously set fuse. No SIGALRM will be raised.

Notes

  • Asynchronous programming via signals is bad. The best way to handle situations where something happens after some time has elapsed is to use an asynchronous loop primitive such as iopause(). The problem is that some external libraries only provide synchronous functions (including functions talking to the network!) with no obvious way to set a timeout. The alarm_* set of functions is meant to work around that, with hopefully better granularity than the POSIX alarm() function.
skalibs-2.9.1.0/doc/libstddjb/alloc.html000066400000000000000000000073271355335115400200150ustar00rootroot00000000000000 skalibs: the alloc library interface

libstddjb
libskarnet
skalibs
Software
skarnet.org

The alloc library interface

The following functions are declared in the skalibs/alloc.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

alloc is the skalibs heap memory manager. It's actually a wrapper for the malloc() series of functions; it unifies a few system-dependent malloc behaviours. It's also the API to implement and preload if for some reason you need to plug in your own allocator: replacing alloc() is much easier than replacing malloc() safely.

As a general rule, you should not be using the alloc interface directly. Allocating and freeing individual cells in the heap is a recipe for heap fragmentation, as well as cell tracking nightmares leading to memory leaks. You should use the higher-level stralloc and genalloc interfaces to handle dynamic arrays of objects.

C's lack of automatic management of heap memory is not a drawback: it's a feature of the language. It allows for code that is one or two orders of magnitude faster than the equivalent in a higher-level language, and very low on resources consumption. However, it requires more attention from the programmer. Good APIs can significantly reduce the difficulty of keeping track of every heap-allocated cell, and every smart programmer should favor them over basic interfaces like malloc().

alloc is used internally by skalibs to implement stralloc, and nowhere else.

Functions

char *alloc (size_t len)
Allocates a block of len bytes in the heap and returns a pointer to the start of the block (or NULL if it failed). Though the pointer type is char *, the block of memory is correctly aligned for any type of object. If len is 0, the function returns a pointer that cannot be written to, but that is not null. Note that this is different from the required C99 behaviour for malloc().

void alloc_free (void *p)
Frees the block of heap memory pointed to by p.

int alloc_realloc (char **p, size_t newlen)
Redimension the block of heap memory pointed to by *p to newlen bytes. The block may have to be moved, in which case *p will be modified. Normally returns 1; if an error occurred, returns 0 and sets errno, and neither *p nor its contents are modified.

int alloc_re (char **p, size_t oldlen, size_t newlen)
Legacy interface for reallocation. It works like alloc_realloc, except that the original block length must be provided as the oldlen argument.

skalibs-2.9.1.0/doc/libstddjb/allreadwrite.html000066400000000000000000000127251355335115400214000ustar00rootroot00000000000000 skalibs: the allreadwrite library interface

libstddjb
libskarnet
skalibs
Software
skarnet.org

The allreadwrite library interface

The following functions are declared in the skalibs/allreadwrite.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

allreadwrite is a set of IO function helpers. It's the basis for safe reading and writing, either in blocking or in non-blocking mode. The buffer interface relies heavily on allreadwrite.

Unless the IO you need is very simple, you generally should not be using the allreadwrite functions directly; you should use higher-level APIs such as buffer and bufalloc.

Function types

typedef ssize_t iofunc_t (int fd, char *buf, size_t len)
This is the simplified type of IO functions such as read() and write().

typedef size_t alliofunc_t (int fd, char *buf, size_t len)
This is the type of an IO operation that expects all of its len bytes to be sent or received, and that will loop around a lower-level IO function until either len bytes have been transmitted or an error has occurred. The return value is the actual number of transmitted bytes; if this value is lesser than len, it means that an error has occurred and errno is set.

Functions

ssize_t sanitize_read (ssize_t r)
Reading functions such as read() and fd_read return a positive number when they succeed, -1 when they fail, and 0 when they read an EOF. No data available on the descriptor when reading in non-blocking mode is treated as a failure: -1 EWOULDBLOCK. But sometimes (namely, in asynchronous IO loops) it's preferrable to handle EOF as an exception condition and EWOULDBLOCK as a normal condition. sanitize_read(), when applied to the result of a basic reading function, returns 0 if r is -1 and errno is EWOULDBLOCK (or EAGAIN). If r is zero, it returns -1 EPIPE. Else it returns r.

(No system reading function can ever set errno to EPIPE, and the semantics are appropriate, so EPIPE is a good candidate to signal EOF on reading.)

size_t allreadwrite (iofunc_t *f, int fd, char *s, size_t len)
*f must be a basic reading or writing function such as fd_read or fd_write. allreadwrite() performs *f on fd, s and len until len bytes have been read or written, or until an error occurs. It returns the total number of handled bytes, and sets errno if this number is not len. allreadwrite may block if fd is in blocking mode; if fd is in non-blocking mode, it might set errno to EWOULDBLOCK or EAGAIN.

ssize_t fd_read (int fd, char *s, size_t len)
Safe wrapper around the read() function.

ssize_t fd_write (int fd, char const *s, size_t len)
Safe wrapper around the write() function.

ssize_t fd_recv (int fd, char *s, size_t len, unsigned int flags)
Safe wrapper around the recv() function.

ssize_t fd_send (int fd, char const *s, size_t len, unsigned int flags)
Safe wrapper around the send() function.

size_t allread (int fd, char *s, size_t len)
Equivalent to allreadwrite(&fd_read, fd, s, len) : attempts to read len bytes from fd into s, looping around fd_read() if necessary, until either len bytes are read or an error occurs. EOF is reported as EPIPE.

size_t allwrite (int fd, char const *s, size_t len)
Equivalent to allreadwrite((iofunc_t *)&fd_write, fd, s, len) : attempts to write len bytes from s to fd, looping around fd_write() if necessary, until either len bytes are written or an error occurs.

skalibs-2.9.1.0/doc/libstddjb/bitarray.html000066400000000000000000000120311355335115400205240ustar00rootroot00000000000000 skalibs: the bitarray library interface

libstddjb
libskarnet
skalibs
Software
skarnet.org

The bitarray library interface

The following functions are declared in the skalibs/bitarray.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

bitarray is a set of primitives to operate efficiently on large bitfields.

A bitfield is represented by a pre-allocated block of unsigned char; bitarray does not care if that block has been BSS-, stack- or heap-allocated. Bitfields that can grow in size should be stored in a stralloc.

Bits in a bitfield of length n are numbered from 0 to n-1.

Functions

size_t bitarray_div8 (size_t n)
Returns the minimum number of bytes needed to store a field of n bits.

void bitarray_clearsetn (unsigned char *s, size_t start, size_t len, int h)
Sets (if h is nonzero) or clears (if h is zero) len bits in field s, starting at bit start.

void bitarray_clearn (unsigned char *s, size_t start, size_t len)
Clears len bits in field s, starting at bit start.

void bitarray_setn (unsigned char *s, size_t start, size_t len)
Sets len bits in field s, starting at bit start.

int bitarray_peek (unsigned char const *s, size_t n)
Returns the value of the nth bit in field s.

void bitarray_poke (unsigned char *s, size_t n, int h)
Sets (if h is nonzero) or clears (if h is zero) the nth bit in field s.

void bitarray_clear (unsigned char *s, size_t n)
Clears the nth bit in field s.

void bitarray_set (unsigned char *s, size_t n)
Sets the nth bit in field s.

int bitarray_testandpoke (unsigned char *s, size_t n, int h)
Sets (if h is nonzero) or clears (if h is zero) the nth bit in field s, and returns the previous value of that bit.

int bitarray_testandclear (unsigned char *s, size_t n)
Clear the nth bit in field s, and returns the previous value of that bit.

int bitarray_testandset (unsigned char *s, size_t n)
Sets the nth bit in field s, and returns the previous value of that bit.

size_t bitarray_first (unsigned char const *s, size_t len, int h)
Returns the number of the first set (if h is nonzero) or clear (if h is zero) bit in s, len being the total number of bits. If all bits in s are the negation of h, then len is returned.

size_t bitarray_firstclear (unsigned char const *s, size_t len)
Returns the number of the first clear bit in s, len being the total number of bits. If all bits in s are set, len is returned.

size_t bitarray_firstclear_skip (unsigned char const *s, size_t len, size_t skip)
Like bitarray_firstclear, but the first skip bits are ignored: the function cannot return less than skip. It is a programming error if skip > len.

size_t bitarray_firstset (unsigned char const *s, size_t len)
Returns the number of the first set bit in s, len being the total number of bits. If all bits in s are clear, len is returned.

size_t bitarray_firstset_skip (unsigned char const *s, size_t len, size_t skip)
Like bitarray_firstset, but the first skip bits are ignored: the function cannot return less than skip. It is a programming error if skip > len.

size_t bitarray_countones (unsigned char const *s, size_t len)
Returns the number of set bits in s, len being the total number of bits being tested.

skalibs-2.9.1.0/doc/libstddjb/bufalloc.html000066400000000000000000000015751355335115400205110ustar00rootroot00000000000000 skalibs: the bufalloc header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/bufalloc.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/buffer.html000066400000000000000000000015601355335115400201650ustar00rootroot00000000000000 skalibs: the buffer header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/buffer.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/bytestr.html000066400000000000000000000015671355335115400204170ustar00rootroot00000000000000 skalibs: the bytestr header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/bytestr.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/cdb.html000066400000000000000000000015721355335115400174470ustar00rootroot00000000000000 skalibs: the cdb header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/cdb.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/cdb_make.html000066400000000000000000000016161355335115400204430ustar00rootroot00000000000000 skalibs: the cdb_make header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/cdb_make.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/direntry.html000066400000000000000000000016121355335115400205520ustar00rootroot00000000000000 skalibs: the direntry header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/direntry.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/djbtime.html000066400000000000000000000147261355335115400203420ustar00rootroot00000000000000 skalibs: the djbtime library interface

libstddjb
skalibs
skalibs
Software
skarnet.org

The djbtime library interface

The following functions are declared in the skalibs/djbtime.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

djbtime is a set of functions to convert tai_t and tain_t structures, and TAI time, from and to other time formats and user-friendly representations.

Data structures

  • TAI time with 1-second precision is represented as a tai_t.
  • TAI time with more precision is represented as a tain_t.
  • UTC time is represented as an unsigned 64-bit integer equal to 2^62 added to the number of seconds since the Epoch. It's a trivial extension of the standard 32-bit Unix time that will expire in 2038.
  • Broken-down GMT or local time with more than a 1-second precision is stored in a localtmn_t structure, containing a struct tm tm field and an unsigned long nano field.

Functions

UTC

int utc_from_tai (uint64_t *u, tai_t const *t)
Converts the absolute TAI64 time in *t to an UTC time, stored in *u as an unsigned 64-bit integer. *u is actually 2^62 plus the number of seconds since the Epoch. The function returns 1 if it succeeds, or 0 (and sets errno) if an error occurs. If *t happens to hit a leap second, the function returns 2 instead of 1.

int tai_from_utc (tai_t *t, uint64_t u)
Converts the UTC time in u, stored as an unsigned 64-bit integer (2^62 plus the number of seconds since the Epoch), to a TAI64 time in *t. The function returns 1 if it succeeds, or 0 (and sets errno) if an error occurs.

NTP

int ntp_from_tain (uint64_t *ntp, tain_t const *a)
Converts the absolute TAI64N time in *a to a 64-bit NTP timestamp, stored in *ntp. The higher 32 bits of *ntp represent a number of seconds ; the lower 32 bits are the fractional part of the timestamp. The function returns 1 if it succeeds, or 0 (and sets errno) if an error occurs (for instance: *a cannot be represented in the valid NTP range).

int tain_from_ntp (tain_t *a, uint64_t ntp)
Converts the NTP timestamp in ntp to a TAI64N time in *a. The function returns 1 if it succeeds, or 0 (and sets errno) if an error occurs.

Local time

The following functions convert time between an internal representation and a broken-down struct tm. Conversions are performed to get leap seconds handling right, depending on whether skalibs has been configured for a TAI-10 or a UTC system clock, and on whether the current timezone takes leap seconds into account or not.

int localtm_from_tai (struct tm *tm, tai_t const *t, int lo)
Converts the TAI time in *t to broken-down GMT (if lo is zero) or local (if lo is nonzero) time in *tm. The function returns 1 if it succeeds, or 0 (and sets errno) if an error occurs (for instance: *t cannot be validly represented in a struct tm). If *t happens to hit a leap second, the value of tm→tm_sec is 60.

int localtm_from_utc (struct tm *tm, uint64_t u, int lo)
Converts the UTC time in u to broken-down GMT (if lo is zero) or local (if lo is nonzero) time in *tm. The function returns 1 if it succeeds, or 0 (and sets errno) if an error occurs (for instance: u cannot be validly represented in a struct tm).

int localtm_from_sysclock (struct tm *tm, uint64_t u, int lo)
Converts the time in u to broken-down GMT (if lo is zero) or local (if lo is nonzero) time in *tm. u will be interpreted as a TAI-10 value (with --enable-tai-clock) or as a UTC value (without --enable-tai-clock). The function returns 1 if it succeeds, or 0 (and sets errno) if an error occurs (for instance: u cannot be validly represented in a struct tm).

int utc_from_localtm (uint64_t *u, struct tm const *tm)
Converts the broken-down local time in *tm to an UTC value in *u. The function returns 1 if it succeeds, or 0 (and sets errno) if an error occurs.

int tai_from_localtm (tai_t *t, struct tm const *tm)
Converts the broken-down local time in *tm to a TAI value in *t. The function returns 1 if it succeeds, or 0 (and sets errno) if an error occurs.

int sysclock_from_localtm (uint64_t *u, struct tm const *tm)
Converts the broken-down local time in *tm to a value in *u - either TAI-10 or UTC depending on your system clock. The function returns 1 if it succeeds, or 0 (and sets errno) if an error occurs.

The following functions use the localtmn_t type to hold both a broken-down time and a nanosecond count:

typedef struct localtmn_s localtmn_t, *localtmn_t_ref ;
struct localtmn_s
{
  struct tm tm ;
  uint32_t nano ;
} ;

The prototypes are self-explaining:

int localtmn_from_tain (localtmn_t *tmn, tain_t const *a, int lo) ;
int tain_from_localtmn (tain_t *a, localtmn_t const *tmn) ;
int localtmn_from_sysclock (localtmn_t *tmn, tain_t const *a, int lo) ;
int sysclock_from_localtmn (tain_t *a, localtmn_t const *tmn) ;

skalibs-2.9.1.0/doc/libstddjb/djbunix.html000066400000000000000000001000031355335115400203470ustar00rootroot00000000000000 skalibs: the djbunix library interface

libstddjb
libskarnet
skalibs
Software
skarnet.org

The djbunix library interface

The following functions are declared in the skalibs/djbunix.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

djbunix is an alternative API to management of basic Unix concepts: file descriptors, files, environment, and so on. It is a rather chaotic mix of safe wrappers around Unix system calls, better reimplementations of standard libc functionalities, and higher-level manipulations of Unix concepts.

Understanding djbunix is essential to understanding any piece of code depending on skalibs.

Functions

Basic fd operations

int coe (int fd)
Sets the close-on-exec flag on fd. Returns 0 if it succeeds, or -1 (and sets errno) if it fails.

int uncoe (int fd)
Clears the close-on-exec flag on fd. Returns 0 if it succeeds, or -1 (and sets errno) if it fails.

int ndelay_on (int fd)
Sets the O_NONBLOCK flag on fd: sets it to non-blocking mode. Returns 0 if it succeeds, or -1 (and sets errno) if it fails.

int ndelay_off (int fd)
Clears the O_NONBLOCK flag on fd: sets it to blocking mode. Returns 0 if it succeeds, or -1 (and sets errno) if it fails.

int pipenb (int *p)
Like pipe(), but both ends of the created pipe are in non-blocking mode.

int pipecoe (int *p)
Like pipe(), but both ends of the created pipe are close-on-exec.

int pipenbcoe (int *p)
Like pipe(), but both ends of the created pipe are in non-blocking mode and close-on-exec.

int fd_copy (int to, int from)
Copies the open fd from to number to. If to was already open, it is closed before the copy. Returns 0 if it succeeds, or -1 (and sets errno) if it fails.

int fd_copy2 (int to1, int from1, int to2, int from2)
Copies the open fd from1 to number to2. Also copies from2 to to2 at the same time. Returns 0 if it succeeds, or -1 (and sets errno) if it fails.

int fd_move (int to, int from)
Moves the open fd from to number to. If to was already open, it is closed before the move. Returns 0 if it succeeds, or -1 (and sets errno) if it fails.

int fd_move2 (int to1, int from1, int to2, int from2)
Moves the open fd from to number to. Also moves from2 to to2 at the same time. This is useful for instance when you want to swap two fds: fd_move2 will handle the situation correctly. Returns 0 if it succeeds, or -1 (and sets errno) if it fails.

void fd_close (int fd)
Closes fd. This is a safe wrapper around close().

int fd_chmod (int fd, unsigned int mode)
Safe wrapper around fchmod().

int fd_chown (int fd, uid_t uid, gid_t gid)
Safe wrapper around fchown(). This function requires root privileges.

int fd_sync (int fd)
Safe wrapper around fsync().

int fd_chdir (int fd)
Safe wrapper around fchdir().

int fd_cat (int from, int to)
Synchronously copies data from fd from to fd to, until it encounters EOF or an error. Returns -1 (and sets errno) if it fails; returns the number of transmitted bytes if it gets an EOF.

When the underlying OS allows it, zero-copy transmission is performed. Currently, the following zero-copy implementations are supported:

size_t fd_catn (int from, int to, size_t n)
Synchronously copies at most n bytes from fd from to fd to. Returns the total number of transmitted bytes; sets errno if this number is lesser than n. EOF is reported as EPIPE. See above for zero-copy transmission; zero-copy transmission is not attempted for less than 64k of data.

int fd_ensure_open (int fd, int w)
If fd is not open, opens it to /dev/null, for reading if w is zero, and for writing otherwise. Returns 1 if it succeeds and 0 if it fails.

int fd_sanitize (void)
Ensures stdin, stdout and stderr are open. If one of those file descriptors was closed, it now points to /dev/null. Returns 1 if it succeeds and 0 if it fails.

int lock_ex (int fd)
Gets an exclusive advisory lock on fd. fd must point to a regular file, open for writing. Blocks until the lock can be obtained. Returns 0 if it succeeds, or -1 (and sets errno) if it fails.

int lock_exnb (int fd)
Gets an exclusive advisory lock on fd. fd must point to a regular file, open for writing. Returns 0 if it succeeds, or -1 (and sets errno) if it fails. If the lock is held and the function would block, it immediately returns with -1 EWOULDBLOCK.

int lock_sh (int fd)
Gets a shared advisory lock on fd. fd must point to a regular file, open for reading. Blocks until the lock can be obtained. Returns 0 if it succeeds, or -1 (and sets errno) if it fails.

int lock_shnb (int fd)
Gets a shared advisory lock on fd. fd must point to a regular file, open for reading. Returns 0 if it succeeds, or -1 (and sets errno) if it fails. If the lock is held and the function would block, it immediately returns with -1 EWOULDBLOCK.

int lock_un (int fd)
Releases a previously held lock on fd. Returns 0 if it succeeds, or -1 (and sets errno) if it fails.

void lock_unx (int fd)
Like lock_un, but without a return code and without modifying errno.

int open2 (char const *file, unsigned int flags)
Safe wrapper around open() when it takes 2 arguments.

int open3 (char const *file, unsigned int flags)
Safe wrapper around open() when it takes 3 arguments.

int open_read (char const *file)
Opens file in read-only, non-blocking mode. Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.

int openb_read (char const *file)
Opens file in read-only, blocking mode. Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.

int open_readb (char const *file)
Opens file in read-only, blocking mode. Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails. This call does not block. The open() system call is actually performed with the O_NONBLOCK option, and blocking mode is set afterwards; this behaviour allows for more transparent interactions with FIFOs.

int open_excl (char const *file)
Opens file in write-only, non-blocking mode, with the additional O_EXCL and O_CREAT flags. Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.

int open_append (char const *file)
Opens file in write-only, non-blocking mode, with the additional O_APPEND and O_CREAT flags. Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.

int open_trunc (char const *file)
Opens file in write-only, non-blocking mode, with the additional O_TRUNC and O_CREAT flags. Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.

int open_create (char const *file)
Opens file in write-only, non-blocking mode, with the additional O_CREAT flag. Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.

int open_write (char const *file)
Opens file in write-only, non-blocking mode. Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.

Executable search and execution, and environment

void execvep_loose (char const *file, char const *const *argv, char const *const *envp, char const *path)
Executes into the executable file at file, with the command line set to argv and the environment set to envp. If file is not an absolute path, it is searched in the path string, which must contain a colon-separated list of search directories such as the contents of the PATH environment variable. The function returns if it fails, and sets errno to the most relevant error that happened.

void execvep (char const *file, char const *const *argv, char const *const *envp, char const *path)
Like execvep_loose(), but if file contains a slash, it is treated as an absolute path.

void pathexec_run (char const *file, char const *const *argv, char const *const *envp)
Performs execvep(file, argv, envp, path), path being the contents of the PATH environment variable. If PATH is not set, path is set to the value given to the --with-default-path option of the skalibs' ./configure script, or to /usr/bin:/bin by default. The function returns if it fails, and sets errno appropriately.

pathexec_run() is the standard skalibs API to perform an exec call with a path search. It is recommended that you use it instead of the Single Unix execvp() or execlp() functions, because execvp and execlp default to execution of the /bin/sh interpreter with file as an argument if they cannot find a suitable executable file, and this is:

  1. a security risk,
  2. probably not what you want.

execvep() and pathexec_run() just fail with ENOENT when they cannot find a file to exec into, which is the sensible behaviour.

void pathexec0_run (char const *const *argv, char const *const *envp)
Performs pathexec_run(argv[0], argv, envp). If argv is empty, i.e. argv[0] is null, the process exits 0 instead. Rationale: executing the empty command line should amount to executing true, i.e. simply exiting 0.

void pathexec_r_name (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen)
Alters envp (which does not have to be NULL-terminated, but the number envlen of elements must be provided) with the modifier string modifs of length modiflen, then performs pathexec_run(file, argv, altered-envp).

void pathexec_r (char const *const *argv, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen)
Same as pathexec_r_name, except that the file argument is read from argv[0].

int pathexec_env (char const *var, char const *value)
Adds the "add variable var with value value" instruction (if value is not null) or the "unset var" instruction (if value is null) to a static hidden modifier string, used by the following three functions. Returns 1 if it succeeds and 0 (and sets errno) if it fails.

void pathexec_fromenv (char const *const *argv, char const *const *envp, size_t envlen)
Performs pathexec_r() with the given arguments and the hidden modifier string.

void pathexec (char const *const *argv)
Executes into the argv command line, with the current environment modified by the hidden modifier string.

void pathexec0 (char const *const *argv)
Executes into the argv command line, with the current environment modified by the hidden modifier string. If this command line is empty, exit 0 instead.

void xexecvep (char const *, char const *const *, char const *const *, char const *)
void xpathexec_r (char const *const *, char const *const *, size_t, char const *, size_t)
void xpathexec_r_name (char const *, char const *const *, char const *const *, size_t, char const *, size_t)
void xpathexec_fromenv (char const *const *, char const *const *, size_t)
void xpathexec_run (char const *, char const *const *, char const *const *)
void xpathexec0_run (char const *const *, char const *const *)
void xpathexec (char const *const *)
void xpathexec0 (char const *const *)

Those functions provide the same functionality as the non-x-prefixed versions, but if the execution fails (i.e. the process cannot exec into a new program), then the process dies with a 111 exit code and an error message on stderr.

The env library interface provides additional functions to manipulate modifier strings and environments.

Forking children

pid_t doublefork ()
Performs a double fork. Returns -1 if it fails (and sets errno, EINTR meaning that the intermediate process was killed by a signal), 0 if the current process is the grandchild, and the grandchild's PID if the current process is the parent.

pid_t child_spawn0 (char const *file, char const *const *argv, char const *const *envp)
Forks and executes a child as with pathexec_run(file, argv, envp). Returns 0 if it fails, and the pid of the child if it succeeds. Implemented via posix_spawn() on systems that support it.

pid_t child_spawn1_pipe (char const *file, char const *const *argv, char const *const *envp, int *fd, int w)
Like child_spawn0(), except that a pipe is created between the child's stdin (if w is 0) or stdout (if w is nonzero) and the parent. The parent's end of the pipe will be stored in *fd.

pid_t child_spawn1_socket (char const *file, char const *const *argv, char const *const *envp, int *fd)
Like child_spawn0, except that a socket is created between the parent and the child. Both the child's stdin and stdout point to the socket; the parent has its end of the socket available in *fd.

pid_t child_spawn2 (char const *file, char const *const *argv, char const *const *envp, int *fds)
Like child_spawn0(), except that two pipes are created between the parent and the child. fds must point to an array of 2 ints: this array is read as well as written by child_spawn2(). On function call, the numbers in fds must describe what fds should be used in the child to contain the communication pipes (for instance, if the child will read from its parent on stdin and writes to its parent on stdout, fds must contain 0 and 1). On function return, fds contains the descriptors for the pipes that read from / write to the child.

pid_t child_spawn (char const *file, char const *const *argv, char const *const *envp, int *fds, unsigned int nfds)
More generic spawning function. fds must point to an array of at least nfds ints; file descriptors reading from or writing to the child will be stored there. The function returns 0 on failure or the pid of the child on success.

  • If nfds is 0, then the function behaves like child_spawn0, except all ignored signals will be un-ignored in the child
  • If nfds is 1 or more, then fds will contain pipes between the child and the parent. The parent will read on even-numbered ones (starting on fds[0]) and write on odd-numbered ones.

Waiting for children

unsigned int wait_reap ()
Instantly reaps all the pending zombies, without blocking, without a look at the exit codes. Returns the number of reaped zombies.

int waitn (pid_t *pids, unsigned int n)
Waits until all processes whose PIDs are stored in the pids array, of size n, have died. Returns 1 if it succeeds, and 0 (and sets errno) if it fails. The pid array is not guaranteed to be unchanged.

int waitn_reap (pid_t *pids, unsigned int n)
Instantly reaps all zombies whose PIDs are stored in the pids array, of size n. Returns -1 (and sets errno) if it fails, and the number of reaped zombies if it succeeds. The pid array is not guaranteed to be unchanged.

pid_t wait_nohang (int *wstat)
Instantly reaps one zombie, and stores the status information into *wstat. Returns the PID of the reaped zombie if it succeeds, 0 if there was nothing to reap (and the current process still has children), -1 ECHILD if there was nothing to reap (and the current process has no children), or -1 (and sets errno) if it fails.

pid_t waitpid_nointr (pid_t pid, int *wstat, int flags)
Safe wrapper around waitpid().

pid_t wait_pid_nohang (pid_t pid, int *wstat)
Instantly reaps an undetermined number of zombies until it finds pid. Stores the status information for dead pid into *wstat. Returns pid if it succeeds, 0 if there was nothing to reap (and the current process still has children), -1 ECHILD if there was nothing to reap (and the current process has no children), or -1 (and sets errno) if it fails.

int wait_pids_nohang (pid_t const *pids, unsigned int len, int *wstat)
Instantly reaps an undetermined number of zombies until it finds one whose PID is in the pids array, of size len. Stores the status information for that dead process into *wstat. Returns the index of the found PID in pids, starting at 1. Returns 0 if there was nothing to reap (and the current process still has children), -1 ECHILD if there was nothing to reap (and the current process has no children), or -1 (and sets errno) if it fails.

When asynchronously dealing with a child (resp. several children) and getting a SIGCHLD - which should be handled via a selfpipe - it is generally a good idea to use the wait_pid_nohang() (resp. wait_pids_nohang()) function over the basic Unix APIs. This allows a program to:

  • Automatically and silently take care of children it does not know it has. This situation can happen when a process forks and the parent execs. When the child dies, the new parent process has to drag the "zombie bastard" along, which is ugly; wait_pids_nohang() prevents this.
  • Still take appropriate care of its legitimate children, in any order.

Reading and writing whole files

int slurp (stralloc *sa, int fd)
Slurps the contents of open descriptor fd into the *sa stralloc. If you are doing this, you should either have full control over the slurped file, or run your process with suitable limits to the amount of heap memory it can get. The function returns 1 if it succeeds, or 0 (and sets errno) if it fails.

int openslurpclose (stralloc *sa, char const *file)
Slurps the contents of file file into *sa. Returns 1 if it succeeds, and 0 (and sets errno) if it fails.

ssize_t openreadnclose (char const *file, char *s, size_t n)
Reads at most n bytes from file file into preallocated buffer s. Returns -1 (and sets errno) if it fails; else returns the number of read bytes. If that number is not n, errno is set to EPIPE.

ssize_t openreadnclose_nb (char const *file, char *s, size_t n)
Like openreadnclose, but can fail with EAGAIN if the file cannot be immediately read (for instance if it's a named pipe or other special file).

int openreadfileclose (char const *file, stralloc *sa, size_t n)
Reads at most n bytes from file file into the *sa stralloc, which is grown (if needed) to just accommodate the file size. Returns 1 if it succeeds and 0 (and sets errno) if it fails.

int openwritenclose_unsafe_internal (char const *file, char const *s, size_t len, dev_t *dev, ino_t *ino, int dosync)
Writes the n bytes stored at s into file file. The previous contents of file are destroyed even if the function fails. If dosync is nonzero, the new contents of file are synced to disk before the function returns. If dev and ino are not null, they're used to store the device and inode number of file. The function returns 1 if it succeeds, or 0 (and sets errno) if it fails.

int openwritenclose_unsafe (char const *file, char const *s, size_t len)
int openwritenclose_unsafe_sync (char const *file, char const *s, size_t len)
int openwritenclose_unsafe_devino (char const *file, char const *s, size_t len, dev_t *dev, ino_t *ino)
int openwritenclose_unsafe_devino_sync (char const *file, char const *s, size_t len, dev_t *dev, ino_t *ino)

Trivial shortcuts around openwritenclose_unsafe_internal(). The reader can easily figure out what they do.

int openwritenclose_suffix_internal (char const *file, char const *s, size_t len, dev_t *dev, ino_t *ino, int dosync, char const *suffix)
Writes the n bytes stored at s into file file, by first writing into filesuffix and atomically renaming filesuffix to file. IOW, the old contents of file are preserved if the operation fails, and are atomically replaced with the new contents if the operation succeeds. If dosync is nonzero, the new contents of filesuffix are synced to disk before the atomic replace. If dev and ino are not null, they're used to store the device and inode number of file. The function returns 1 if it succeeds, or 0 (and sets errno) if it fails.

int openwritenclose_suffix (char const *file, char const *s, size_t len, char const *suffix)
int openwritenclose_suffix_sync (char const *file, char const *s, size_t len, char const *suffix)
int openwritenclose_suffix_devino (char const *file, char const *s, size_t len, dev_t *dev, ino_t *ino, char const *suffix)
int openwritenclose_suffix_devino_sync (char const *file, char const *s, size_t len, dev_t *dev, ino_t *ino, char const *suffix)

Trivial shortcuts around openwritenclose_suffix_internal(). The reader can easily figure out what they do.

int openwritevnclose_unsafe_internal (char const *file, struct iovec const *v, unsigned int vlen, dev_t *dev, ino_t *ino, int dosync)
Like openwritenclose_unsafe_internal, but the content to write is taken from a scatter/gather array of vlen elements instead of a single string.

int openwritevnclose_unsafe (char const *file, struct iovec const *v, unsigned int vlen)
int openwritevnclose_unsafe_sync (char const *file, struct iovec const *v, unsigned int vlen)
int openwritevnclose_unsafe_devino (char const *file, struct iovec const *v, unsigned int vlen, dev_t *dev, ino_t *ino)
int openwritevnclose_unsafe_devino_sync (char const *file, struct iovec const *v, unsigned int vlen, dev_t *dev, ino_t *ino)

Trivial wrappers around openwritevnclose_unsafe_internal().

int openwritevnclose_suffix_internal (char const *file, struct iovec const *v, unsigned int vlen, dev_t *dev, ino_t *ino, int dosync, char const *suffix)
Like openwritenclose_suffix_internal, but the content to write is taken from a scatter/gather array of vlen elements instead of a single string.

int openwritenclose_suffix (char const *file, char const *s, size_t len, char const *suffix)
int openwritenclose_suffix_sync (char const *file, char const *s, size_t len, char const *suffix)
int openwritenclose_suffix_devino (char const *file, char const *s, size_t len, dev_t *dev, ino_t *ino, char const *suffix)
int openwritenclose_suffix_devino_sync (char const *file, char const *s, size_t len, dev_t *dev, ino_t *ino, char const *suffix)

Trivial wrappers around openwritevnclose_suffix_internal().

Filesystem deletion

The following operations are not atomic, so if they fail, the relevant subtree might end up partially deleted.

int rm_rf (char const *path)
Deletes the filesystem subtree at path. Returns 0 if it succeeds or -1 (and sets errno) if it fails.

int rm_rf_tmp (char const *path, stralloc *tmp)
Deletes the filesystem subtree at path, using *tmp as heap-allocated temporary space. Returns 0 if it succeeds or -1 (and sets errno) if it fails.

int rm_rf_in_tmp (stralloc *tmp, size_t n)
Deletes a filesystem subtree, using *tmp as heap-allocated temporary space. Returns 0 if it succeeds or -1 (and sets errno) if it fails. When the function is called, *tmp must contain the null-terminated name of the subtree to delete at offset n.

int rmstar (char const *dir)
Deletes all the filesystem subtrees in directory dir. Returns 0 if it succeeds or -1 (and sets errno) if it fails.

int rmstar_tmp (char const *dir, stralloc *tmp)
Deletes all the filesystem subtrees in directory dir, using *tmp as heap-allocated temporary space. Returns 0 if it succeeds or -1 (and sets errno) if it fails.

Filesystem copy

int hiercopy_tmp (char const *src, char const *dst, stralloc *tmp)
Recursively copies the filesystem hierarchy at src into dst, preserving modes, and also preserving the uids/gids if the process is running as the super-user. Uses *tmp as heap-allocated temporary space. Returns 1 if it succeeds or 0 (and sets errno) if it fails.

int hiercopy (char const *src, char const *dst)
Same as above, using the satmp global stralloc as heap-allocated temporary space.

Variable length wrappers around Single Unix calls

int sarealpath (stralloc *sa, char const *path)
Resolves path into a symlink-free absolute path, appending the result to the *sa stralloc. Returns 0 if it succeeds and -1 (and sets errno) if it fails.

int sarealpath_tmp (stralloc *sa, char const *path, stralloc *tmp)
Resolves path into a symlink-free absolute path, appending the result to *sa. Uses *tmp as heap-allocated temporary space. Returns 0 if it succeeds and -1 (and sets errno) if it fails.

int sabasename (stralloc *sa, char const *s, size_t len)
Appends the basename of filename s (of length len) to *sa. Returns 1 if it succeeds and 0 (and sets errno) if it fails.

int sadirname (stralloc *sa, char const *s, size_t len)
Appends the dirname of filename s (of length len) to *sa. Returns 1 if it succeeds and 0 (and sets errno) if it fails.

int sagetcwd (stralloc *sa)
Appends the current working directory to *sa. Returns 0 if it succeeds and -1 (and sets errno) if it fails.

int sareadlink (stralloc *sa, char const *link)
Appends the contents of symbolic link link to *sa. Returns 0 if it succeeds and -1 (and sets errno) if it fails.

int sagethostname (stralloc *sa)
Appends the machine's hostname to *sa. Returns 0 if it succeeds and -1 (and sets errno) if it fails.

Temporization

void deepsleepuntil (tain_t const *deadline, tain_t *stamp)
Sleeps until the absolute time represented by the tain_t *deadline. *stamp must contain the current time. When the function returns, *stamp has been updated to reflect the new current time.

void deepsleep (unsigned int n)
Sleeps n seconds. Signals received during that time are handled, but do not interrupt the sleep.

void deepmillisleep (unsigned long n)
Sleeps n milliseconds. Signals received during that time are handled, but do not interrupt the sleep.

Miscellaneous functions

size_t path_canonicalize (char *out, char const *in, int check)
Writes into out the canonical form of the Unix path given in in. The out array must be preallocated with at least strlen(in)+2 bytes. Returns the length of the out path, without counting the terminating null byte. If check is nonzero, in is tested for every foobar/.. element, and the function returns 0, and sets errno appropriately, if foobar is not a valid directory; in that case, out contains the problematic path.

skalibs-2.9.1.0/doc/libstddjb/env.html000066400000000000000000000015571355335115400175120ustar00rootroot00000000000000 skalibs: the env header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/env.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/envalloc.html000066400000000000000000000016311355335115400205160ustar00rootroot00000000000000 skalibs: the envalloc header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/envalloc.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/fmtscan.html000066400000000000000000000015751355335115400203550ustar00rootroot00000000000000 skalibs: the fmtscan header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/fmtscan.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/gccattributes.html000066400000000000000000000025711355335115400215620ustar00rootroot00000000000000 skalibs: the gccattributes header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/gccattributes.h header

skalibs/gccattributes.h is a set of wrappers around gcc attributes (duh). It defines macros that are always valid, and that have no effect if the compiler is not gcc or the used version of gcc does not support the wanted attribute.

For instance:

 extern size_t str_len (char const *) gccattr_pure ;

defines the str_len function as pure if it is supported.

The source code is self-explanatory.

skalibs-2.9.1.0/doc/libstddjb/genalloc.html000066400000000000000000000027271355335115400205060ustar00rootroot00000000000000 skalibs: the genalloc library interface

libstddjb
libskarnet
skalibs
Software
skarnet.org

The genalloc library interface

The following functions are declared in the skalibs/genalloc.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

genalloc is the skalibs way of handling dynamic arrays, i.e. dynamically growing arrays of fixed-size objects. Any array that needs to be stored in heap memory can be implemented via genalloc.

Most genalloc functions are just macro calls around stralloc functions.

The genalloc.h header is actually very simple and the prototypes there are self-explaining.

skalibs-2.9.1.0/doc/libstddjb/genwrite.html000066400000000000000000000066121355335115400205430ustar00rootroot00000000000000 skalibs: the genwrite library interface

libstddjb
libskarnet
skalibs
Software
skarnet.org

The genwrite library interface

The following functions are declared in the skalibs/genwrite.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

genwrite is syntactic sugar to help write functions that might want to write either to memory or to a file descriptor.

Writing to memory is achieved via appending to a stralloc; writing to a file descriptor is achieved via appending to a buffer or a bufalloc.

Usage

A genwrite_t structure contains a pointer to a function that writes stuff to the target without flushing it (which can be genwrite_put_stralloc, genwrite_put_buffer, genwrite_put_bufalloc or any compatible user-defined function) in .put, a pointer to a function that flushes the target (which can be genwrite_flush_stralloc, genwrite_flush_buffer, genwrite_flush_bufalloc or any compatible user-defined function) in .flush, and a pointer to the target writing structure in .target.

Users should define a genwrite_t first, using the provided functions, and give applications a pointer gp to this structure. To write len characters at position s to the target, the application should then call (*gp->put)(gp->target, s, len). When it is done writing, the application should call (*gp->flush)(gp->target) to flush the output.

genwrite_stdout and genwrite_stderr are predefined; they write to buffer_1 and buffer_2 respectively.

Macros

GENWRITE_STRALLOC_INIT(sa)
Declares a genwrite_t writing to the stralloc *sa.

GENWRITE_BUFFER_INIT(b)
Declares a genwrite_t writing to the buffer *b. Use of such a buffer might interact badly with nonblocking I/O.

GENWRITE_BUFALLOC_INIT(ba)
Declares a genwrite_t writing to the bufalloc *ba.

Note

Object-oriented programming in C is inefficient and cumbersome. It is usually possible to avoid it in Unix system programming, because Unix primitives are often generic enough. Unfortunately, it is not the case here: Unix does not provide an abstraction representing either a file or a memory buffer. So an object-oriented approach is unavoidable.

skalibs-2.9.1.0/doc/libstddjb/getpeereid.html000066400000000000000000000015601355335115400210310ustar00rootroot00000000000000 skalibs: the getpeereid header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/getpeereid.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/index.html000066400000000000000000000161671355335115400200340ustar00rootroot00000000000000 skalibs: the stddjb library interface

libskarnet
skalibs
Software
www.skarnet.org

The stddjb library interface

libstddjb is the base, and the most important part, of skalibs. It is a set of general-purpose C functions wrapping some system calls, hiding some Unix portability problems, providing some basic low-level buffering functions and string handling, and generally offering a nice API to Unix programming - in many ways nicer and safer than the "standard" Unix APIs like stdio.h.

It is mostly based on some excellent code written and placed into the public domain by D. J. Bernstein.

Compiling

  • The libstddjb functions are available under the skalibs/stddjb.h header, which includes a lot of lower-level headers. If you know what lower-level headers to use, you might speed up your compilation process by including them directly.

Programming

The following headers are automatically generated at compile-time, when the headers subsystem is made. The skalibs/stddjb.h file also includes them.

  • skalibs/uint16.h: operations with 16-bit unsigned integers
  • skalibs/uint32.h: operations with 32-bit unsigned integers
  • skalibs/uint64.h: operations with 64-bit unsigned integers
  • skalibs/types.h: portable helpers for common Unix types: size_t, uid_t, gid_t, pid_t, time_t, dev_t and ino_t.
  • skalibs/error.h: portable macros for errno management
  • skalibs/setgroups.h: stub for the setgroups() function, for systems that do not define it
  • skalibs/ip46.h: IPv4/IPv6 abstraction layer

Additionally, stddjb.h also includes the following headers, which are not associated with any code and are mostly self-explanatory:

  • skalibs/gccattributes.h: wrappers around a few GCC-specific optimizations
  • skalibs/diuint.h: for associative arrays of unsigned integers
  • skalibs/diuint32.h: for associative arrays of 32-bit unsigned integers
  • skalibs/disize.h: for associative arrays of size_t
  • skalibs/environ.h: declaration of the environ variable
  • skalibs/nsig.h: the number of system signals, for systems that do not define it
  • skalibs/nonposix.h: feature test macros for non-POSIX-compliant systems
skalibs-2.9.1.0/doc/libstddjb/iobuffer.html000066400000000000000000000016151355335115400205160ustar00rootroot00000000000000 skalibs: the iobuffer header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/iobuffer.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/iopause.html000066400000000000000000000213311355335115400203570ustar00rootroot00000000000000 skalibs: the iopause library interface

libstddjb
libskarnet
skalibs
Software
skarnet.org

The iopause library interface

The following functions are declared in the skalibs/iopause.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

iopause is the skalibs API for event loop selection. It's a wrapper around the system's ppoll() or poll() (if available) or select() (if neither ppoll() n or poll() is available) function. It works around some system-dependent quirks; also it works with absolute dates instead of timeouts. This is a good thing: see below.

iopause is a derived work from Dan J. Bernstein's iopause library, but the skalibs implementation is subtly different.

Data structures

An iopause_fd structure is similar to a struct pollfd structure, and must be filled the same way. Usually, the user declares an array of iopause_fd and fills it, one element per descriptor to select on. If x is an iopause_fd:

  • x.fd must be set to the fd number to select on.
  • x.events must be a disjunction of the following flags:
    • IOPAUSE_READ if the fd is to be selected for reading.
    • IOPAUSE_WRITE if the fd is to be selected for writing.
  • When the selection function returns, x.revents contains a disjunction of the following flags:
    • IOPAUSE_READ if the fd is readable (this includes reception of an EOF).
    • IOPAUSE_WRITE if the fd is writable.
    • IOPAUSE_EXCEPT if an exception (such as EOF or an error) occurred on the fd.

Unlike poll() or select(), which use a timeout argument, the iopause() function uses a deadline argument, i.e. an absolute time at which it must return 0 if no event has happened so far, as well as a stamp argument, i.e. an absolute time meaning now. Those arguments are stored in tain_ts. Here is why:

The event loop pattern is mostly used to multiplex several asynchronous events that can happen independently, at the same time or not. Let's say you have 3 events, x, y and z. Each of those has a separate timeout: if x happens before x-timeout milliseconds, you call the x-event-handler function, but if x-timeout milliseconds elapse without x happening, you call x-timeout-handler function. And similarly with y and z.

But the selection function returning does not mean x has happened or that x has timed out. It might also mean that y has happened, that y has timed out, that z has happened, that z has timed out, or something else entirely. In the post-selection part of the loop, the proper handler is called for the event or timeout that has happened; then the loop is executed again, and in the pre-selection part of the loop, the array describing the events is filled, and the selection timeout is computed.

How are you going to compute that global selection timeout? Easy: it's the shortest of the three. But we just spent some amount of time waiting, so the individual timeouts must be recomputed! This means:

  • You need a way to know the time spent in a selection primitive, which basically means getting a timestamp before the selection and once again after the timestamp.
  • You need to recompute every individual timeout everytime you enter the loop.

That is really cumbersome. A much simpler way of doing things is:

  • Always keep a reasonably accurate estimation of the current time in a stamp variable. That means getting the current time at the start of the process, and updating it right after any action that takes a significant amount of time. When to update stamp can be difficult to estimate in CPU-bound processes; fortunately, most processes using an event loop are IO-bound, and the only actions that take a non-negligible amount of time in an IO-bound process are the blocking primitives. So, stamp must be updated right after a selection function returns, and if the program has been correctly written and cannot block anywhere else, it's the only place where it needs to be.
  • For every event, compute the deadline of that event: x-deadline is x-timeout added to the current stamp value when x enters the loop. This is done only once per event: you never have to recompute event deadlines - unlike timeouts, which diminish over time, deadlines do not change.
  • At every iteration, the selection deadline is the earliest of all the available event deadlines.
  • As an added bonus: after the selection function returns and stamp has been updated, it is easy to check which events have timed out and which have not: x has timed out iff x-deadline is earlier than stamp.

Maintaining a global timestamp and using absolute times instead of relative times really is the right way to work with event loops, and the iopause interface reflects that. Of course, you need a reliable, bug-free time library and a monotonic, constant system clock to handle absolute times correctly; that is why iopause relies on the tai library.

Functions

int iopause (iopause_fd *x, unsigned int len, tain_t const *deadline, tain_t const *stamp)
Blocks until one of the events described in the x array, of length len, happens, or until the absolute date *deadline is reached. deadline may be null, in which case the function blocks indefinitely until an event happens. If deadline is not null, then stamp must not be null, and must contain an accurate estimation of the current time. The function returns the number of events that have happened, 0 for a timeout, or -1 (and sets errno) for an error.

int iopause_stamp (iopause_fd *x, unsigned int len, tain_t const *deadline, tain_t *stamp)
Like iopause(), but if stamp is not null, it is updated right before the function returns. This helps the user always keep a reasonably accurate estimation of the current time in stamp; it is recommended to use this function instead of the lower-level iopause().

Underlying implementations

iopause is an alias to one of iopause_ppoll, iopause_poll or iopause_select. It is always aliased to iopause_ppoll if the ppoll() function is available on the system; else, it's aliased to iopause_poll by default, and users can alias it to iopause_select instead if they configure skalibs with the --enable-iopause-select option.

poll() has a more comfortable API than select(), but its maximum precision is 1 millisecond, which might not be enough for some applications; using select() instead incurs some CPU overhead for the API conversion, but has a 1 microsecond precision. ppoll() gets the best of both worlds with the same interface model as poll() and a 1 nanosecond precision, which is why skalibs always uses it when available.

skalibs-2.9.1.0/doc/libstddjb/ip46.html000066400000000000000000000154271355335115400175050ustar00rootroot00000000000000 skalibs: the ip46 library interface

libstddjb
libskarnet
skalibs
Software
skarnet.org

The ip46 library interface

The following functions and structures are declared in the skalibs/ip46.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

ip46 is a set of macros and functions to support both IPv4 and IPv6 network operations in an abstracted way.

If skalibs has been built with the --disable-ipv6 configure option, or it detects at build time than the target does not support IPv6, then ip46 structures and functions will be directly aliased to their IPv4 implementations with no overhead at all.

Data structures

An ip46full_t is a structure that contains either an IPv4 or an IPv6 address. If a is an ip46full_t, then:

  • ip46_is6(&a) is 1 if a is IPv6 and 0 otherwise.
  • a.ip points to 16 (if IPv6) or 4 (if IPv4) bytes containing the address, in network byte order.

If skalibs has been build with IPv6 support, an ip46_t is the same type as an ip46full_t. Otherwise, an ip46_t is a structure that just contains an IPv4 address.

Functions

int ip46_from_ip4 (ip46_t *a, char const *ip)
Stores the IPv4 pointed to by ip into *a. Returns 1.

int ip46_from_ip6 (ip46_t *a, char const *ip)
Stores the IPv6 pointed to by ip into *a. Returns 1, except if IPv6 is unavailable, in which case it returns 0 ENOSYS.

size_t ip46_fmt (char *s, ip46_t const *a)
Formats the address in *a into the string s, which must be preallocated. Returns the number of bytes written. The address will be accordingly formatted as IPv4 or IPv6.

size_t ip46_scan (char const *s, ip46_t *a)
Scans the string s for an IPv4 or IPv6 address. If it finds one, writes it into *a and returns the number of bytes read. If it cannot, returns 0.

size_t ip46_scanlist (ip46_t *list, size_t max, char const *s, size_t *n)
Scans the string s for a list of comma-, semicolon-, space-, tab- or newline-separated IPv4 or IPv6 addresses, up to a maximum of max. It stores them into the (preallocated) ip46_t array pointed to by list. It returns the number of bytes read (0 if s does not contain a valid IP list at all), and stores the number of found and scanned addresses into *n.

int socket_connect46 (int fd, ip46_t *a, uint16_t port)
Connects the socket fd to address *a and port port. Returns 0 in case of success, and -1 (and sets errno) in case of failure.

int socket_bind46 (int fd, ip46_t *a, uint16_t port)
Binds the socket fd to address *a and port port. Returns 0 in case of success, and -1 (and sets errno) in case of failure.

int socket_bind46_reuse (int fd, ip46_t *a, uint16_t port)
Same as the previous function, with the SO_REUSEADDR option.

int socket_deadlineconnstamp46 (int fd, ip46_t const *a, uint16_t port, tain_t const *deadline, tain_t *stamp)
Attempts to synchronously connect the socket fd to address aa and port port. Returns 1 if it succeeds and 0 (and sets errno) if it fails. stamp must contain an accurate enough timestamp, and is updated when the function returns. If the connection is still pending by deadline, then the attempt stops and the function returns 0 ETIMEDOUT.

ssize_t socket_recv46 (int fd, char *s, size_t len, ip46_t *a, uint16_t *port)
Reads a datagram from socket fd. The message is stored into buffer s of max length len, and stores the sender information into address *a and port *port. Returns the length of the read datagram, or -1 if it fails.

ssize_t socket_send46 (int fd, char const *s, size_t len, ip46_t const *a, uint16_t port)
Writes a datagram to socket fd. The message is read from buffer s of length len, and the recipient information is address *a and port port. Returns the number of written bytes, or -1 if it fails.

int socket_local46 (int fd, ip46_t *a, uint16_t *port)
Gets the local information about bound socket fd: the local IP address is stored into *a and the local port into *port. Returns 0 in case of success, and -1 (and sets errno) in case of failure.

int socket_remote46 (int fd, ip46_t *a, uint16_t *port)
Gets the peer information about connected socket fd: the remote IP address is stored into *a and the remote port into *port. Returns 0 in case of success, and -1 (and sets errno) in case of failure.

ssize_t socket_recvnb46 (int fd, char *s, size_t len, ip46_t *a, uint16_t *port, tain_t const *deadline, tain_t *stamp)
Like socket_recv46, except that the function blocks until a datagram is received. *stamp must be an accurate enough approximation of the current time, and is updated when the function returns. If no datagram has arrived by absolute date *deadline, the function returns -1 ETIMEOUT.

ssize_t socket_sendnb46 (int fd, char const *s, size_t len, ip46_t const *a, uint16_t port, tain_t const *deadline, tain_t *stamp)
Like socket_send46, except that the function blocks until a datagram has been effectively sent. *stamp must be an accurate enough approximation of the current time, and is updated when the function returns. If the message still has not been sent by absolute date *deadline, the function returns -1 ETIMEOUT.

skalibs-2.9.1.0/doc/libstddjb/lolstdio.html000066400000000000000000000065661355335115400205600ustar00rootroot00000000000000 skalibs: the lolstdio library interface

libstddjb
libskarnet
skalibs
Software
skarnet.org

The lolstdio library interface

The following functions are declared in the skalibs/lolstdio.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

lolstdio is a set of convenience functions providing printf-style formatting but interacting with buffers or bufallocs instead of stdio FILEs.

Like any printf-style functions, the lolstdio functions are rather complex and inefficient, and not recommended for general use; they are provided as a quick and dirty way to debug or test things. Programmers are advised to use type-specific formatting functions instead in production-quality code.

Be aware that functions writing into buffers interact badly with non-blocking fds (and asynchronism in general) - just as you cannot use FILEs with non-blocking output. Functions writing into bufallocs, however, are fine, because bufallocs are much more suited to asynchronous writing than fixed-size buffers or FILEs are.

The current lolstdio implementation relies on the libc's vsnprintf function.

Functions

int vbprintf (buffer *b, char const *format, va_list args)
Like vfprintf except that the result is written to the buffer b.

int bprintf (buffer *b, char const *format, ...)
Like fprintf except that the result is written to the buffer b.

int lolprintf (char const *format, ...)
Like printf except that the result is written to the buffer buffer_1.

int vbaprintf (bufalloc *ba, char const *format, va_list args)
Like vfprintf except that the result is written to the bufalloc ba.

int baprintf (bufalloc *ba, char const *format, ...)
Like fprintf except that the result is written to the bufalloc ba.

skalibs-2.9.1.0/doc/libstddjb/mininetstring.html000066400000000000000000000016001355335115400216010ustar00rootroot00000000000000 skalibs: the mininetstring header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/mininetstring.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/netstring.html000066400000000000000000000015541355335115400207340ustar00rootroot00000000000000 skalibs: the netstring header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/netstring.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/safewrappers.html000066400000000000000000000076371355335115400214310ustar00rootroot00000000000000 skalibs: safe wrappers

libstddjb
libskarnet
skalibs
Software
skarnet.org

Safe wrappers

Lots of functions in libstddjb, declared for instance in allreadwrite.h or djbunix.h, are just "safe wrappers" around corresponding system functions. For instance, fd_read() is a safe wrapper around the system read() function.

The problem

Quite a lot of system calls are defined by The Open Group Base Specifications as interruptible: when the process is in the middle of such a system call and receives a signal that it does not ignore, the system call immediately returns -1 EINTR (after the signal handler, if any, has been executed).

Most of the time, this is not an issue: unignored signals usually kill the process anyway. Or stop it - and when it resumes, system calls are simply restarted, not interrupted. EINTR can only happen when a signal handler has been installed, and a signal is actually caught by the signal handler during an interruptible system call. And to avoid EINTR, users can use the SA_RESTART flag when installing the signal handler with sigaction().

However, there is a common case where using SA_RESTART is a bad idea: when writing an asynchronous event loop.

An asynchronous event loop is organized around a select() or poll() system call that is the only blocking operation in the whole loop. That call takes a timeout as an argument. If a signal handler is installed with SA_RESTART and a signal arrives in the middle of the select/poll call - which happens often since it is blocking - then the select/poll is restarted with the same arguments, including the timeout. This is not good: time has elapsed, the timeout should be recomputed. Some versions of select update the values in the struct timeval even when select() is interrupted, but it is not portable, and not applicable to poll(). So it is necessary, in this case, to have select/poll return -1 EINTR when a signal is caught. And that means SA_RESTART should not be used.

Which also means that other system calls performed when the signal handler has been installed, for instance in the body of the loop, will not be protected, and can return -1 EINTR if a signal is caught at the wrong time.

The solution

So, in order to be perfectly reliable, when a program has caught a signal without SA_RESTART and makes an interruptible system call, it must check whether the return value is -1 EINTR, and restart the system call if it is the case. This is annoying to write; so, skalibs provides small wrappers around interruptible system calls, so that programmers can just call those safe wrappers and never bother with this again.

The performance loss from having a wrapper layer is totally negligible compared to the cost of using a system call in the first place.

skalibs-2.9.1.0/doc/libstddjb/segfault.html000066400000000000000000000016161355335115400205300ustar00rootroot00000000000000 skalibs: the segfault header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/segfault.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/selfpipe.html000066400000000000000000000177571355335115400205420ustar00rootroot00000000000000 skalibs: the selfpipe library interface

libstddjb
skalibs
skalibs
Software
skarnet.org

The selfpipe library interface

The selfpipe functions are declared in the skalibs/selfpipe.h header and implemented in the libskarnet.a or libskarnet.so library.

What does it do ?

Signal handlers suck.

They do. I don't care how experienced you are with C/Unix programming, they do. You can be Ken Thompson, if you use signal handlers as a regular part of your C programming model, you are going to screw up, and write buggy code.

Unix is tricky enough with interruptions. Even when you have a single thread, signals can make the execution flow very non-intuitive. They mess up the logic of linear and structured code, they introduce non-determinism; you always have to think "and what if I get interrupted here and the flow goes into a handler...". This is annoying.

Moreover, signal handler code is very limited in what it can do. It can't use any non-reentrant function! If you call a non-reentrant function, and by chance you were precisely in that non-reentrant function code when you got interrupted by a signal... you lose. That means, no malloc(). No bufferized IO. No globals. The list goes on and on.
If you're going to catch signals, you'll want to handle them outside the signal handler. You actually want to spend the least possible time inside a signal handler - just enough to notify your main execution flow that there's a signal to take care of.

And, of course, signal handlers don't mix with event loops, which is a classic source of headaches for programmers and led to the birth of abominations such as pselect. So much for the "everything is a file" concept that Unix was built on.

A signal should be an event like any other. There should be a unified interface - receiving a signal should make some fd readable or something.

And that's exactly what the self-pipe trick, invented by DJB, does.

As long as you're in some kind of event loop, the self-pipe trick allows you to forget about signal handlers... forever. It works this way:

  1. Create a pipe p. Make both ends close-on-exec and nonblocking.
  2. Write a tiny signal handler ("top half") for all the signals you want to catch. This signal handler should just write one byte into p[1], and do nothing more; ideally, the written byte identifies the signal.
  3. In your event loop, add p[0] to the list of fds you're watching for readability.

When you get a signal, a byte will be written to the self-pipe, and your execution flow will resume. When you next go through the event loop, p[0] will be readable; you'll then be able to read a byte from it, identify the signal, and handle it - in your unrestricted main environment (the "bottom half" of the handler).

The selfpipe library does it all for you - you don't even have to write the top half yourself. You can forget their existence and recover some peace of mind.

Note that in an asynchronous event loop, you need to protect your system calls against EINTR by using safe wrappers.

How do I use it ?

Starting

int fd = selfpipe_init() ;

selfpipe_init() sets up a selfpipe. You must use that function first.
If fd is -1, then an error occurred. Else fd is a non-blocking descriptor that can be used in your event loop. It will be selected for readability when you've caught a signal.

Trapping/untrapping signals

int r = selfpipe_trap(SIGTERM) ;

selfpipe_trap() catches a signal and sends it to the selfpipe. Uncaught signals won't trigger the selfpipe. r is 0 if the operation succeeded, and -1 if it failed. If it succeeded, you can forget about the trapped signal entirely.
In our example, if r is 0, then a SIGTERM will instantly trigger readability on fd.

int r = selfpipe_untrap(SIGTERM) ;

Conversely, selfpipe_untrap() uncatches a signal; the selfpipe will not manage it anymore. r is 0 if the operation succeeded and -1 if it failed.

int r ;
sigset_t set ;
sigemptyset(&set) ;
sigaddset(&set, SIGTERM) ;
sigaddset(&set, SIGHUP) ;
r = selfpipe_trapset(&set) ;

selfpipe_trap() and selfpipe_untrap() handle signals one by one. Alternatively (and often preferrably), you can use selfpipe_trapset() to directly handle signal sets. When you call selfpipe_trapset(), signals that are present in set will be caught by the selfpipe, and signals that are absent from set will be uncaught. r is 0 if the operation succeeded and -1 if it failed.

Handling events

int c = selfpipe_read() ;

Call selfpipe_read() when your fd is readable. That's where you write your real signal handler: in the body of your event loop, in a "normal" context.
c is -1 if an error occurred - in which case chances are it's a serious one and your system has become very unstable. c is 0 if there are no more pending signals. If c is positive, it is the number of the signal that was caught.

Finishing

selfpipe_finish() ;

Call selfpipe_finish() when you're done using the selfpipe. Signal handlers will be restored to their previous value.

Any limitations ?

Some, as always.

  • The selfpipe library uses a global pipe; so, it's not safe for multithreading. I'm not sure how multithreaded programs handle signals; I personally don't like multithreading and never use it, so I'm not knowledgeable about it. Anyway, if your program is multithreaded, chances are you don't have an asynchronous event loop, so the self-pipe trick has less benefits for you.
  • In rare cases, the self-pipe can theoretically be filled, if some application sends more than PIPE_BUF signals before you have time to selfpipe_read(). On most Unix systems, PIPE_BUF is 4096, so it's a very acceptable margin. Unless your code is waiting where it should not be, only malicious applications will fill the self-pipe - and malicious applications could just send you a SIGKILL and be done with you, so this is not a concern. Protect yourself from malicious applications with clever use of uids.

Hey, Linux has signalfd() for this !

Yes, the Linux team loves to gratuitously add new system calls to do things that could already be done before without much effort. This adds API complexity, which is not a sign of good engineering.

However, now that signalfd() exists, it is indeed marginally more efficient than a pipe, and it saves one fd: so the selfpipe library is implemented via signalfd() when this call is available.

skalibs-2.9.1.0/doc/libstddjb/sgetopt.html000066400000000000000000000015531355335115400204030ustar00rootroot00000000000000 skalibs: the sgetopt header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/sgetopt.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/sig.html000066400000000000000000000015451355335115400175010ustar00rootroot00000000000000 skalibs: the sig header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/sig.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/siovec.html000066400000000000000000000016061355335115400202050ustar00rootroot00000000000000 skalibs: the siovec header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/siovec.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/skamisc.html000066400000000000000000000015671355335115400203550ustar00rootroot00000000000000 skalibs: the skamisc header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/skamisc.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/socket.html000066400000000000000000000015701355335115400202050ustar00rootroot00000000000000 skalibs: the socket header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/socket.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/stralloc.html000066400000000000000000000113671355335115400205450ustar00rootroot00000000000000 skalibs: the stralloc library interface

libstddjb
libskarnet
skalibs
Software
skarnet.org

The stralloc library interface

The following functions are declared in the skalibs/stralloc.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

stralloc is the preferred skalibs way of storing objects into heap memory. It focuses on strings of char, which is the generic way to handle any object. For easy structure manipulation, the genalloc series of functions can be used; those functions are mostly macros wrapping calls to their stralloc counterparts.

A stralloc is a structure containing the following fields:

  • s: a pointer to a zone of heap memory. The stralloc functions internally manipulate those via the alloc series of functions. It is recommended to never modify that field manually.
  • len: the used length of the allocated zone. It is the only field that the user can modify directly.
  • a: the number of allocated bytes. The user should never have to access that field, because the memory allocation management should be entirely transparent. len cannot exceed a: if an operation needs a bigger len, it will automatically reallocate as needed.

The benefits of using stralloc are as follows:

  • Memory allocation is performed on-demand and automatically, with a suitable size. Heuristics are used to accommodate constantly growing strings while minimizing the amount of needed reallocations.
  • If every heap-allocated object is represented by a stralloc, then it is very easy to identify what pointer is in the heap. When you stop using a pointer p, should you free it ? Sometimes it's not easy to find out. When you stop using a stralloc sa, you know you must call stralloc_free(&sa). Store your strong references as strallocs and weak references as simple pointers, and never free simple pointers. This policy allows me to boast that no skarnet.org software has ever leaked memory.
  • Repeated for emphasis: the golden rule for programming with strallocs is every pointer to the heap must be owned by a stralloc. Every pointer you handle yourself either does not point to the heap, or is weak. That sometimes implies unusual programming practices, such as having storage separated from structure, but it's hands down the easiest way to keep control of your heap in complex situations.
  • The indirection layer makes weak references immune to reallocation troubles. The s field may change when a reallocation happens, but the stralloc structure's address never changes.

A stralloc can be declared anywhere: static/global data, stack or heap. (Of course, as a general rule, you should favor the stack whenever possible.) A stralloc should be initialized to STRALLOC_ZERO before its first use.

Functions

int stralloc_catb (stralloc *sa, char const *s, size_t len)
Appends the len bytes pointed to by s to the end of the memory zone handled by *sa, automatically allocating more memory if needed. Returns 1 if it succeeds, and 0 if it fails.

void stralloc_free (stralloc *sa)
Frees *sa, i.e. calls alloc_free on sa→s then zeroes the structure. *sa is then reusable. However, it is not good practice to call this function if you're going to reuse *sa soon: it takes time and causes memory fragmentation. Just setting sa→len to 0 allows you to instantly reuse the allocated block of memory.

The above are the most important and fundamental functions of skalibs/stralloc.h. Other functions can be found in this header and their prototypes are self-explaining.

skalibs-2.9.1.0/doc/libstddjb/strerr.html000066400000000000000000000015661355335115400202430ustar00rootroot00000000000000 skalibs: the strerr header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/strerr.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/strerr2.html000066400000000000000000000015721355335115400203220ustar00rootroot00000000000000 skalibs: the strerr2 header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/strerr2.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libstddjb/tai.html000066400000000000000000000502731355335115400174760ustar00rootroot00000000000000 skalibs: the tai library interface

libstddjb
libskarnet
skalibs
Software
skarnet.org

The tai library interface

The following functions are declared in the skalibs/tai.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

tai is a set of data structures and primitives to represent and perform operations on time.

The point of tai is to handle time without ever having to deal with annoyances such as Y2K, Y2038, NTP limits, non-linear clocks, and the like. By using the tai interface, you ensure your program will behave properly no matter what.

What is the problem ?

The standard APIs for time management under Unix are broken in more or less subtle ways. The most obvious thing is that they do not pass year 2038. A less obvious problem is that they do not handle leap seconds correctly. Here are a few references you should read to understand what is going on:

The meat and potatoes of all this is that programmers cannot simply rely on standard Unix APIs such as gettimeofday() (which, by the way, is marked as obsolescent, but it's not going to disappear tomorrow) to measure time intervals or even to give precise absolute time, and in any case those APIs will become obsolete in 2038.

So what does tai do ?

tai implements - among other things - the TAI64 and TAI64N formats, which are used in all of skalibs. This gives a programmer access to precise linear absolute time, which is suitable for both timestamping (wallclock usage) and time interval measurements (stopwatch usage). Additionally, TAI64 passes Y2038 (it can represent dates exceeding the estimated lifespan of the universe).

tai has been inspired by Dan J. Bernstein's libtai library, but does not borrow any code from it.

Data structures

A tai_t structure holds an absolute date with a one-second precision. A tain_t structure holds an absolute date with a maximum of one-nanosecond precision, as permitted by the underlying system call. If flag-usert is clear, the system clock will be read via gettimeofday() system call, which has a one-microsecond precision; if it is set, the system clock will be read via the clock_gettime() system call, which has a one-nanosecond precision. In either case, a current tain_t will be unable to be more precise than the underlying implementation.

A tai_t, as well as a tain_t, can also hold a (possibly negative) relative time, i.e. a difference of absolute dates. It is up to the programmer to make sure that a relative time is never interpreted as an absolute TAI64 date, and vice-versa.

Functions

Wallclock operations

int tai_now (tai_t *t)
Writes the current time as a TAI value to *t, with a 1-second precision. The current time is based on the system clock. Make sure skalibs has been compiled with or without the --enable-tai-clock configure option according to your system clock synchronization method: skalibs supports a system clock set to TAI-10 or to UTC. The function returns 1 if it succeeds, or 0 (and sets errno) if it fails.

int sysclock_get (tain_t *a)
Reads the current value of the system clock (as in CLOCK_REALTIME) into *a. Returns 1 if it succeeds or 0 (and sets errno) if it fails. Note that despite being a tain_t, *a does not contain a TAI value - it only contains an internal, Y2038-safe representation of the value of the system clock, which should be either TAI-10 or UTC. You should not use this function directly unless you know exactly what you are doing.

int sysclock_set (tain_t const *a)
Sets the system clock to *a, provided *a has the correct internal representation. You should not use this function directly unless you know exactly what you are doing.

int tain_wallclock_read (tain_t *a)
Reads the current time into *a, as a TAI64N value. Returns 1 if it succeeds or 0 (and sets errno) if it fails. Here a contains a valid TAI64N stamp, no matter what the system clock is set to: arithmetic operations can be performed on it.

int tain_setnow (tain_t const *a)
Sets the current time to *a. Returns 1 if it succeeds or 0 (and sets errno) if it fails. a must contain a valid TAI64N stamp; proper operations will be automatically run to convert that stamp into the right format for the system clock.

int tain_now_set_wallclock (tain_t *a)
Tells skalibs that future invocations of tain_now() (see below) should use a wall clock, i.e. the system time as returned by clock_gettime(CLOCK_REALTIME) or gettimeofday(). Also reads the current time into *a. Returns 1 if it succeeds or 0 (and sets errno) if it fails. A wall clock is the default: it is not necessary to call this function before invoking tain_now() at the start of a program.

Stopwatch operations

The following two operations can only succeed if your system provides the clock_gettime() primitive with at least one of the CLOCK_MONOTONIC or CLOCK_BOOTTIME clocks. Otherwise, they will fail with errno set to ENOSYS.

int tain_stopwatch_init (tain_t *a, clock_t cl, tain_t *offset)
Initializes a stopwatch in *offset, using a clock named cl. Typically, cl is something like CLOCK_MONOTONIC, when it is defined by the system. The actual value of *offset is meaningless to the user; offset's only use is to be given as a second parameter to tain_stopwatch_read(). The function returns 1 if it succeeds or 0 (and sets errno) if it fails. On success, the current time, as given by the system clock (a wall clock), is returned in *a.

What tain_stopwatch_init() does is synchronize the "stopwatch clock" to the system clock. Right after tain_stopwatch_init() has been called, the absolute times given by tain_stopwatch_read() and tain_wallclock_read() are the same. Then, depending on the accuracy of the system clock, a drift may appear; calling tain_stopwatch_init() again resets that drift to zero.

int tain_stopwatch_read (tain_t *a, clock_t cl, tain_t const *offset)
Gives the absolute time, as a TAI64N value, in *a. This absolute time is computed as a linear increase (as measured with the cl clock, which should be a monotonic clock such as CLOCK_MONOTONIC) since the last time tain_stopwatch_init() was called with parameter offset. tain_stopwatch_read() guarantees precise time interval measurements; however, the time it gives can slightly differ from the result of tain_wallclock_read(). The function returns 1 if it succeeds or 0 (and sets errno) if it fails.

int tain_now_set_stopwatch (tain_t *a)
Tells skalibs that future invocations of tain_now() (see below) should use a stopwatch, i.e. the system time as returned by clock_gettime(CLOCK_MONOTONIC) or similar, if supported by the system. This is useful when it is more important for a program to compute unchanging time intervals no matter what the system clock does, than to display absolute time that is in sync with a human view of time (which is the cause and reason of most system clock jumps).
If no monotonic clock is supported by the system, this function does not change what tain_now() refers to (i.e. it will keep referring to the system clock).
Returns 1 on success and 0 (and sets errno) on failure. On success, the current time, as given by the system clock (a wall clock), is returned in *a.

All-purpose time reading

int tain_now (tain_t *a)
Writes the current time, as a TAI value, to *a. This is the function you should use by default. It returns 1 if it succeeds or 0 (and sets errno) if it fails.

tain_now() relies on the concept that there is One True Time Source for the process, and that is where it reads time from. By default, the One True Time Source is the system clock (a wall clock), and tain_now() is actually an alias to tain_wallclock_read(). At the start of a program, calling tain_now_set_stopwatch() will define a monotonic clock (if supported by the system) as the One True Time Source, which will make tain_now() resistant to system clock jumps, but will also make it unsuitable for timestamping.

In other words: the first time you need to read the clock, or at the start of your program, you should use tain_now_set_wallclock() or tain_now_set_stopwatch() depending on whether you want the One True Time Source to be the system clock (CLOCK_REALTIME or gettimeofday()) or a stopwatch (CLOCK_MONOTONIC, if supported). Afterwards, every time you need to read from that time source, use tain_now(). skalibs functions that may block, such as iopause_g, internally call tain_now() to update the timestamp they're using, so they will use the time source you have defined. (Functions ending in _g use the STAMP global variable to store the current timestamp.)

Converting to/from libc representations

The following functions only convert from a certain structure format to another; they do not make any assumption about the format of the time contained in those structures. For instance, for the tai_from_timeval function, if the struct timeval contains an absolute UTC time, then the tai_t will also contain the same UTC time. Despite being a tai_t, it may contain something else than TAI time.

If you need conversion from the native machine system clock format to TAI, see the next section.

int tai_from_time (tai_t *t, time_t u)
int tai_relative_from_time (tai_t *t, time_t u)

Those functions convert an absolute (resp. relative) time in a time_t to an absolute (resp. relative) time in a tai_t, with a 1-second precision. They return 1, unless the time_t value is invalid (in which case they return 0).

int time_from_tai (time_t *u, tai_t const *t)
int time_from_tai_relative (time_t *u, tai_t const *t)

The inverse functions of the previous ones. Be aware that time_t is 32 bits on some systems and cannot store all values of a tai_t (in which case the functions will return 0 EOVERFLOW).

int tain_from_timeval (tain_t *a, struct timeval const *tv)
int tain_relative_from_timeval (tain_t *a, struct timeval const *tv)
int tain_from_timespec (tain_t *a, struct timespec const *ts)
int tain_relative_from_timespec (tain_t *a, struct timespec const *ts)
int timeval_from_tain (struct timeval *tv, tain_t const *a)
int timeval_from_tain_relative (struct timeval *tv, tain_t const *a)
int timespec_from_tain (struct timespec *ts, tain_t const *a)
int timespec_from_tain_relative (struct timespec *ts, tain_t const *a)

Same conversion operations, between tain_t and a struct timeval or struct timespec. The 1-microsecond (for struct timeval) or 1-nanosecond (for struct timespec) precision is preserved.

Conversion between TAI and the system clock format

Unlike the previous functions, the functions listed here will always operate on valid absolute timestamps. Only TAI64 time is stored in tai_t structures, and only TAI64N time is stored in tain_t structures. These functions will convert to/from TAI, from/to the machine system clock format, i.e. TAI-10 or UTC depending on whether skalibs was compiled with the --enable-tai-clock configure option). This is useful to get valid TAI/TAI64N timestamps out of information exported by the system, for instance the time_t returned by time(), or in the st_atim, st_mtim or st_ctim fields of a struct stat.

The functions return 1 in case of success, or 0 if the conversion could not be performed; in which case errno is set to EINVAL if the input argument was not a valid timestamp, to EOVERFLOW if the output could not be represented in the chosen format (which may happen on systems with a 32 bit time_t), or other error codes.

int tai_from_time_sysclock (tai_t *a, time_t t)
int time_sysclock_from_tai (time_t *t, tai_t const *a)
int tain_from_timeval_sysclock (tain_t *a, struct timeval const *tv)
int timeval_sysclock_from_tain (struct timeval *tv, tain_t const *a)
int timespec_sysclock_from_tain (struct timespec *ts, tain_t const *a)

Conversions to/from basic types

int tain_uint (tain_t *a, unsigned int c)
Stores a relative time of c seconds into a. Normally returns 1, but may return 0 EINVAL on pathological numbers.

int tain_from_millisecs (tain_t *a, int ms)
This function makes a tain_t representing a relative time of ms milliseconds. ms must be non-negative. The function returns 1, unless ms is negative, in which case it returns 0 EINVAL.

int tain_to_millisecs (tain_t const *a)
If *a contains a non-negative relative time that fits into a 31-bit integer number of milliseconds, the function returns that number. Else it returns -1 EINVAL.

Time computations

int tai_add (tai_t *t, tai_t const *t1, tai_t const *t2)
Stores *t1 + *t2 into t. Of course, *t1 and *t2 must not both represent absolute times. The function normally returns 1, but will return 0 on bad inputs.

int tai_sub (tai_t *t, tai_t const *t1, tai_t const *t2)
Stores *t1 - *t2 into t. *t1 cannot be relative if *t2 is absolute. If they are both relative or both absolute, then *t is relative, else it's absolute. The function normally returns 1, but will return 0 on bad inputs.

int tain_add (tain_t *a, tain_t const *a1, tain_t const *a2)
int tain_sub (tain_t *a, tain_t const *a1, tain_t const *a2)

Same thing with tain_t.

int tain_addsec (tain_t *a, tain_t const *a1, int c)
Adds c seconds to *a1 and stores the result into a. c may be negative.

void tain_half (tain_t *a, tain_t const *b)
Stores *b/2 into a. *b must be relative.

Comparing dates or durations

int tai_less (tai_t const *t1, tai_t const *t2)
int tain_less (tain_t const *t1, tain_t const *t2)

Those functions return nonzero iff *t1 is lesser than *t2. *t1 and *t2 must be both relative, or both absolute.

Packing and unpacking

void tai_pack (char *s, tai_t const *t)
Marshals *t into the buffer s points to, which must be preallocated with at least TAI_PACK (8) characters. Afterwards, the buffer contains the external TAI64 format representation of *t.

void tai_unpack (char const *s, tai_t *t)
Unmarshals the external TAI64 format label pointed to by s (at least TAI_PACK characters) and stores the result into t.

void tain_pack (char *s, tain_t const *a)
void tain_unpack (char const *s, tain_t *a)

Same thing with external TAI64N format, using TAIN_PACK (12) characters.

Formatting and scanning

unsigned int tain_fmt (char *s, tain_t const *a)
Writes into s an ASCII representation of *a in external TAI64N format. s must point to a preallocated buffer of at least TAIN_PACK*2 (24) characters. The function returns the number of bytes that have been written to s (24).

unsigned int tain_scan (char const *s, tain_t *a)
Reads 24 characters from s; if those characters are a valid ASCII representation of the external TAI64N format of some time value, this value is stored into a, and 24 is returned. Else 0 is returned.

Timestamping

A TAI64N timestamp is a string of 25 characters: a single '@' character followed by the ASCII representation of the TAI64N external format of an absolute date.

unsigned int timestamp_fmt (char *s, tain_t const *a)
Writes a TAI64N timestamp representing the absolute date *a into the 25 characters pointed to by s. Returns 25.

unsigned int timestamp_scan (char const *s, tain_t *a)
Reads 25 characters at s. If those characters are a valid TAI64N timestamp, stores the absolute date in a and returns 25. Else, returns 0.

int timestamp (char *s)
Writes the current time (read from the system clock) as a TAI64N timestamp into s. Returns 1 if it succeeds or 0 (and sets errno) if it fails.

TAI64N timestamps are an efficient, robust, and easy-to-use way of timestampping log lines. They're easy to recognize in automatic data parsers. Log files where every line starts with a TAI64N timestamp can be merged and alphanumerically sorted: the resulting file will be chronologically sorted.

The s6 package provides tools to convert TAI64N timestamps into human-readable dates. Please do not embed human-readable dates in your log files, thus making parsing tools unnecessarily hard to write; use TAI64N timestamps instead, design tools that can parse them, and translate them to human-readable form at human analysis time.

skalibs-2.9.1.0/doc/libstddjb/webipc.html000066400000000000000000000016011355335115400201610ustar00rootroot00000000000000 skalibs: the webipc header

libstddjb
libskarnet
skalibs
Software
skarnet.org

The skalibs/webipc.h header

TODO: write this documentation page. (Sorry!)

skalibs-2.9.1.0/doc/libunixonacid/000077500000000000000000000000001355335115400167135ustar00rootroot00000000000000skalibs-2.9.1.0/doc/libunixonacid/index.html000066400000000000000000000037351355335115400207200ustar00rootroot00000000000000 skalibs: the unixonacid library interface

libskarnet
skalibs
Software
skarnet.org

The unixonacid library interface

libunixonacid provides higher-level interfaces to Unix concepts such as the filesystem - for instance, it provides a way to access several files atomically, be it for reading or for writing - or interprocess communication.

Compiling

  • Use #include <skalibs/unixonacid.h>

Programming

The skalibs/unixonacid.h header is actually a concatenation of other headers, every one of each declaring related structures, macros and functions.

skalibs-2.9.1.0/doc/libunixonacid/kolbak.html000066400000000000000000000024331355335115400210460ustar00rootroot00000000000000 skalibs: the kolbak library interface

libunixonacid
libskarnet
skalibs
Software
skarnet.org

The kolbak library interface

The following functions are declared in the skalibs/kolbak.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

kolbak implements simple queuing of callback functions to use when sending a message to a peer and expecting an answer, which will be handled by the callback function. The queue is a circular buffer.

FIXME: To be completed.

skalibs-2.9.1.0/doc/libunixonacid/skaclient.html000066400000000000000000000050441355335115400215610ustar00rootroot00000000000000 skalibs: the skaclient library interface

libunixonacid
libskarnet
skalibs
Software
skarnet.org

The skaclient library interface

The following functions are declared in the skalibs/skaclient.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

skaclient is a client-server initiation protocol framework, allowing a process (the "client") to either connect to another process (the "server") via a Unix domain socket, or spawn such a "server" process itself. The client and the server then communicate via two sockets, one for synchronous data, the other for asynchronous data; they exchange unixmessages.

The skaclient framework is used in several places in skarnet.org software, whenever a server can send asynchronous data to its client. For instance:

  • Communication between notification subscribers such as s6-ftrig-wait and their own s6-ftrigrd daemon
  • Communication between clients of the s6lock library and a s6lockd server
  • Communication between a client such as s6-dnsip4-filter, in need of asynchronous DNS service, and its own skadnsd daemon
  • The skabus Unix bus infrastructure is entirely based on the skaclient framework to transmit unixmessages across processes.

Programming

FIXME: to be completed.

skalibs-2.9.1.0/doc/libunixonacid/unix-timed.html000066400000000000000000000021221355335115400216610ustar00rootroot00000000000000 skalibs: the unix-timed library interface

libunixonacid
libskarnet
skalibs
Software
skarnet.org

The unix-timed library interface

The following functions are declared in the skalibs/unix-timed.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

FIXME: to be completed.

skalibs-2.9.1.0/doc/libunixonacid/unix-transactional.html000066400000000000000000000021761355335115400234320ustar00rootroot00000000000000 skalibs: the unix-transactional library interface

libunixonacid
libskarnet
skalibs
Software
www.skarnet.org

The unix-transactional library interface

The following functions are declared in the skalibs/unix-transactional.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

FIXME: to be completed.

skalibs-2.9.1.0/doc/libunixonacid/unixmessage.html000066400000000000000000000024401355335115400221310ustar00rootroot00000000000000 skalibs: the unixmessage library interface

libunixonacid
libskarnet
skalibs
Software
skarnet.org

The unixmessage library interface

The following functions are declared in the skalibs/unixmessage.h header, and implemented in the libskarnet.a or libskarnet.so library.

General information

unixmessage implements message transmission over Unix domain sockets. Messages are made of standard untyped data (strings), but can also include file descriptors using fd-passing.

FIXME: To be completed.

skalibs-2.9.1.0/doc/license.html000066400000000000000000000056431355335115400164030ustar00rootroot00000000000000 skalibs: license

skalibs
Software
skarnet.org

skalibs license

Source code

The skalibs source code from skalibs is released under the ISC license, the text of which can be found in the COPYING file enclosed in the package.

The license has been chosen for its simplicity - it's short and to the point - and above all its permissivity. There is nothing legitimate you should not be able to do with the skalibs code. If the license somehow stands in the way, please let me know.

Documentation

However, the skalibs documentation, which you are currently reading, and which is available in the doc/ subdirectory of the official skalibs tarball, is not provided under the same license.

The license for the skalibs documentation is more restrictive than the license for the source code. Namely:

  • The exact same disclaimer applies.
  • You have the right to download, use and modify the documentation.
  • You have the right to distribute unmodified copies of the documentation.
  • You have the right to distribute modified copies of the documentation, provided that:
    • The contents and links (not necessarily the appearance) of this file, license.html, are left unmodified;
    • On your documentation's main page, you explicitly state that the documentation has been modified, and you set up a link to the original skalibs site, explicitly stating that the original software and documentation can be found there;
    • The parts of the documentation that you have modified are unarguably and undeniably distinguishable from the unmodified parts. You can, for instance, use a different text color, different background color, or different text font.

I am aware that the previous restrictions sound completely ridiculous while the official skalibs documentation is incomplete. As of 2.9.0.0, I'm not going to enforce those restrictions, but if you're going to provide documentation for skalibs, don't keep it to yourself, please send it to me instead. :-)

skalibs-2.9.1.0/doc/upgrade.html000066400000000000000000000266051355335115400164110ustar00rootroot00000000000000 skalibs: how to upgrade

skalibs
Software
skarnet.org

in 2.9.1.0

  • skalibs now works on GNU Hurd without patches.
  • New function: path_canonicalize

in 2.9.0.0

  • Formatting and scanning functions and macros have been refactored.
  • The configure script now emulates autotools-created configure scripts more closely. In particular, it's now possible to declare an out-of-path compiler in CC.
  • tain_* functions dealing with wall clocks and stopwatches have been refactored. The --enable-clock and --enable-monotonic configure switches have been removed. tain_now() can now be told at run time to use a wall clock (default, or via tain_now_set_wallclock()) or a stopwatch (via tain_now_set_stopwatch()), instead of it being fixed at build time.
  • Cross-compilation has been made a lot easier, by removing the need to provide a whole sysdeps directory anymore. Only a few sysdeps - the ones that need code execution on the target to be autodetected - have to be provided manually, via a --with-sysdep-K=V option to configure. Currently, that means one: --with-sysdep-devurandom=yes or --with-sysdep-devurandom=no.

in 2.8.1.0

  • New functions:
    • skalibs_regcomp(), which accepts empty regexes even when regcomp() does not (e.g. the BSDs).

in 2.8.0.1

  • Changes to skalibs/djbtime.h functions that produce UTC time: when a leap second is hit, utc_from_tai() now returns 2, and functions writing a struct tm put 60 into the struct's tm_sec field.

in 2.8.0.0

  • The avltreeb macros have been removed. Instead, the AVLTREEN_DECLARE_AND_INIT() macro has been added.
  • The mkdir_unique() function has been removed. (It duplicated the functionality of the standard mkdtemp() function.)
  • New functions: env_dump(), mk?temp(), autosurf(), autosurf_name()
  • The ancilautoclose and nbwaitall sysdeps have been removed.
  • New header: skalibs/posixishard.h
  • libskarnet.a now builds as PIC by default no matter the toolchain's settings. Use the --disable-all-pic configure option to build static libraries as non-PIC.

in 2.7.0.0

  • New functions: ipc_timed_sendv(), unlink_void(), skagetln_loose(), skagetlnsep_loose(), genset_deepfree(), gensetdyn_deepfree()
  • The dir_close() function now returns void and leaves errno unchanged.
  • The absolutepath() and sarealpath_tmp() functions, as well as the avl*_deletenode(), skalibs/mininetstring.h and prot families of functions, have been removed.
  • skalibs/djbunix.h does not include skalibs/env.h anymore.

in 2.6.4.0

in 2.6.3.1

  • No functional changes.

in 2.6.3.0

  • New dir_fd function wrapping dirfd() (Solaris doesn't have dirfd()).
  • memmem implementation for platforms that don't provide it.
  • memmem wrappers: byte_search, siovec_search.
  • New functions: atomic_symlink, skagetlnmaxsep, child_spawn3
  • New header: skalibs/posixplz.h. Some header reorganization.
  • New family of functions: skalibs/textmessage.h, skalibs/textclient.h
  • skalibs/environ.h and skalibs/getpeereid.h are now obsolescent.

in 2.6.2.0

  • New functions: access_at(), skaclient_timed_aflush().

in 2.6.1.0

in 2.6.0.2

  • No functional changes.

in 2.6.0.1

  • openwritenclose() and openwritevnclose() now use mkstemp() instead of relying on an unpredictable name (which required a random generator to be fully initialized).

in 2.6.0.0

  • New functions: unixmessage_receiver_hasmsginbuf(), skalibs_setgroups(), setgroups_with_egid(), setgroups_and_gid(). The setgroups_and_gid() function is the one that should be used, if possible: it does the right thing even on the BSDs. (That's an achievement.)

in 2.5.1.1

  • No functional changes.

in 2.5.1.0

What has changed in skalibs

in 2.5.0.0

  • Support for old versions of OpenBSD dropped. At least OpenBSD 5.7 and newer are still supported.
  • --enable-replace-libc compilation flag dropped
  • skalibs/ushort.h, skalibs/uint.h and skalibs/ulong.h removed. skalibs/types.h is now a generic header for fmtscan primitives for various types.
  • uint16, uint32 and uint64 types replaced with POSIX uint16_t, uint32_t and uint64_t.
  • APIs changed across all skalibs functions to support more POSIXly correct types. Main benefit: correct 64-bit support on 64-bit archs with 32-bit int.

in 2.4.0.2

  • No functional changes.

in 2.4.0.1

  • No functional changes.

in 2.4.0.0

  • More support for advanced fd callbacks in unixmessage_sender and unixconnection.
  • ipc_timed_send(), ipc_timed_recv()
  • rt.lib sysdep removed; spawn.lib and timer.lib sysdeps added
  • Leap second for 2016-12-31 23:59:60 UTC added
  • Complete librandom rewrite
  • skalibs/alarm.h added

in 2.3.10.0

  • Support for advanced fd callbacks in unixmessage_sender.

in 2.3.9.0

  • New functions: bitarray_firstclear_skip and bitarray_firstset_skip.

in 2.3.8.3

  • No functional changes.

in 2.3.8.2

  • No functional changes.

in 2.3.8.1

  • No functional changes.

in 2.3.8.0

  • The /etc/leapsecs.dat file is no longer necessary.

in 2.3.7.1

  • No functional changes.

in 2.3.7.0

  • New functions: atomic_rm_rf(), atomic_rm_rf_tmp().

in 2.3.6.1

  • No functional changes.

in 2.3.6.0

  • New function: openreadnclose_nb.

in 2.3.5.2

  • No functional changes.

in 2.3.5.1

  • No functional changes.

in 2.3.5.0

  • New functions: bitarray_count(), openwritevnclose_at()

in 2.3.4.0

  • New function: stat_at()
  • The rest of the changes are bugfixes or QoL.

in 2.3.3.0

  • New sha512 functions, see skalibs/sha512.h

in 2.3.2.0

  • New macro: gid0_scan()

in 2.3.1.3

  • Bugfix release, no functional changes.

in 2.3.1.2

  • The child_spawn* family of functions now resets all signals to their default values when spawning a program on systems with posix_spawn(). This should not change anything - it's just paranoia.
  • Minor bugfixes.

in 2.3.1.1

  • Bugfix release, no functional changes.

in 2.3.1.0

  • wait_status() now returns 256 + signal number when WIFSIGNALED().
  • new macro wait_estatus() to get WIFSIGNALED information in an exit code.
  • new functions in djbunix.h: hiercopy(), hiercopy_tmp()

in 2.3.0.1

  • wait_status() now returns 256 (instead of 126) when WIFSIGNALED().

in 2.3.0.0

  • buffer_getvall and buffer_putvall have a different interface. (And now work.)
  • buffer_read and buffer_write are now deprecated.
  • various siovec additions, such as siovec_trunc

in 2.2.1.0

  • unixconnection added.
  • sig_name and sig_number added.

in 2.2.0.0

  • TAI64 and TAI64N conversion functions revisited. API slightly changed, made more consistent.

in 2.1.0.0

  • unixmessage_drop added, part of unixmessage/skaclient hardening against fd leakage
  • unixmessage_sender_flush return code aligned with the convention in the rest of skalibs
  • unixmessage_sender_flush now handles short writes
  • skaclient_start(_async) prototype changed: now takes an option argument

in 2.0.0.0

  • The packaging system has completely changed.
  • Programs should now link with -lskarnet followed by the appropriate sysdeps links.
  • No compatibility is ensured. Most APIs haven't changed, but no guarantee is offered.
  • The most important change is probably the disparition of struct tai and struct taia, replaced with the tai_t and tain_t types. Attosecond precision has been removed - processor speed is almost capped now, and it looks like nanosecond precision will be enough for the foreseeable future.
  • Buffer implementation has changed, and some interfaces too, mainly the buffer_flush and bufalloc_flush return code.
  • skaclient, skalibs' client-server communication suite, has been entirely reimplemented: it's now using the new "unixmessage" set of primitives for easier fd-passing.
skalibs-2.9.1.0/package/000077500000000000000000000000001355335115400147115ustar00rootroot00000000000000skalibs-2.9.1.0/package/deps.mak000066400000000000000000004042331355335115400163440ustar00rootroot00000000000000# # This file has been generated by tools/gen-deps.sh # src/include/skalibs/alarm.h: src/include/skalibs/tai.h src/include/skalibs/alloc.h: src/include/skalibs/gccattributes.h src/include/skalibs/allreadwrite.h: src/include/skalibs/functypes.h src/include/skalibs/avlnode.h: src/include/skalibs/functypes.h src/include/skalibs/gccattributes.h src/include/skalibs/avltree.h: src/include/skalibs/avlnode.h src/include/skalibs/functypes.h src/include/skalibs/gensetdyn.h src/include/skalibs/avltreen.h: src/include/skalibs/avlnode.h src/include/skalibs/functypes.h src/include/skalibs/genset.h 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/gccattributes.h src/include/skalibs/posixishard.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/genqdyn.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/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/error.h: src/include/skalibs/gccattributes.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/genqdyn.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/netstring.h: src/include/skalibs/buffer.h src/include/skalibs/stralloc.h src/include/skalibs/posixishard.h: src/include/skalibs/gccattributes.h src/include/skalibs/posixplz.h: src/include/skalibs/functypes.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/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/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/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/textclient.h: src/include/skalibs/allreadwrite.h src/include/skalibs/tai.h src/include/skalibs/textmessage.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/textclient.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/libdatastruct/genqdyn-internal.h: src/include/skalibs/genqdyn.h src/librandom/random-internal.h: src/include/skalibs/surf.h src/libstdcrypto/md5-internal.h: src/include/skalibs/md5.h src/libstdcrypto/sha1-internal.h: src/include/skalibs/sha1.h src/libstdcrypto/sha256-internal.h: src/include/skalibs/sha256.h src/libstdcrypto/sha512-internal.h: src/include/skalibs/sha512.h src/libstddjb/djbtime-internal.h: src/include/skalibs/uint64.h src/libstddjb/fmtscan-internal.h: src/include/skalibs/fmtscan.h src/include/skalibs/uint64.h src/libstddjb/selfpipe-internal.h: src/include/skalibs/sig.h src/include/skalibs/sysdeps.h src/libunixonacid/skaclient-internal.h: src/include/skalibs/kolbak.h src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h src/libbiguint/bu_addc.o src/libbiguint/bu_addc.lo: src/libbiguint/bu_addc.c src/include/skalibs/biguint.h src/include/skalibs/bsdsnowflake.h src/libbiguint/bu_addmod.o src/libbiguint/bu_addmod.lo: src/libbiguint/bu_addmod.c src/include/skalibs/biguint.h src/libbiguint/bu_cmp.o src/libbiguint/bu_cmp.lo: src/libbiguint/bu_cmp.c src/include/skalibs/biguint.h src/libbiguint/bu_copy.o src/libbiguint/bu_copy.lo: src/libbiguint/bu_copy.c src/include/skalibs/biguint.h src/include/skalibs/bsdsnowflake.h src/libbiguint/bu_copy_internal.o src/libbiguint/bu_copy_internal.lo: src/libbiguint/bu_copy_internal.c src/include/skalibs/biguint.h src/libbiguint/bu_div.o src/libbiguint/bu_div.lo: src/libbiguint/bu_div.c src/include/skalibs/biguint.h src/libbiguint/bu_div_internal.o src/libbiguint/bu_div_internal.lo: src/libbiguint/bu_div_internal.c src/include/skalibs/biguint.h src/libbiguint/bu_divmod.o src/libbiguint/bu_divmod.lo: src/libbiguint/bu_divmod.c src/include/skalibs/biguint.h src/libbiguint/bu_divmod_internal.o src/libbiguint/bu_divmod_internal.lo: src/libbiguint/bu_divmod_internal.c src/include/skalibs/biguint.h src/libbiguint/bu_fmt.o src/libbiguint/bu_fmt.lo: src/libbiguint/bu_fmt.c src/include/skalibs/biguint.h src/include/skalibs/uint32.h src/libbiguint/bu_gcd.o src/libbiguint/bu_gcd.lo: src/libbiguint/bu_gcd.c src/include/skalibs/biguint.h src/libbiguint/bu_invmod.o src/libbiguint/bu_invmod.lo: src/libbiguint/bu_invmod.c src/include/skalibs/biguint.h src/libbiguint/bu_len.o src/libbiguint/bu_len.lo: src/libbiguint/bu_len.c src/include/skalibs/biguint.h src/libbiguint/bu_mod.o src/libbiguint/bu_mod.lo: src/libbiguint/bu_mod.c src/include/skalibs/biguint.h src/libbiguint/bu_mul.o src/libbiguint/bu_mul.lo: src/libbiguint/bu_mul.c src/include/skalibs/biguint.h src/include/skalibs/uint64.h src/libbiguint/bu_mulmod.o src/libbiguint/bu_mulmod.lo: src/libbiguint/bu_mulmod.c src/include/skalibs/biguint.h src/libbiguint/bu_pack.o src/libbiguint/bu_pack.lo: src/libbiguint/bu_pack.c src/include/skalibs/biguint.h src/include/skalibs/uint32.h src/libbiguint/bu_pack_big.o src/libbiguint/bu_pack_big.lo: src/libbiguint/bu_pack_big.c src/include/skalibs/biguint.h src/include/skalibs/uint32.h src/libbiguint/bu_scan.o src/libbiguint/bu_scan.lo: src/libbiguint/bu_scan.c src/include/skalibs/biguint.h src/include/skalibs/bitarray.h src/include/skalibs/bsdsnowflake.h src/libbiguint/bu_scan_internal.o src/libbiguint/bu_scan_internal.lo: src/libbiguint/bu_scan_internal.c src/include/skalibs/biguint.h src/include/skalibs/uint32.h src/libbiguint/bu_scanlen.o src/libbiguint/bu_scanlen.lo: src/libbiguint/bu_scanlen.c src/include/skalibs/biguint.h src/include/skalibs/fmtscan.h src/libbiguint/bu_slbc.o src/libbiguint/bu_slbc.lo: src/libbiguint/bu_slbc.c src/include/skalibs/biguint.h src/libbiguint/bu_srbc.o src/libbiguint/bu_srbc.lo: src/libbiguint/bu_srbc.c src/include/skalibs/biguint.h src/libbiguint/bu_subc.o src/libbiguint/bu_subc.lo: src/libbiguint/bu_subc.c src/include/skalibs/biguint.h src/include/skalibs/bsdsnowflake.h src/libbiguint/bu_submod.o src/libbiguint/bu_submod.lo: src/libbiguint/bu_submod.c src/include/skalibs/biguint.h src/libbiguint/bu_unpack.o src/libbiguint/bu_unpack.lo: src/libbiguint/bu_unpack.c src/include/skalibs/biguint.h src/include/skalibs/uint32.h src/libbiguint/bu_unpack_big.o src/libbiguint/bu_unpack_big.lo: src/libbiguint/bu_unpack_big.c src/include/skalibs/biguint.h src/include/skalibs/uint32.h src/libbiguint/bu_zero.o src/libbiguint/bu_zero.lo: src/libbiguint/bu_zero.c src/include/skalibs/biguint.h src/libdatastruct/avlnode_delete.o src/libdatastruct/avlnode_delete.lo: src/libdatastruct/avlnode_delete.c src/libdatastruct/avlnode-internal.h src/include/skalibs/avlnode.h src/libdatastruct/avlnode_doublerotate.o src/libdatastruct/avlnode_doublerotate.lo: src/libdatastruct/avlnode_doublerotate.c src/libdatastruct/avlnode-internal.h src/include/skalibs/avlnode.h src/libdatastruct/avlnode_extreme.o src/libdatastruct/avlnode_extreme.lo: src/libdatastruct/avlnode_extreme.c src/include/skalibs/avlnode.h src/libdatastruct/avlnode_extremenode.o src/libdatastruct/avlnode_extremenode.lo: src/libdatastruct/avlnode_extremenode.c src/include/skalibs/avlnode.h src/libdatastruct/avlnode_height.o src/libdatastruct/avlnode_height.lo: src/libdatastruct/avlnode_height.c src/include/skalibs/avlnode.h src/libdatastruct/avlnode_insertnode.o src/libdatastruct/avlnode_insertnode.lo: src/libdatastruct/avlnode_insertnode.c src/libdatastruct/avlnode-internal.h src/include/skalibs/avlnode.h src/libdatastruct/avlnode_iter.o src/libdatastruct/avlnode_iter.lo: src/libdatastruct/avlnode_iter.c src/include/skalibs/avlnode.h src/libdatastruct/avlnode_iter_withcancel.o src/libdatastruct/avlnode_iter_withcancel.lo: src/libdatastruct/avlnode_iter_withcancel.c src/include/skalibs/avlnode.h src/libdatastruct/avlnode_rotate.o src/libdatastruct/avlnode_rotate.lo: src/libdatastruct/avlnode_rotate.c src/libdatastruct/avlnode-internal.h src/include/skalibs/avlnode.h src/libdatastruct/avlnode_search.o src/libdatastruct/avlnode_search.lo: src/libdatastruct/avlnode_search.c src/include/skalibs/avlnode.h src/libdatastruct/avlnode_searchnode.o src/libdatastruct/avlnode_searchnode.lo: src/libdatastruct/avlnode_searchnode.c src/libdatastruct/avlnode-internal.h src/include/skalibs/avlnode.h src/libdatastruct/avlnode_zero.o src/libdatastruct/avlnode_zero.lo: src/libdatastruct/avlnode_zero.c src/include/skalibs/avlnode.h src/libdatastruct/avltree_delete.o src/libdatastruct/avltree_delete.lo: src/libdatastruct/avltree_delete.c src/include/skalibs/avlnode.h src/include/skalibs/avltree.h src/include/skalibs/gensetdyn.h src/libdatastruct/avltree_free.o src/libdatastruct/avltree_free.lo: src/libdatastruct/avltree_free.c src/include/skalibs/avltree.h src/include/skalibs/gensetdyn.h src/libdatastruct/avltree_init.o src/libdatastruct/avltree_init.lo: src/libdatastruct/avltree_init.c src/include/skalibs/avlnode.h src/include/skalibs/avltree.h src/include/skalibs/gensetdyn.h src/libdatastruct/avltree_insert.o src/libdatastruct/avltree_insert.lo: src/libdatastruct/avltree_insert.c src/include/skalibs/avltree.h src/libdatastruct/avltree_newnode.o src/libdatastruct/avltree_newnode.lo: src/libdatastruct/avltree_newnode.c src/include/skalibs/avlnode.h src/include/skalibs/avltree.h src/include/skalibs/gensetdyn.h src/libdatastruct/avltree_zero.o src/libdatastruct/avltree_zero.lo: src/libdatastruct/avltree_zero.c src/include/skalibs/avltree.h src/libdatastruct/avltreen_delete.o src/libdatastruct/avltreen_delete.lo: src/libdatastruct/avltreen_delete.c src/include/skalibs/avlnode.h src/include/skalibs/avltreen.h src/include/skalibs/genset.h src/libdatastruct/avltreen_init.o src/libdatastruct/avltreen_init.lo: src/libdatastruct/avltreen_init.c src/include/skalibs/avlnode.h src/include/skalibs/avltreen.h src/include/skalibs/genset.h src/libdatastruct/avltreen_insert.o src/libdatastruct/avltreen_insert.lo: src/libdatastruct/avltreen_insert.c src/include/skalibs/avltreen.h src/libdatastruct/avltreen_newnode.o src/libdatastruct/avltreen_newnode.lo: src/libdatastruct/avltreen_newnode.c src/include/skalibs/avlnode.h src/include/skalibs/avltreen.h src/include/skalibs/genset.h src/libdatastruct/genqdyn_clean.o src/libdatastruct/genqdyn_clean.lo: src/libdatastruct/genqdyn_clean.c src/libdatastruct/genqdyn-internal.h src/libdatastruct/genqdyn_free.o src/libdatastruct/genqdyn_free.lo: src/libdatastruct/genqdyn_free.c src/include/skalibs/genqdyn.h src/include/skalibs/stralloc.h src/libdatastruct/genqdyn_init.o src/libdatastruct/genqdyn_init.lo: src/libdatastruct/genqdyn_init.c src/include/skalibs/genqdyn.h src/include/skalibs/stralloc.h src/libdatastruct/genqdyn_pop.o src/libdatastruct/genqdyn_pop.lo: src/libdatastruct/genqdyn_pop.c src/libdatastruct/genqdyn-internal.h src/include/skalibs/genqdyn.h src/libdatastruct/genqdyn_push.o src/libdatastruct/genqdyn_push.lo: src/libdatastruct/genqdyn_push.c src/include/skalibs/genqdyn.h src/include/skalibs/stralloc.h src/libdatastruct/genqdyn_unpush.o src/libdatastruct/genqdyn_unpush.lo: src/libdatastruct/genqdyn_unpush.c src/include/skalibs/genqdyn.h src/include/skalibs/stralloc.h src/libdatastruct/genqdyn_zero.o src/libdatastruct/genqdyn_zero.lo: src/libdatastruct/genqdyn_zero.c src/include/skalibs/genqdyn.h src/libdatastruct/genset.o src/libdatastruct/genset.lo: src/libdatastruct/genset.c src/include/skalibs/genset.h src/libdatastruct/genset_deepfree.o src/libdatastruct/genset_deepfree.lo: src/libdatastruct/genset_deepfree.c src/include/skalibs/functypes.h src/include/skalibs/genset.h src/libdatastruct/genset_iter_nocancel.o src/libdatastruct/genset_iter_nocancel.lo: src/libdatastruct/genset_iter_nocancel.c src/include/skalibs/bitarray.h src/include/skalibs/genset.h src/libdatastruct/genset_iter_withcancel.o src/libdatastruct/genset_iter_withcancel.lo: src/libdatastruct/genset_iter_withcancel.c src/include/skalibs/genset.h src/libdatastruct/gensetdyn_deepfree.o src/libdatastruct/gensetdyn_deepfree.lo: src/libdatastruct/gensetdyn_deepfree.c src/include/skalibs/functypes.h src/include/skalibs/gensetdyn.h src/libdatastruct/gensetdyn_delete.o src/libdatastruct/gensetdyn_delete.lo: src/libdatastruct/gensetdyn_delete.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h src/libdatastruct/gensetdyn_free.o src/libdatastruct/gensetdyn_free.lo: src/libdatastruct/gensetdyn_free.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h src/include/skalibs/stralloc.h src/libdatastruct/gensetdyn_init.o src/libdatastruct/gensetdyn_init.lo: src/libdatastruct/gensetdyn_init.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h src/include/skalibs/stralloc.h src/libdatastruct/gensetdyn_iter.o src/libdatastruct/gensetdyn_iter.lo: src/libdatastruct/gensetdyn_iter.c src/include/skalibs/bitarray.h src/include/skalibs/gensetdyn.h src/libdatastruct/gensetdyn_iter_withcancel.o src/libdatastruct/gensetdyn_iter_withcancel.lo: src/libdatastruct/gensetdyn_iter_withcancel.c src/include/skalibs/gensetdyn.h 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/libposixplz/posixplz-internal.h src/include/skalibs/posixplz.h src/libposixplz/execvep_internal.o src/libposixplz/execvep_internal.lo: src/libposixplz/execvep_internal.c src/include/skalibs/bytestr.h src/include/skalibs/posixplz.h src/libposixplz/execvep_loose.o src/libposixplz/execvep_loose.lo: src/libposixplz/execvep_loose.c src/libposixplz/posixplz-internal.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/mkbtemp.o src/libposixplz/mkbtemp.lo: src/libposixplz/mkbtemp.c src/include/skalibs/djbunix.h src/include/skalibs/posixplz.h src/libposixplz/mkctemp.o src/libposixplz/mkctemp.lo: src/libposixplz/mkctemp.c src/include/skalibs/djbunix.h src/include/skalibs/posixplz.h src/libposixplz/mkfiletemp.o src/libposixplz/mkfiletemp.lo: src/libposixplz/mkfiletemp.c src/include/skalibs/posixplz.h src/include/skalibs/surf.h src/libposixplz/mkhtemp.o src/libposixplz/mkhtemp.lo: src/libposixplz/mkhtemp.c src/include/skalibs/posixplz.h src/libposixplz/mklinktemp.o src/libposixplz/mklinktemp.lo: src/libposixplz/mklinktemp.c src/include/skalibs/djbunix.h src/libposixplz/posixplz-internal.h src/include/skalibs/posixplz.h src/libposixplz/mkltemp.o src/libposixplz/mkltemp.lo: src/libposixplz/mkltemp.c src/include/skalibs/posixplz.h src/libposixplz/mkptemp.o src/libposixplz/mkptemp.lo: src/libposixplz/mkptemp.c src/include/skalibs/djbunix.h src/include/skalibs/posixplz.h src/libposixplz/setgroups.o src/libposixplz/setgroups.lo: src/libposixplz/setgroups.c src/include/skalibs/nonposix.h src/include/skalibs/posixishard.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/posixishard.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/libposixplz/unlink_void.o src/libposixplz/unlink_void.lo: src/libposixplz/unlink_void.c src/include/skalibs/posixplz.h src/librandom/autosurf.o src/librandom/autosurf.lo: src/librandom/autosurf.c src/include/skalibs/random.h src/include/skalibs/surf.h src/librandom/autosurf_name.o src/librandom/autosurf_name.lo: src/librandom/autosurf_name.c src/librandom/random-internal.h src/include/skalibs/surf.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 src/librandom/random_makeseed.o src/librandom/random_makeseed.lo: src/librandom/random_makeseed.c src/include/skalibs/sha1.h src/include/skalibs/tai.h src/include/skalibs/uint32.h src/librandom/random_name.o src/librandom/random_name.lo: src/librandom/random_name.c src/librandom/random-internal.h src/include/skalibs/random.h src/librandom/random_oklist.o src/librandom/random_oklist.lo: src/librandom/random_oklist.c src/librandom/random-internal.h src/librandom/random_sauniquename.o src/librandom/random_sauniquename.lo: src/librandom/random_sauniquename.c src/include/skalibs/random.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h src/librandom/random_string.o src/librandom/random_string.lo: src/librandom/random_string.c src/include/skalibs/allreadwrite.h src/include/skalibs/nonposix.h src/librandom/random-internal.h src/include/skalibs/random.h src/include/skalibs/sysdeps.h src/librandom/random_uint32.o src/librandom/random_uint32.lo: src/librandom/random_uint32.c src/include/skalibs/nonposix.h src/include/skalibs/random.h src/include/skalibs/sysdeps.h src/include/skalibs/uint32.h src/librandom/random_unsort.o src/librandom/random_unsort.lo: src/librandom/random_unsort.c src/include/skalibs/random.h src/librandom/surf.o src/librandom/surf.lo: src/librandom/surf.c src/include/skalibs/surf.h src/include/skalibs/uint32.h src/librandom/surf_init.o src/librandom/surf_init.lo: src/librandom/surf_init.c src/include/skalibs/surf.h src/include/skalibs/uint32.h src/libstdcrypto/md5_final.o src/libstdcrypto/md5_final.lo: src/libstdcrypto/md5_final.c src/libstdcrypto/md5-internal.h src/include/skalibs/md5.h src/include/skalibs/uint32.h src/libstdcrypto/md5_init.o src/libstdcrypto/md5_init.lo: src/libstdcrypto/md5_init.c src/include/skalibs/md5.h src/libstdcrypto/md5_transform.o src/libstdcrypto/md5_transform.lo: src/libstdcrypto/md5_transform.c src/libstdcrypto/md5-internal.h src/libstdcrypto/md5_update.o src/libstdcrypto/md5_update.lo: src/libstdcrypto/md5_update.c src/libstdcrypto/md5-internal.h src/include/skalibs/md5.h src/include/skalibs/uint32.h src/libstdcrypto/rc4.o src/libstdcrypto/rc4.lo: src/libstdcrypto/rc4.c src/include/skalibs/bytestr.h src/include/skalibs/rc4.h src/libstdcrypto/rc4_init.o src/libstdcrypto/rc4_init.lo: src/libstdcrypto/rc4_init.c src/include/skalibs/bytestr.h src/include/skalibs/rc4.h src/libstdcrypto/sha1_feed.o src/libstdcrypto/sha1_feed.lo: src/libstdcrypto/sha1_feed.c src/include/skalibs/bytestr.h src/libstdcrypto/sha1-internal.h src/include/skalibs/sha1.h src/libstdcrypto/sha1_final.o src/libstdcrypto/sha1_final.lo: src/libstdcrypto/sha1_final.c src/libstdcrypto/sha1-internal.h src/include/skalibs/sha1.h src/include/skalibs/uint32.h src/libstdcrypto/sha1_init.o src/libstdcrypto/sha1_init.lo: src/libstdcrypto/sha1_init.c src/include/skalibs/sha1.h src/libstdcrypto/sha1_transform.o src/libstdcrypto/sha1_transform.lo: src/libstdcrypto/sha1_transform.c src/libstdcrypto/sha1-internal.h src/libstdcrypto/sha1_update.o src/libstdcrypto/sha1_update.lo: src/libstdcrypto/sha1_update.c src/libstdcrypto/sha1-internal.h src/include/skalibs/sha1.h src/libstdcrypto/sha256_feed.o src/libstdcrypto/sha256_feed.lo: src/libstdcrypto/sha256_feed.c src/include/skalibs/bytestr.h src/libstdcrypto/sha256-internal.h src/include/skalibs/sha256.h src/libstdcrypto/sha256_final.o src/libstdcrypto/sha256_final.lo: src/libstdcrypto/sha256_final.c src/include/skalibs/bytestr.h src/libstdcrypto/sha256-internal.h src/include/skalibs/sha256.h src/libstdcrypto/sha256_init.o src/libstdcrypto/sha256_init.lo: src/libstdcrypto/sha256_init.c src/include/skalibs/sha256.h src/libstdcrypto/sha256_transform.o src/libstdcrypto/sha256_transform.lo: src/libstdcrypto/sha256_transform.c src/libstdcrypto/sha256-internal.h src/libstdcrypto/sha256_update.o src/libstdcrypto/sha256_update.lo: src/libstdcrypto/sha256_update.c src/libstdcrypto/sha256-internal.h src/include/skalibs/sha256.h src/libstdcrypto/sha512_final.o src/libstdcrypto/sha512_final.lo: src/libstdcrypto/sha512_final.c src/include/skalibs/bytestr.h src/libstdcrypto/sha512-internal.h src/include/skalibs/sha512.h src/include/skalibs/uint64.h src/libstdcrypto/sha512_init.o src/libstdcrypto/sha512_init.lo: src/libstdcrypto/sha512_init.c src/include/skalibs/sha512.h src/libstdcrypto/sha512_transform.o src/libstdcrypto/sha512_transform.lo: src/libstdcrypto/sha512_transform.c src/libstdcrypto/sha512-internal.h src/include/skalibs/sha512.h src/include/skalibs/uint64.h src/libstdcrypto/sha512_update.o src/libstdcrypto/sha512_update.lo: src/libstdcrypto/sha512_update.c src/libstdcrypto/sha512-internal.h src/include/skalibs/sha512.h src/libstddjb/alarm_deadline.o src/libstddjb/alarm_deadline.lo: src/libstddjb/alarm_deadline.c src/libstddjb/alarm-internal.h src/include/skalibs/alarm.h src/include/skalibs/sysdeps.h src/include/skalibs/tai.h src/libstddjb/alarm_disable.o src/libstddjb/alarm_disable.lo: src/libstddjb/alarm_disable.c src/libstddjb/alarm-internal.h src/include/skalibs/alarm.h src/include/skalibs/sysdeps.h src/libstddjb/alarm_milliseconds.o src/libstddjb/alarm_milliseconds.lo: src/libstddjb/alarm_milliseconds.c src/libstddjb/alarm-internal.h src/include/skalibs/alarm.h src/include/skalibs/sysdeps.h src/libstddjb/alarm_timeout.o src/libstddjb/alarm_timeout.lo: src/libstddjb/alarm_timeout.c src/libstddjb/alarm-internal.h src/include/skalibs/alarm.h src/include/skalibs/sysdeps.h src/include/skalibs/tai.h src/libstddjb/alloc.o src/libstddjb/alloc.lo: src/libstddjb/alloc.c src/include/skalibs/alloc.h src/libstddjb/alloc_realloc.o src/libstddjb/alloc_realloc.lo: src/libstddjb/alloc_realloc.c src/include/skalibs/alloc.h src/libstddjb/allread.o src/libstddjb/allread.lo: src/libstddjb/allread.c src/include/skalibs/allreadwrite.h src/libstddjb/allreadv.o src/libstddjb/allreadv.lo: src/libstddjb/allreadv.c src/include/skalibs/allreadwrite.h src/libstddjb/allreadwrite.o src/libstddjb/allreadwrite.lo: src/libstddjb/allreadwrite.c src/include/skalibs/allreadwrite.h src/libstddjb/allreadwritev.o src/libstddjb/allreadwritev.lo: src/libstddjb/allreadwritev.c src/include/skalibs/allreadwrite.h src/include/skalibs/siovec.h src/libstddjb/allwrite.o src/libstddjb/allwrite.lo: src/libstddjb/allwrite.c src/include/skalibs/allreadwrite.h src/include/skalibs/functypes.h src/libstddjb/allwritev.o src/libstddjb/allwritev.lo: src/libstddjb/allwritev.c src/include/skalibs/allreadwrite.h src/libstddjb/baprintf.o src/libstddjb/baprintf.lo: src/libstddjb/baprintf.c src/include/skalibs/bufalloc.h src/include/skalibs/lolstdio.h src/libstddjb/bitarray_and.o src/libstddjb/bitarray_and.lo: src/libstddjb/bitarray_and.c src/include/skalibs/bitarray.h src/libstddjb/bitarray_clearsetn.o src/libstddjb/bitarray_clearsetn.lo: src/libstddjb/bitarray_clearsetn.c src/include/skalibs/bitarray.h src/libstddjb/bitarray_count.o src/libstddjb/bitarray_count.lo: src/libstddjb/bitarray_count.c src/include/skalibs/bitarray.h src/libstddjb/bitarray_firstclear.o src/libstddjb/bitarray_firstclear.lo: src/libstddjb/bitarray_firstclear.c src/include/skalibs/bitarray.h src/libstddjb/bitarray_firstclear_skip.o src/libstddjb/bitarray_firstclear_skip.lo: src/libstddjb/bitarray_firstclear_skip.c src/include/skalibs/bitarray.h src/libstddjb/bitarray_firstset.o src/libstddjb/bitarray_firstset.lo: src/libstddjb/bitarray_firstset.c src/include/skalibs/bitarray.h src/libstddjb/bitarray_firstset_skip.o src/libstddjb/bitarray_firstset_skip.lo: src/libstddjb/bitarray_firstset_skip.c src/include/skalibs/bitarray.h src/libstddjb/bitarray_not.o src/libstddjb/bitarray_not.lo: src/libstddjb/bitarray_not.c src/include/skalibs/bitarray.h src/libstddjb/bitarray_or.o src/libstddjb/bitarray_or.lo: src/libstddjb/bitarray_or.c src/include/skalibs/bitarray.h src/libstddjb/bitarray_testandpoke.o src/libstddjb/bitarray_testandpoke.lo: src/libstddjb/bitarray_testandpoke.c src/include/skalibs/bitarray.h src/libstddjb/bitarray_xor.o src/libstddjb/bitarray_xor.lo: src/libstddjb/bitarray_xor.c src/include/skalibs/bitarray.h src/libstddjb/bprintf.o src/libstddjb/bprintf.lo: src/libstddjb/bprintf.c src/include/skalibs/buffer.h src/include/skalibs/lolstdio.h src/libstddjb/bufalloc_1.o src/libstddjb/bufalloc_1.lo: src/libstddjb/bufalloc_1.c src/include/skalibs/allreadwrite.h src/include/skalibs/bufalloc.h src/libstddjb/bufalloc_2.o src/libstddjb/bufalloc_2.lo: src/libstddjb/bufalloc_2.c src/include/skalibs/allreadwrite.h src/include/skalibs/bufalloc.h src/libstddjb/bufalloc_clean.o src/libstddjb/bufalloc_clean.lo: src/libstddjb/bufalloc_clean.c src/include/skalibs/bufalloc.h src/libstddjb/bufalloc_flush.o src/libstddjb/bufalloc_flush.lo: src/libstddjb/bufalloc_flush.c src/include/skalibs/allreadwrite.h src/include/skalibs/bufalloc.h src/include/skalibs/functypes.h src/libstddjb/bufalloc_getfd.o src/libstddjb/bufalloc_getfd.lo: src/libstddjb/bufalloc_getfd.c src/include/skalibs/bufalloc.h src/libstddjb/bufalloc_getlen.o src/libstddjb/bufalloc_getlen.lo: src/libstddjb/bufalloc_getlen.c src/include/skalibs/bufalloc.h src/libstddjb/bufalloc_init.o src/libstddjb/bufalloc_init.lo: src/libstddjb/bufalloc_init.c src/include/skalibs/bufalloc.h src/include/skalibs/stralloc.h src/libstddjb/buffer_0.o src/libstddjb/buffer_0.lo: src/libstddjb/buffer_0.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/libstddjb/buffer_0f1.o src/libstddjb/buffer_0f1.lo: src/libstddjb/buffer_0f1.c src/include/skalibs/buffer.h src/libstddjb/buffer_0small.o src/libstddjb/buffer_0small.lo: src/libstddjb/buffer_0small.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/libstddjb/buffer_1.o src/libstddjb/buffer_1.lo: src/libstddjb/buffer_1.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/libstddjb/buffer_1small.o src/libstddjb/buffer_1small.lo: src/libstddjb/buffer_1small.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/libstddjb/buffer_2.o src/libstddjb/buffer_2.lo: src/libstddjb/buffer_2.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/libstddjb/buffer_fill.o src/libstddjb/buffer_fill.lo: src/libstddjb/buffer_fill.c src/include/skalibs/buffer.h src/libstddjb/buffer_flush.o src/libstddjb/buffer_flush.lo: src/libstddjb/buffer_flush.c src/include/skalibs/buffer.h src/include/skalibs/cbuffer.h src/libstddjb/buffer_flush1read.o src/libstddjb/buffer_flush1read.lo: src/libstddjb/buffer_flush1read.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/libstddjb/buffer_get.o src/libstddjb/buffer_get.lo: src/libstddjb/buffer_get.c src/include/skalibs/buffer.h src/libstddjb/buffer_getall.o src/libstddjb/buffer_getall.lo: src/libstddjb/buffer_getall.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/libstddjb/buffer_getallnf.o src/libstddjb/buffer_getallnf.lo: src/libstddjb/buffer_getallnf.c src/include/skalibs/buffer.h src/libstddjb/buffer_getfd.o src/libstddjb/buffer_getfd.lo: src/libstddjb/buffer_getfd.c src/include/skalibs/buffer.h src/libstddjb/buffer_getlen.o src/libstddjb/buffer_getlen.lo: src/libstddjb/buffer_getlen.c src/include/skalibs/buffer.h src/libstddjb/buffer_getv.o src/libstddjb/buffer_getv.lo: src/libstddjb/buffer_getv.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/libstddjb/buffer_getvall.o src/libstddjb/buffer_getvall.lo: src/libstddjb/buffer_getvall.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/libstddjb/buffer_getvallnf.o src/libstddjb/buffer_getvallnf.lo: src/libstddjb/buffer_getvallnf.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/libstddjb/buffer_init.o src/libstddjb/buffer_init.lo: src/libstddjb/buffer_init.c src/include/skalibs/buffer.h src/include/skalibs/cbuffer.h src/libstddjb/buffer_put.o src/libstddjb/buffer_put.lo: src/libstddjb/buffer_put.c src/include/skalibs/buffer.h src/libstddjb/buffer_putall.o src/libstddjb/buffer_putall.lo: src/libstddjb/buffer_putall.c src/include/skalibs/buffer.h src/libstddjb/buffer_putallnf.o src/libstddjb/buffer_putallnf.lo: src/libstddjb/buffer_putallnf.c src/include/skalibs/buffer.h src/libstddjb/buffer_putflush.o src/libstddjb/buffer_putflush.lo: src/libstddjb/buffer_putflush.c src/include/skalibs/buffer.h src/libstddjb/buffer_puts.o src/libstddjb/buffer_puts.lo: src/libstddjb/buffer_puts.c src/include/skalibs/buffer.h src/libstddjb/buffer_putsall.o src/libstddjb/buffer_putsall.lo: src/libstddjb/buffer_putsall.c src/include/skalibs/buffer.h src/libstddjb/buffer_putsallflush.o src/libstddjb/buffer_putsallflush.lo: src/libstddjb/buffer_putsallflush.c src/include/skalibs/buffer.h src/libstddjb/buffer_putsallnoflush.o src/libstddjb/buffer_putsallnoflush.lo: src/libstddjb/buffer_putsallnoflush.c src/include/skalibs/buffer.h src/libstddjb/buffer_putsflush.o src/libstddjb/buffer_putsflush.lo: src/libstddjb/buffer_putsflush.c src/include/skalibs/buffer.h src/libstddjb/buffer_putsnoflush.o src/libstddjb/buffer_putsnoflush.lo: src/libstddjb/buffer_putsnoflush.c src/include/skalibs/buffer.h src/libstddjb/buffer_putv.o src/libstddjb/buffer_putv.lo: src/libstddjb/buffer_putv.c src/include/skalibs/buffer.h src/libstddjb/buffer_putvall.o src/libstddjb/buffer_putvall.lo: src/libstddjb/buffer_putvall.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/libstddjb/buffer_putvallnf.o src/libstddjb/buffer_putvallnf.lo: src/libstddjb/buffer_putvallnf.c src/include/skalibs/buffer.h src/include/skalibs/siovec.h src/libstddjb/buffer_putvflush.o src/libstddjb/buffer_putvflush.lo: src/libstddjb/buffer_putvflush.c src/include/skalibs/buffer.h src/libstddjb/byte_chr.o src/libstddjb/byte_chr.lo: src/libstddjb/byte_chr.c src/include/skalibs/bytestr.h 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/byte_zzero.o src/libstddjb/byte_zzero.lo: src/libstddjb/byte_zzero.c src/include/skalibs/bytestr.h src/include/skalibs/gccattributes.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.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 src/libstddjb/case_str.o src/libstddjb/case_str.lo: src/libstddjb/case_str.c src/include/skalibs/bytestr.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/case_upperb.o src/libstddjb/case_upperb.lo: src/libstddjb/case_upperb.c src/include/skalibs/bytestr.h src/libstddjb/case_uppers.o src/libstddjb/case_uppers.lo: src/libstddjb/case_uppers.c src/include/skalibs/bytestr.h src/libstddjb/cbuffer_get.o src/libstddjb/cbuffer_get.lo: src/libstddjb/cbuffer_get.c src/include/skalibs/cbuffer.h src/include/skalibs/siovec.h src/libstddjb/cbuffer_getv.o src/libstddjb/cbuffer_getv.lo: src/libstddjb/cbuffer_getv.c src/include/skalibs/cbuffer.h src/include/skalibs/siovec.h src/libstddjb/cbuffer_init.o src/libstddjb/cbuffer_init.lo: src/libstddjb/cbuffer_init.c src/include/skalibs/cbuffer.h src/libstddjb/cbuffer_put.o src/libstddjb/cbuffer_put.lo: src/libstddjb/cbuffer_put.c src/include/skalibs/cbuffer.h src/include/skalibs/siovec.h src/libstddjb/cbuffer_putv.o src/libstddjb/cbuffer_putv.lo: src/libstddjb/cbuffer_putv.c src/include/skalibs/cbuffer.h src/include/skalibs/siovec.h src/libstddjb/cbuffer_rpeek.o src/libstddjb/cbuffer_rpeek.lo: src/libstddjb/cbuffer_rpeek.c src/include/skalibs/cbuffer.h src/libstddjb/cbuffer_rseek.o src/libstddjb/cbuffer_rseek.lo: src/libstddjb/cbuffer_rseek.c src/include/skalibs/cbuffer.h src/libstddjb/cbuffer_unget.o src/libstddjb/cbuffer_unget.lo: src/libstddjb/cbuffer_unget.c src/include/skalibs/cbuffer.h src/libstddjb/cbuffer_unput.o src/libstddjb/cbuffer_unput.lo: src/libstddjb/cbuffer_unput.c src/include/skalibs/cbuffer.h src/libstddjb/cbuffer_wpeek.o src/libstddjb/cbuffer_wpeek.lo: src/libstddjb/cbuffer_wpeek.c src/include/skalibs/cbuffer.h src/libstddjb/cbuffer_wseek.o src/libstddjb/cbuffer_wseek.lo: src/libstddjb/cbuffer_wseek.c src/include/skalibs/cbuffer.h src/libstddjb/cdb_findnext.o src/libstddjb/cdb_findnext.lo: src/libstddjb/cdb_findnext.c src/include/skalibs/cdb.h src/include/skalibs/uint32.h src/libstddjb/cdb_free.o src/libstddjb/cdb_free.lo: src/libstddjb/cdb_free.c src/include/skalibs/cdb.h src/libstddjb/cdb_hash.o src/libstddjb/cdb_hash.lo: src/libstddjb/cdb_hash.c src/include/skalibs/cdb.h src/libstddjb/cdb_init_map.o src/libstddjb/cdb_init_map.lo: src/libstddjb/cdb_init_map.c src/include/skalibs/bsdsnowflake.h src/include/skalibs/cdb.h src/libstddjb/cdb_make.o src/libstddjb/cdb_make.lo: src/libstddjb/cdb_make.c src/include/skalibs/buffer.h src/include/skalibs/cdb.h src/include/skalibs/cdb_make.h src/include/skalibs/diuint32.h src/include/skalibs/genalloc.h src/include/skalibs/uint32.h src/libstddjb/cdb_mapfile.o src/libstddjb/cdb_mapfile.lo: src/libstddjb/cdb_mapfile.c src/include/skalibs/cdb.h src/include/skalibs/djbunix.h src/libstddjb/cdb_nextkey.o src/libstddjb/cdb_nextkey.lo: src/libstddjb/cdb_nextkey.c src/include/skalibs/cdb.h src/include/skalibs/uint32.h src/libstddjb/cdb_read.o src/libstddjb/cdb_read.lo: src/libstddjb/cdb_read.c src/include/skalibs/allreadwrite.h src/include/skalibs/cdb.h src/include/skalibs/posixishard.h src/libstddjb/cdb_successor.o src/libstddjb/cdb_successor.lo: src/libstddjb/cdb_successor.c src/include/skalibs/cdb.h src/libstddjb/cdb_zero.o src/libstddjb/cdb_zero.lo: src/libstddjb/cdb_zero.c src/include/skalibs/cdb.h src/libstddjb/child_spawn.o src/libstddjb/child_spawn.lo: src/libstddjb/child_spawn.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/sig.h src/include/skalibs/strerr2.h src/include/skalibs/sysdeps.h src/include/skalibs/types.h src/libstddjb/child_spawn0.o src/libstddjb/child_spawn0.lo: src/libstddjb/child_spawn0.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/sig.h src/include/skalibs/strerr2.h src/include/skalibs/sysdeps.h src/libstddjb/child_spawn1_internal.o src/libstddjb/child_spawn1_internal.lo: src/libstddjb/child_spawn1_internal.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/sig.h src/include/skalibs/strerr2.h src/include/skalibs/sysdeps.h src/libstddjb/child_spawn1_pipe.o src/libstddjb/child_spawn1_pipe.lo: src/libstddjb/child_spawn1_pipe.c src/libstddjb/djbunix-internal.h src/include/skalibs/djbunix.h src/libstddjb/child_spawn1_socket.o src/libstddjb/child_spawn1_socket.lo: src/libstddjb/child_spawn1_socket.c src/libstddjb/djbunix-internal.h src/include/skalibs/djbunix.h src/include/skalibs/webipc.h src/libstddjb/child_spawn2.o src/libstddjb/child_spawn2.lo: src/libstddjb/child_spawn2.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/sig.h src/include/skalibs/strerr2.h src/include/skalibs/sysdeps.h src/libstddjb/child_spawn3.o src/libstddjb/child_spawn3.lo: src/libstddjb/child_spawn3.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/sig.h src/include/skalibs/strerr2.h src/include/skalibs/sysdeps.h src/include/skalibs/types.h 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/dir_fd.o src/libstddjb/dir_fd.lo: src/libstddjb/dir_fd.c src/include/skalibs/direntry.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.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_dump.o src/libstddjb/env_dump.lo: src/libstddjb/env_dump.c src/include/skalibs/bytestr.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/nonposix.h src/include/skalibs/unix-transactional.h src/libstddjb/env_get.o src/libstddjb/env_get.lo: src/libstddjb/env_get.c 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 src/libstddjb/env_merge.o src/libstddjb/env_merge.lo: src/libstddjb/env_merge.c src/include/skalibs/bytestr.h src/include/skalibs/env.h src/libstddjb/env_string.o src/libstddjb/env_string.lo: src/libstddjb/env_string.c src/include/skalibs/env.h src/include/skalibs/stralloc.h src/libstddjb/envalloc_0.o src/libstddjb/envalloc_0.lo: src/libstddjb/envalloc_0.c src/include/skalibs/envalloc.h src/include/skalibs/genalloc.h src/libstddjb/envalloc_make.o src/libstddjb/envalloc_make.lo: src/libstddjb/envalloc_make.c src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/genalloc.h src/libstddjb/envalloc_merge.o src/libstddjb/envalloc_merge.lo: src/libstddjb/envalloc_merge.c src/include/skalibs/bytestr.h src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/genalloc.h 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_isalready.o src/libstddjb/error_isalready.lo: src/libstddjb/error_isalready.c src/include/skalibs/bsdsnowflake.h src/include/skalibs/error.h src/libstddjb/error_temp.o src/libstddjb/error_temp.lo: src/libstddjb/error_temp.c src/include/skalibs/error.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 src/libstddjb/fd_chmod.o src/libstddjb/fd_chmod.lo: src/libstddjb/fd_chmod.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/libstddjb/fd_chown.o src/libstddjb/fd_chown.lo: src/libstddjb/fd_chown.c src/include/skalibs/djbunix.h src/libstddjb/fd_close.o src/libstddjb/fd_close.lo: src/libstddjb/fd_close.c src/include/skalibs/djbunix.h src/libstddjb/fd_copy.o src/libstddjb/fd_copy.lo: src/libstddjb/fd_copy.c src/include/skalibs/djbunix.h src/libstddjb/fd_copy2.o src/libstddjb/fd_copy2.lo: src/libstddjb/fd_copy2.c src/include/skalibs/djbunix.h src/libstddjb/fd_ensure_open.o src/libstddjb/fd_ensure_open.lo: src/libstddjb/fd_ensure_open.c src/include/skalibs/djbunix.h src/libstddjb/fd_move.o src/libstddjb/fd_move.lo: src/libstddjb/fd_move.c src/include/skalibs/djbunix.h src/libstddjb/fd_move2.o src/libstddjb/fd_move2.lo: src/libstddjb/fd_move2.c src/include/skalibs/djbunix.h src/libstddjb/fd_read.o src/libstddjb/fd_read.lo: src/libstddjb/fd_read.c src/include/skalibs/allreadwrite.h src/libstddjb/fd_readv.o src/libstddjb/fd_readv.lo: src/libstddjb/fd_readv.c src/include/skalibs/allreadwrite.h src/libstddjb/fd_recv.o src/libstddjb/fd_recv.lo: src/libstddjb/fd_recv.c src/include/skalibs/allreadwrite.h src/libstddjb/fd_send.o src/libstddjb/fd_send.lo: src/libstddjb/fd_send.c src/include/skalibs/allreadwrite.h src/libstddjb/fd_sync.o src/libstddjb/fd_sync.lo: src/libstddjb/fd_sync.c src/include/skalibs/djbunix.h src/libstddjb/fd_write.o src/libstddjb/fd_write.lo: src/libstddjb/fd_write.c src/include/skalibs/allreadwrite.h src/libstddjb/fd_writev.o src/libstddjb/fd_writev.lo: src/libstddjb/fd_writev.c src/include/skalibs/allreadwrite.h src/libstddjb/filecopy_suffix.o src/libstddjb/filecopy_suffix.lo: src/libstddjb/filecopy_suffix.c src/include/skalibs/djbunix.h src/libstddjb/filecopy_unsafe.o src/libstddjb/filecopy_unsafe.lo: src/libstddjb/filecopy_unsafe.c src/include/skalibs/djbunix.h src/libstddjb/fmtscan_asc.o src/libstddjb/fmtscan_asc.lo: src/libstddjb/fmtscan_asc.c src/include/skalibs/fmtscan.h src/libstddjb/fmtscan_num.o src/libstddjb/fmtscan_num.lo: src/libstddjb/fmtscan_num.c src/include/skalibs/fmtscan.h src/libstddjb/genalloc_deepfree.o src/libstddjb/genalloc_deepfree.lo: src/libstddjb/genalloc_deepfree.c src/include/skalibs/genalloc.h src/include/skalibs/stralloc.h src/libstddjb/genwrite_flush_bufalloc.o src/libstddjb/genwrite_flush_bufalloc.lo: src/libstddjb/genwrite_flush_bufalloc.c src/include/skalibs/bufalloc.h src/include/skalibs/genwrite.h src/libstddjb/genwrite_flush_buffer.o src/libstddjb/genwrite_flush_buffer.lo: src/libstddjb/genwrite_flush_buffer.c src/include/skalibs/buffer.h src/include/skalibs/genwrite.h src/libstddjb/genwrite_flush_stralloc.o src/libstddjb/genwrite_flush_stralloc.lo: src/libstddjb/genwrite_flush_stralloc.c src/include/skalibs/genwrite.h src/libstddjb/genwrite_put_bufalloc.o src/libstddjb/genwrite_put_bufalloc.lo: src/libstddjb/genwrite_put_bufalloc.c src/include/skalibs/bufalloc.h src/include/skalibs/genwrite.h src/libstddjb/genwrite_put_buffer.o src/libstddjb/genwrite_put_buffer.lo: src/libstddjb/genwrite_put_buffer.c src/include/skalibs/buffer.h src/include/skalibs/genwrite.h src/libstddjb/genwrite_put_stralloc.o src/libstddjb/genwrite_put_stralloc.lo: src/libstddjb/genwrite_put_stralloc.c src/include/skalibs/genwrite.h src/include/skalibs/stralloc.h src/libstddjb/genwrite_stderr.o src/libstddjb/genwrite_stderr.lo: src/libstddjb/genwrite_stderr.c src/include/skalibs/buffer.h src/include/skalibs/genwrite.h 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/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 src/libstddjb/int16_fmtlist.o src/libstddjb/int16_fmtlist.lo: src/libstddjb/int16_fmtlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h src/libstddjb/int16_scan.o src/libstddjb/int16_scan.lo: src/libstddjb/int16_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h src/include/skalibs/uint64.h src/libstddjb/int16_scanlist.o src/libstddjb/int16_scanlist.lo: src/libstddjb/int16_scanlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h src/libstddjb/int320_scan.o src/libstddjb/int320_scan.lo: src/libstddjb/int320_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h src/libstddjb/int32_fmtlist.o src/libstddjb/int32_fmtlist.lo: src/libstddjb/int32_fmtlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h src/libstddjb/int32_scan.o src/libstddjb/int32_scan.lo: src/libstddjb/int32_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h src/include/skalibs/uint64.h src/libstddjb/int32_scanlist.o src/libstddjb/int32_scanlist.lo: src/libstddjb/int32_scanlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h src/libstddjb/int640_scan.o src/libstddjb/int640_scan.lo: src/libstddjb/int640_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h src/libstddjb/int64_fmt_generic.o src/libstddjb/int64_fmt_generic.lo: src/libstddjb/int64_fmt_generic.c src/include/skalibs/uint64.h src/libstddjb/int64_fmtlist.o src/libstddjb/int64_fmtlist.lo: src/libstddjb/int64_fmtlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h src/libstddjb/int64_scan.o src/libstddjb/int64_scan.lo: src/libstddjb/int64_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h src/libstddjb/int64_scan_base_max.o src/libstddjb/int64_scan_base_max.lo: src/libstddjb/int64_scan_base_max.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h src/libstddjb/int64_scanlist.o src/libstddjb/int64_scanlist.lo: src/libstddjb/int64_scanlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h src/libstddjb/iobuffer_fill.o src/libstddjb/iobuffer_fill.lo: src/libstddjb/iobuffer_fill.c src/include/skalibs/iobuffer.h src/libstddjb/iobuffer_flush.o src/libstddjb/iobuffer_flush.lo: src/libstddjb/iobuffer_flush.c src/include/skalibs/iobuffer.h src/libstddjb/iobuffer_init.o src/libstddjb/iobuffer_init.lo: src/libstddjb/iobuffer_init.c src/include/skalibs/iobuffer.h src/libstddjb/iobuffer_kfromu.o src/libstddjb/iobuffer_kfromu.lo: src/libstddjb/iobuffer_kfromu.c src/include/skalibs/buffer.h src/include/skalibs/iobuffer.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/iobuffer_salvage.o src/libstddjb/iobuffer_salvage.lo: src/libstddjb/iobuffer_salvage.c src/include/skalibs/iobuffer.h src/libstddjb/iobuffer_ufromk.o src/libstddjb/iobuffer_ufromk.lo: src/libstddjb/iobuffer_ufromk.c src/include/skalibs/iobuffer.h src/include/skalibs/sysdeps.h src/libstddjb/iobufferk_fill.o src/libstddjb/iobufferk_fill.lo: src/libstddjb/iobufferk_fill.c src/include/skalibs/iobuffer.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/iobufferk_finish.o src/libstddjb/iobufferk_finish.lo: src/libstddjb/iobufferk_finish.c src/include/skalibs/djbunix.h src/include/skalibs/iobuffer.h src/include/skalibs/sysdeps.h src/libstddjb/iobufferk_flush.o src/libstddjb/iobufferk_flush.lo: src/libstddjb/iobufferk_flush.c src/include/skalibs/iobuffer.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/iobufferk_init.o src/libstddjb/iobufferk_init.lo: src/libstddjb/iobufferk_init.c src/include/skalibs/djbunix.h src/include/skalibs/iobuffer.h src/include/skalibs/sysdeps.h src/libstddjb/iobufferk_isworking.o src/libstddjb/iobufferk_isworking.lo: src/libstddjb/iobufferk_isworking.c src/include/skalibs/iobuffer.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/iobufferu_fill.o src/libstddjb/iobufferu_fill.lo: src/libstddjb/iobufferu_fill.c src/include/skalibs/buffer.h src/include/skalibs/iobuffer.h src/libstddjb/iobufferu_finish.o src/libstddjb/iobufferu_finish.lo: src/libstddjb/iobufferu_finish.c src/include/skalibs/alloc.h src/include/skalibs/iobuffer.h src/libstddjb/iobufferu_flush.o src/libstddjb/iobufferu_flush.lo: src/libstddjb/iobufferu_flush.c src/include/skalibs/buffer.h src/include/skalibs/iobuffer.h src/libstddjb/iobufferu_init.o src/libstddjb/iobufferu_init.lo: src/libstddjb/iobufferu_init.c src/include/skalibs/alloc.h src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/iobuffer.h src/libstddjb/iopause.o src/libstddjb/iopause.lo: src/libstddjb/iopause.c src/include/skalibs/config.h src/include/skalibs/iopause.h src/include/skalibs/sysdeps.h src/libstddjb/iopause_poll.o src/libstddjb/iopause_poll.lo: src/libstddjb/iopause_poll.c src/include/skalibs/iopause.h src/include/skalibs/tai.h src/libstddjb/iopause_ppoll.o src/libstddjb/iopause_ppoll.lo: src/libstddjb/iopause_ppoll.c src/include/skalibs/iopause.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/include/skalibs/tai.h src/libstddjb/iopause_select.o src/libstddjb/iopause_select.lo: src/libstddjb/iopause_select.c src/include/skalibs/bsdsnowflake.h src/include/skalibs/iopause.h src/include/skalibs/tai.h src/libstddjb/iopause_stamp.o src/libstddjb/iopause_stamp.lo: src/libstddjb/iopause_stamp.c src/include/skalibs/iopause.h src/include/skalibs/tai.h src/libstddjb/ip46_scan.o src/libstddjb/ip46_scan.lo: src/libstddjb/ip46_scan.c src/include/skalibs/fmtscan.h src/include/skalibs/ip46.h src/libstddjb/ip46_scanlist.o src/libstddjb/ip46_scanlist.lo: src/libstddjb/ip46_scanlist.c src/include/skalibs/fmtscan.h src/include/skalibs/ip46.h src/libstddjb/ip4_fmt.o src/libstddjb/ip4_fmt.lo: src/libstddjb/ip4_fmt.c src/include/skalibs/fmtscan.h src/include/skalibs/uint32.h src/libstddjb/ip4_fmtu32.o src/libstddjb/ip4_fmtu32.lo: src/libstddjb/ip4_fmtu32.c src/include/skalibs/fmtscan.h src/include/skalibs/uint32.h src/libstddjb/ip4_scan.o src/libstddjb/ip4_scan.lo: src/libstddjb/ip4_scan.c src/include/skalibs/fmtscan.h src/include/skalibs/types.h src/libstddjb/ip4_scanlist.o src/libstddjb/ip4_scanlist.lo: src/libstddjb/ip4_scanlist.c src/include/skalibs/fmtscan.h src/libstddjb/ip4_scanlist_u32.o src/libstddjb/ip4_scanlist_u32.lo: src/libstddjb/ip4_scanlist_u32.c src/include/skalibs/fmtscan.h src/libstddjb/ip4_scanu32.o src/libstddjb/ip4_scanu32.lo: src/libstddjb/ip4_scanu32.c src/include/skalibs/fmtscan.h src/include/skalibs/uint32.h src/libstddjb/ip6_fmt.o src/libstddjb/ip6_fmt.lo: src/libstddjb/ip6_fmt.c src/include/skalibs/diuint.h src/include/skalibs/fmtscan.h src/libstddjb/ip6_scan.o src/libstddjb/ip6_scan.lo: src/libstddjb/ip6_scan.c src/include/skalibs/fmtscan.h src/include/skalibs/uint16.h src/libstddjb/ip6_scanlist.o src/libstddjb/ip6_scanlist.lo: src/libstddjb/ip6_scanlist.c src/include/skalibs/fmtscan.h src/libstddjb/ipc_accept.o src/libstddjb/ipc_accept.lo: src/libstddjb/ipc_accept.c src/include/skalibs/bytestr.h src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/include/skalibs/webipc.h src/libstddjb/ipc_bind.o src/libstddjb/ipc_bind.lo: src/libstddjb/ipc_bind.c src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/webipc.h src/libstddjb/ipc_bind_reuse.o src/libstddjb/ipc_bind_reuse.lo: src/libstddjb/ipc_bind_reuse.c src/include/skalibs/nonposix.h src/include/skalibs/webipc.h src/libstddjb/ipc_connect.o src/libstddjb/ipc_connect.lo: src/libstddjb/ipc_connect.c src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/webipc.h src/libstddjb/ipc_connected.o src/libstddjb/ipc_connected.lo: src/libstddjb/ipc_connected.c src/include/skalibs/allreadwrite.h src/include/skalibs/nonposix.h src/include/skalibs/webipc.h src/libstddjb/ipc_dgram.o src/libstddjb/ipc_dgram.lo: src/libstddjb/ipc_dgram.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/webipc.h src/libstddjb/ipc_listen.o src/libstddjb/ipc_listen.lo: src/libstddjb/ipc_listen.c src/include/skalibs/nonposix.h src/include/skalibs/webipc.h src/libstddjb/ipc_local.o src/libstddjb/ipc_local.lo: src/libstddjb/ipc_local.c src/include/skalibs/bytestr.h src/include/skalibs/nonposix.h src/include/skalibs/webipc.h src/libstddjb/ipc_pair.o src/libstddjb/ipc_pair.lo: src/libstddjb/ipc_pair.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/webipc.h src/libstddjb/ipc_recv.o src/libstddjb/ipc_recv.lo: src/libstddjb/ipc_recv.c src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/webipc.h src/libstddjb/ipc_send.o src/libstddjb/ipc_send.lo: src/libstddjb/ipc_send.c src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/webipc.h src/libstddjb/ipc_stream.o src/libstddjb/ipc_stream.lo: src/libstddjb/ipc_stream.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/webipc.h src/libstddjb/ipc_timed_connect.o src/libstddjb/ipc_timed_connect.lo: src/libstddjb/ipc_timed_connect.c src/include/skalibs/error.h src/include/skalibs/iopause.h src/include/skalibs/webipc.h src/libstddjb/leapsecs_add.o src/libstddjb/leapsecs_add.lo: src/libstddjb/leapsecs_add.c src/libstddjb/djbtime-internal.h src/include/skalibs/uint64.h src/libstddjb/leapsecs_sub.o src/libstddjb/leapsecs_sub.lo: src/libstddjb/leapsecs_sub.c src/libstddjb/djbtime-internal.h src/include/skalibs/uint64.h src/libstddjb/leapsecs_table.o src/libstddjb/leapsecs_table.lo: src/libstddjb/leapsecs_table.c src/libstddjb/djbtime-internal.h src/include/skalibs/tai.h src/include/skalibs/uint64.h src/libstddjb/localtm_fmt.o src/libstddjb/localtm_fmt.lo: src/libstddjb/localtm_fmt.c src/include/skalibs/djbtime.h src/include/skalibs/types.h src/libstddjb/localtm_from_ltm64.o src/libstddjb/localtm_from_ltm64.lo: src/libstddjb/localtm_from_ltm64.c src/include/skalibs/bsdsnowflake.h src/include/skalibs/djbtime.h src/include/skalibs/sysdeps.h src/include/skalibs/tai.h src/include/skalibs/uint64.h src/libstddjb/localtm_from_sysclock.o src/libstddjb/localtm_from_sysclock.lo: src/libstddjb/localtm_from_sysclock.c src/include/skalibs/djbtime.h src/include/skalibs/uint64.h src/libstddjb/localtm_from_tai.o src/libstddjb/localtm_from_tai.lo: src/libstddjb/localtm_from_tai.c src/include/skalibs/djbtime.h src/include/skalibs/uint64.h src/libstddjb/localtm_from_utc.o src/libstddjb/localtm_from_utc.lo: src/libstddjb/localtm_from_utc.c src/include/skalibs/djbtime.h src/include/skalibs/uint64.h src/libstddjb/localtm_scan.o src/libstddjb/localtm_scan.lo: src/libstddjb/localtm_scan.c src/include/skalibs/djbtime.h src/include/skalibs/types.h src/libstddjb/localtmn_fmt.o src/libstddjb/localtmn_fmt.lo: src/libstddjb/localtmn_fmt.c src/include/skalibs/djbtime.h src/include/skalibs/uint32.h src/libstddjb/localtmn_from_sysclock.o src/libstddjb/localtmn_from_sysclock.lo: src/libstddjb/localtmn_from_sysclock.c src/include/skalibs/djbtime.h src/libstddjb/localtmn_from_tain.o src/libstddjb/localtmn_from_tain.lo: src/libstddjb/localtmn_from_tain.c src/include/skalibs/djbtime.h src/libstddjb/localtmn_scan.o src/libstddjb/localtmn_scan.lo: src/libstddjb/localtmn_scan.c src/include/skalibs/djbtime.h src/include/skalibs/uint32.h src/libstddjb/lock_ex.o src/libstddjb/lock_ex.lo: src/libstddjb/lock_ex.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/lock_exnb.o src/libstddjb/lock_exnb.lo: src/libstddjb/lock_exnb.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/lock_sh.o src/libstddjb/lock_sh.lo: src/libstddjb/lock_sh.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/lock_shnb.o src/libstddjb/lock_shnb.lo: src/libstddjb/lock_shnb.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/lock_un.o src/libstddjb/lock_un.lo: src/libstddjb/lock_un.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/lock_unx.o src/libstddjb/lock_unx.lo: src/libstddjb/lock_unx.c src/include/skalibs/djbunix.h src/libstddjb/lolprintf.o src/libstddjb/lolprintf.lo: src/libstddjb/lolprintf.c src/include/skalibs/buffer.h src/include/skalibs/lolstdio.h src/libstddjb/ltm64_from_localtm.o src/libstddjb/ltm64_from_localtm.lo: src/libstddjb/ltm64_from_localtm.c src/include/skalibs/djbtime.h src/include/skalibs/tai.h src/libstddjb/ltm64_from_sysclock.o src/libstddjb/ltm64_from_sysclock.lo: src/libstddjb/ltm64_from_sysclock.c src/include/skalibs/config.h src/include/skalibs/djbtime.h src/include/skalibs/tai.h src/libstddjb/ltm64_from_tai.o src/libstddjb/ltm64_from_tai.lo: src/libstddjb/ltm64_from_tai.c src/libstddjb/djbtime-internal.h src/include/skalibs/djbtime.h src/libstddjb/ltm64_from_utc.o src/libstddjb/ltm64_from_utc.lo: src/libstddjb/ltm64_from_utc.c src/libstddjb/djbtime-internal.h src/include/skalibs/djbtime.h src/include/skalibs/uint64.h src/libstddjb/ndelay_off.o src/libstddjb/ndelay_off.lo: src/libstddjb/ndelay_off.c src/include/skalibs/djbunix.h src/libstddjb/ndelay_on.o src/libstddjb/ndelay_on.lo: src/libstddjb/ndelay_on.c src/include/skalibs/djbunix.h src/libstddjb/netstring_append.o src/libstddjb/netstring_append.lo: src/libstddjb/netstring_append.c src/include/skalibs/netstring.h src/include/skalibs/stralloc.h src/include/skalibs/uint64.h src/libstddjb/netstring_appendv.o src/libstddjb/netstring_appendv.lo: src/libstddjb/netstring_appendv.c src/include/skalibs/bytestr.h src/include/skalibs/netstring.h src/include/skalibs/siovec.h src/include/skalibs/stralloc.h src/include/skalibs/uint64.h src/libstddjb/netstring_decode.o src/libstddjb/netstring_decode.lo: src/libstddjb/netstring_decode.c src/include/skalibs/netstring.h src/include/skalibs/stralloc.h src/include/skalibs/uint64.h src/libstddjb/netstring_encode.o src/libstddjb/netstring_encode.lo: src/libstddjb/netstring_encode.c src/include/skalibs/netstring.h src/include/skalibs/stralloc.h src/include/skalibs/uint64.h src/libstddjb/netstring_get.o src/libstddjb/netstring_get.lo: src/libstddjb/netstring_get.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/bytestr.h src/include/skalibs/netstring.h src/include/skalibs/posixishard.h src/include/skalibs/stralloc.h src/include/skalibs/types.h src/libstddjb/netstring_put.o src/libstddjb/netstring_put.lo: src/libstddjb/netstring_put.c src/include/skalibs/buffer.h src/include/skalibs/netstring.h src/include/skalibs/uint64.h src/libstddjb/ntp_from_tain.o src/libstddjb/ntp_from_tain.lo: src/libstddjb/ntp_from_tain.c src/include/skalibs/djbtime.h src/include/skalibs/tai.h src/include/skalibs/uint64.h src/libstddjb/open2.o src/libstddjb/open2.lo: src/libstddjb/open2.c src/include/skalibs/nonposix.h src/libstddjb/open3.o src/libstddjb/open3.lo: src/libstddjb/open3.c src/include/skalibs/nonposix.h src/libstddjb/open_append.o src/libstddjb/open_append.lo: src/libstddjb/open_append.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/libstddjb/open_create.o src/libstddjb/open_create.lo: src/libstddjb/open_create.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/libstddjb/open_excl.o src/libstddjb/open_excl.lo: src/libstddjb/open_excl.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/libstddjb/open_read.o src/libstddjb/open_read.lo: src/libstddjb/open_read.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/libstddjb/open_readb.o src/libstddjb/open_readb.lo: src/libstddjb/open_readb.c src/include/skalibs/djbunix.h src/libstddjb/open_trunc.o src/libstddjb/open_trunc.lo: src/libstddjb/open_trunc.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/libstddjb/open_write.o src/libstddjb/open_write.lo: src/libstddjb/open_write.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/libstddjb/openb_read.o src/libstddjb/openb_read.lo: src/libstddjb/openb_read.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/libstddjb/openreadfileclose.o src/libstddjb/openreadfileclose.lo: src/libstddjb/openreadfileclose.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/libstddjb/openreadnclose.o src/libstddjb/openreadnclose.lo: src/libstddjb/openreadnclose.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/libstddjb/openslurpclose.o src/libstddjb/openslurpclose.lo: src/libstddjb/openslurpclose.c src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/libstddjb/openwritenclose.o src/libstddjb/openwritenclose.lo: src/libstddjb/openwritenclose.c src/include/skalibs/djbunix.h src/libstddjb/openwritenclose_suffix.o src/libstddjb/openwritenclose_suffix.lo: src/libstddjb/openwritenclose_suffix.c src/include/skalibs/djbunix.h src/libstddjb/openwritenclose_unsafe.o src/libstddjb/openwritenclose_unsafe.lo: src/libstddjb/openwritenclose_unsafe.c src/include/skalibs/djbunix.h 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/path_canonicalize.o src/libstddjb/path_canonicalize.lo: src/libstddjb/path_canonicalize.c 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/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/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/rm_rf.o src/libstddjb/rm_rf.lo: src/libstddjb/rm_rf.c src/include/skalibs/djbunix.h src/include/skalibs/skamisc.h src/libstddjb/rm_rf_in_tmp.o src/libstddjb/rm_rf_in_tmp.lo: src/libstddjb/rm_rf_in_tmp.c src/include/skalibs/direntry.h src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/libstddjb/rm_rf_tmp.o src/libstddjb/rm_rf_tmp.lo: src/libstddjb/rm_rf_tmp.c src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/libstddjb/rmstar.o src/libstddjb/rmstar.lo: src/libstddjb/rmstar.c src/include/skalibs/djbunix.h src/include/skalibs/skamisc.h src/libstddjb/sabasename.o src/libstddjb/sabasename.lo: src/libstddjb/sabasename.c src/include/skalibs/bytestr.h src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/libstddjb/sadirname.o src/libstddjb/sadirname.lo: src/libstddjb/sadirname.c src/include/skalibs/bytestr.h src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/libstddjb/sagetcwd.o src/libstddjb/sagetcwd.lo: src/libstddjb/sagetcwd.c src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/libstddjb/sagethostname.o src/libstddjb/sagethostname.lo: src/libstddjb/sagethostname.c src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/libstddjb/sanitize_read.o src/libstddjb/sanitize_read.lo: src/libstddjb/sanitize_read.c src/include/skalibs/allreadwrite.h src/include/skalibs/error.h src/libstddjb/sareadlink.o src/libstddjb/sareadlink.lo: src/libstddjb/sareadlink.c src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/libstddjb/sarealpath.o src/libstddjb/sarealpath.lo: src/libstddjb/sarealpath.c src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/libstddjb/satmp.o src/libstddjb/satmp.lo: src/libstddjb/satmp.c src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h src/libstddjb/sauniquename.o src/libstddjb/sauniquename.lo: src/libstddjb/sauniquename.c src/include/skalibs/djbunix.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h src/include/skalibs/tai.h src/include/skalibs/types.h src/libstddjb/selfpipe_finish.o src/libstddjb/selfpipe_finish.lo: src/libstddjb/selfpipe_finish.c src/include/skalibs/djbunix.h 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_init.o src/libstddjb/selfpipe_init.lo: src/libstddjb/selfpipe_init.c src/include/skalibs/djbunix.h src/libstddjb/selfpipe-internal.h src/include/skalibs/selfpipe.h src/include/skalibs/sysdeps.h src/libstddjb/selfpipe_internal.o src/libstddjb/selfpipe_internal.lo: src/libstddjb/selfpipe_internal.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/libstddjb/selfpipe-internal.h src/include/skalibs/sysdeps.h src/libstddjb/selfpipe_read.o src/libstddjb/selfpipe_read.lo: src/libstddjb/selfpipe_read.c src/include/skalibs/allreadwrite.h src/libstddjb/selfpipe-internal.h src/include/skalibs/selfpipe.h src/include/skalibs/sysdeps.h 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/sgetopt.o src/libstddjb/sgetopt.lo: src/libstddjb/sgetopt.c src/include/skalibs/buffer.h src/include/skalibs/sgetopt.h src/libstddjb/sig0_scan.o src/libstddjb/sig0_scan.lo: src/libstddjb/sig0_scan.c src/include/skalibs/sig.h src/include/skalibs/types.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 src/libstddjb/sig_blockset.o src/libstddjb/sig_blockset.lo: src/libstddjb/sig_blockset.c src/include/skalibs/sig.h src/libstddjb/sig_catch.o src/libstddjb/sig_catch.lo: src/libstddjb/sig_catch.c src/include/skalibs/sig.h src/libstddjb/sig_name.o src/libstddjb/sig_name.lo: src/libstddjb/sig_name.c src/libstddjb/sig-internal.h src/include/skalibs/sig.h src/libstddjb/sig_number.o src/libstddjb/sig_number.lo: src/libstddjb/sig_number.c src/libstddjb/sig-internal.h src/include/skalibs/sig.h src/libstddjb/sig_pause.o src/libstddjb/sig_pause.lo: src/libstddjb/sig_pause.c src/include/skalibs/sig.h src/libstddjb/sig_push.o src/libstddjb/sig_push.lo: src/libstddjb/sig_push.c src/include/skalibs/sig.h src/libstddjb/sig_restoreto.o src/libstddjb/sig_restoreto.lo: src/libstddjb/sig_restoreto.c src/include/skalibs/sig.h src/libstddjb/sig_shield.o src/libstddjb/sig_shield.lo: src/libstddjb/sig_shield.c src/include/skalibs/sig.h src/libstddjb/sig_stack.o src/libstddjb/sig_stack.lo: src/libstddjb/sig_stack.c src/include/skalibs/nonposix.h src/include/skalibs/nsig.h src/include/skalibs/sig.h src/libstddjb/sig_table.o src/libstddjb/sig_table.lo: src/libstddjb/sig_table.c src/libstddjb/sig-internal.h src/libstddjb/sig_unblock.o src/libstddjb/sig_unblock.lo: src/libstddjb/sig_unblock.c src/include/skalibs/sig.h src/libstddjb/sig_unshield.o src/libstddjb/sig_unshield.lo: src/libstddjb/sig_unshield.c src/include/skalibs/sig.h src/libstddjb/sigfpe.o src/libstddjb/sigfpe.lo: src/libstddjb/sigfpe.c src/include/skalibs/segfault.h src/libstddjb/sigsegv.o src/libstddjb/sigsegv.lo: src/libstddjb/sigsegv.c src/include/skalibs/segfault.h src/libstddjb/siovec_bytechr.o src/libstddjb/siovec_bytechr.lo: src/libstddjb/siovec_bytechr.c src/include/skalibs/bytestr.h src/include/skalibs/siovec.h src/libstddjb/siovec_bytein.o src/libstddjb/siovec_bytein.lo: src/libstddjb/siovec_bytein.c src/include/skalibs/bytestr.h src/include/skalibs/siovec.h src/libstddjb/siovec_deal.o src/libstddjb/siovec_deal.lo: src/libstddjb/siovec_deal.c src/include/skalibs/siovec.h 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_loose.o src/libstddjb/skagetln_loose.lo: src/libstddjb/skagetln_loose.c 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/skagetlnsep_loose.o src/libstddjb/skagetlnsep_loose.lo: src/libstddjb/skagetlnsep_loose.c 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 src/libstddjb/skasigaction.o src/libstddjb/skasigaction.lo: src/libstddjb/skasigaction.c src/include/skalibs/config.h src/include/skalibs/sig.h src/libstddjb/slurp.o src/libstddjb/slurp.lo: src/libstddjb/slurp.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/libstddjb/socket_accept4.o src/libstddjb/socket_accept4.lo: src/libstddjb/socket_accept4.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/include/skalibs/sysdeps.h src/include/skalibs/uint16.h src/libstddjb/socket_accept4_u32.o src/libstddjb/socket_accept4_u32.lo: src/libstddjb/socket_accept4_u32.c src/include/skalibs/socket.h src/include/skalibs/uint32.h src/libstddjb/socket_accept6.o src/libstddjb/socket_accept6.lo: src/libstddjb/socket_accept6.c src/include/skalibs/djbunix.h src/include/skalibs/ip46.h src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/include/skalibs/sysdeps.h src/include/skalibs/uint16.h src/libstddjb/socket_bind4.o src/libstddjb/socket_bind4.lo: src/libstddjb/socket_bind4.c src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/include/skalibs/uint16.h src/libstddjb/socket_bind4r.o src/libstddjb/socket_bind4r.lo: src/libstddjb/socket_bind4r.c src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/libstddjb/socket_bind6.o src/libstddjb/socket_bind6.lo: src/libstddjb/socket_bind6.c src/include/skalibs/ip46.h src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/include/skalibs/uint16.h src/libstddjb/socket_bind6r.o src/libstddjb/socket_bind6r.lo: src/libstddjb/socket_bind6r.c src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/libstddjb/socket_conn4.o src/libstddjb/socket_conn4.lo: src/libstddjb/socket_conn4.c src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/include/skalibs/uint16.h src/libstddjb/socket_conn4_u32.o src/libstddjb/socket_conn4_u32.lo: src/libstddjb/socket_conn4_u32.c src/include/skalibs/socket.h src/include/skalibs/uint32.h src/libstddjb/socket_conn6.o src/libstddjb/socket_conn6.lo: src/libstddjb/socket_conn6.c src/include/skalibs/ip46.h src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/include/skalibs/uint16.h src/libstddjb/socket_connected.o src/libstddjb/socket_connected.lo: src/libstddjb/socket_connected.c src/include/skalibs/allreadwrite.h src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/libstddjb/socket_deadlineconnstamp4.o src/libstddjb/socket_deadlineconnstamp4.lo: src/libstddjb/socket_deadlineconnstamp4.c src/include/skalibs/error.h src/include/skalibs/socket.h src/libstddjb/socket_deadlineconnstamp46.o src/libstddjb/socket_deadlineconnstamp46.lo: src/libstddjb/socket_deadlineconnstamp46.c src/include/skalibs/error.h src/include/skalibs/ip46.h src/include/skalibs/socket.h src/libstddjb/socket_deadlineconnstamp4_u32.o src/libstddjb/socket_deadlineconnstamp4_u32.lo: src/libstddjb/socket_deadlineconnstamp4_u32.c src/include/skalibs/socket.h src/include/skalibs/uint32.h src/libstddjb/socket_deadlineconnstamp6.o src/libstddjb/socket_deadlineconnstamp6.lo: src/libstddjb/socket_deadlineconnstamp6.c src/include/skalibs/error.h src/include/skalibs/socket.h src/libstddjb/socket_delay.o src/libstddjb/socket_delay.lo: src/libstddjb/socket_delay.c src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/libstddjb/socket_internal.o src/libstddjb/socket_internal.lo: src/libstddjb/socket_internal.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/socket_ioloop.o src/libstddjb/socket_ioloop.lo: src/libstddjb/socket_ioloop.c src/include/skalibs/error.h src/include/skalibs/iopause.h src/include/skalibs/socket.h src/libstddjb/socket_ioloop_send4.o src/libstddjb/socket_ioloop_send4.lo: src/libstddjb/socket_ioloop_send4.c src/include/skalibs/socket.h src/libstddjb/socket_ioloop_send6.o src/libstddjb/socket_ioloop_send6.lo: src/libstddjb/socket_ioloop_send6.c src/include/skalibs/socket.h src/libstddjb/socket_local4.o src/libstddjb/socket_local4.lo: src/libstddjb/socket_local4.c src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/include/skalibs/uint16.h src/libstddjb/socket_local46.o src/libstddjb/socket_local46.lo: src/libstddjb/socket_local46.c src/include/skalibs/ip46.h src/include/skalibs/nonposix.h src/include/skalibs/uint16.h src/libstddjb/socket_local6.o src/libstddjb/socket_local6.lo: src/libstddjb/socket_local6.c src/include/skalibs/ip46.h src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/include/skalibs/uint16.h src/libstddjb/socket_recv4.o src/libstddjb/socket_recv4.lo: src/libstddjb/socket_recv4.c src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/include/skalibs/uint16.h src/libstddjb/socket_recv6.o src/libstddjb/socket_recv6.lo: src/libstddjb/socket_recv6.c src/include/skalibs/ip46.h src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/include/skalibs/uint16.h src/libstddjb/socket_remote4.o src/libstddjb/socket_remote4.lo: src/libstddjb/socket_remote4.c src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/include/skalibs/uint16.h src/libstddjb/socket_remote46.o src/libstddjb/socket_remote46.lo: src/libstddjb/socket_remote46.c src/include/skalibs/ip46.h src/include/skalibs/nonposix.h src/include/skalibs/uint16.h src/libstddjb/socket_remote6.o src/libstddjb/socket_remote6.lo: src/libstddjb/socket_remote6.c src/include/skalibs/ip46.h src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/include/skalibs/uint16.h src/libstddjb/socket_send4.o src/libstddjb/socket_send4.lo: src/libstddjb/socket_send4.c src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/include/skalibs/uint16.h src/libstddjb/socket_send6.o src/libstddjb/socket_send6.lo: src/libstddjb/socket_send6.c src/include/skalibs/ip46.h src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/include/skalibs/uint16.h src/libstddjb/socket_tcp4.o src/libstddjb/socket_tcp4.lo: src/libstddjb/socket_tcp4.c src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/libstddjb/socket_tcp6.o src/libstddjb/socket_tcp6.lo: src/libstddjb/socket_tcp6.c src/include/skalibs/djbunix.h src/include/skalibs/ip46.h src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/libstddjb/socket_timeoutconn.o src/libstddjb/socket_timeoutconn.lo: src/libstddjb/socket_timeoutconn.c src/include/skalibs/socket.h src/include/skalibs/tai.h src/libstddjb/socket_tryr.o src/libstddjb/socket_tryr.lo: src/libstddjb/socket_tryr.c src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/libstddjb/socket_udp4.o src/libstddjb/socket_udp4.lo: src/libstddjb/socket_udp4.c src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/libstddjb/socket_udp6.o src/libstddjb/socket_udp6.lo: src/libstddjb/socket_udp6.c src/include/skalibs/djbunix.h src/include/skalibs/ip46.h src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/libstddjb/socket_waitconn.o src/libstddjb/socket_waitconn.lo: src/libstddjb/socket_waitconn.c src/include/skalibs/allreadwrite.h src/include/skalibs/iopause.h src/include/skalibs/socket.h src/libstddjb/socketpair_internal.o src/libstddjb/socketpair_internal.lo: src/libstddjb/socketpair_internal.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/stamp.o src/libstddjb/stamp.lo: src/libstddjb/stamp.c src/include/skalibs/tai.h src/libstddjb/str_chr.o src/libstddjb/str_chr.lo: src/libstddjb/str_chr.c src/include/skalibs/bytestr.h src/libstddjb/str_fmt.o src/libstddjb/str_fmt.lo: src/libstddjb/str_fmt.c src/include/skalibs/fmtscan.h src/libstddjb/str_rchr.o src/libstddjb/str_rchr.lo: src/libstddjb/str_rchr.c src/include/skalibs/bytestr.h src/libstddjb/str_start.o src/libstddjb/str_start.lo: src/libstddjb/str_start.c src/include/skalibs/bytestr.h src/libstddjb/str_strn.o src/libstddjb/str_strn.lo: src/libstddjb/str_strn.c src/include/skalibs/bytestr.h src/libstddjb/stralloc_append.o src/libstddjb/stralloc_append.lo: src/libstddjb/stralloc_append.c src/include/skalibs/stralloc.h src/libstddjb/stralloc_catb.o src/libstddjb/stralloc_catb.lo: src/libstddjb/stralloc_catb.c src/include/skalibs/stralloc.h src/libstddjb/stralloc_catv.o src/libstddjb/stralloc_catv.lo: src/libstddjb/stralloc_catv.c src/include/skalibs/siovec.h src/include/skalibs/stralloc.h src/libstddjb/stralloc_copyb.o src/libstddjb/stralloc_copyb.lo: src/libstddjb/stralloc_copyb.c src/include/skalibs/stralloc.h src/libstddjb/stralloc_free.o src/libstddjb/stralloc_free.lo: src/libstddjb/stralloc_free.c src/include/skalibs/alloc.h src/include/skalibs/stralloc.h src/libstddjb/stralloc_insertb.o src/libstddjb/stralloc_insertb.lo: src/libstddjb/stralloc_insertb.c src/include/skalibs/stralloc.h src/libstddjb/stralloc_ready_tuned.o src/libstddjb/stralloc_ready_tuned.lo: src/libstddjb/stralloc_ready_tuned.c src/include/skalibs/alloc.h src/include/skalibs/stralloc.h src/libstddjb/stralloc_reverse.o src/libstddjb/stralloc_reverse.lo: src/libstddjb/stralloc_reverse.c src/include/skalibs/stralloc.h src/libstddjb/stralloc_reverse_blocks.o src/libstddjb/stralloc_reverse_blocks.lo: src/libstddjb/stralloc_reverse_blocks.c src/include/skalibs/stralloc.h src/libstddjb/stralloc_shrink.o src/libstddjb/stralloc_shrink.lo: src/libstddjb/stralloc_shrink.c src/include/skalibs/alloc.h src/include/skalibs/stralloc.h src/libstddjb/stralloc_zero.o src/libstddjb/stralloc_zero.lo: src/libstddjb/stralloc_zero.c src/include/skalibs/stralloc.h src/libstddjb/strerr.o src/libstddjb/strerr.lo: src/libstddjb/strerr.c src/include/skalibs/buffer.h src/include/skalibs/strerr.h src/libstddjb/strerr_sys.o src/libstddjb/strerr_sys.lo: src/libstddjb/strerr_sys.c src/include/skalibs/strerr.h src/libstddjb/string_format.o src/libstddjb/string_format.lo: src/libstddjb/string_format.c src/include/skalibs/bytestr.h src/include/skalibs/stralloc.h src/libstddjb/string_quote.o src/libstddjb/string_quote.lo: src/libstddjb/string_quote.c src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h src/libstddjb/string_quote_nodelim.o src/libstddjb/string_quote_nodelim.lo: src/libstddjb/string_quote_nodelim.c src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h src/libstddjb/string_quote_nodelim_mustquote.o src/libstddjb/string_quote_nodelim_mustquote.lo: src/libstddjb/string_quote_nodelim_mustquote.c src/include/skalibs/fmtscan.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h src/libstddjb/string_unquote.o src/libstddjb/string_unquote.lo: src/libstddjb/string_unquote.c src/include/skalibs/skamisc.h src/libstddjb/string_unquote_nodelim.o src/libstddjb/string_unquote_nodelim.lo: src/libstddjb/string_unquote_nodelim.c src/include/skalibs/skamisc.h src/libstddjb/string_unquote_withdelim.o src/libstddjb/string_unquote_withdelim.lo: src/libstddjb/string_unquote_withdelim.c src/include/skalibs/bytestr.h src/include/skalibs/fmtscan.h src/include/skalibs/posixishard.h src/include/skalibs/skamisc.h src/libstddjb/strn_fmt.o src/libstddjb/strn_fmt.lo: src/libstddjb/strn_fmt.c src/include/skalibs/fmtscan.h src/include/skalibs/types.h src/libstddjb/subgetopt.o src/libstddjb/subgetopt.lo: src/libstddjb/subgetopt.c src/include/skalibs/sgetopt.h src/libstddjb/subgetopt_here.o src/libstddjb/subgetopt_here.lo: src/libstddjb/subgetopt_here.c src/include/skalibs/sgetopt.h src/libstddjb/sysclock_from_localtm.o src/libstddjb/sysclock_from_localtm.lo: src/libstddjb/sysclock_from_localtm.c src/include/skalibs/djbtime.h src/include/skalibs/uint64.h src/libstddjb/sysclock_from_localtmn.o src/libstddjb/sysclock_from_localtmn.lo: src/libstddjb/sysclock_from_localtmn.c src/include/skalibs/djbtime.h src/libstddjb/sysclock_from_ltm64.o src/libstddjb/sysclock_from_ltm64.lo: src/libstddjb/sysclock_from_ltm64.c src/include/skalibs/config.h src/include/skalibs/djbtime.h src/include/skalibs/uint64.h src/libstddjb/sysclock_from_tai.o src/libstddjb/sysclock_from_tai.lo: src/libstddjb/sysclock_from_tai.c src/include/skalibs/config.h src/include/skalibs/djbtime.h src/include/skalibs/tai.h src/libstddjb/sysclock_from_tain.o src/libstddjb/sysclock_from_tain.lo: src/libstddjb/sysclock_from_tain.c src/include/skalibs/tai.h src/libstddjb/sysclock_from_utc.o src/libstddjb/sysclock_from_utc.lo: src/libstddjb/sysclock_from_utc.c src/include/skalibs/config.h src/include/skalibs/djbtime.h src/include/skalibs/uint64.h src/libstddjb/sysclock_get.o src/libstddjb/sysclock_get.lo: src/libstddjb/sysclock_get.c src/include/skalibs/sysdeps.h src/include/skalibs/tai.h src/libstddjb/sysclock_set.o src/libstddjb/sysclock_set.lo: src/libstddjb/sysclock_set.c src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/include/skalibs/tai.h src/libstddjb/tai_add.o src/libstddjb/tai_add.lo: src/libstddjb/tai_add.c src/include/skalibs/tai.h src/libstddjb/tai_from_localtm.o src/libstddjb/tai_from_localtm.lo: src/libstddjb/tai_from_localtm.c src/include/skalibs/djbtime.h src/include/skalibs/uint64.h src/libstddjb/tai_from_ltm64.o src/libstddjb/tai_from_ltm64.lo: src/libstddjb/tai_from_ltm64.c src/libstddjb/djbtime-internal.h src/include/skalibs/djbtime.h src/libstddjb/tai_from_sysclock.o src/libstddjb/tai_from_sysclock.lo: src/libstddjb/tai_from_sysclock.c src/include/skalibs/config.h src/include/skalibs/djbtime.h src/include/skalibs/tai.h src/include/skalibs/uint64.h src/libstddjb/tai_from_utc.o src/libstddjb/tai_from_utc.lo: src/libstddjb/tai_from_utc.c src/libstddjb/djbtime-internal.h src/include/skalibs/djbtime.h src/include/skalibs/tai.h src/libstddjb/tai_now.o src/libstddjb/tai_now.lo: src/libstddjb/tai_now.c src/include/skalibs/tai.h src/libstddjb/tai_pack.o src/libstddjb/tai_pack.lo: src/libstddjb/tai_pack.c src/include/skalibs/tai.h src/include/skalibs/uint64.h src/libstddjb/tai_pack_little.o src/libstddjb/tai_pack_little.lo: src/libstddjb/tai_pack_little.c src/include/skalibs/tai.h src/include/skalibs/uint64.h src/libstddjb/tai_sub.o src/libstddjb/tai_sub.lo: src/libstddjb/tai_sub.c src/include/skalibs/tai.h src/libstddjb/tai_u64.o src/libstddjb/tai_u64.lo: src/libstddjb/tai_u64.c src/include/skalibs/bsdsnowflake.h src/include/skalibs/tai.h src/include/skalibs/uint64.h src/libstddjb/tai_unpack.o src/libstddjb/tai_unpack.lo: src/libstddjb/tai_unpack.c src/include/skalibs/tai.h src/include/skalibs/uint64.h src/libstddjb/tai_unpack_little.o src/libstddjb/tai_unpack_little.lo: src/libstddjb/tai_unpack_little.c src/include/skalibs/tai.h src/include/skalibs/uint64.h src/libstddjb/tain_add.o src/libstddjb/tain_add.lo: src/libstddjb/tain_add.c src/include/skalibs/tai.h src/libstddjb/tain_addsec.o src/libstddjb/tain_addsec.lo: src/libstddjb/tain_addsec.c src/include/skalibs/tai.h src/include/skalibs/uint64.h src/libstddjb/tain_approx.o src/libstddjb/tain_approx.lo: src/libstddjb/tain_approx.c src/include/skalibs/tai.h src/libstddjb/tain_fmt.o src/libstddjb/tain_fmt.lo: src/libstddjb/tain_fmt.c src/include/skalibs/fmtscan.h src/include/skalibs/tai.h src/libstddjb/tain_frac.o src/libstddjb/tain_frac.lo: src/libstddjb/tain_frac.c src/include/skalibs/tai.h src/libstddjb/tain_from_localtmn.o src/libstddjb/tain_from_localtmn.lo: src/libstddjb/tain_from_localtmn.c src/include/skalibs/djbtime.h src/libstddjb/tain_from_millisecs.o src/libstddjb/tain_from_millisecs.lo: src/libstddjb/tain_from_millisecs.c src/include/skalibs/tai.h src/libstddjb/tain_from_ntp.o src/libstddjb/tain_from_ntp.lo: src/libstddjb/tain_from_ntp.c src/include/skalibs/djbtime.h src/include/skalibs/tai.h src/include/skalibs/uint64.h src/libstddjb/tain_from_sysclock.o src/libstddjb/tain_from_sysclock.lo: src/libstddjb/tain_from_sysclock.c src/include/skalibs/tai.h src/libstddjb/tain_from_timespec.o src/libstddjb/tain_from_timespec.lo: src/libstddjb/tain_from_timespec.c src/include/skalibs/tai.h src/libstddjb/tain_from_timespec_sysclock.o src/libstddjb/tain_from_timespec_sysclock.lo: src/libstddjb/tain_from_timespec_sysclock.c src/include/skalibs/tai.h src/libstddjb/tain_from_timeval.o src/libstddjb/tain_from_timeval.lo: src/libstddjb/tain_from_timeval.c src/include/skalibs/tai.h src/libstddjb/tain_from_timeval_sysclock.o src/libstddjb/tain_from_timeval_sysclock.lo: src/libstddjb/tain_from_timeval_sysclock.c src/include/skalibs/tai.h src/libstddjb/tain_half.o src/libstddjb/tain_half.lo: src/libstddjb/tain_half.c src/include/skalibs/tai.h src/libstddjb/tain_infinite_relative.o src/libstddjb/tain_infinite_relative.lo: src/libstddjb/tain_infinite_relative.c src/include/skalibs/tai.h src/libstddjb/tain_less.o src/libstddjb/tain_less.lo: src/libstddjb/tain_less.c src/include/skalibs/tai.h src/libstddjb/tain_nano500.o src/libstddjb/tain_nano500.lo: src/libstddjb/tain_nano500.c src/include/skalibs/tai.h src/libstddjb/tain_now.o src/libstddjb/tain_now.lo: src/libstddjb/tain_now.c src/include/skalibs/tai.h src/libstddjb/tain_now_set_stopwatch.o src/libstddjb/tain_now_set_stopwatch.lo: src/libstddjb/tain_now_set_stopwatch.c src/include/skalibs/sysdeps.h src/include/skalibs/tai.h src/libstddjb/tain_now_set_wallclock.o src/libstddjb/tain_now_set_wallclock.lo: src/libstddjb/tain_now_set_wallclock.c src/include/skalibs/tai.h src/libstddjb/tain_pack.o src/libstddjb/tain_pack.lo: src/libstddjb/tain_pack.c src/include/skalibs/tai.h src/include/skalibs/uint32.h src/libstddjb/tain_pack_little.o src/libstddjb/tain_pack_little.lo: src/libstddjb/tain_pack_little.c src/include/skalibs/tai.h src/include/skalibs/uint32.h src/libstddjb/tain_relative_from_timespec.o src/libstddjb/tain_relative_from_timespec.lo: src/libstddjb/tain_relative_from_timespec.c src/include/skalibs/tai.h src/libstddjb/tain_relative_from_timeval.o src/libstddjb/tain_relative_from_timeval.lo: src/libstddjb/tain_relative_from_timeval.c src/include/skalibs/tai.h src/libstddjb/tain_scan.o src/libstddjb/tain_scan.lo: src/libstddjb/tain_scan.c src/include/skalibs/fmtscan.h src/include/skalibs/tai.h src/libstddjb/tain_setnow.o src/libstddjb/tain_setnow.lo: src/libstddjb/tain_setnow.c src/include/skalibs/tai.h src/libstddjb/tain_stopwatch.o src/libstddjb/tain_stopwatch.lo: src/libstddjb/tain_stopwatch.c src/include/skalibs/sysdeps.h src/include/skalibs/tai.h src/libstddjb/tain_sub.o src/libstddjb/tain_sub.lo: src/libstddjb/tain_sub.c src/include/skalibs/tai.h src/libstddjb/tain_to_millisecs.o src/libstddjb/tain_to_millisecs.lo: src/libstddjb/tain_to_millisecs.c src/include/skalibs/tai.h src/include/skalibs/uint64.h src/libstddjb/tain_ulong.o src/libstddjb/tain_ulong.lo: src/libstddjb/tain_ulong.c src/include/skalibs/tai.h src/libstddjb/tain_unpack.o src/libstddjb/tain_unpack.lo: src/libstddjb/tain_unpack.c src/include/skalibs/tai.h src/include/skalibs/uint32.h src/libstddjb/tain_unpack_little.o src/libstddjb/tain_unpack_little.lo: src/libstddjb/tain_unpack_little.c src/include/skalibs/tai.h src/include/skalibs/uint32.h src/libstddjb/tain_wallclock_read.o src/libstddjb/tain_wallclock_read.lo: src/libstddjb/tain_wallclock_read.c src/include/skalibs/tai.h src/libstddjb/tain_zero.o src/libstddjb/tain_zero.lo: src/libstddjb/tain_zero.c src/include/skalibs/tai.h src/libstddjb/time_from_tai.o src/libstddjb/time_from_tai.lo: src/libstddjb/time_from_tai.c src/include/skalibs/bsdsnowflake.h src/include/skalibs/sysdeps.h src/include/skalibs/tai.h src/include/skalibs/uint64.h src/libstddjb/time_from_tai_relative.o src/libstddjb/time_from_tai_relative.lo: src/libstddjb/time_from_tai_relative.c src/include/skalibs/bsdsnowflake.h src/include/skalibs/sysdeps.h src/include/skalibs/tai.h src/libstddjb/time_sysclock_from_tai.o src/libstddjb/time_sysclock_from_tai.lo: src/libstddjb/time_sysclock_from_tai.c src/include/skalibs/bsdsnowflake.h src/include/skalibs/sysdeps.h src/include/skalibs/tai.h src/include/skalibs/uint64.h src/libstddjb/timespec_from_tain.o src/libstddjb/timespec_from_tain.lo: src/libstddjb/timespec_from_tain.c src/include/skalibs/tai.h src/libstddjb/timespec_from_tain_relative.o src/libstddjb/timespec_from_tain_relative.lo: src/libstddjb/timespec_from_tain_relative.c src/include/skalibs/tai.h src/libstddjb/timespec_sysclock_from_tain.o src/libstddjb/timespec_sysclock_from_tain.lo: src/libstddjb/timespec_sysclock_from_tain.c src/include/skalibs/tai.h src/libstddjb/timestamp.o src/libstddjb/timestamp.lo: src/libstddjb/timestamp.c src/include/skalibs/tai.h src/libstddjb/timestamp_fmt.o src/libstddjb/timestamp_fmt.lo: src/libstddjb/timestamp_fmt.c src/include/skalibs/tai.h src/libstddjb/timestamp_r.o src/libstddjb/timestamp_r.lo: src/libstddjb/timestamp_r.c src/include/skalibs/tai.h src/libstddjb/timestamp_scan.o src/libstddjb/timestamp_scan.lo: src/libstddjb/timestamp_scan.c src/include/skalibs/tai.h 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/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 src/libstddjb/ucharn_scan.o src/libstddjb/ucharn_scan.lo: src/libstddjb/ucharn_scan.c src/include/skalibs/fmtscan.h src/libstddjb/ucharn_scan_little.o src/libstddjb/ucharn_scan_little.lo: src/libstddjb/ucharn_scan_little.c src/include/skalibs/fmtscan.h src/libstddjb/ucspi_get.o src/libstddjb/ucspi_get.lo: src/libstddjb/ucspi_get.c src/include/skalibs/env.h src/libstddjb/uint160_scan.o src/libstddjb/uint160_scan.lo: src/libstddjb/uint160_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h src/libstddjb/uint16_bswap.o src/libstddjb/uint16_bswap.lo: src/libstddjb/uint16_bswap.c src/include/skalibs/uint16.h src/libstddjb/uint16_fmtlist.o src/libstddjb/uint16_fmtlist.lo: src/libstddjb/uint16_fmtlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h src/libstddjb/uint16_pack.o src/libstddjb/uint16_pack.lo: src/libstddjb/uint16_pack.c src/include/skalibs/uint16.h src/libstddjb/uint16_pack_big.o src/libstddjb/uint16_pack_big.lo: src/libstddjb/uint16_pack_big.c src/include/skalibs/uint16.h src/libstddjb/uint16_reverse.o src/libstddjb/uint16_reverse.lo: src/libstddjb/uint16_reverse.c src/include/skalibs/uint16.h src/libstddjb/uint16_scan.o src/libstddjb/uint16_scan.lo: src/libstddjb/uint16_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h src/include/skalibs/uint64.h src/libstddjb/uint16_scanlist.o src/libstddjb/uint16_scanlist.lo: src/libstddjb/uint16_scanlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h src/libstddjb/uint16_unpack.o src/libstddjb/uint16_unpack.lo: src/libstddjb/uint16_unpack.c src/include/skalibs/uint16.h src/libstddjb/uint16_unpack_big.o src/libstddjb/uint16_unpack_big.lo: src/libstddjb/uint16_unpack_big.c src/include/skalibs/uint16.h src/libstddjb/uint320_scan.o src/libstddjb/uint320_scan.lo: src/libstddjb/uint320_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h src/libstddjb/uint32_bswap.o src/libstddjb/uint32_bswap.lo: src/libstddjb/uint32_bswap.c src/include/skalibs/uint32.h src/libstddjb/uint32_fmtlist.o src/libstddjb/uint32_fmtlist.lo: src/libstddjb/uint32_fmtlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h src/libstddjb/uint32_pack.o src/libstddjb/uint32_pack.lo: src/libstddjb/uint32_pack.c src/include/skalibs/uint32.h src/libstddjb/uint32_pack_big.o src/libstddjb/uint32_pack_big.lo: src/libstddjb/uint32_pack_big.c src/include/skalibs/uint32.h src/libstddjb/uint32_reverse.o src/libstddjb/uint32_reverse.lo: src/libstddjb/uint32_reverse.c src/include/skalibs/uint32.h src/libstddjb/uint32_scan.o src/libstddjb/uint32_scan.lo: src/libstddjb/uint32_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h src/include/skalibs/uint64.h src/libstddjb/uint32_scanlist.o src/libstddjb/uint32_scanlist.lo: src/libstddjb/uint32_scanlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h src/libstddjb/uint32_unpack.o src/libstddjb/uint32_unpack.lo: src/libstddjb/uint32_unpack.c src/include/skalibs/uint32.h src/libstddjb/uint32_unpack_big.o src/libstddjb/uint32_unpack_big.lo: src/libstddjb/uint32_unpack_big.c src/include/skalibs/uint32.h src/libstddjb/uint640_fmt_generic.o src/libstddjb/uint640_fmt_generic.lo: src/libstddjb/uint640_fmt_generic.c src/include/skalibs/fmtscan.h src/include/skalibs/uint64.h src/libstddjb/uint640_scan.o src/libstddjb/uint640_scan.lo: src/libstddjb/uint640_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h src/libstddjb/uint640_scan_base_max.o src/libstddjb/uint640_scan_base_max.lo: src/libstddjb/uint640_scan_base_max.c src/include/skalibs/fmtscan.h src/include/skalibs/uint64.h src/libstddjb/uint64_bswap.o src/libstddjb/uint64_bswap.lo: src/libstddjb/uint64_bswap.c src/include/skalibs/uint64.h src/libstddjb/uint64_fmt_generic.o src/libstddjb/uint64_fmt_generic.lo: src/libstddjb/uint64_fmt_generic.c src/include/skalibs/fmtscan.h src/include/skalibs/uint64.h src/libstddjb/uint64_fmtlist.o src/libstddjb/uint64_fmtlist.lo: src/libstddjb/uint64_fmtlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h src/libstddjb/uint64_fmtlist_generic.o src/libstddjb/uint64_fmtlist_generic.lo: src/libstddjb/uint64_fmtlist_generic.c src/include/skalibs/uint64.h src/libstddjb/uint64_pack.o src/libstddjb/uint64_pack.lo: src/libstddjb/uint64_pack.c src/include/skalibs/uint64.h src/libstddjb/uint64_pack_big.o src/libstddjb/uint64_pack_big.lo: src/libstddjb/uint64_pack_big.c src/include/skalibs/uint64.h src/libstddjb/uint64_reverse.o src/libstddjb/uint64_reverse.lo: src/libstddjb/uint64_reverse.c src/include/skalibs/uint64.h src/libstddjb/uint64_scan.o src/libstddjb/uint64_scan.lo: src/libstddjb/uint64_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h src/libstddjb/uint64_scan_base_max.o src/libstddjb/uint64_scan_base_max.lo: src/libstddjb/uint64_scan_base_max.c src/include/skalibs/fmtscan.h src/include/skalibs/uint64.h src/libstddjb/uint64_scanlist.o src/libstddjb/uint64_scanlist.lo: src/libstddjb/uint64_scanlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h src/libstddjb/uint64_unpack.o src/libstddjb/uint64_unpack.lo: src/libstddjb/uint64_unpack.c src/include/skalibs/uint64.h src/libstddjb/uint64_unpack_big.o src/libstddjb/uint64_unpack_big.lo: src/libstddjb/uint64_unpack_big.c src/include/skalibs/uint64.h src/libstddjb/uncoe.o src/libstddjb/uncoe.lo: src/libstddjb/uncoe.c src/include/skalibs/djbunix.h src/libstddjb/unsanitize_read.o src/libstddjb/unsanitize_read.lo: src/libstddjb/unsanitize_read.c src/include/skalibs/allreadwrite.h src/include/skalibs/error.h src/libstddjb/utc_from_localtm.o src/libstddjb/utc_from_localtm.lo: src/libstddjb/utc_from_localtm.c src/include/skalibs/djbtime.h src/include/skalibs/uint64.h src/libstddjb/utc_from_ltm64.o src/libstddjb/utc_from_ltm64.lo: src/libstddjb/utc_from_ltm64.c src/include/skalibs/config.h src/libstddjb/djbtime-internal.h src/include/skalibs/djbtime.h src/include/skalibs/uint64.h src/libstddjb/utc_from_sysclock.o src/libstddjb/utc_from_sysclock.lo: src/libstddjb/utc_from_sysclock.c src/include/skalibs/config.h src/include/skalibs/djbtime.h src/include/skalibs/tai.h src/include/skalibs/uint64.h src/libstddjb/utc_from_tai.o src/libstddjb/utc_from_tai.lo: src/libstddjb/utc_from_tai.c src/libstddjb/djbtime-internal.h src/include/skalibs/djbtime.h src/libstddjb/vbaprintf.o src/libstddjb/vbaprintf.lo: src/libstddjb/vbaprintf.c src/include/skalibs/bufalloc.h src/include/skalibs/lolstdio.h src/include/skalibs/stralloc.h src/libstddjb/vbprintf.o src/libstddjb/vbprintf.lo: src/libstddjb/vbprintf.c src/include/skalibs/buffer.h src/include/skalibs/lolstdio.h src/libstddjb/wait_nointr.o src/libstddjb/wait_nointr.lo: src/libstddjb/wait_nointr.c src/include/skalibs/djbunix.h src/libstddjb/wait_pid_nohang.o src/libstddjb/wait_pid_nohang.lo: src/libstddjb/wait_pid_nohang.c src/include/skalibs/djbunix.h src/libstddjb/wait_pids_nohang.o src/libstddjb/wait_pids_nohang.lo: src/libstddjb/wait_pids_nohang.c src/include/skalibs/djbunix.h src/libstddjb/wait_reap.o src/libstddjb/wait_reap.lo: src/libstddjb/wait_reap.c src/include/skalibs/djbunix.h src/libstddjb/waitn.o src/libstddjb/waitn.lo: src/libstddjb/waitn.c src/include/skalibs/djbunix.h src/libstddjb/waitn_reap.o src/libstddjb/waitn_reap.lo: src/libstddjb/waitn_reap.c src/include/skalibs/djbunix.h 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/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 src/libstddjb/xpathexec_fromenv.o src/libstddjb/xpathexec_fromenv.lo: src/libstddjb/xpathexec_fromenv.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h src/libstddjb/xpathexec_r.o src/libstddjb/xpathexec_r.lo: src/libstddjb/xpathexec_r.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h src/libstddjb/xpathexec_r_name.o src/libstddjb/xpathexec_r_name.lo: src/libstddjb/xpathexec_r_name.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h src/libstddjb/xpathexec_run.o src/libstddjb/xpathexec_run.lo: src/libstddjb/xpathexec_run.c src/include/skalibs/djbunix.h src/include/skalibs/strerr2.h src/libunixonacid/access_at.o src/libunixonacid/access_at.lo: src/libunixonacid/access_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/atomic_rm_rf.o src/libunixonacid/atomic_rm_rf.lo: src/libunixonacid/atomic_rm_rf.c src/include/skalibs/skamisc.h src/include/skalibs/unix-transactional.h src/libunixonacid/atomic_rm_rf_tmp.o src/libunixonacid/atomic_rm_rf_tmp.lo: src/libunixonacid/atomic_rm_rf_tmp.c src/include/skalibs/djbunix.h src/include/skalibs/random.h src/include/skalibs/stralloc.h src/include/skalibs/unix-transactional.h src/libunixonacid/atomic_symlink.o src/libunixonacid/atomic_symlink.lo: src/libunixonacid/atomic_symlink.c src/include/skalibs/posixplz.h src/include/skalibs/unix-transactional.h src/libunixonacid/bufalloc_timed_flush.o src/libunixonacid/bufalloc_timed_flush.lo: src/libunixonacid/bufalloc_timed_flush.c src/include/skalibs/bufalloc.h src/include/skalibs/functypes.h src/include/skalibs/unix-timed.h src/libunixonacid/buffer_timed_fill.o src/libunixonacid/buffer_timed_fill.lo: src/libunixonacid/buffer_timed_fill.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/functypes.h src/include/skalibs/unix-timed.h src/libunixonacid/buffer_timed_flush.o src/libunixonacid/buffer_timed_flush.lo: src/libunixonacid/buffer_timed_flush.c src/include/skalibs/buffer.h src/include/skalibs/functypes.h src/include/skalibs/unix-timed.h src/libunixonacid/buffer_timed_get.o src/libunixonacid/buffer_timed_get.lo: src/libunixonacid/buffer_timed_get.c src/include/skalibs/buffer.h src/include/skalibs/functypes.h src/include/skalibs/unix-timed.h src/libunixonacid/dd_cancel.o src/libunixonacid/dd_cancel.lo: src/libunixonacid/dd_cancel.c src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/include/skalibs/unix-transactional.h src/libunixonacid/dd_close.o src/libunixonacid/dd_close.lo: src/libunixonacid/dd_close.c src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h src/libunixonacid/dd_commit.o src/libunixonacid/dd_commit.lo: src/libunixonacid/dd_commit.c src/include/skalibs/djbunix.h src/include/skalibs/random.h src/include/skalibs/stralloc.h src/include/skalibs/unix-transactional.h src/libunixonacid/dd_commit_devino.o src/libunixonacid/dd_commit_devino.lo: src/libunixonacid/dd_commit_devino.c src/include/skalibs/unix-transactional.h src/libunixonacid/dd_open_read.o src/libunixonacid/dd_open_read.lo: src/libunixonacid/dd_open_read.c src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h src/libunixonacid/dd_open_write.o src/libunixonacid/dd_open_write.lo: src/libunixonacid/dd_open_write.c src/include/skalibs/djbunix.h src/include/skalibs/random.h src/include/skalibs/stralloc.h src/include/skalibs/unix-transactional.h src/libunixonacid/ipc_timed_recv.o src/libunixonacid/ipc_timed_recv.lo: src/libunixonacid/ipc_timed_recv.c src/include/skalibs/allreadwrite.h src/include/skalibs/functypes.h src/include/skalibs/unix-timed.h src/include/skalibs/webipc.h src/libunixonacid/ipc_timed_send.o src/libunixonacid/ipc_timed_send.lo: src/libunixonacid/ipc_timed_send.c src/include/skalibs/error.h src/include/skalibs/iopause.h src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/unix-timed.h src/libunixonacid/ipc_timed_sendv.o src/libunixonacid/ipc_timed_sendv.lo: src/libunixonacid/ipc_timed_sendv.c src/include/skalibs/error.h src/include/skalibs/iopause.h src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/siovec.h src/include/skalibs/unix-timed.h src/libunixonacid/kolbak_call.o src/libunixonacid/kolbak_call.lo: src/libunixonacid/kolbak_call.c src/include/skalibs/kolbak.h src/include/skalibs/unixmessage.h src/libunixonacid/kolbak_enqueue.o src/libunixonacid/kolbak_enqueue.lo: src/libunixonacid/kolbak_enqueue.c src/include/skalibs/kolbak.h src/include/skalibs/unixmessage.h src/libunixonacid/kolbak_queue_init.o src/libunixonacid/kolbak_queue_init.lo: src/libunixonacid/kolbak_queue_init.c src/include/skalibs/kolbak.h src/libunixonacid/kolbak_unenqueue.o src/libunixonacid/kolbak_unenqueue.lo: src/libunixonacid/kolbak_unenqueue.c src/include/skalibs/kolbak.h src/libunixonacid/netstring_timed_get.o src/libunixonacid/netstring_timed_get.lo: src/libunixonacid/netstring_timed_get.c src/include/skalibs/buffer.h src/include/skalibs/iopause.h src/include/skalibs/netstring.h src/include/skalibs/unix-timed.h src/libunixonacid/open2_at.o src/libunixonacid/open2_at.lo: src/libunixonacid/open2_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/open3_at.o src/libunixonacid/open3_at.lo: src/libunixonacid/open3_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/open_appendat.o src/libunixonacid/open_appendat.lo: src/libunixonacid/open_appendat.c src/include/skalibs/unix-transactional.h src/libunixonacid/open_appendatb.o src/libunixonacid/open_appendatb.lo: src/libunixonacid/open_appendatb.c src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h src/libunixonacid/open_readat.o src/libunixonacid/open_readat.lo: src/libunixonacid/open_readat.c src/include/skalibs/unix-transactional.h src/libunixonacid/open_readatb.o src/libunixonacid/open_readatb.lo: src/libunixonacid/open_readatb.c src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h src/libunixonacid/open_truncat.o src/libunixonacid/open_truncat.lo: src/libunixonacid/open_truncat.c src/include/skalibs/unix-transactional.h src/libunixonacid/open_truncatb.o src/libunixonacid/open_truncatb.lo: src/libunixonacid/open_truncatb.c src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h src/libunixonacid/open_writeat.o src/libunixonacid/open_writeat.lo: src/libunixonacid/open_writeat.c src/include/skalibs/unix-transactional.h src/libunixonacid/open_writeatb.o src/libunixonacid/open_writeatb.lo: src/libunixonacid/open_writeatb.c src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h src/libunixonacid/opengetlnclose.o src/libunixonacid/opengetlnclose.lo: src/libunixonacid/opengetlnclose.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/djbunix.h src/include/skalibs/skamisc.h src/include/skalibs/unix-transactional.h src/libunixonacid/opengetlnclose_at.o src/libunixonacid/opengetlnclose_at.lo: src/libunixonacid/opengetlnclose_at.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/djbunix.h src/include/skalibs/skamisc.h src/include/skalibs/unix-transactional.h src/libunixonacid/openreadnclose_at.o src/libunixonacid/openreadnclose_at.lo: src/libunixonacid/openreadnclose_at.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h src/libunixonacid/openslurpclose_at.o src/libunixonacid/openslurpclose_at.lo: src/libunixonacid/openslurpclose_at.c src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h src/libunixonacid/openwritenclose_at.o src/libunixonacid/openwritenclose_at.lo: src/libunixonacid/openwritenclose_at.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h src/libunixonacid/openwritevnclose_at.o src/libunixonacid/openwritevnclose_at.lo: src/libunixonacid/openwritevnclose_at.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/siovec.h src/include/skalibs/unix-transactional.h src/libunixonacid/skaclient_default_cb.o src/libunixonacid/skaclient_default_cb.lo: src/libunixonacid/skaclient_default_cb.c src/include/skalibs/posixishard.h src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h src/libunixonacid/skaclient_end.o src/libunixonacid/skaclient_end.lo: src/libunixonacid/skaclient_end.c src/include/skalibs/djbunix.h src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h src/libunixonacid/skaclient_init.o src/libunixonacid/skaclient_init.lo: src/libunixonacid/skaclient_init.c src/libunixonacid/skaclient-internal.h src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h src/libunixonacid/skaclient_put.o src/libunixonacid/skaclient_put.lo: src/libunixonacid/skaclient_put.c src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h src/libunixonacid/skaclient_putmsg.o src/libunixonacid/skaclient_putmsg.lo: src/libunixonacid/skaclient_putmsg.c src/include/skalibs/kolbak.h src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h src/libunixonacid/skaclient_putmsgv.o src/libunixonacid/skaclient_putmsgv.lo: src/libunixonacid/skaclient_putmsgv.c src/include/skalibs/kolbak.h src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h src/libunixonacid/skaclient_putv.o src/libunixonacid/skaclient_putv.lo: src/libunixonacid/skaclient_putv.c src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h src/libunixonacid/skaclient_send.o src/libunixonacid/skaclient_send.lo: src/libunixonacid/skaclient_send.c src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h src/libunixonacid/skaclient_sendmsg.o src/libunixonacid/skaclient_sendmsg.lo: src/libunixonacid/skaclient_sendmsg.c src/include/skalibs/skaclient.h src/libunixonacid/skaclient_sendmsgv.o src/libunixonacid/skaclient_sendmsgv.lo: src/libunixonacid/skaclient_sendmsgv.c src/include/skalibs/skaclient.h src/libunixonacid/skaclient_sendv.o src/libunixonacid/skaclient_sendv.lo: src/libunixonacid/skaclient_sendv.c src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h src/libunixonacid/skaclient_server_ack.o src/libunixonacid/skaclient_server_ack.lo: src/libunixonacid/skaclient_server_ack.c src/include/skalibs/djbunix.h src/include/skalibs/posixishard.h src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h src/include/skalibs/webipc.h src/libunixonacid/skaclient_server_bidi_ack.o src/libunixonacid/skaclient_server_bidi_ack.lo: src/libunixonacid/skaclient_server_bidi_ack.c src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h src/libunixonacid/skaclient_server_init.o src/libunixonacid/skaclient_server_init.lo: src/libunixonacid/skaclient_server_init.c src/include/skalibs/allreadwrite.h src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h src/libunixonacid/skaclient_start.o src/libunixonacid/skaclient_start.lo: src/libunixonacid/skaclient_start.c src/include/skalibs/kolbak.h src/libunixonacid/skaclient-internal.h src/include/skalibs/skaclient.h src/libunixonacid/skaclient_start_async.o src/libunixonacid/skaclient_start_async.lo: src/libunixonacid/skaclient_start_async.c src/include/skalibs/error.h src/include/skalibs/kolbak.h src/libunixonacid/skaclient-internal.h src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h src/include/skalibs/webipc.h src/libunixonacid/skaclient_start_cb.o src/libunixonacid/skaclient_start_cb.lo: src/libunixonacid/skaclient_start_cb.c src/include/skalibs/posixishard.h src/libunixonacid/skaclient-internal.h src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h src/libunixonacid/skaclient_startf.o src/libunixonacid/skaclient_startf.lo: src/libunixonacid/skaclient_startf.c src/include/skalibs/kolbak.h src/libunixonacid/skaclient-internal.h src/include/skalibs/skaclient.h src/libunixonacid/skaclient_startf_async.o src/libunixonacid/skaclient_startf_async.lo: src/libunixonacid/skaclient_startf_async.c src/include/skalibs/djbunix.h src/include/skalibs/kolbak.h src/libunixonacid/skaclient-internal.h src/include/skalibs/skaclient.h 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/textclient_command.o src/libunixonacid/textclient_command.lo: src/libunixonacid/textclient_command.c src/include/skalibs/posixishard.h src/include/skalibs/textclient.h src/libunixonacid/textclient_commandv.o src/libunixonacid/textclient_commandv.lo: src/libunixonacid/textclient_commandv.c src/include/skalibs/posixishard.h src/include/skalibs/textclient.h src/libunixonacid/textclient_end.o src/libunixonacid/textclient_end.lo: src/libunixonacid/textclient_end.c src/include/skalibs/djbunix.h src/include/skalibs/textclient.h src/include/skalibs/textmessage.h src/libunixonacid/textclient_server_init.o src/libunixonacid/textclient_server_init.lo: src/libunixonacid/textclient_server_init.c src/include/skalibs/djbunix.h src/include/skalibs/textclient.h src/libunixonacid/textclient_server_init_frompipe.o src/libunixonacid/textclient_server_init_frompipe.lo: src/libunixonacid/textclient_server_init_frompipe.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/posixishard.h src/include/skalibs/textclient.h src/include/skalibs/textmessage.h src/include/skalibs/types.h src/libunixonacid/textclient_server_init_fromsocket.o src/libunixonacid/textclient_server_init_fromsocket.lo: src/libunixonacid/textclient_server_init_fromsocket.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/textclient.h src/include/skalibs/textmessage.h src/include/skalibs/types.h src/include/skalibs/unix-timed.h src/libunixonacid/textclient_start.o src/libunixonacid/textclient_start.lo: src/libunixonacid/textclient_start.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/sysdeps.h src/include/skalibs/textclient.h src/include/skalibs/textmessage.h src/include/skalibs/unix-timed.h src/include/skalibs/webipc.h src/libunixonacid/textclient_startf.o src/libunixonacid/textclient_startf.lo: src/libunixonacid/textclient_startf.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/posixishard.h src/include/skalibs/textclient.h src/include/skalibs/textmessage.h src/libunixonacid/textclient_zero.o src/libunixonacid/textclient_zero.lo: src/libunixonacid/textclient_zero.c src/include/skalibs/textclient.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 src/libunixonacid/timed_getlnmax.o src/libunixonacid/timed_getlnmax.lo: src/libunixonacid/timed_getlnmax.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/functypes.h src/include/skalibs/skamisc.h src/include/skalibs/unix-timed.h src/libunixonacid/unixconnection_free.o src/libunixonacid/unixconnection_free.lo: src/libunixonacid/unixconnection_free.c src/include/skalibs/unixconnection.h src/include/skalibs/unixmessage.h src/libunixonacid/unixconnection_init.o src/libunixonacid/unixconnection_init.lo: src/libunixonacid/unixconnection_init.c src/include/skalibs/unixconnection.h src/include/skalibs/unixmessage.h src/libunixonacid/unixconnection_init_withclosecb.o src/libunixonacid/unixconnection_init_withclosecb.lo: src/libunixonacid/unixconnection_init_withclosecb.c src/include/skalibs/unixconnection.h src/include/skalibs/unixmessage.h src/libunixonacid/unixconnection_zero.o src/libunixonacid/unixconnection_zero.lo: src/libunixonacid/unixconnection_zero.c src/include/skalibs/unixconnection.h src/libunixonacid/unixmessage_bits_closeall.o src/libunixonacid/unixmessage_bits_closeall.lo: src/libunixonacid/unixmessage_bits_closeall.c src/include/skalibs/bitarray.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_bits_closenone.o src/libunixonacid/unixmessage_bits_closenone.lo: src/libunixonacid/unixmessage_bits_closenone.c src/include/skalibs/bitarray.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_drop.o src/libunixonacid/unixmessage_drop.lo: src/libunixonacid/unixmessage_drop.c src/include/skalibs/djbunix.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_handle.o src/libunixonacid/unixmessage_handle.lo: src/libunixonacid/unixmessage_handle.c src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_put.o src/libunixonacid/unixmessage_put.lo: src/libunixonacid/unixmessage_put.c src/include/skalibs/bitarray.h src/include/skalibs/disize.h src/include/skalibs/genalloc.h src/include/skalibs/posixishard.h src/include/skalibs/siovec.h src/include/skalibs/stralloc.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_receive.o src/libunixonacid/unixmessage_receive.lo: src/libunixonacid/unixmessage_receive.c src/include/skalibs/allreadwrite.h src/include/skalibs/cbuffer.h src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/stralloc.h src/include/skalibs/sysdeps.h src/include/skalibs/uint16.h src/include/skalibs/uint32.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_receiver_0.o src/libunixonacid/unixmessage_receiver_0.lo: src/libunixonacid/unixmessage_receiver_0.c src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_receiver_free.o src/libunixonacid/unixmessage_receiver_free.lo: src/libunixonacid/unixmessage_receiver_free.c src/include/skalibs/cbuffer.h src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_receiver_hasmsginbuf.o src/libunixonacid/unixmessage_receiver_hasmsginbuf.lo: src/libunixonacid/unixmessage_receiver_hasmsginbuf.c src/include/skalibs/cbuffer.h src/include/skalibs/siovec.h src/include/skalibs/uint32.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_receiver_init.o src/libunixonacid/unixmessage_receiver_init.lo: src/libunixonacid/unixmessage_receiver_init.c src/include/skalibs/cbuffer.h src/include/skalibs/stralloc.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_sender_1.o src/libunixonacid/unixmessage_sender_1.lo: src/libunixonacid/unixmessage_sender_1.c src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_sender_closecb.o src/libunixonacid/unixmessage_sender_closecb.lo: src/libunixonacid/unixmessage_sender_closecb.c src/include/skalibs/djbunix.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_sender_flush.o src/libunixonacid/unixmessage_sender_flush.lo: src/libunixonacid/unixmessage_sender_flush.c src/include/skalibs/allreadwrite.h src/include/skalibs/disize.h src/include/skalibs/djbunix.h src/include/skalibs/genalloc.h src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/uint16.h src/include/skalibs/uint32.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_sender_free.o src/libunixonacid/unixmessage_sender_free.lo: src/libunixonacid/unixmessage_sender_free.c src/include/skalibs/disize.h src/include/skalibs/djbunix.h src/include/skalibs/genalloc.h src/include/skalibs/stralloc.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_sender_getfd.o src/libunixonacid/unixmessage_sender_getfd.lo: src/libunixonacid/unixmessage_sender_getfd.c src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_sender_init.o src/libunixonacid/unixmessage_sender_init.lo: src/libunixonacid/unixmessage_sender_init.c src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_sender_init_withclosecb.o src/libunixonacid/unixmessage_sender_init_withclosecb.lo: src/libunixonacid/unixmessage_sender_init_withclosecb.c src/include/skalibs/genalloc.h src/include/skalibs/stralloc.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_sender_timed_flush.o src/libunixonacid/unixmessage_sender_timed_flush.lo: src/libunixonacid/unixmessage_sender_timed_flush.c src/include/skalibs/functypes.h src/include/skalibs/unix-timed.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_sender_x.o src/libunixonacid/unixmessage_sender_x.lo: src/libunixonacid/unixmessage_sender_x.c src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_sender_zero.o src/libunixonacid/unixmessage_sender_zero.lo: src/libunixonacid/unixmessage_sender_zero.c src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_timed_handle.o src/libunixonacid/unixmessage_timed_handle.lo: src/libunixonacid/unixmessage_timed_handle.c src/include/skalibs/functypes.h src/include/skalibs/unix-timed.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_timed_receive.o src/libunixonacid/unixmessage_timed_receive.lo: src/libunixonacid/unixmessage_timed_receive.c src/include/skalibs/functypes.h src/include/skalibs/unix-timed.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_unput.o src/libunixonacid/unixmessage_unput.lo: src/libunixonacid/unixmessage_unput.c src/include/skalibs/disize.h src/include/skalibs/djbunix.h src/include/skalibs/genalloc.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_v_zero.o src/libunixonacid/unixmessage_v_zero.lo: src/libunixonacid/unixmessage_v_zero.c src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_zero.o src/libunixonacid/unixmessage_zero.lo: src/libunixonacid/unixmessage_zero.c src/include/skalibs/unixmessage.h skalibs-2.9.1.0/package/info000066400000000000000000000001111355335115400155600ustar00rootroot00000000000000package=skalibs version=2.9.1.0 category=prog package_macro_name=SKALIBS skalibs-2.9.1.0/patch-for-solaris000077500000000000000000000013141355335115400166000ustar00rootroot00000000000000#!/usr/xpg4/bin/sh patchit () { if head -n 1 $1 | grep -qF -- -e ; then echo '#!/usr/xpg4/bin/sh -e' > $1.tmp else echo '#!/usr/xpg4/bin/sh' > $1.tmp fi tail -n +2 $1 >> $1.tmp mv -f $1.tmp $1 chmod 0755 $1 } # Solaris doesn't understand POSIX.1-2008 either. sed -e 's/XOPEN_SOURCE=700/XOPEN_SOURCE=600/' < configure > configure.tmp mv -f configure.tmp configure patchit ./configure patchit ./tools/install.sh patchit ./tools/gen-deps.sh patchit ./tools/gen-types.sh patchit ./tools/gen-types-internal.sh patchit ./tools/gen-bits.sh patchit ./tools/make-sysdepsh.sh echo 'SHELL := /usr/xpg4/bin/sh' > Makefile.tmp echo >> Makefile.tmp cat Makefile >> Makefile.tmp mv -f Makefile.tmp Makefile skalibs-2.9.1.0/src/000077500000000000000000000000001355335115400141055ustar00rootroot00000000000000skalibs-2.9.1.0/src/headers/000077500000000000000000000000001355335115400155205ustar00rootroot00000000000000skalibs-2.9.1.0/src/headers/bits-bendian000066400000000000000000000002711355335115400200020ustar00rootroot00000000000000#define uint@BITS@_little_endian(s, n) uint@BITS@_reverse((s), (n)) #define uint@BITS@_big_endian(s, n) #define uint@BITS@_little(u) uint@BITS@_bswap(u) #define uint@BITS@_big(u) (u) skalibs-2.9.1.0/src/headers/bits-footer000066400000000000000000000000531355335115400176760ustar00rootroot00000000000000 typedef uint@BITS@_t uint@BITS@ ; #endif skalibs-2.9.1.0/src/headers/bits-header000066400000000000000000000001471355335115400176340ustar00rootroot00000000000000/* ISC license. */ #ifndef UINT@BITS@_H #define UINT@BITS@_H #include #include skalibs-2.9.1.0/src/headers/bits-lendian000066400000000000000000000002711355335115400200140ustar00rootroot00000000000000#define uint@BITS@_little_endian(s, n) #define uint@BITS@_big_endian(s, n) uint@BITS@_reverse((s), (n)) #define uint@BITS@_little(u) (u) #define uint@BITS@_big(u) uint@BITS@_bswap(u) skalibs-2.9.1.0/src/headers/bits-template000066400000000000000000000057041355335115400202230ustar00rootroot00000000000000extern void uint@BITS@_pack (char *, uint@BITS@_t) ; extern void uint@BITS@_pack_big (char *, uint@BITS@_t) ; extern void uint@BITS@_unpack (char const *, uint@BITS@_t *) ; extern void uint@BITS@_unpack_big (char const *, uint@BITS@_t *) ; extern void uint@BITS@_reverse (char *, size_t) ; extern uint@BITS@_t uint@BITS@_bswap (uint@BITS@_t) ; #define UINT@BITS@_FMT @DFMT@ #define UINT@BITS@_OFMT @OFMT@ #define UINT@BITS@_XFMT @XFMT@ #define UINT@BITS@_BFMT @BFMT@ #define uint@BITS@_fmt_base uint64_fmt_generic #define uint@BITS@0_fmt_base uint640_fmt_generic #define uint@BITS@_fmt(s, u) uint@BITS@_fmt_base(s, (u), 10) #define uint@BITS@0_fmt(s, u, n) uint@BITS@0_fmt_base(s, u, (n), 10) #define uint@BITS@_ofmt(s, o) uint@BITS@_fmt_base(s, (o), 8) #define uint@BITS@0_ofmt(s, o, n) uint@BITS@0_fmt_base(s, o, (n), 8) #define uint@BITS@_xfmt(s, x) uint@BITS@_fmt_base(s, (x), 16) #define uint@BITS@0_xfmt(s, x, n) uint@BITS@0_fmt_base(s, x, (n), 16) #define uint@BITS@_bfmt(s, b) uint@BITS@0_fmt_base(s, (b), 2) #define uint@BITS@0_bfmt(s, b, n) uint@BITS@0_fmt_base(s, b, (n), 2) extern size_t uint@BITS@_fmtlist (char *, uint@BITS@_t const *, size_t) ; extern size_t uint@BITS@_scan_base (char const *, uint@BITS@_t *, uint8_t) ; extern size_t uint@BITS@0_scan_base (char const *, uint@BITS@_t *, uint8_t) ; #define uint@BITS@_scan(s, u) uint@BITS@_scan_base(s, (u), 10) #define uint@BITS@0_scan(s, u) uint@BITS@0_scan_base(s, (u), 10) #define uint@BITS@_oscan(s, u) uint@BITS@_scan_base(s, (u), 8) #define uint@BITS@0_oscan(s, u) uint@BITS@0_scan_base(s, (u), 8) #define uint@BITS@_xscan(s, u) uint@BITS@_scan_base(s, (u), 16) #define uint@BITS@0_xscan(s, u) uint@BITS@0_scan_base(s, (u), 16) #define uint@BITS@_bscan(s, u) uint@BITS@_scan_base(s, (u), 2) #define uint@BITS@0_bscan(s, u) uint@BITS@0_scan_base(s, (u), 2) extern size_t uint@BITS@_scanlist (uint@BITS@_t *, size_t, char const *, size_t *) ; #define int@BITS@_fmt_base int64_fmt_generic #define int@BITS@_fmt(s, u) int@BITS@_fmt_base(s, (u), 10) #define int@BITS@_ofmt(s, o) int@BITS@_fmt_base(s, (o), 8) #define int@BITS@_xfmt(s, x) int@BITS@_fmt_base(s, (x), 16) #define int@BITS@_bfmt(s, b) int@BITS@0_fmt_base(s, (b), 2) extern size_t int@BITS@_fmtlist (char *, int@BITS@_t const *, size_t) ; extern size_t int@BITS@_scan_base (char const *, int@BITS@_t *, uint8_t) ; extern size_t int@BITS@0_scan_base (char const *, int@BITS@_t *, uint8_t) ; #define int@BITS@_scan(s, u) int@BITS@_scan_base(s, (u), 10) #define int@BITS@0_scan(s, u) int@BITS@0_scan_base(s, (u), 10) #define int@BITS@_oscan(s, u) int@BITS@_scan_base(s, (u), 8) #define int@BITS@0_oscan(s, u) int@BITS@0_scan_base(s, (u), 8) #define int@BITS@_xscan(s, u) int@BITS@_scan_base(s, (u), 16) #define int@BITS@0_xscan(s, u) int@BITS@0_scan_base(s, (u), 16) #define int@BITS@_bscan(s, u) int@BITS@_scan_base(s, (u), 2) #define int@BITS@0_bscan(s, u) int@BITS@0_scan_base(s, (u), 2) extern size_t int@BITS@_scanlist (int@BITS@_t *, size_t, char const *, size_t *) ; skalibs-2.9.1.0/src/headers/ip46-footer000066400000000000000000000010431355335115400175170ustar00rootroot00000000000000 #define ip46_from_ip(i, s, h) ((h) ? ip46_from_ip6(i, s) : ip46_from_ip4(i, s)) #define socket_recvnb46_g(fd, buf, len, i, port, deadline) socket_recvnb46(fd, buf, len, i, port, (deadline), &STAMP) #define socket_sendnb46_g(fd, buf, len, i, port, deadline) socket_sendnb46(fd, buf, len, i, port, (deadline), &STAMP) extern int socket_deadlineconnstamp46 (int, ip46_t const *, uint16_t, tain_t const *, tain_t *) ; #define socket_deadlineconnstamp46_g(fd, ip, port, deadline) socket_deadlineconnstamp46(fd, ip, port, (deadline), &STAMP) #endif skalibs-2.9.1.0/src/headers/ip46-header000066400000000000000000000016771355335115400174660ustar00rootroot00000000000000/* ISC license. */ #ifndef IP46_H #define IP46_H #include #include #include #include #include #define IP46_FMT IP6_FMT #define IP4_ANY "\0\0\0" #define IP6_ANY "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" #define IP4_LOCAL "\177\0\0\1" #define IP6_LOCAL "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1" typedef struct ip46full_s ip46full_t, *ip46full_t_ref ; struct ip46full_s { char ip[16] ; unsigned int is6: 1 ; } ; #define IP46FULL_ZERO { .ip = IP6_ANY, .is6 = 0 } #define ip46full_is6(i) ((i)->is6) #define ip46full_fmt(s, i) ((i)->is6 ? ip6_fmt(s, (i)->ip) : ip4_fmt(s, (i)->ip)) extern size_t ip46full_scan (char const *, ip46full_t *) ; extern size_t ip46full_scanlist (ip46full_t *, size_t, char const *, size_t *) ; #define ip46full_from_ip4(i, ip4) (memcpy((i)->ip, ip4, 4), memset((i)->ip + 4, 0, 12), (i)->is6 = 0) #define ip46full_from_ip6(i, ip6) (memcpy((i)->ip, ip6, 16), (i)->is6 = 1) skalibs-2.9.1.0/src/headers/ip46-with000066400000000000000000000032771355335115400172070ustar00rootroot00000000000000typedef ip46full_t ip46_t, *ip46_t_ref ; #define IP46_ZERO IP46FULL_ZERO #define SKALIBS_IPV6_ENABLED #define SKALIBS_IP_SIZE 16 #define ip46_is6(i) ip46full_is6(i) #define ip46_fmt(s, i) ip46full_fmt(s, i) #define ip46_scan(s, i) ip46full_scan(s, i) #define ip46_scanlist(out, max, s, num) ip46full_scanlist(out, max, s, num) #define ip46_from_ip4(i, ip4) (ip46full_from_ip4(i, ip4), 1) #define ip46_from_ip6(i, ip6) (ip46full_from_ip6(i, ip6), 1) #define socket_connect46(s, i, port) ((i)->is6 ? socket_connect6(s, (i)->ip, port) : socket_connect4(s, (i)->ip, port)) #define socket_bind46(s, i, port) ((i)->is6 ? socket_bind6(s, (i)->ip, port) : socket_bind4(s, (i)->ip, port)) #define socket_bind46_reuse(s, i, port) ((i)->is6 ? socket_bind6_reuse(s, (i)->ip, port) : socket_bind4_reuse(s, (i)->ip, port)) #define socket_tcp46(h) ((h) ? socket_tcp6() : socket_tcp4()) #define socket_udp46(h) ((h) ? socket_udp6() : socket_udp4()) #define socket_recv46(fd, s, len, i, port) ((i)->is6 ? socket_recv6(fd, s, len, (i)->ip, port) : socket_recv4(fd, s, len, (i)->ip, port)) #define socket_send46(fd, s, len, i, port) ((i)->is6 ? socket_send6(fd, s, len, (i)->ip, port) : socket_send4(fd, s, len, (i)->ip, port)) extern int socket_local46 (int, ip46_t *, uint16_t *) ; extern int socket_remote46 (int, ip46_t *, uint16_t *) ; #define socket_recvnb46(fd, buf, len, i, port, deadline, stamp) ((i)->is6 ? socket_recvnb6(fd, buf, len, (i)->ip, port, deadline, stamp) : socket_recvnb4(fd, buf, len, (i)->ip, port, deadline, stamp)) #define socket_sendnb46(fd, buf, len, i, port, deadline, stamp) ((i)->is6 ? socket_sendnb6(fd, buf, len, (i)->ip, port, deadline, stamp) : socket_sendnb4(fd, buf, len, (i)->ip, port, deadline, stamp)) skalibs-2.9.1.0/src/headers/ip46-without000066400000000000000000000024461355335115400177340ustar00rootroot00000000000000typedef struct ip46_s ip46_t, *ip46_t_ref ; struct ip46_s { char ip[4] ; } ; #define IP46_ZERO { .ip = "\0\0\0" } #undef SKALIBS_IPV6_ENABLED #define SKALIBS_IP_SIZE 4 #define ip46_is6(ip) 0 #define ip46_fmt(s, i) ip4_fmt(s, (i)->ip) #define ip46_scan(s, i) ip4_scan(s, (i)->ip) #define ip46_scanlist(out, max, s, num) ip4_scanlist((out)->ip, max, s, num) #define ip46_from_ip4(i, ip4) (memmove((i)->ip, (ip4), 4), 1) #define ip46_from_ip6(i, ip6) (errno = ENOSYS, 0) #define socket_connect46(s, i, port) socket_connect4(s, (i)->ip, port) #define socket_bind46(s, i, port) socket_bind4(s, (i)->ip, port) #define socket_bind46_reuse(s, i, port) socket_bind4_reuse(s, (i)->ip, port) #define socket_tcp46(h) socket_tcp4() #define socket_udp46(h) socket_udp4() #define socket_recv46(fd, s, len, i, port) socket_recv4(fd, s, len, (i)->ip, port) #define socket_send46(fd, s, len, i, port) socket_send4(fd, s, len, (i)->ip, port) #define socket_local46(fd, i, port) socket_local4(fd, (i)->ip, port) #define socket_remote46(fd, i, port) socket_remote4(fd, (i)->ip, port) #define socket_recvnb46(fd, buf, len, i, port, deadline, stamp) socket_recvnb4(fd, buf, len, (i)->ip, port, deadline, stamp) #define socket_sendnb46(fd, buf, len, i, port, deadline, stamp) socket_sendnb4(fd, buf, len, (i)->ip, port, deadline, stamp) skalibs-2.9.1.0/src/headers/signed-template000066400000000000000000000006521355335115400205300ustar00rootroot00000000000000#define @TYPE@_PACK @BYTES@ #define @type@_pack uint@BITS@_pack #define @type@_pack_big uint@BITS@_pack_big #define @type@_unpack uint@BITS@_unpack #define @type@_unpack_big uint@BITS@_unpack_big #define @TYPE@_FMT (1+UINT@BITS@_FMT) #define @type@_fmt int@BITS@_fmt #define @type@_fmtlist int@BITS@_fmtlist #define @type@_scan int@BITS@_scan #define @type@0_scan int@BITS@0_scan #define @type@_scanlist int@BITS@_scanlist skalibs-2.9.1.0/src/headers/types-footer000066400000000000000000000000101355335115400200720ustar00rootroot00000000000000 #endif skalibs-2.9.1.0/src/headers/types-header000066400000000000000000000003061355335115400200340ustar00rootroot00000000000000/* ISC license. */ #ifndef SKALIBS_TYPES_H #define SKALIBS_TYPES_H #include #include #include #include #include skalibs-2.9.1.0/src/headers/uint64-defs000066400000000000000000000007361355335115400175210ustar00rootroot00000000000000 extern size_t uint64_fmt_generic (char *, uint64_t, uint8_t) ; extern size_t uint640_fmt_generic (char *, uint64_t, size_t, uint8_t) ; extern size_t int64_fmt_generic (char *, int64_t, uint8_t) ; extern size_t uint64_fmtlist_generic (char *, void const *, size_t, uint8_t, uint64_t (*)(void const *, size_t)) ; extern size_t uint64_scan_base_max (char const *, uint64_t *, uint8_t, uint64_t) ; extern size_t int64_scan_base_max (char const *, int64_t *, uint8_t, uint64_t) ; skalibs-2.9.1.0/src/headers/uint64-include000066400000000000000000000000341355335115400202120ustar00rootroot00000000000000#include skalibs-2.9.1.0/src/headers/uint64-macros000066400000000000000000000006251355335115400200610ustar00rootroot00000000000000 #ifndef INT_LEAST64_MIN # define INT_LEAST64_MIN INT64_MIN #endif #ifndef INT_FAST64_MIN # define INT_FAST64_MIN INT64_MIN #endif #ifndef INT_LEAST64_MAX # define INT_LEAST64_MAX INT64_MAX #endif #ifndef INT_FAST64_MAX # define INT_FAST64_MAX INT64_MAX #endif #ifndef UINT_LEAST64_MAX # define UINT_LEAST64_MAX UINT64_MAX #endif #ifndef UINT_FAST64_MAX # define UINT_FAST64_MAX UINT64_MAX #endif skalibs-2.9.1.0/src/headers/uint64-noulong64000066400000000000000000000004311355335115400204230ustar00rootroot00000000000000 typedef unsigned long long uint64_t ; typedef signed long long int64_t ; #ifndef INT64_MIN # define INT64_MIN (-1-0x7fffffffffffffffll) #endif #ifndef INT64_MAX # define INT64_MAX 0x7fffffffffffffffll #endif #ifndef UINT64_MAX # define UINT64_MAX 0xffffffffffffffffull #endif skalibs-2.9.1.0/src/headers/uint64-ulong64000066400000000000000000000004051355335115400200670ustar00rootroot00000000000000 typedef unsigned long uint64_t ; typedef long int64_t ; #ifndef INT64_MIN # define INT64_MIN (-1-0x7fffffffffffffffl) #endif #ifndef INT64_MAX # define INT64_MAX 0x7fffffffffffffffl #endif #ifndef UINT64_MAX # define UINT64_MAX 0xfffffffffffffffful #endif skalibs-2.9.1.0/src/headers/unsigned-template000066400000000000000000000027361355335115400211000ustar00rootroot00000000000000#define @TYPE@_PACK @BYTES@ #define @type@_pack uint@BITS@_pack #define @type@_pack_big uint@BITS@_pack_big #define @type@_unpack uint@BITS@_unpack #define @type@_unpack_big uint@BITS@_unpack_big #define @type@_reverse uint@BITS@_reverse #define @type@_big_endian uint@BITS@_big_endian #define @type@_little_endian uint@BITS@_little_endian #define @TYPE@_FMT UINT@BITS@_FMT #define @TYPE@_OFMT UINT@BITS@_OFMT #define @TYPE@_XFMT UINT@BITS@_XFMT #define @TYPE@_BFMT UINT@BITS@_BFMT #define @type@_fmt_base uint@BITS@_fmt_base #define @type@0_fmt_base uint@BITS@0_fmt_base #define @type@_fmt uint@BITS@_fmt #define @type@0_fmt uint@BITS@0_fmt #define @type@_ofmt uint@BITS@_ofmt #define @type@0_ofmt uint@BITS@0_ofmt #define @type@_xfmt uint@BITS@_xfmt #define @type@0_xfmt uint@BITS@0_xfmt #define @type@_bfmt uint@BITS@_bfmt #define @type@0_bfmt uint@BITS@0_bfmt #define @type@_fmtlist uint@BITS@_fmtlist #define @type@_scan_base uint@BITS@_scan_base #define @type@0_scan_base uint@BITS@0_scan_base #define @type@_scanlist uint@BITS@_scanlist #define @type@_scan(s, u) @type@_scan_base(s, (u), 10) #define @type@0_scan(s, u) @type@0_scan_base(s, (u), 10) #define @type@_oscan(s, u) @type@_scan_base(s, (u), 8) #define @type@0_oscan(s, u) @type@0_scan_base(s, (u), 8) #define @type@_xscan(s, u) @type@_scan_base(s, (u), 16) #define @type@0_xscan(s, u) @type@0_scan_base(s, (u), 16) #define @type@_bscan(s, u) @type@_scan_base(s, (u), 2) #define @type@0_bscan(s, u) @type@0_scan_base(s, (u), 2) skalibs-2.9.1.0/src/include/000077500000000000000000000000001355335115400155305ustar00rootroot00000000000000skalibs-2.9.1.0/src/include/skalibs/000077500000000000000000000000001355335115400171605ustar00rootroot00000000000000skalibs-2.9.1.0/src/include/skalibs/alarm.h000066400000000000000000000004021355335115400204210ustar00rootroot00000000000000/* ISC license. */ #ifndef ALARM_H #define ALARM_H #include extern int alarm_milliseconds (unsigned int) ; extern int alarm_timeout (tain_t const *) ; extern int alarm_deadline (tain_t const *) ; extern void alarm_disable (void) ; #endif skalibs-2.9.1.0/src/include/skalibs/alloc.h000066400000000000000000000004231355335115400204220ustar00rootroot00000000000000/* ISC license. */ #ifndef ALLOC_H #define ALLOC_H #include #include extern void *alloc (size_t) ; #define alloc_free(p) free(p) #define alloc_re(p, old, new) alloc_realloc(p, new) extern int alloc_realloc (void **, size_t) ; #endif skalibs-2.9.1.0/src/include/skalibs/allreadwrite.h000066400000000000000000000017111355335115400220100ustar00rootroot00000000000000/* ISC license. */ #ifndef ALLREADWRITE_H #define ALLREADWRITE_H #include #include extern ssize_t sanitize_read (ssize_t) ; extern ssize_t unsanitize_read (ssize_t) ; extern size_t allreadwrite (iofunc_t_ref, int, char *, size_t) ; extern size_t allreadwritev (iovfunc_t_ref, int, struct iovec const *, unsigned int) ; extern ssize_t fd_read (int, char *, size_t) ; extern ssize_t fd_write (int, char const *, size_t) ; extern ssize_t fd_recv (int, char *, size_t, unsigned int) ; extern ssize_t fd_send (int, char const *, size_t, unsigned int) ; extern size_t allread (int, char *, size_t) ; extern size_t allwrite (int, char const *, size_t) ; extern size_t allreadv (int, struct iovec const *, unsigned int) ; extern size_t allwritev (int, struct iovec const *, unsigned int) ; extern ssize_t fd_readv (int, struct iovec const *, unsigned int) ; extern ssize_t fd_writev (int, struct iovec const *, unsigned int) ; #endif skalibs-2.9.1.0/src/include/skalibs/avlnode.h000066400000000000000000000037121355335115400207640ustar00rootroot00000000000000/* ISC license. */ #ifndef AVLNODE_H #define AVLNODE_H #include #include #include #define AVLNODE_MAXDEPTH 49 /* enough for 2^32 nodes in the worst case */ typedef int avliterfunc_t (uint32_t, unsigned int, void *) ; typedef avliterfunc_t *avliterfunc_t_ref ; typedef struct avlnode_s avlnode, *avlnode_ref ; struct avlnode_s { uint32_t data ; uint32_t child[2] ; signed char balance : 2 ; } ; #define AVLNODE_ZERO { .data = 0, .child = { UINT32_MAX, UINT32_MAX }, .balance = 0 } extern avlnode const avlnode_zero ; extern uint32_t avlnode_searchnode (avlnode const *, uint32_t, uint32_t, void const *, dtokfunc_t_ref, cmpfunc_t_ref, void *) ; extern int avlnode_search (avlnode const *, uint32_t, uint32_t, void const *, uint32_t *, dtokfunc_t_ref, cmpfunc_t_ref, void *) ; extern unsigned int avlnode_height (avlnode const *, uint32_t, uint32_t) gccattr_pure ; extern uint32_t avlnode_extremenode (avlnode const *, uint32_t, uint32_t, int) gccattr_pure ; #define avlnode_minnode(s, max, r) avlnode_extremenode(s, max, (r), 0) #define avlnode_maxnode(s, max, r) avlnode_extremenode(s, max, (r), 1) extern int avlnode_extreme (avlnode const *, uint32_t, uint32_t, int, uint32_t *) ; #define avlnode_min(s, max, r, data) avlnode_extreme(s, max, (r), 0, data) #define avlnode_max(s, max, r, data) avlnode_extreme(s, max, (r), 1, data) extern uint32_t avlnode_insertnode (avlnode *, uint32_t, uint32_t, uint32_t, dtokfunc_t_ref, cmpfunc_t_ref, void *) ; extern uint32_t avlnode_delete (avlnode *, uint32_t, uint32_t *, void const *, dtokfunc_t_ref, cmpfunc_t_ref, void *) ; extern uint32_t avlnode_iter_nocancel (avlnode *, uint32_t, uint32_t, uint32_t, avliterfunc_t_ref, void *) ; #define avlnode_iter(tree, max, root, f, stuff) (avlnode_iter_nocancel(tree, max, max, root, f, stuff) == (max)) extern int avlnode_iter_withcancel (avlnode *, uint32_t, uint32_t, avliterfunc_t_ref, avliterfunc_t_ref, void *) ; #endif skalibs-2.9.1.0/src/include/skalibs/avltree.h000066400000000000000000000051761355335115400210040ustar00rootroot00000000000000/* ISC license. */ #ifndef AVLTREE_H #define AVLTREE_H #include #include #include #include typedef struct avltree_s avltree, *avltree_ref ; struct avltree_s { gensetdyn x ; uint32_t root ; dtokfunc_t_ref dtok ; cmpfunc_t_ref kcmp ; void *external ; } ; #define AVLTREE_ZERO { .x = GENSETDYN_ZERO, .root = UINT32_MAX, .dtok = 0, .kcmp = 0, .external = 0 } extern avltree const avltree_zero ; #define avltree_len(t) gensetdyn_n(&(t)->x) #define avltree_totalsize(t) ((uint32_t)(t)->x.storage.len) #define avltree_nodes(t) ((avlnode *)(t)->x.storage.s) #define avltree_data(t, i) ((uint32_t)avltree_nodes(t)[i].data) #define avltree_root(t) ((t)->root) #define avltree_setroot(t, r) ((t)->root = (r)) extern void avltree_free (avltree *) ; extern void avltree_init (avltree *, uint32_t, uint32_t, uint32_t, dtokfunc_t_ref, cmpfunc_t_ref, void *) ; #define AVLTREE_INIT(b, num, den, dtk, f, p) { .x = GENSETDYN_INIT(avlnode, (b), num, den), .root = UINT32_MAX, .dtok = (dtk), .kcmp = (f), .external = (p) } #define avltree_searchnode(t, k) avlnode_searchnode(avltree_nodes(t), avltree_totalsize(t), avltree_root(t), k, (t)->dtok, (t)->kcmp, (t)->external) #define avltree_search(t, k, data) avlnode_search(avltree_nodes(t), avltree_totalsize(t), avltree_root(t), k, (data), (t)->dtok, (t)->kcmp, (t)->external) #define avltree_height(t) avlnode_height(avltree_nodes(t), avltree_totalsize(t), avltree_root(t)) #define avltree_extremenode(t, h) avlnode_extremenode(avltree_nodes(t), avltree_totalsize(t), avltree_root(t), h) #define avltree_minnode(t) avltree_extremenode((t), 0) #define avltree_maxnode(t) avltree_extremenode((t), 1) #define avltree_extreme(t, h, data) avlnode_extreme(avltree_nodes(t), avltree_totalsize(t), avltree_root(t), (h), data) #define avltree_min(t, data) avltree_extreme((t), 0, data) #define avltree_max(t, data) avltree_extreme((t), 1, data) extern int avltree_newnode (avltree *, uint32_t, uint32_t *) ; #define avltree_insertnode(t, i) avltree_setroot(t, avlnode_insertnode(avltree_nodes(t), avltree_totalsize(t), avltree_root(t), i, (t)->dtok, (t)->kcmp, (t)->external)) extern int avltree_insert (avltree *, uint32_t) ; extern int avltree_delete (avltree *, void const *) ; #define avltree_iter(t, f, p) avlnode_iter(avltree_nodes(t), avltree_totalsize(t), avltree_root(t), f, p) #define avltree_iter_nocancel(t, cut, f, p) avlnode_iter(avltree_nodes(t), avltree_totalsize(t), cut, avltree_root(t), f, p) #define avltree_iter_withcancel(t, f, cancelf, p) avlnode_iter_withcancel(avltree_nodes(t), avltree_totalsize(t), avltree_root(t), f, cancelf, p) #endif skalibs-2.9.1.0/src/include/skalibs/avltreen.h000066400000000000000000000056401355335115400211560ustar00rootroot00000000000000/* ISC license. */ #ifndef AVLTREEN_H #define AVLTREEN_H #include #include #include #include /* avltreen is the structure managing the AVL tree. It needs pre-declared arrays: "storage", an array of avlnode, and "freelist", an array of uint32_t, given as arguments to avltreen_init(). Pointers to those arrays are then stored in the genset. */ typedef struct avltreen_s avltreen, *avltreen_ref ; struct avltreen_s { genset x ; uint32_t root ; dtokfunc_t_ref dtok ; cmpfunc_t_ref kcmp ; void *external ; } ; #define AVLTREEN_ZERO { .x = GENSET_ZERO, .root = UINT32_MAX, .dtok = 0, .kcmp = 0, .external = 0 } #define avltreen_totalsize(t) ((t)->x.max) #define avltreen_len(t) genset_n(&(t)->x) #define avltreen_nodes(t) ((avlnode *)(t)->x.storage) #define avltreen_data(t, i) (avltreen_nodes(t)[i].data) #define avltreen_root(t) ((t)->root) #define avltreen_setroot(t, r) ((t)->root = (r)) extern void avltreen_init (avltreen *, avlnode *, uint32_t *, uint32_t, dtokfunc_t_ref, cmpfunc_t_ref, void *) ; #define AVLTREEN_DECLARE_AND_INIT(name, size, dtk, cmp, p) \ avlnode name##_storage[size] ; \ uint32_t name##_freelist[size] ; \ avltreen name ; \ avltreen_init(&name, name##_storage, name##_freelist, size, dtk, cmp, p) #define avltreen_searchnode(t, k) avlnode_searchnode(avltreen_nodes(t), avltreen_totalsize(t), avltreen_root(t), (k), (t)->dtok, (t)->kcmp, (t)->external) #define avltreen_search(t, k, data) avlnode_search(avltreen_nodes(t), avltreen_totalsize(t), avltreen_root(t), k, (data), (t)->dtok, (t)->kcmp, (t)->external) #define avltreen_height(t) avlnode_height(avltreen_nodes(t), avltreen_totalsize(t), avltreen_root(t)) #define avltreen_extremenode(t, h) avlnode_extremenode(avltreen_nodes(t), avltreen_totalsize(t), avltreen_root(t), h) #define avltreen_minnode(t) avltreen_extremenode((t), 0) #define avltreen_maxnode(t) avltreen_extremenode((t), 1) #define avltreen_extreme(t, h, data) avlnode_extreme(avltreen_nodes(t), avltreen_totalsize(t), avltreen_root(t), (h), data) #define avltreen_min(t, data) avltreen_extreme((t), 0, data) #define avltreen_max(t, data) avltreen_extreme((t), 1, data) extern uint32_t avltreen_newnode (avltreen *, uint32_t) ; #define avltreen_insertnode(t, i) avltreen_setroot(t, avlnode_insertnode(avltreen_nodes(t), avltreen_totalsize(t), avltreen_root(t), i, (t)->dtok, (t)->kcmp, (t)->external)) extern int avltreen_insert (avltreen *, uint32_t) ; extern int avltreen_delete (avltreen *, void const *) ; #define avltreen_iter(t, f, p) avlnode_iter(avltreen_nodes(t), avltreen_totalsize(t), avltreen_root(t), f, p) #define avltreen_iter_nocancel(t, cut, f, p) avlnode_iter_nocancel(avltreen_nodes(t), avltreen_totalsize(t), cut, avltreen_root(t), f, p) #define avltreen_iter_withcancel(t, f, cancelf, p) avlnode_iter_withcancel(avltreen_nodes(t), avltreen_totalsize(t), avltreen_root(t), f, cancelf, p) #endif skalibs-2.9.1.0/src/include/skalibs/biguint.h000066400000000000000000000053221355335115400207740ustar00rootroot00000000000000/* ISC license. */ #ifndef BIGUINT_H #define BIGUINT_H #include #include #include extern void bu_pack (char *, uint32_t const *, unsigned int) ; extern void bu_unpack (char const *, uint32_t *, unsigned int) ; extern void bu_pack_big (char *, uint32_t const *, unsigned int) ; extern void bu_unpack_big (char const *, uint32_t *, unsigned int) ; extern size_t bu_fmt (char *, uint32_t const *, unsigned int) ; extern size_t bu_scanlen (char const *, size_t *) ; extern int bu_scan (char const *, size_t, uint32_t *, unsigned int, size_t) ; extern unsigned int bu_len (uint32_t const *, unsigned int) gccattr_pure ; extern void bu_zero (uint32_t *, unsigned int) ; extern int bu_copy (uint32_t *, unsigned int, uint32_t const *, unsigned int) ; extern int bu_cmp (uint32_t const *, unsigned int, uint32_t const *, unsigned int) gccattr_pure ; #define bu_add(c, cn, a, an, b, bn) bu_addc(c, cn, a, an, b, (bn), 0) extern int bu_addc (uint32_t *, unsigned int, uint32_t const *, unsigned int, uint32_t const *, unsigned int, int) ; #define bu_sub(c, cn, a, an, b, bn) bu_subc(c, cn, a, an, b, (bn), 0) extern int bu_subc (uint32_t *, unsigned int, uint32_t const *, unsigned int, uint32_t const *, unsigned int, int) ; extern int bu_mul (uint32_t *, unsigned int, uint32_t const *, unsigned int, uint32_t const *, unsigned int) ; extern int bu_div (uint32_t const *, unsigned int, uint32_t const *, unsigned int, uint32_t *, unsigned int, uint32_t *, unsigned int) ; extern int bu_mod (uint32_t *, unsigned int, uint32_t const *, unsigned int) ; extern int bu_gcd (uint32_t *, unsigned int, uint32_t const *, unsigned int, uint32_t const *, unsigned int) ; #define bu_slb(a, n) bu_slbc(a, n, 0) extern int bu_slbc (uint32_t *, unsigned int, int) ; #define bu_srb(a, n) bu_srbc(a, n, 0) extern int bu_srbc (uint32_t *, unsigned int, int) ; extern int bu_addmod (uint32_t *, unsigned int, uint32_t const *, unsigned int, uint32_t const *, unsigned int, uint32_t const *, unsigned int) ; extern int bu_submod (uint32_t *, unsigned int, uint32_t const *, unsigned int, uint32_t const *, unsigned int, uint32_t const *, unsigned int) ; extern int bu_invmod (uint32_t *, unsigned int, uint32_t const *, unsigned int) ; extern int bu_divmod (uint32_t *, unsigned int, uint32_t const *, unsigned int, uint32_t const *, unsigned int, uint32_t const *, unsigned int) ; extern void bu_scan_internal (char const *, size_t, uint32_t *) ; extern void bu_copy_internal (uint32_t *, uint32_t const *, unsigned int) ; extern void bu_div_internal (uint32_t *, unsigned int, uint32_t const *, unsigned int, uint32_t *, unsigned int) ; extern void bu_divmod_internal (uint32_t *, uint32_t *, uint32_t const *, unsigned int) ; #endif skalibs-2.9.1.0/src/include/skalibs/bitarray.h000066400000000000000000000036111355335115400211470ustar00rootroot00000000000000/* ISC license. */ #ifndef BITARRAY_H #define BITARRAY_H #include #include #define bitarray_div8(n) ((n) ? 1U + (((n) - 1) >> 3) : 0U) extern void bitarray_clearsetn (unsigned char *, size_t, size_t, int) ; #define bitarray_clearn(s, start, len) bitarray_clearsetn(s, start, (len), 0) #define bitarray_setn(s, start, len) bitarray_clearsetn(s, start, (len), 1) #define bitarray_peek(s, n) (((s)[(n)>>3] & (1U<<((n)&7))) ? 1 : 0) #define bitarray_isset(b, n) bitarray_peek(b, n) #define bitarray_clear(s, n) ((s)[(n)>>3] &= ~(1U << ((n) & 7))) #define bitarray_set(s, n) ((s)[(n)>>3] |= 1U << ((n) & 7)) #define bitarray_poke(s, n, h) ((h) ? bitarray_set(s, n) : bitarray_clear(s, n)) extern int bitarray_testandpoke (unsigned char *, size_t, int) ; #define bitarray_testandclear(b, n) bitarray_testandpoke(b, n, 0) #define bitarray_testandset(b, n) bitarray_testandpoke(b, n, 1) extern size_t bitarray_firstclear (unsigned char const *, size_t) gccattr_pure ; extern size_t bitarray_firstset (unsigned char const *, size_t) gccattr_pure ; #define bitarray_first(s, n, h) ((h) ? bitarray_firstset(s, n) : bitarray_firstclear(s, n)) extern size_t bitarray_firstclear_skip (unsigned char const *, size_t, size_t) gccattr_pure ; extern size_t bitarray_firstset_skip (unsigned char const *, size_t, size_t) gccattr_pure ; #define bitarray_first_skip(s, n, k, h) ((h) ? bitarray_firstset_skip(s, n, k) : bitarray_firstclear_skip(s, n, k)) extern size_t bitarray_countones (unsigned char const *, size_t) gccattr_pure ; extern void bitarray_not (unsigned char *, size_t, size_t) ; extern void bitarray_and (unsigned char *, unsigned char const *, unsigned char const *, size_t) ; extern void bitarray_or (unsigned char *, unsigned char const *, unsigned char const *, size_t) ; extern void bitarray_xor (unsigned char *, unsigned char const *, unsigned char const *, size_t) ; #endif skalibs-2.9.1.0/src/include/skalibs/bsdsnowflake.h000066400000000000000000000023741355335115400220210ustar00rootroot00000000000000/* ISC license. */ #ifndef SKALIBS_BSDSNOWFLAKE_H #define SKALIBS_BSDSNOWFLAKE_H /* Like skalibs/nonposix.h, this header is supposed to be included *before* system headers. Unlike skalibs/nonposix.h, though, it does not define ftms that enable non-portable behaviour; it just attempts to work around blatant brokenness, things that actually ARE defined by POSIX but where OSes just ignore the spec. The BSDs are experts at this, hence the name. */ #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__bsdi__) || defined(__DragonFly__) /* BSDs: the eponym. Sometimes you just need to recognize who they are and what they do. */ #ifndef SKALIBS_BSD_SUCKS #define SKALIBS_BSD_SUCKS #endif /* Other times you just need to say you're a BSD so they deign to define symbols like EOVERFLOW. Give me my POSIX symbols, pretty please? */ #ifndef _BSD_SOURCE #define _BSD_SOURCE #endif #endif #if defined(__APPLE__) && defined(__MACH__) /* MacOS: needs this for full SUSv3 conformance. That's how you can tell it's really a BSD inside. With additional layers of crap. */ #ifndef _DARWIN_C_SOURCE #define _DARWIN_C_SOURCE #endif #endif /* __APPLE__ && __MACH__ */ #endif /* SKALIBS_BSDSNOWFLAKE_H */ skalibs-2.9.1.0/src/include/skalibs/bufalloc.h000066400000000000000000000024451355335115400211250ustar00rootroot00000000000000/* ISC license. */ #ifndef BUFALLOC_H #define BUFALLOC_H #include #include #include typedef struct bufalloc bufalloc, *bufalloc_ref ; struct bufalloc { stralloc x ; size_t p ; int fd ; ssize_t (*op) (int, char const *, size_t) ; } ; #define BUFALLOC_ZERO { STRALLOC_ZERO, 0, -1, 0 } #define BUFALLOC_INIT(f, d) { STRALLOC_ZERO, 0, (d), (f) } extern void bufalloc_init (bufalloc *, ssize_t (*)(int, char const *, size_t), int) ; #define bufalloc_shrink(ba) stralloc_shrink(&(ba)->x) #define bufalloc_free(ba) stralloc_free(&(ba)->x) #define bufalloc_put(ba, s, n) stralloc_catb(&(ba)->x, s, n) #define bufalloc_puts(ba, s) stralloc_cats(&(ba)->x, s) #define bufalloc_putv(ba, v, n) stralloc_catv(&(ba)->x, v, n) #define bufalloc_unput(ba, n) ((ba)->x.len -= (n)) #define bufalloc_fd(ba) ((ba)->fd) extern int bufalloc_getfd (bufalloc const *) gccattr_pure ; extern int bufalloc_flush (bufalloc *) ; extern void bufalloc_clean (bufalloc *) ; #define bufalloc_len(ba) ((ba)->x.len - (ba)->p) extern size_t bufalloc_getlen (bufalloc const *) gccattr_pure ; #define bufalloc_isempty(ba) ((ba)->x.len == (ba)->p) extern bufalloc bufalloc_1_ ; #define bufalloc_1 (&bufalloc_1_) extern bufalloc bufalloc_2_ ; #define bufalloc_2 (&bufalloc_2_) #endif skalibs-2.9.1.0/src/include/skalibs/buffer.h000066400000000000000000000077221355335115400206120ustar00rootroot00000000000000/* ISC license. */ #ifndef BUFFER_H #define BUFFER_H #include #include #include #include #include typedef struct buffer_s buffer, buffer_t, *buffer_ref, *buffer_t_ref ; struct buffer_s { iovfunc_t_ref op ; int fd ; cbuffer_t c ; } ; #define BUFFER_ZERO { 0, -1, CBUFFER_ZERO } /* Circular buffers need to be 1 char bigger than the storage space, so that the head == tail case is nonambiguous (empty, not full). */ #define BUFFER_INSIZE 8192 #define BUFFER_OUTSIZE 8192 #define BUFFER_ERRSIZE 1024 #define BUFFER_INSIZE_SMALL 512 #define BUFFER_OUTSIZE_SMALL 512 #define BUFFER_INIT(f, d, buf, len) { (f), (d), CBUFFER_INIT(buf, len) } extern int buffer_init (buffer *, iovfunc_t_ref, int, char *, size_t) ; /* Writing */ extern int buffer_flush (buffer *) ; #define buffer_putnoflush(b, s, len) cbuffer_put(&(b)->c, s, len) #define buffer_putvnoflush(b, v, n) cbuffer_putv(&(b)->c, v, n) extern size_t buffer_putsnoflush (buffer *, char const *) ; extern int buffer_putallnoflush (buffer *, char const *, size_t) ; extern int buffer_putvallnoflush (buffer *, struct iovec const *, unsigned int) ; extern int buffer_putsallnoflush (buffer *, char const *) ; extern int buffer_putall (buffer *, char const *, size_t, size_t *) ; extern int buffer_putvall (buffer *, struct iovec const *, unsigned int, size_t *) ; extern int buffer_putsall (buffer *, char const *, size_t *) ; #define buffer_putallflush(b, s, len, w) (buffer_putall(b, s, len, w) && buffer_flush(b)) #define buffer_putvallflush(b, v, n, w) (buffer_putvall(b, v, n, w) && buffer_flush(b)) extern int buffer_putsallflush (buffer *, char const *, size_t *) ; extern ssize_t buffer_put (buffer *, char const *, size_t) ; extern ssize_t buffer_putv (buffer *, struct iovec const *, unsigned int) ; extern ssize_t buffer_puts (buffer *, char const *) ; extern ssize_t buffer_putflush (buffer *, char const *, size_t) ; extern ssize_t buffer_putvflush (buffer *, struct iovec const *, unsigned int) ; extern ssize_t buffer_putsflush (buffer *, char const *) ; #define buffer_unput(b, n) cbuffer_unput(&(b)->c, n) #define buffer_wpeek(b, v) cbuffer_wpeek(&(b)->c, v) #define buffer_wseek(b, n) cbuffer_wseek(&(b)->c, n) /* Reading */ extern ssize_t buffer_fill (buffer *) ; #define buffer_getnofill(b, s, len) cbuffer_get(&(b)->c, s, len) #define buffer_getvnofill(b, v, n) cbuffer_getv(&(b)->c, v, n) extern int buffer_getallnofill (buffer *, char *, size_t) ; extern int buffer_getvallnofill (buffer *, struct iovec const *, unsigned int) ; extern int buffer_getall (buffer *, char *, size_t, size_t *) ; extern int buffer_getvall (buffer *, struct iovec const *, unsigned int, size_t *) ; extern ssize_t buffer_get (buffer *, char *, size_t) ; extern ssize_t buffer_getv (buffer *, struct iovec const *, unsigned int) ; #define buffer_unget(b, n) cbuffer_unget(&(b)->c, n) #define buffer_rpeek(b, v) cbuffer_rpeek(&(b)->c, v) #define buffer_rseek(b, n) cbuffer_rseek(&(b)->c, n) /* Utility */ #define buffer_len(b) cbuffer_len(&(b)->c) extern size_t buffer_getlen (buffer const *) gccattr_pure ; #define buffer_available(b) cbuffer_available(&(b)->c) #define buffer_isempty(b) cbuffer_isempty(&(b)->c) #define buffer_isfull(b) cbuffer_isfull(&(b)->c) #define buffer_fd(b) ((b)->fd) extern int buffer_getfd (buffer const *) gccattr_pure ; #define buffer_isreadable(b) (!buffer_isfull(b)) #define buffer_iswritable(b) (!buffer_isempty(b)) /* Globals */ #define buffer_read fd_readv #define buffer_write fd_writev extern iovfunc_t buffer_flush1read ; extern buffer buffer_0_ ; #define buffer_0 (&buffer_0_) extern buffer buffer_0small_ ; #define buffer_0small (&buffer_0small_) extern buffer buffer_0f1_ ; #define buffer_0f1 (&buffer_0f1_) extern buffer buffer_1_ ; #define buffer_1 (&buffer_1_) extern buffer buffer_1small_ ; #define buffer_1small (&buffer_1small_) extern buffer buffer_2_ ; #define buffer_2 (&buffer_2_) #endif skalibs-2.9.1.0/src/include/skalibs/bytestr.h000066400000000000000000000036601355335115400210320ustar00rootroot00000000000000/* ISC license. */ #ifndef BYTESTR_H #define BYTESTR_H #include /* for Alphas and other archs where char != 8bit */ #define T8(x) ((x) & 0xffU) #include #include #include #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 #define str_nlen strnlen #define str_diff strcmp #define str_diffn strncmp #define str_copy(to, from) strlen(strcpy(to, from)) #define case_diffs strcasecmp #define case_diffn strncasecmp extern size_t byte_chr (char const *, size_t, int) gccattr_pure ; 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) ; extern void byte_zzero (char *, size_t) ; #define str_diffb(a, n, b) strncmp(a, (b), n) extern size_t str_chr (char const *, int) gccattr_pure ; extern size_t str_rchr (char const *, int) gccattr_pure ; extern int str_start (char const *, char const *) gccattr_pure ; #define str_equal(s, t) (!strcmp(s, t)) extern size_t str_strn (char const *, size_t, char const *, size_t) gccattr_pure ; extern void case_lowers (char *) ; extern void case_lowerb (char *, size_t) ; extern void case_uppers (char *) ; extern void case_upperb (char *, size_t) ; #define case_diffb(a, n, b) case_diffn(a, (b), n) #define case_equals(a, b) (!strcasecmp(a, b)) #define case_equalb(a, n, b) (!strcasecmp(a, (b), n)) #define case_starts(s, t) case_startb(s, strlen(s), t) extern int case_startb (char const *, size_t, char const *) gccattr_pure ; extern size_t case_str (char const *, char const *) gccattr_pure ; #endif skalibs-2.9.1.0/src/include/skalibs/cbuffer.h000066400000000000000000000034761355335115400207570ustar00rootroot00000000000000/* ISC license. */ #ifndef CBUFFER_H #define CBUFFER_H #include #include #include typedef struct cbuffer_s cbuffer_t, *cbuffer_t_ref ; struct cbuffer_s { char *x ; size_t a ; /* total length */ size_t p ; /* head */ size_t n ; /* tail */ } ; #define CBUFFER_ZERO { 0, 0, 0, 0 } /* Circular buffers need to be 1 char bigger than the storage space, so that the head == tail case is nonambiguous (empty). */ #define CBUFFER_INIT(buf, len) { (buf), (len), 0, 0 } extern int cbuffer_init (cbuffer_t *, char *, size_t) ; /* Writing */ extern size_t cbuffer_put (cbuffer_t *, char const *, size_t) ; extern size_t cbuffer_putv (cbuffer_t *, struct iovec const *, unsigned int) ; #define cbuffer_puts(b, s) cbuffer_put(b, (s), strlen(s)) #define cbuffer_UNPUT(b, w) ((b)->n = ((b)->a + (b)->n - w) % (b)->a, w) ; extern size_t cbuffer_unput (cbuffer_t *, size_t) ; extern void cbuffer_wpeek (cbuffer_t const *, struct iovec *) ; #define cbuffer_WSEEK(b, w) ((b)->n = ((b)->n + (w)) % (b)->a, w) extern size_t cbuffer_wseek (cbuffer_t *, size_t) ; /* Reading */ extern size_t cbuffer_get (cbuffer_t *, char *, size_t) ; extern size_t cbuffer_getv (cbuffer_t *, struct iovec const *, unsigned int) ; #define cbuffer_UNGET(b, n) ((b)->p = ((b)->a + (b)->p - n) % (b)->a, n) ; extern size_t cbuffer_unget (cbuffer_t *, size_t) ; extern void cbuffer_rpeek (cbuffer_t const *, struct iovec *) ; #define cbuffer_RSEEK(b, n) ((b)->p = ((b)->p + (n)) % (b)->a, n) extern size_t cbuffer_rseek (cbuffer_t *, size_t) ; /* Utility */ #define cbuffer_len(b) ((size_t)(((b)->a - (b)->p + (b)->n) % (b)->a)) #define cbuffer_available(b) ((size_t)(((b)->a - (b)->n + (b)->p - 1) % (b)->a)) #define cbuffer_isempty(b) (!cbuffer_len(b)) #define cbuffer_isfull(b) (!cbuffer_available(b)) #endif skalibs-2.9.1.0/src/include/skalibs/cdb.h000066400000000000000000000036411355335115400200650ustar00rootroot00000000000000/* ISC license. */ #ifndef CDB_H #define CDB_H #include #include #define CDB_HASHSTART 5381 extern uint32_t cdb_hashadd (uint32_t, unsigned char) gccattr_const ; extern uint32_t cdb_hash (char const *, unsigned int) gccattr_pure ; typedef struct cdb cdb_t, *cdb_t_ref ; struct cdb { char *map ; /* 0 if no map */ int fd ; /* -1 if uninitted, negative if mapped, nonnegative if nomapped */ uint32_t size ; /* initialized if map is nonzero */ uint32_t loop ; /* number of hash slots searched under this key */ uint32_t khash ; /* initialized if loop is nonzero */ uint32_t kpos ; /* initialized if loop is nonzero */ uint32_t hpos ; /* initialized if loop is nonzero */ uint32_t hslots ; /* initialized if loop is nonzero */ uint32_t dpos ; /* initialized if cdb_findnext() returns 1 */ uint32_t dlen ; /* initialized if cdb_findnext() returns 1 */ } ; #define CDB_ZERO { .map = 0, .fd = -1, .size = 0, .loop = 0, .khash = 0, .kpos = 0, .hpos = 0, .hslots = 0, .dpos = 0, .dlen = 0 } extern struct cdb const cdb_zero ; extern void cdb_free (struct cdb *) ; #define cdb_init(c, fd) (cdb_init_map(c, (fd), 1) ? 0 : -1) extern int cdb_init_map (struct cdb *, int fd, int) ; extern int cdb_mapfile (struct cdb *, char const *) ; extern int cdb_read (struct cdb *, char *, unsigned int, uint32_t) ; #define cdb_findstart(c) ((c)->loop = 0) extern int cdb_findnext (struct cdb *, char const *, unsigned int) ; #define cdb_find(c, s, len) (cdb_findstart(c), cdb_findnext(c, s, len)) #define cdb_datapos(c) ((c)->dpos) #define cdb_datalen(c) ((c)->dlen) #define cdb_keypos(c) ((c)->kpos) #define cdb_keylen(c) ((c)->dpos - (c)->kpos) #define cdb_traverse_init(c, kpos) (*(kpos) = 2048) #define cdb_firstkey(c, kpos) (cdb_traverse_init(c, kpos), cdb_nextkey(c, kpos)) extern int cdb_nextkey (struct cdb *, uint32_t *) ; extern int cdb_successor (struct cdb *, char const *, unsigned int) ; #endif skalibs-2.9.1.0/src/include/skalibs/cdb_make.h000066400000000000000000000012661355335115400210630ustar00rootroot00000000000000/* ISC license. */ #ifndef CDB_MAKE_H #define CDB_MAKE_H #include #include #include #include #include typedef struct cdb_make cdb_make, *cdb_make_ref ; struct cdb_make { genalloc hplist ; /* array of diuint32 */ uint32_t pos ; buffer b ; char buf[BUFFER_OUTSIZE] ; } ; #define CDB_MAKE_ZERO { .hplist = GENALLOC_ZERO, .pos = 2048, .b = BUFFER_INIT(&fd_writev, -1, 0, 0) } extern int cdb_make_start (struct cdb_make *, int) ; extern int cdb_make_add (struct cdb_make *, char const *, unsigned int, char const *, unsigned int) ; extern int cdb_make_finish (struct cdb_make *) ; #endif skalibs-2.9.1.0/src/include/skalibs/datastruct.h000066400000000000000000000003671355335115400215150ustar00rootroot00000000000000/* ISC license. */ #ifndef DATASTRUCT_H #define DATASTRUCT_H #include #include #include #include #include #include #endif skalibs-2.9.1.0/src/include/skalibs/direntry.h000066400000000000000000000004061355335115400211710ustar00rootroot00000000000000/* ISC license. */ #ifndef DIRENTRY_H #define DIRENTRY_H #include typedef struct dirent direntry, direntry_t, *direntry_ref, *direntry_t_ref ; extern void dir_close (DIR *) ; extern int dir_fd (DIR *) ; /* Solaris doesn't have dirfd() */ #endif skalibs-2.9.1.0/src/include/skalibs/disize.h000066400000000000000000000003531355335115400206210ustar00rootroot00000000000000/* ISC license. */ #ifndef DISIZE_H #define DISIZE_H #include typedef struct disize_s disize, *disize_ref ; struct disize_s { size_t left ; size_t right ; } ; #define DISIZE_ZERO { .left = 0, .right = 0 } #endif skalibs-2.9.1.0/src/include/skalibs/diuint.h000066400000000000000000000003331355335115400206240ustar00rootroot00000000000000/* ISC license. */ #ifndef DIUINT_H #define DIUINT_H typedef struct diuint diuint, *diuint_ref ; struct diuint { unsigned int left ; unsigned int right ; } ; #define DIUINT_ZERO { .left = 0, .right = 0 } #endif skalibs-2.9.1.0/src/include/skalibs/diuint32.h000066400000000000000000000003721355335115400207740ustar00rootroot00000000000000/* ISC license. */ #ifndef DIUINT32_H #define DIUINT32_H #include typedef struct diuint32_s diuint32, *diuint32_ref ; struct diuint32_s { uint32_t left ; uint32_t right ; } ; #define DIUINT32_ZERO { .left = 0, .right = 0 } #endif skalibs-2.9.1.0/src/include/skalibs/djbtime.h000066400000000000000000000045511355335115400207540ustar00rootroot00000000000000/* ISC license. */ #ifndef DJBTIME_H #define DJBTIME_H #include #include #include #include /* UTC <--> TAI conversions */ /* sysclock can be either TAI-10 or UTC */ extern int utc_from_tai (uint64_t *, tai_t const *) ; extern int tai_from_utc (tai_t *, uint64_t) ; extern int utc_from_sysclock (uint64_t *) ; extern int sysclock_from_utc (uint64_t *) ; /* NTP internal format */ #define NTP_OFFSET 2208988800UL extern int ntp_from_tain (uint64_t *, tain_t const *) ; #define ntp_from_tain_g(u) ntp_from_tain((u), &STAMP) extern int tain_from_ntp (tain_t *, uint64_t) ; /* localtime handling - replaces caltimedate functions */ /* ltm64 can be either TAI-10 or UTC depending on the current timezone */ /* normally ltm64 is the same as sysclock, but we allow it to be different */ /* for instance for musl TAI-10 systems */ typedef struct localtmn_s localtmn_t, *localtmn_t_ref ; struct localtmn_s { struct tm tm ; uint32_t nano ; } ; extern int ltm64_from_tai (uint64_t *, tai_t const *) ; extern int tai_from_ltm64 (tai_t *, uint64_t) ; extern int ltm64_from_utc (uint64_t *) ; extern int utc_from_ltm64 (uint64_t *) ; extern int ltm64_from_sysclock (uint64_t *) ; extern int sysclock_from_ltm64 (uint64_t *) ; extern int localtm_from_ltm64 (struct tm *, uint64_t, int) ; extern int ltm64_from_localtm (uint64_t *, struct tm const *) ; extern int localtm_from_sysclock (struct tm *, uint64_t, int) ; extern int sysclock_from_localtm (uint64_t *, struct tm const *) ; extern int localtm_from_utc (struct tm *, uint64_t, int) ; extern int utc_from_localtm (uint64_t *, struct tm const *) ; extern int localtm_from_tai (struct tm *, tai_t const *, int) ; extern int tai_from_localtm (tai_t *, struct tm const *) ; extern int localtmn_from_tain (localtmn_t *, tain_t const *, int) ; #define localtmn_from_tain_g(l, h) localtmn_from_tain(l, &STAMP, h) extern int tain_from_localtmn (tain_t *, localtmn_t const *) ; extern int localtmn_from_sysclock (localtmn_t *, tain_t const *, int) ; extern int sysclock_from_localtmn (tain_t *, localtmn_t const *) ; #define LOCALTM_FMT 21 extern size_t localtm_fmt (char *, struct tm const *) ; extern size_t localtm_scan (char const *, struct tm *) ; #define LOCALTMN_FMT 31 extern size_t localtmn_fmt (char *, localtmn_t const *) ; extern size_t localtmn_scan (char const *, localtmn_t *) ; #endif skalibs-2.9.1.0/src/include/skalibs/djbunix.h000066400000000000000000000247001355335115400207770ustar00rootroot00000000000000/* ISC license. */ #ifndef DJBUNIX_H #define DJBUNIX_H #include #include #include #include #include #include #include #define DJBUNIX_FLAG_NB 0x01U #define DJBUNIX_FLAG_COE 0x02U extern int coe (int) ; extern int uncoe (int) ; extern int ndelay_on (int) ; extern int ndelay_off (int) ; extern int pipe_internal (int *, unsigned int) ; #define pipenb(p) pipe_internal(p, DJBUNIX_FLAG_NB) #define pipecoe(p) pipe_internal(p, DJBUNIX_FLAG_COE) #define pipenbcoe(p) pipe_internal(p, DJBUNIX_FLAG_NB|DJBUNIX_FLAG_COE) extern int fd_copy (int, int) ; extern int fd_copy2 (int, int, int, int) ; extern int fd_move (int, int) ; extern int fd_move2 (int, int, int, int) ; extern void fd_close (int) ; extern int fd_chmod (int, unsigned int) ; extern int fd_chown (int, uid_t, gid_t) ; extern int fd_sync (int) ; extern int fd_cat (int, int) ; extern size_t fd_catn (int, int, size_t) ; extern int fd_ensure_open (int, int) ; #define fd_sanitize() (fd_ensure_open(0, 0) && fd_ensure_open(1, 1) && fd_ensure_open(2, 1)) extern int lock_ex (int) ; extern int lock_exnb (int) ; extern int lock_sh (int) ; extern int lock_shnb (int) ; extern int lock_un (int) ; extern void lock_unx (int) ; extern int open2 (char const *, unsigned int) ; extern int open3 (char const *, unsigned int, unsigned int) ; extern int open_read (char const *) ; extern int openb_read (char const *) ; extern int open_readb (char const *) ; extern int open_excl (char const *) ; extern int open_append (char const *) ; extern int open_create (char const *) ; extern int open_trunc (char const *) ; extern int open_write (char const *) ; extern int socket_internal (int, int, int, unsigned int) ; extern int socketpair_internal (int, int, int, unsigned int, int *) ; extern size_t path_canonicalize (char *, char const *, int) ; 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 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 *) ; extern void pathexec0 (char const *const *) ; extern void xpathexec_r (char const *const *, char const *const *, size_t, char const *, size_t) gccattr_noreturn ; extern void xpathexec_r_name (char const *, char const *const *, char const *const *, size_t, char const *, size_t) gccattr_noreturn ; extern void xpathexec_fromenv (char const *const *, char const *const *, size_t) gccattr_noreturn ; extern void xexecvep (char const *, char const *const *, char const *const *, char const *) gccattr_noreturn ; extern void xpathexec_run (char const *, char const *const *, char const *const *) gccattr_noreturn ; extern void xpathexec0_run (char const *const *, char const *const *) gccattr_noreturn ; extern void xpathexec (char const *const *) gccattr_noreturn ; extern void xpathexec0 (char const *const *) gccattr_noreturn ; extern pid_t wait_nointr (int *) ; extern pid_t waitpid_nointr (pid_t, int *, int) ; #define wait_pid(pid, wstat) waitpid_nointr(pid, (wstat), 0) #define wait_nohang(wstat) waitpid_nointr(-1, (wstat), WNOHANG) extern pid_t wait_pid_nohang (pid_t, int *) ; extern int wait_pids_nohang (pid_t const *, unsigned int, int *) ; #define wait_status(w) (WIFSIGNALED(w) ? 256 + WTERMSIG(w) : WEXITSTATUS(w)) #define wait_estatus(w) (WIFSIGNALED(w) ? 128 + WTERMSIG(w) : WEXITSTATUS(w) >= 128 ? 128 : WEXITSTATUS(w)) extern unsigned int wait_reap (void) ; extern int waitn (pid_t *, unsigned int) ; extern int waitn_reap (pid_t *, unsigned int) ; extern int fd_chdir (int) ; extern int sarealpath (stralloc *, char const *) ; extern int sabasename (stralloc *, char const *, size_t) ; extern int sadirname (stralloc *, char const *, size_t) ; extern int sagetcwd (stralloc *) ; extern int sareadlink (stralloc *, char const *) ; extern int sagethostname (stralloc *) ; extern int slurp (stralloc *, int) ; extern int openslurpclose (stralloc *, char const *) ; extern ssize_t openreadnclose (char const *, char *, size_t) ; extern ssize_t openreadnclose_nb (char const *, char *, size_t) ; extern int openreadfileclose (char const *, stralloc *, size_t) ; #define writenclose_unsafe(fd, s, n) writenclose_unsafe_internal(fd, s, (n), 0, 0, 0) #define writenclose_unsafe_sync(fd, s, n) writenclose_unsafe_internal(fd, s, (n), 0, 0, 1) #define writenclose_unsafe_devino(fd, s, n, dev, ino) writenclose_unsafe_internal(fd, s, n, dev, (ino), 0) #define writenclose_unsafe_devino_sync(fd, s, n, dev, ino) writenclose_unsafe_internal(fd, s, n, dev, (ino), 1) extern int writenclose_unsafe_internal (int, char const *, size_t, dev_t *, ino_t *, int) ; #define openwritenclose_unsafe(f, s, n) openwritenclose_unsafe_internal(f, s, (n), 0, 0, 0) #define openwritenclose_unsafe_sync(f, s, n) openwritenclose_unsafe_internal(f, s, (n), 0, 0, 1) #define openwritenclose_unsafe_devino(f, s, n, dev, ino) openwritenclose_unsafe_internal(f, s, n, dev, (ino), 0) #define openwritenclose_unsafe_devino_sync(f, s, n, dev, ino) openwritenclose_unsafe_internal(f, s, n, dev, (ino), 1) extern int openwritenclose_unsafe_internal (char const *, char const *, size_t, dev_t *, ino_t *, int) ; #define openwritenclose_suffix(f, s, n, t) openwritenclose_suffix_internal(f, s, n, 0, 0, 0, t) #define openwritenclose_suffix_sync(f, s, n, t) openwritenclose_suffix_internal(f, s, n, 0, 0, 1, t) #define openwritenclose_suffix_devino(f, s, n, t, dev, ino) openwritenclose_suffix_internal(f, s, n, dev, (ino), 0, t) #define openwritenclose_suffix_devino_sync(f, s, n, t, dev, ino) openwritenclose_suffix_internal(f, s, n, dev, (ino), 1, t) extern int openwritenclose_suffix_internal (char const *, char const *, size_t, dev_t *, ino_t *, int, char const *) ; #define openwritenclose(f, s, n) openwritenclose_internal(f, s, (n), 0, 0, 0) #define openwritenclose_sync(f, s, n) openwritenclose_internal(f, s, (n), 0, 0, 1) #define openwritenclose_devino(f, s, n, dev, ino) openwritenclose_internal(f, s, n, dev, (ino), 0) #define openwritenclose_devino_sync(f, s, n, dev, ino) openwritenclose_internal(f, s, n, dev, (ino), 1) extern int openwritenclose_internal (char const *, char const *, size_t, dev_t *, ino_t *, int) ; #define writenvclose_unsafe(fd, v, n) writevnclose_unsafe_internal(fd, v, (n), 0, 0, 0) #define writevnclose_unsafe_sync(fd, v, n) writevnclose_unsafe_internal(fd, v, (n), 0, 0, 1) #define writevnclose_unsafe_devino(fd, v, n, dev, ino) writevnclose_unsafe_internal(fd, v, n, dev, (ino), 0) #define writevnclose_unsafe_devino_sync(fd, v, n, dev, ino) writevnclose_unsafe_internal(fd, v, n, dev, (ino), 1) extern int writevnclose_unsafe_internal (int, struct iovec const *, unsigned int, dev_t *, ino_t *, int) ; #define openwritevnclose_unsafe(f, v, n) openwritevnclose_unsafe_internal(f, v, (n), 0, 0, 0) #define openwritevnclose_unsafe_sync(f, v, n) openwritevnclose_unsafe_internal(f, v, (n), 0, 0, 1) #define openwritevnclose_unsafe_devino(f, v, n, dev, ino) openwritevnclose_unsafe_internal(f, v, n, dev, (ino), 0) #define openwritevnclose_unsafe_devino_sync(f, v, n, dev, ino) openwritevnclose_unsafe_internal(f, v, n, dev, (ino), 1) extern int openwritevnclose_unsafe_internal (char const *, struct iovec const *, unsigned int, dev_t *, ino_t *, int) ; #define openwritevnclose_suffix(f, v, n, t) openwritevnclose_suffix_internal(f, v, n, 0, 0, 0, t) #define openwritevnclose_suffix_sync(f, v, n, t) openwritevnclose_suffix_internal(f, v, n, 0, 0, 1, t) #define openwritevnclose_suffix_devino(f, v, n, t, dev, ino) openwritevnclose_suffix_internal(f, v, n, dev, (ino), 0, t) #define openwritevnclose_suffix_devino_sync(f, v, n, t, dev, ino) openwritevnclose_suffix_internal(f, v, n, dev, (ino), 1, t) extern int openwritevnclose_suffix_internal (char const *, struct iovec const *, unsigned int, dev_t *, ino_t *, int, char const *) ; #define openwritevnclose(f, v, n) openwritevnclose_internal(f, v, (n), 0, 0, 0) #define openwritevnclose_sync(f, v, n) openwritevnclose_internal(f, v, (n), 0, 0, 1) #define openwritevnclose_devino(f, v, n, dev, ino) openwritevnclose_internal(f, v, n, dev, (ino), 0) #define openwritevnclose_devino_sync(f, v, n, dev, ino) openwritevnclose_internal(f, v, n, dev, (ino), 1) extern int openwritevnclose_internal (char const *, struct iovec const *, unsigned int, dev_t *, ino_t *, int) ; extern int rm_rf (char const *) ; extern int rm_rf_tmp (char const *, stralloc *) ; extern int rm_rf_in_tmp (stralloc *, size_t) ; /* caution ! */ extern int rmstar (char const *) ; extern int rmstar_tmp (char const *, stralloc *) ; 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 *) ; extern int hiercopy_tmp (char const *, char const *, stralloc *) ; /* Simple spawn functions with 0 or 1 communicating fds. */ extern pid_t child_spawn0 (char const *, char const *const *, char const *const *) ; extern pid_t child_spawn1_pipe (char const *, char const *const *, char const *const *, int *, int) ; extern pid_t child_spawn1_socket (char const *, char const *const *, char const *const *, int *) ; /* Spawn function with 2 communicating pipes. The int * points to 2 fds. Input: fds[0] and fds[1] are the fds to move the pipes to in the child. Output: fds[0] and fds[1] contain the pipes to the child. */ extern pid_t child_spawn2 (char const *, char const *const *, char const *const *, int *) ; /* Same, with an additional pipe from the child to the parent. The int * points to 3 fds. The additional fd# is available to the child in the defined env variable. */ #define SKALIBS_CHILD_SPAWN_FDS_ENVVAR "SKALIBS_CHILD_SPAWN_FDS" extern pid_t child_spawn3 (char const *, char const *const *, char const *const *, int *) ; /* Generalization of the previous functions. * uses posix_spawn() if available, else uses fork+exec * requests n (the last arg) communication fds between parent and child. Uses pipes. * if n=1, equivalent to child_spawn1_pipe; child writes, parent reads. * if n>=2, parent reads on even and writes on odd. */ extern pid_t child_spawn (char const *, char const *const *, char const *const *, int *, unsigned int) ; #endif skalibs-2.9.1.0/src/include/skalibs/env.h000066400000000000000000000024321355335115400201220ustar00rootroot00000000000000/* ISC license. */ #ifndef SKALIBS_ENV_H #define SKALIBS_ENV_H #include #include #include extern size_t env_len (char const *const *) gccattr_pure ; extern char const *env_get (char const *) gccattr_deprecated ; extern char const *env_get2 (char const *const *, char const *) gccattr_pure ; extern char const *ucspi_get (char const *) gccattr_pure ; extern int env_addmodif (stralloc *, char const *, char const *) ; extern int env_make (char const **, size_t, char const *, size_t) ; extern size_t env_merge (char const **, size_t, char const *const *, size_t, char const *, size_t) ; extern int env_string (stralloc *, char const *const *, size_t) ; #define SKALIBS_ENVDIR_VERBATIM 0x01 #define SKALIBS_ENVDIR_NOCHOMP 0x02 extern int envdir_internal (char const *, stralloc *, unsigned int, char) ; #define envdir(path, sa) envdir_internal(path, (sa), 0, '\n') #define envdir_chomp(path, sa) envdir_internal(path, (sa), SKALIBS_ENVDIR_NOCHOMP, '\n') #define envdir_verbatim_chomp(path, sa) envdir_internal(path, (sa), SKALIBS_ENVDIR_VERBATIM, '\n') #define envdir_verbatim(path, sa) envdir_internal(path, (sa), SKALIBS_ENVDIR_VERBATIM|SKALIBS_ENVDIR_NOCHOMP, '\n') extern int env_dump (char const *, mode_t, char const *const *) ; #endif skalibs-2.9.1.0/src/include/skalibs/envalloc.h000066400000000000000000000006231355335115400211350ustar00rootroot00000000000000/* ISC license. */ #ifndef ENVALLOC_H #define ENVALLOC_H #include #include #define ENVALLOC_ZERO GENALLOC_ZERO extern int envalloc_make (genalloc *, size_t, char const *, size_t) ; extern int envalloc_uniq (genalloc *, char) ; extern int envalloc_merge (genalloc *, char const *const *, size_t, char const *, size_t) ; extern int envalloc_0 (genalloc *) ; #endif skalibs-2.9.1.0/src/include/skalibs/environ.h000066400000000000000000000001311355335115400210040ustar00rootroot00000000000000/* ISC license. */ /* This header is being deprecated */ #include skalibs-2.9.1.0/src/include/skalibs/error.h000066400000000000000000000004211355335115400204570ustar00rootroot00000000000000/* ISC license. */ #ifndef SKALIBS_ERROR_H #define SKALIBS_ERROR_H #include extern int error_temp (int) gccattr_const ; extern int error_isalready (int) gccattr_const ; #define error_isagain(e) (((e) == EAGAIN) || ((e) == EWOULDBLOCK)) #endif skalibs-2.9.1.0/src/include/skalibs/fmtscan.h000066400000000000000000000024011355335115400207610ustar00rootroot00000000000000/* ISC license. */ #ifndef FMTSCAN_H #define FMTSCAN_H #include #include #include /* fmt */ extern size_t str_fmt (char *, char const *) ; extern size_t strn_fmt (char *, char const *, size_t) ; extern unsigned char fmtscan_asc (unsigned char) gccattr_const ; #define IP4_FMT 20 extern size_t ip4_fmt (char *, char const *) ; extern size_t ip4_fmtu32 (char *, uint32_t) ; extern size_t ucharn_fmt (char *, char const *, size_t) ; extern size_t ucharn_fmt_little (char *, char const *, size_t) ; #define IP6_FMT 40 extern size_t ip6_fmt (char *, char const *) ; /* scan */ extern unsigned char fmtscan_num (unsigned char, unsigned char) gccattr_const ; extern size_t ip4_scan (char const *, char *) ; extern size_t ip4_scanu32 (char const *, uint32_t *) ; extern size_t ip4_scanlist_u32 (uint32_t *, size_t, char const *, size_t *) ; extern size_t ip4_scanlist (char *, size_t, char const *, size_t *) ; extern size_t ip6_scan (char const *, char *) ; extern size_t ip6_scanlist (char *, size_t, char const *, size_t *) ; extern size_t ucharn_scan (char const *, char *, size_t) ; extern size_t ucharn_scan_little (char const *, char *, size_t) ; extern size_t ucharn_findlen (char const *) gccattr_pure ; #endif skalibs-2.9.1.0/src/include/skalibs/functypes.h000066400000000000000000000027201355335115400213520ustar00rootroot00000000000000/* ISC license. */ #ifndef FUNCTYPES_H #define FUNCTYPES_H #include #include #include typedef int uintcmpfunc_t (unsigned int, unsigned int, void *) ; typedef uintcmpfunc_t *uintcmpfunc_t_ref ; typedef int uint32cmpfunc_t (uint32_t, uint32_t, void *) ; typedef uint32cmpfunc_t *uint32cmpfunc_t_ref ; typedef int cmpfunc_t (void const *, void const *, void *) ; typedef cmpfunc_t *cmpfunc_t_ref ; typedef void *dtokfunc_t (uint32_t, void *) ; typedef dtokfunc_t *dtokfunc_t_ref ; typedef int iterfunc_t (char *, void *) ; typedef iterfunc_t *iterfunc_t_ref ; typedef void freefunc_t (void *) ; typedef freefunc_t *freefunc_t_ref ; typedef int initfunc_t (void *) ; typedef initfunc_t *initfunc_t_ref ; typedef ssize_t getfunc_t (void *) ; typedef getfunc_t *getfunc_t_ref ; typedef size_t ugetfunc_t (void *) ; typedef ugetfunc_t *ugetfunc_t_ref ; typedef ssize_t iofunc_t (int, char *, size_t) ; typedef iofunc_t *iofunc_t_ref ; typedef ssize_t iovfunc_t (int, struct iovec const *, unsigned int) ; typedef iovfunc_t *iovfunc_t_ref ; typedef size_t alliofunc_t (int, char *, size_t) ; typedef alliofunc_t *alliofunc_t_ref ; typedef size_t alliovfunc_t (int, struct iovec const *, unsigned int) ; typedef alliovfunc_t *alliovfunc_t_ref ; typedef int createfunc_t (char const *, mode_t, void *) ; typedef createfunc_t *createfunc_t_ref ; typedef int linkfunc_t (char const *, char const *) ; typedef linkfunc_t *linkfunc_t_ref ; #endif skalibs-2.9.1.0/src/include/skalibs/gccattributes.h000066400000000000000000000027731355335115400222050ustar00rootroot00000000000000/* ISC license. */ #ifndef GCCATTRIBUTES_H #define GCCATTRIBUTES_H #ifdef __GNUC__ #define gccattr_noreturn __attribute__((__noreturn__)) #define gccattr_noinline __attribute__((__noinline__)) #define gccattr_inline __attribute__((__always_inline__)) #define gccattr_const __attribute__((__const__)) #define gccattr_unused __attribute__((__unused__)) #define gccattr_used __attribute__((__used__)) #define gccattr_weak __attribute__((__weak__)) #define gccattr_aligned __attribute__((__aligned__)) # if (__GNUC__ >= 3) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 96)) #define gccattr_malloc __attribute__((__malloc__)) #define gccattr_pure __attribute__((__pure__)) # else #define gccattr_malloc #define gccattr_pure # endif # if (__GNUC__ >= 3) #define gccattr_deprecated __attribute__((__deprecated__)) # else #define gccattr_deprecated # endif #else #define gccattr_noreturn #define gccattr_noinline #define gccattr_inline #define gccattr_const #define gccattr_unused #define gccattr_used #define gccattr_weak #define gccattr_aligned #define gccattr_malloc #define gccattr_pure #define gccattr_deprecated #endif #ifdef GCCATTR_COMPAT_0_22 #define _a_noreturn gccattr_noreturn #define _a_noinline gccattr_noinline #define _a_inline gccattr_inline #define _a_const gccattr_const #define _a_unused gccattr_unused #define _a_used gccattr_used #define _a_weak gccattr_weak #define _a_aligned gccattr_aligned #define _a_malloc gccattr_malloc #define _a_pure gccattr_pure #define _a_deprecated gccattr_deprecated #endif #endif skalibs-2.9.1.0/src/include/skalibs/genalloc.h000066400000000000000000000032111355335115400211120ustar00rootroot00000000000000/* ISC license. */ #ifndef GENALLOC_H #define GENALLOC_H #include #include typedef stralloc genalloc, *genalloc_ref ; #define GENALLOC_ZERO STRALLOC_ZERO #define genalloc_zero stralloc_zero #define genalloc_s(type, g) ((type *)((g)->s)) #define genalloc_len(type, g) ((g)->len/sizeof(type)) #define genalloc_setlen(type, g, n) ((g)->len = (n)*sizeof(type)) #define genalloc_ready(type, g, n) stralloc_ready((g), (n)*sizeof(type)) #define genalloc_ready_tuned(type, g, n, base, fracnum, fracden) stralloc_ready_tuned((g), (n)*sizeof(type), base, fracnum, fracden) #define genalloc_readyplus(type, g, n) stralloc_readyplus((g), (n)*sizeof(type)) #define genalloc_free(type, g) stralloc_free(g) #define genalloc_shrink(type, g) stralloc_shrink(g) #define genalloc_catb(type, g, s, n) stralloc_catb((g), (char const *)(s), (n)*sizeof(type)) #define genalloc_copyb(type, g, s, n) stralloc_copyb((g), (char const *)(s), (n)*sizeof(type)) #define genalloc_copy(type, g1, g2) stralloc_copy((g1), g2) #define genalloc_cat(type, g1, g2) stralloc_cat((g1), g2) #define genalloc_append(type, g, p) stralloc_catb((g), (char const *)(p), sizeof(type)) #define genalloc_reverse(type, g) stralloc_reverse_blocks((g), sizeof(type)) #define genalloc_insertb(type, g, offset, s, n) stralloc_insertb((g), (offset)*sizeof(type), (char const *)(s), (n)*sizeof(type)) #define genalloc_insert(type, g1, offset, g2) stralloc_insert((g1), (offset)*sizeof(type), (g2)) #define genalloc_deepfree(type, g, f) genalloc_deepfree_size(g, (freefunc_t_ref)(f), sizeof(type)) extern void genalloc_deepfree_size (genalloc *, freefunc_t_ref, size_t) ; #endif skalibs-2.9.1.0/src/include/skalibs/genqdyn.h000066400000000000000000000017251355335115400210030ustar00rootroot00000000000000/* ISC license. */ #ifndef SKALIBS_GENQDYN_H #define SKALIBS_GENQDYN_H #include #include typedef struct genqdyn_s genqdyn, *genqdyn_ref ; struct genqdyn_s { stralloc queue ; size_t esize ; size_t head ; unsigned int num ; unsigned int den ; } ; #define GENQDYN_ZERO { .queue = STRALLOC_ZERO, .esize = 1, .head = 0, .num = 0, .den = 1 } extern genqdyn const genqdyn_zero ; #define GENQDYN_INIT(type, n, d) { .queue = STRALLOC_ZERO, .esize = sizeof(type), .head = 0, .num = n, .den = d } extern void genqdyn_init (genqdyn *, size_t, unsigned int, unsigned int) ; #define genqdyn_n(g) ((g)->queue.len / (g)->esize - (g)->head) ; extern void genqdyn_free (genqdyn *) ; extern int genqdyn_push (genqdyn *, void const *) ; extern int genqdyn_unpush (genqdyn *) ; #define GENQDYN_PEEK(type, g) ((type *)((g)->queue.s + (g)->esize * (g)->head)) #define genqdyn_peek(g) GENQDYN_PEEK(void, (g)) extern int genqdyn_pop(genqdyn *) ; #endif skalibs-2.9.1.0/src/include/skalibs/genset.h000066400000000000000000000030501355335115400206140ustar00rootroot00000000000000/* ISC license. */ #ifndef GENSET_H #define GENSET_H #include #include typedef struct genset_s genset, *genset_ref ; struct genset_s { char *storage ; uint32_t *freelist ; uint32_t esize ; uint32_t max ; uint32_t sp ; } ; #define GENSET_ZERO { .storage = 0, .freelist = 0, .esize = 1, .max = 0, .sp = 0 } extern void genset_init (genset *, void *, uint32_t *, uint32_t, uint32_t) ; #define GENSET_init(g, type, storage, fl, size) genset_init(g, storage, fl, sizeof(type), size) #define genset_p(type, g, i) ((type *)((g)->storage + (i) * (g)->esize)) extern uint32_t genset_new (genset *) ; extern int genset_delete (genset *, uint32_t) ; #define genset_n(g) ((g)->max - (g)->sp) extern uint32_t genset_iter_nocancel (genset *, uint32_t, iterfunc_t_ref, void *) ; #define genset_iter(g, f, stuff) genset_iter_nocancel(g, (g)->max, f, stuff) extern int genset_iter_withcancel (genset *, iterfunc_t_ref, iterfunc_t_ref, void *) ; extern void genset_deepfree (genset *, freefunc_t_ref) ; #define GENSETB_TYPE(type, size) struct { type storage[size] ; uint32_t freelist[size] ; genset info ; } #define GENSETB_init(type, g, size) GENSET_init(&(g)->info, type, (g)->storage, (g)->freelist, size) #define gensetb_p(type, g, i) genset_p(type, &(g)->info, i) #define gensetb_new(g) genset_new(&(g)->info) #define gensetb_delete(g, i) genset_delete(&(g)->info, i) #define gensetb_n(g) genset_n(&(g)->info) #define gensetb_iter(g, f, p) genset_iter(&(g)->info, f, p) #define gensetb_deepfree(g, f) genset_deepfree(&(g)->info, f) #endif skalibs-2.9.1.0/src/include/skalibs/gensetdyn.h000066400000000000000000000032021355335115400213260ustar00rootroot00000000000000/* ISC license. */ #ifndef GENSETDYN_H #define GENSETDYN_H #include #include #include #include typedef struct gensetdyn_s gensetdyn, *gensetdyn_ref ; struct gensetdyn_s { stralloc storage ; genalloc freelist ; /* array of uint32_t */ uint32_t esize ; uint32_t base ; uint32_t fracnum ; uint32_t fracden ; } ; #define GENSETDYN_ZERO { .storage = STRALLOC_ZERO, .freelist = GENALLOC_ZERO, .esize = 1, .base = 0, .fracnum = 0, .fracden = 1 } extern gensetdyn const gensetdyn_zero ; #define GENSETDYN_INIT(type, b, num, den) { .storage = STRALLOC_ZERO, .freelist = GENALLOC_ZERO, .esize = sizeof(type), .base = (b), .fracnum = (num), .fracden = (den) } extern void gensetdyn_init (gensetdyn *, uint32_t, uint32_t, uint32_t, uint32_t) ; #define gensetdyn_n(g) ((uint32_t)((g)->storage.len - genalloc_len(uint32_t, &(g)->freelist))) extern int gensetdyn_ready (gensetdyn *, uint32_t) ; #define gensetdyn_readyplus(x, n) gensetdyn_ready(x, gensetdyn_n(x) + (n)) extern void gensetdyn_free (gensetdyn *) ; extern void gensetdyn_deepfree (gensetdyn *, freefunc_t_ref) ; extern int gensetdyn_new (gensetdyn *, uint32_t *) ; extern int gensetdyn_delete (gensetdyn *, uint32_t) ; #define gensetdyn_p(g, i) ((g)->storage.s + (i) * (g)->esize) #define GENSETDYN_P(type, g, i) ((type *)gensetdyn_p(g, i)) extern uint32_t gensetdyn_iter_nocancel (gensetdyn *, uint32_t, iterfunc_t_ref, void *) ; #define gensetdyn_iter(g, f, stuff) gensetdyn_iter_nocancel(g, gensetdyn_n(g), f, stuff) extern int gensetdyn_iter_withcancel (gensetdyn *, iterfunc_t_ref, iterfunc_t_ref, void *) ; #endif skalibs-2.9.1.0/src/include/skalibs/genwrite.h000066400000000000000000000024071355335115400211600ustar00rootroot00000000000000/* ISC license. */ #ifndef GENWRITE_H #define GENWRITE_H #include typedef ssize_t genwrite_put_func_t (void *, char const *, size_t) ; typedef genwrite_put_func_t *genwrite_put_func_t_ref ; typedef int genwrite_flush_func_t (void *) ; typedef genwrite_flush_func_t *genwrite_flush_func_t_ref ; typedef struct genwrite_s genwrite_t, *genwrite_t_ref ; struct genwrite_s { genwrite_put_func_t_ref put ; genwrite_flush_func_t_ref flush ; void *target ; } ; #define GENWRITE_ZERO { .put = 0, .flush = 0, .target = 0 } extern genwrite_put_func_t genwrite_put_stralloc ; extern genwrite_flush_func_t genwrite_flush_stralloc ; extern genwrite_put_func_t genwrite_put_buffer ; extern genwrite_flush_func_t genwrite_flush_buffer ; extern genwrite_put_func_t genwrite_put_bufalloc ; extern genwrite_flush_func_t genwrite_flush_bufalloc ; #define GENWRITE_STRALLOC_INIT(sa) { .put = &genwrite_put_stralloc, .flush = &genwrite_flush_stralloc, .target = (sa) } #define GENWRITE_BUFFER_INIT(b) { .put = &genwrite_put_buffer, .flush = &genwrite_flush_buffer, .target = (b) } #define GENWRITE_BUFALLOC_INIT(ba) { .put = &genwrite_put_bufalloc, .flush = &genwrite_flush_bufalloc, .target = (ba) } extern genwrite_t genwrite_stdout ; extern genwrite_t genwrite_stderr ; #endif skalibs-2.9.1.0/src/include/skalibs/getpeereid.h000066400000000000000000000001311355335115400214410ustar00rootroot00000000000000/* ISC license. */ /* This header is being deprecated */ #include skalibs-2.9.1.0/src/include/skalibs/iobuffer.h000066400000000000000000000105131355335115400211320ustar00rootroot00000000000000/* ISC license. */ #ifndef IOBUFFER_H #define IOBUFFER_H #define IOBUFFER_SIZE 65536U /* iobufferu */ #include #include #include #define IOBUFFERU_SIZE (IOBUFFER_SIZE+1) typedef struct iobufferu_s iobufferu, *iobufferu_ref ; struct iobufferu_s { buffer b[2] ; char *buf ; } ; extern int iobufferu_init (iobufferu *, int, int) ; extern ssize_t iobufferu_fill (iobufferu *) ; extern int iobufferu_flush (iobufferu *) ; extern void iobufferu_finish (iobufferu *) ; #define iobufferu_len(u) buffer_len(&(u)->b[0]) #define iobufferu_available(u) buffer_available(&(u)->b[1]) #define iobufferu_isempty(u) buffer_isempty(&(u)->b[0]) #define iobufferu_isfull(u) buffer_isfull(&(u)->b[1]) #define iobufferu_fd(u, h) buffer_fd((u)->b[h]) #define iobufferu_isreadable(u) iobufferu_available(u) #define iobufferu_iswritable(u) iobufferu_len(u) #define iobufferu_nonblock(u, h) ndelay_on(iobufferu_fd(u, h)) #define iobufferu_block(u, h) ndelay_off(iobufferu_fd(u, h)) #define iobufferu_nbstate(u, h, j) (j ? iobufferu_nonblock(u, h) : iobufferu_block(u, h)) /* iobufferk */ #define IOBUFFERK_SIZE IOBUFFER_SIZE typedef struct iobufferk_s iobufferk, *iobufferk_ref ; struct iobufferk_s { int fd[2] ; int p[2] ; unsigned int n ; unsigned int type : 2 ; unsigned int nb : 2 ; } ; typedef int iobufferk_output_func_t (iobufferk *) ; typedef iobufferk_output_func_t *iobufferk_output_func_t_ref ; typedef ssize_t iobufferk_input_func_t (iobufferk *) ; typedef iobufferk_input_func_t *iobufferk_input_func_t_ref ; typedef void iobufferk_finish_func_t (iobufferk *) ; typedef iobufferk_finish_func_t *iobufferk_finish_func_t_ref ; extern iobufferk_output_func_t iobufferk_isworking ; extern int iobufferk_init (iobufferk *, int, int) ; extern iobufferk_input_func_t_ref const iobufferk_fill_f[4] ; extern iobufferk_output_func_t_ref const iobufferk_flush_f[4] ; extern iobufferk_finish_func_t_ref const iobufferk_finish_f[4] ; #define iobufferk_fill(k) (*iobufferk_fill_f[(k)->type])(k) #define iobufferk_flush(k) (*iobufferk_flush_f[(k)->type])(k) #define iobufferk_finish(k) (*iobufferk_finish_f[(k)->type])(k) #define iobufferk_len(k) ((k)->n) #define iobufferk_available(k) (IOBUFFERK_SIZE - (k)->n) #define iobufferk_isempty(k) (!iobufferk_len(k)) #define iobufferk_isfull(k) (!iobufferk_available(k)) #define iobufferk_fd(k, h) ((k)->fd[h]) #define iobufferk_isreadable(k) iobufferk_available(k) #define iobufferk_iswritable(k) iobufferk_len(k) #define iobufferk_nonblock(k, h) ((k)->nb |= (1 << (h)), 0) #define iobufferk_block(k, h) ((k)->nb &= (3 - (1 << (h))), 0) #define iobufferk_nbstate(k, h, j) (j ? iobufferk_nonblock(k, h) : iobufferk_block(k, h)) /* iobuffer */ typedef union iobufferku_u iobufferku, *iobufferku_ref ; union iobufferku_u { iobufferk k ; iobufferu u ; } ; typedef struct iobuffer_s iobuffer, *iobuffer_ref ; struct iobuffer_s { iobufferku x ; unsigned int isk : 1 ; } ; extern int iobuffer_ufromk (iobufferu *, iobufferk *) ; extern int iobuffer_kfromu (iobufferk *, iobufferu *) ; extern int iobuffer_salvage (iobuffer *) ; extern int iobuffer_init (iobuffer *, int, int) ; extern ssize_t iobuffer_fill (iobuffer *) ; extern int iobuffer_flush (iobuffer *) ; #define iobuffer_finish(b) ((b)->isk ? iobufferk_finish(&(b)->x.k) : iobufferu_finish(&(b)->x.u)) #define iobuffer_len(b) ((b)->isk ? iobufferk_len(&(b)->x.k) : iobufferu_len(&(b)->x.u)) #define iobuffer_available(b) ((b)->isk ? iobufferk_available(&(b)->x.k) : iobufferu_available(&(b)->x.u)) #define iobuffer_isempty(b) ((b)->isk ? iobufferk_isempty(&(b)->x.k) : iobufferu_isempty(&(b)->x.u)) #define iobuffer_isfull(b) ((b)->isk ? iobufferk_isfull(&(b)->x.k) : iobufferu_isfull(&(b)->x.u)) #define iobuffer_fd(b, h) ((b)->isk ? iobufferk_fd(&(b)->x.k, h) : iobufferu_fd(&(b)->x.u, h)) #define iobuffer_isreadable(b) ((b)->isk ? iobufferk_isreadable(&(b)->x.k) : iobufferu_isreadable(&(b)->x.u)) #define iobuffer_iswritable(b) ((b)->isk ? iobufferk_iswritable(&(b)->x.k) : iobufferu_iswritable(&(b)->x.u)) #define iobuffer_nonblock(b, h) ((b)->isk ? iobufferk_nonblock(&(b)->x.k, h) : iobufferu_nonblock(&(b)->x.u, h)) #define iobuffer_block(b, h) ((b)->isk ? iobufferk_block(&(b)->x.k, h) : iobufferu_block(&(b)->x.u, h)) #define iobuffer_nbstate(b, h, j) ((b)->isk ? iobufferk_nbstate(&(b)->x.k, h, j) : iobufferu_nbstate(&(b)->x.u, h, j)) #endif skalibs-2.9.1.0/src/include/skalibs/iopause.h000066400000000000000000000015671355335115400210070ustar00rootroot00000000000000/* ISC license. */ #ifndef IOPAUSE_H #define IOPAUSE_H #include #include typedef struct pollfd iopause_fd, *iopause_fd_ref ; #define IOPAUSE_READ (POLLIN|POLLHUP) #define IOPAUSE_WRITE POLLOUT #define IOPAUSE_EXCEPT (POLLERR|POLLHUP|POLLNVAL) typedef int iopause_func_t (iopause_fd *, unsigned int, tain_t const *, tain_t const *) ; typedef iopause_func_t *iopause_func_t_ref ; extern iopause_func_t iopause_select ; extern iopause_func_t iopause_poll ; extern iopause_func_t iopause_ppoll ; extern iopause_func_t_ref const iopause_ ; #define iopause (*iopause_) extern int iopause_stamp (iopause_fd *, unsigned int, tain_t const *, tain_t *) ; #define iopause_g(x, n, deadline) iopause_stamp(x, n, (deadline), &STAMP) extern void deepsleepuntil (tain_t const *, tain_t *) ; #define deepsleepuntil_g(deadline) deepsleepuntil((deadline), &STAMP) #endif skalibs-2.9.1.0/src/include/skalibs/kolbak.h000066400000000000000000000016331355335115400205770ustar00rootroot00000000000000/* ISC license. */ #ifndef KOLBAK_H #define KOLBAK_H #include #include typedef struct kolbak_closure_s kolbak_closure_t, *kolbak_closure_t_ref ; struct kolbak_closure_s { unixmessage_handler_func_t_ref f ; void *data ; } ; #define KOLBAK_CLOSURE_ZERO { .f = 0, .data = 0 } typedef struct kolbak_queue_s kolbak_queue_t, *kolbak_queue_t_ref ; struct kolbak_queue_s { kolbak_closure_t *x ; size_t n ; size_t head ; size_t tail ; } ; #define KOLBAK_QUEUE_ZERO { .x = 0, .n = 0, .head = 0, .tail = 0 } #define KOLBAK_QUEUE_INIT(s, len) { .x = (s), .n = (len), .head = 0, .tail = 0 } extern int kolbak_queue_init (kolbak_queue_t *, kolbak_closure_t *, size_t) ; extern int kolbak_enqueue (kolbak_queue_t *, unixmessage_handler_func_t_ref, void *) ; extern int kolbak_unenqueue (kolbak_queue_t *) ; extern int kolbak_call (unixmessage_t const *, kolbak_queue_t *) ; #endif skalibs-2.9.1.0/src/include/skalibs/lolstdio.h000066400000000000000000000012721355335115400211640ustar00rootroot00000000000000/* ISC license. */ #ifndef LOLSTDIO_H #define LOLSTDIO_H #include #include #include #include #ifdef DEBUG # define LOLDEBUG(...) do \ { \ buffer_puts(buffer_2, PROG) ; \ buffer_puts(buffer_2, ": debug: ") ; \ bprintf(buffer_2, __VA_ARGS__) ; \ buffer_putflush(buffer_2, "\n", 1) ; \ } while (0) #else # define LOLDEBUG(...) #endif extern int vbprintf (buffer *, char const *, va_list) ; extern int bprintf (buffer *, char const *, ...) ; extern int lolprintf (char const *, ...) ; extern int vbaprintf (bufalloc *, char const *, va_list) ; extern int baprintf (bufalloc *, char const *, ...) ; #endif skalibs-2.9.1.0/src/include/skalibs/md5.h000066400000000000000000000012201355335115400200110ustar00rootroot00000000000000/* ISC license. */ #ifndef MD5_H #define MD5_H #include #include typedef struct MD5Schedule MD5Schedule, *MD5Schedule_ref ; struct MD5Schedule { uint32_t buf[4] ; uint32_t bits[2] ; unsigned char in[64] ; } ; #define MD5_INIT() { .buf = { 0x67452301U, 0xefcdab89U, 0x98badcfeU, 0x10325476U }, .bits = { 0, 0 }, .in = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" } extern void md5_init (MD5Schedule *) ; extern void md5_update (MD5Schedule *, char const *, size_t) ; extern void md5_final (MD5Schedule *, char * /* 16 chars */) ; #endif skalibs-2.9.1.0/src/include/skalibs/netstring.h000066400000000000000000000016321355335115400213500ustar00rootroot00000000000000/* ISC license. */ #ifndef NETSTRING_H #define NETSTRING_H #include #include #include #include extern int netstring_appendb (stralloc *, char const *, size_t) ; #define netstring_appends(sa, s) netstring_appendb((sa), (s), strlen(s)) #define netstring_append(to, from) netstring_appendb((to), (from)->s, (from)->len) extern int netstring_appendv (stralloc *, struct iovec const *, unsigned int) ; extern int netstring_encode (stralloc *, char const *, size_t) ; extern ssize_t netstring_decode (stralloc *, char const *, size_t) ; extern int netstring_okeof (buffer *, size_t) ; extern int netstring_get (buffer *, stralloc *, size_t *) ; extern int netstring_put (buffer *, char const *, size_t, size_t *) ; #define netstring_putba(ba, s, n) netstring_appendb(&(ba)->x, s, n) #define netstring_putbav(ba, v, n) netstring_appendv(&(ba)->x, v, n) #endif skalibs-2.9.1.0/src/include/skalibs/nonposix.h000066400000000000000000000032521355335115400212100ustar00rootroot00000000000000/* ISC license. */ #ifndef SKALIBS_NONPOSIX_H #define SKALIBS_NONPOSIX_H /* Drop all pretense of standardness: some libc headers are *more* broken when you define standard feature test macros than when you don't (I'm looking at you, FreeBSD). */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE #if defined(sun) || defined(__sun) /* Solaris: the socket API is not POSIX unless you enable this */ #ifndef _XPG4_2 #define _XPG4_2 #endif #ifndef _XPG6 #define _XPG6 #endif /* Solaris: for settimeofday() and similar. Notice how you have to define by hand a macro with double underscores. */ #ifndef __EXTENSIONS__ #define __EXTENSIONS__ #endif #endif /* sun || __sun */ #if defined(__linux__) || defined(__GNU__) /* GNU (Linux or Hurd): most extensions are unavailable unless you enable _GNU_SOURCE. Some Linux interfaces are also unavailable without it. */ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #else /* __linux__ || __GNU__ */ /* Various BSDs and others: _BSD_SOURCE opens up a lot of extensions. We guard this under not-GNU because recent glibcs scream their heads off if you define _BSD_SOURCE. Stay classy, GNU. */ #ifndef _BSD_SOURCE #define _BSD_SOURCE #endif #endif /* __linux__ || __GNU__ */ #ifdef __NetBSD__ /* NetBSD: of course they had to have their own macros too. */ #ifndef _NETBSD_SOURCE #define _NETBSD_SOURCE #endif #ifndef _INCOMPLETE_XOPEN_C063 #define _INCOMPLETE_XOPEN_C063 #endif #endif /* __NetBSD__ */ /* old versions of BSD and some broken GNU toolchains: system headers are not self-contained, starting with sys/types.h normally always works. */ #include #endif /* SKALIBS_NONPOSIX_H */ skalibs-2.9.1.0/src/include/skalibs/nsig.h000066400000000000000000000006101355335115400202660ustar00rootroot00000000000000/* ISC license. */ /* This header MUST be paired with skalibs/nonposix.h which must be included before system headers. */ #ifndef NSIG_H #include #define SKALIBS_DEFAULT_NSIG 65 #ifndef NSIG # define NSIG SKALIBS_DEFAULT_NSIG #endif /* OpenBSD is a fucking snowflake */ #ifdef __OpenBSD__ #define SKALIBS_NSIG (NSIG-1) #else #define SKALIBS_NSIG NSIG #endif #endif skalibs-2.9.1.0/src/include/skalibs/posixishard.h000066400000000000000000000013471355335115400216730ustar00rootroot00000000000000/* ISC license. */ #ifndef SKALIBS_POSIXISHARD_H #define SKALIBS_POSIXISHARD_H #include #include /* This header must be used with some broken OSes who have serious trouble implementing even easy parts of POSIX. It's supposed to be included *after* system headers, so it won't catch behaviour such as "this macro must be defined prior to including system headers in order to define that symbol". If that's what you need, include skalibs/nonposix.h instead, which must happen *before* system headers. */ extern size_t strnlen (char const *, size_t) gccattr_pure ; #ifndef EPROTO #define EPROTO EPROTOTYPE #endif #ifndef MSG_NOSIGNAL #define MSG_NOSIGNAL 0 #endif #endif skalibs-2.9.1.0/src/include/skalibs/posixplz.h000066400000000000000000000026621355335115400212270ustar00rootroot00000000000000/* ISC license. */ #ifndef SKALIBS_POSIXPLZ_H #define SKALIBS_POSIXPLZ_H #include #include #include #include #include /* Stuff that doesn't have its own POSIX header for some reason. */ extern char **environ ; /* 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 void execvep_loose (char const *, char const *const *, char const *const *, char const *) ; extern void unlink_void (char const *) ; extern pid_t doublefork (void) ; extern int touch (char const *) ; extern int mkfiletemp (char *, createfunc_t_ref, mode_t, void *) ; extern int mklinktemp (char const *, char *, linkfunc_t_ref) ; extern int mkptemp (char *) ; extern int mkltemp (char const *, char *) ; extern int mkhtemp (char const *, char *) ; extern int mkctemp (char *, mode_t, dev_t) ; extern int mkbtemp (char *, mode_t, dev_t) ; /* Wrappers around functions that should be specified better. */ #define skalibs_regcomp(re, s, flags) regcomp(re, (s)[0] ? (s) : ".*", flags) #endif skalibs-2.9.1.0/src/include/skalibs/random.h000066400000000000000000000010431355335115400206070ustar00rootroot00000000000000/* ISC license. */ #ifndef RANDOM_H #define RANDOM_H #include #include #include extern void random_makeseed (char *) ; /* fills 160 bytes */ extern int random_init (void) ; extern void random_finish (void) ; extern unsigned char random_char (void) ; extern void random_string (char *, size_t) ; extern uint32_t random_uint32 (uint32_t) ; extern void random_name (char *, size_t) ; extern void random_unsort (char *, size_t, size_t) ; extern int random_sauniquename (stralloc *, size_t) ; #endif skalibs-2.9.1.0/src/include/skalibs/rc4.h000066400000000000000000000005611355335115400200230ustar00rootroot00000000000000/* ISC license. */ #ifndef RC4_H #define RC4_H #include #define RC4_THROWAWAY 128 typedef struct RC4Schedule RC4Schedule, *RC4Schedule_ref ; struct RC4Schedule { unsigned char tab[256] ; unsigned char x, y ; } ; extern void rc4_init (RC4Schedule *, char const *, size_t) ; extern void rc4 (RC4Schedule *, char const *, char *, size_t) ; #endif skalibs-2.9.1.0/src/include/skalibs/segfault.h000066400000000000000000000002301355335115400211360ustar00rootroot00000000000000/* ISC license. */ #ifndef SEGFAULT_H #define SEGFAULT_H extern int sigsegv (void) ; extern int sigfpe (void) ; #define segfault() sigsegv() #endif skalibs-2.9.1.0/src/include/skalibs/selfpipe.h000066400000000000000000000004661355335115400211460ustar00rootroot00000000000000/* ISC license. */ #ifndef SELFPIPE_H #define SELFPIPE_H #include extern int selfpipe_init (void) ; extern int selfpipe_trap (int) ; extern int selfpipe_untrap (int) ; extern int selfpipe_trapset (sigset_t const *) ; extern int selfpipe_read (void) ; extern void selfpipe_finish (void) ; #endif skalibs-2.9.1.0/src/include/skalibs/setgroups.h000066400000000000000000000014731355335115400213710ustar00rootroot00000000000000/* ISC license. */ #ifndef SKALIBS_SETGROUPS_H #define SKALIBS_SETGROUPS_H #include #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 extern int setgroups_and_gid (gid_t, size_t, gid_t const *) ; extern int setgroups_with_egid (size_t, gid_t const *) ; extern int skalibs_setgroups (size_t, gid_t const *) ; #else /* No setgroups() at all? not much we can do. */ #include #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) #endif #endif skalibs-2.9.1.0/src/include/skalibs/sgetopt.h000066400000000000000000000021201355335115400210110ustar00rootroot00000000000000/* ISC license. */ #ifndef SGETOPT_H #define SGETOPT_H /* reentrant */ typedef struct subgetopt_s subgetopt_t, *subgetopt_t_ref ; struct subgetopt_s { int ind ; int err ; int problem ; char const *arg ; unsigned int pos ; char const *prog ; } ; #define SUBGETOPT_ZERO { .ind = 1, .err = 1, .problem = 0, .arg = 0, .pos = 0, .prog = 0 } extern int subgetopt_r (int, char const *const *, char const *, subgetopt_t *) ; /* non-reentrant */ extern int sgetopt_r (int, char const *const *, char const *, subgetopt_t *) ; extern subgetopt_t subgetopt_here ; #define subgetopt(argc, argv, opts) subgetopt_r((argc), (argv), (opts), &subgetopt_here) #define sgetopt(argc, argv, opts) sgetopt_r((argc), (argv), (opts), &subgetopt_here) #define sgetopt_prog() (subgetopt_here.prog = PROG) /* define SUBGETOPT_SHORT if you don't mind potential name conflicts */ #ifdef SUBGETOPT_SHORT # define getopt sgetopt # define optarg subgetopt_here.arg # define optind subgetopt_here.ind # define opterr subgetopt_here.err # define optopt subgetopt_here.problem # define opteof (-1) #endif #endif skalibs-2.9.1.0/src/include/skalibs/sha1.h000066400000000000000000000011621355335115400201650ustar00rootroot00000000000000/* ISC license. */ #ifndef SHA1_H #define SHA1_H #include #include typedef struct SHA1Schedule SHA1Schedule, *SHA1Schedule_ref ; struct SHA1Schedule { uint32_t buf[5] ; uint32_t bits[2] ; uint32_t in[16] ; unsigned int b ; } ; #define SHA1_INIT() { .buf = { 0x67452301U, 0xefcdab89U, 0x98badcfeU, 0x10325476U, 0xc3d2e1f0U }, .bits = { 0, 0 }, .in = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, .b = 0 } extern void sha1_init (SHA1Schedule *) ; extern void sha1_update (SHA1Schedule *, char const *, size_t) ; extern void sha1_final (SHA1Schedule *, char * /* 20 chars */) ; #endif skalibs-2.9.1.0/src/include/skalibs/sha256.h000066400000000000000000000020661355335115400203450ustar00rootroot00000000000000/* ISC license. */ /* SHA256 routines */ /* Written by David Madore () */ /* Adapted by Laurent Bercot. */ /* This version last modified 2010-01-08 */ /* Note: these routines do not depend on endianness. */ #ifndef SHA256_H #define SHA256_H #include #include typedef struct SHA256Schedule_s SHA256Schedule, *SHA256Schedule_ref ; struct SHA256Schedule_s { uint32_t buf[8] ; /* The eight chaining variables */ uint32_t bits[2] ; /* Count number of message bits */ uint32_t in[16] ; /* Data being fed in */ unsigned int b ; /* Our position within the 512 bits (always between 0 and 63) */ } ; #define SHA256_INIT() { .buf = { 0x6a09e667U, 0xbb67ae85U, 0x3c6ef372U, 0xa54ff53aU, 0x510e527fU, 0x9b05688cU, 0x1f83d9abU, 0x5be0cd19U }, .bits = { 0, 0 }, .in = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, .b = 0 } extern void sha256_init (SHA256Schedule *) ; extern void sha256_update (SHA256Schedule *, char const *, size_t) ; extern void sha256_final (SHA256Schedule *, char *digest) ; #endif skalibs-2.9.1.0/src/include/skalibs/sha512.h000066400000000000000000000012501355335115400203320ustar00rootroot00000000000000/* ISC license. */ #ifndef SHA512_H #define SHA512_H #include #include typedef struct SHA512Schedule_s SHA512Schedule, *SHA512Schedule_ref ; struct SHA512Schedule_s { uint64_t len ; uint64_t h[8] ; unsigned char buf[128] ; } ; #define SHA512_INIT() { .len = 0, .h = { 0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL, 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL, 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL } } extern void sha512_init (SHA512Schedule *) ; extern void sha512_update (SHA512Schedule *, char const *, size_t) ; extern void sha512_final (SHA512Schedule *, char *digest) ; #endif skalibs-2.9.1.0/src/include/skalibs/sig.h000066400000000000000000000025561355335115400201230ustar00rootroot00000000000000/* ISC license. */ #ifndef SIG_H #define SIG_H #include #include #include typedef void skasighandler_t (int) ; typedef skasighandler_t *skasighandler_t_ref ; struct skasigaction { skasighandler_t_ref handler ; unsigned int flags : 2 ; } ; #define SKASA_MASKALL 0x01 #define SKASA_NOCLDSTOP 0x02 extern struct skasigaction const SKASIG_DFL ; extern struct skasigaction const SKASIG_IGN ; extern int skasigaction (int, struct skasigaction const *, struct skasigaction *) ; #define sig_catcha(sig, ac) skasigaction(sig, (ac), 0) #define sig_restore(sig) skasigaction((sig), &SKASIG_DFL, 0) extern void sig_restoreto (sigset_t const *, unsigned int) ; extern int sig_catch (int, skasighandler_t_ref) ; #define sig_ignore(sig) sig_catcha((sig), &SKASIG_IGN) #define sig_uncatch(sig) sig_restore(sig) #define SIGSTACKSIZE 16 extern int sig_pusha (int, struct skasigaction const *) ; extern int sig_pop (int) ; extern int sig_push (int, skasighandler_t_ref) ; extern void sig_block (int) ; extern void sig_blockset (sigset_t const *) ; extern void sig_unblock (int) ; extern void sig_blocknone (void) ; extern void sig_pause (void) ; extern void sig_shield (void) ; extern void sig_unshield (void) ; extern char const *sig_name (int) ; extern int sig_number (char const *) ; extern size_t sig0_scan (char const *, int *) ; #endif skalibs-2.9.1.0/src/include/skalibs/siovec.h000066400000000000000000000014101355335115400206150ustar00rootroot00000000000000/* ISC license. */ #ifndef SIOVEC_H #define SIOVEC_H #include #include extern size_t siovec_len (struct iovec const *, unsigned int) gccattr_pure ; extern size_t siovec_gather (struct iovec const *, unsigned int, char *, size_t) ; extern size_t siovec_scatter (struct iovec const *, unsigned int, char const *, size_t) ; extern size_t siovec_deal (struct iovec const *, unsigned int, struct iovec const *, unsigned int) ; extern size_t siovec_seek (struct iovec *, unsigned int, size_t) ; extern unsigned int siovec_trunc (struct iovec *, unsigned int, size_t) ; extern size_t siovec_bytechr (struct iovec const *, unsigned int, char) ; extern size_t siovec_bytein (struct iovec const *, unsigned int, char const *, size_t) ; #endif skalibs-2.9.1.0/src/include/skalibs/skaclient.h000066400000000000000000000251451355335115400213150ustar00rootroot00000000000000/* ISC license. */ #ifndef SKACLIENT_H #define SKACLIENT_H #include #include #include #include #include #include /* Server part */ extern int skaclient_server_ack (unixmessage_t const *, unixmessage_sender_t *, unixmessage_sender_t *, char const *, size_t, char const *, size_t) ; extern int skaclient_server_bidi_ack (unixmessage_t const *, unixmessage_sender_t *, unixmessage_sender_t *, unixmessage_receiver_t *, char *, size_t, char *, size_t, char const *, size_t, char const *, size_t) ; extern int skaclient_server_init (unixmessage_receiver_t *, unixmessage_sender_t *, unixmessage_sender_t *, char const *, size_t, char const *, size_t, tain_t const *, tain_t *) ; #define skaclient_server_init_g(in, out, asyncout, before, beforelen, after, afterlen, deadline) skaclient_server_init(in, out, asyncout, before, beforelen, after, afterlen, (deadline), &STAMP) #define skaclient_server_01x_init(before, beforelen, after, afterlen, deadline, stamp) skaclient_server_init(unixmessage_receiver_0, unixmessage_sender_1, unixmessage_sender_x, before, beforelen, after, afterlen, deadline, stamp) #define skaclient_server_01x_init_g(before, beforelen, after, afterlen, deadline) skaclient_server_01x_init(before, beforelen, after, afterlen, (deadline), &STAMP) /* Client part: the rest of this file */ #define SKACLIENT_KOLBAK_SIZE 64 #define SKACLIENT_OPTION_WAITPID 0x00000001U #define SKACLIENT_OPTION_ASYNC_ACCEPT_FDS 0x00000002U #define SKACLIENT_OPTION_SYNC_ACCEPT_FDS 0x00000004U #define skaclient_buffer_type(bufsn, auxbufsn, bufan, auxbufan, qlen) struct { char bufs[bufsn] ; char auxbufs[auxbufsn] ; char bufa[bufan] ; char auxbufa[auxbufan] ; kolbak_closure_t q[qlen] ; } typedef skaclient_buffer_type(UNIXMESSAGE_BUFSIZE, UNIXMESSAGE_AUXBUFSIZE, UNIXMESSAGE_BUFSIZE, UNIXMESSAGE_AUXBUFSIZE, SKACLIENT_KOLBAK_SIZE) skaclient_buffer_t, *skaclient_buffer_t_ref ; /* User structure */ typedef struct skaclient_s skaclient_t, *skaclient_t_ref ; struct skaclient_s { unixmessage_receiver_t syncin ; unixmessage_sender_t syncout ; kolbak_queue_t kq ; unixmessage_receiver_t asyncin ; unixmessage_sender_t asyncout ; pid_t pid ; uint32_t options ; } ; #define SKACLIENT_ZERO { .syncin = UNIXMESSAGE_RECEIVER_ZERO, .syncout = UNIXMESSAGE_SENDER_ZERO, .kq = KOLBAK_QUEUE_ZERO, .asyncin = UNIXMESSAGE_RECEIVER_ZERO, .asyncout = UNIXMESSAGE_SENDER_ZERO, .pid = 0, .options = 0 } extern skaclient_t const skaclient_zero ; /* Callback data for init */ typedef struct skaclient_cbdata_s skaclient_cbdata_t, *skaclient_cbdata_t_ref ; struct skaclient_cbdata_s { skaclient_t *a ; char const *after ; size_t afterlen ; } ; /* Starting and ending */ extern void skaclient_end (skaclient_t *) ; extern int skaclient_start_async (skaclient_t *, char *, size_t, char *, size_t, char *, size_t, char *, size_t, kolbak_closure_t *, size_t, char const *, uint32_t, char const *, size_t, char const *, size_t, skaclient_cbdata_t *) ; #define skaclient_start_async_b(a, sb, path, options, before, beforelen, after, afterlen, blah) skaclient_start_async(a, (sb)->bufs, sizeof((sb)->bufs), (sb)->auxbufs, sizeof((sb)->auxbufs), (sb)->bufa, sizeof((sb)->bufa), (sb)->auxbufa, sizeof((sb)->auxbufa), (sb)->q, sizeof((sb)->q), path, options, before, beforelen, after, afterlen, blah) extern int skaclient_startf_async (skaclient_t *, char *, size_t, char *, size_t, char *, size_t, char *, size_t, kolbak_closure_t *, size_t, char const *, char const *const *, char const *const *, uint32_t, char const *, size_t, char const *, size_t, skaclient_cbdata_t *) ; #define skaclient_startf_async_b(a, sb, prog, argv, envp, options, before, beforelen, after, afterlen, blah) skaclient_startf_async(a, (sb)->bufs, sizeof((sb)->bufs), (sb)->auxbufs, sizeof((sb)->auxbufs), (sb)->bufa, sizeof((sb)->bufa), (sb)->auxbufa, sizeof((sb)->auxbufa), (sb)->q, sizeof((sb)->q) / sizeof(kolbak_closure_t), prog, argv, envp, options, before, beforelen, after, afterlen, blah) extern int skaclient_start (skaclient_t *, char *, size_t, char *, size_t, char *, size_t, char *, size_t, kolbak_closure_t *, size_t, char const *, uint32_t, char const *, size_t, char const *, size_t, tain_t const *, tain_t *) ; #define skaclient_start_b(a, sb, path, options, before, beforelen, after, afterlen, deadline, stamp) skaclient_start(a, (sb)->bufs, sizeof((sb)->bufs), (sb)->auxbufs, sizeof((sb)->auxbufs), (sb)->bufa, sizeof((sb)->bufa), (sb)->auxbufa, sizeof((sb)->auxbufa), (sb)->q, sizeof((sb)->q) / sizeof(kolbak_closure_t), path, options, before, beforelen, after, afterlen, deadline, stamp) #define skaclient_start_g(a, bufs, bufsn, auxbufs, auxbufsn, bufa, bufan, auxbufa, auxbufan, q, qlen, path, options, before, beforelen, after, afterlen, deadline) skaclient_start(a, bufs, bufsn, auxbufs, auxbufsn, bufa, bufan, auxbufa, auxbufan, q, qlen, path, options, before, beforelen, after, afterlen, (deadline), &STAMP) #define skaclient_start_b_g(a, sb, path, options, before, beforelen, after, afterlen, deadline) skaclient_start_b(a, sb, path, options, before, beforelen, after, afterlen, (deadline), &STAMP) extern int skaclient_startf (skaclient_t *, char *, size_t, char *, size_t, char *, size_t, char *, size_t, kolbak_closure_t *, size_t, char const *, char const *const *, char const *const *, uint32_t, char const *, size_t, char const *, size_t, tain_t const *, tain_t *) ; #define skaclient_startf_b(a, sb, prog, argv, envp, options, before, beforelen, after, afterlen, deadline, stamp) skaclient_startf(a, (sb)->bufs, sizeof((sb)->bufs), (sb)->auxbufs, sizeof((sb)->auxbufs), (sb)->bufa, sizeof((sb)->bufa), (sb)->auxbufa, sizeof((sb)->auxbufa), (sb)->q, sizeof((sb)->q) / sizeof(kolbak_closure_t), prog, argv, envp, options, before, beforelen, after, afterlen, deadline, stamp) #define skaclient_startf_g(a, bufs, bufsn, auxbufs, auxbufsn, bufa, bufan, auxbufa, auxbufan, q, qlen, prog, argv, envp, options, before, beforelen, after, afterlen, deadline) skaclient_startf(a, bufs, bufsn, auxbufs, auxbufsn, bufa, bufan, auxbufa, auxbufan, q, qlen, prog, argv, envp, options, before, beforelen, after, afterlen, (deadline), &STAMP) #define skaclient_startf_b_g(a, sb, prog, argv, envp, options, before, beforelen, after, afterlen, deadline) skaclient_startf_b(a, sb, prog, argv, envp, options, before, beforelen, after, afterlen, (deadline), &STAMP) /* Writing */ extern int skaclient_putmsg_and_close (skaclient_t *, unixmessage_t const *, unsigned char const *, unixmessage_handler_func_t *, void *) ; #define skaclient_putmsg(a, m, cb, result) skaclient_putmsg_and_close(a, m, unixmessage_bits_closenone, cb, result) extern int skaclient_putmsgv_and_close (skaclient_t *, unixmessage_v_t const *, unsigned char const *, unixmessage_handler_func_t *, void *) ; #define skaclient_putmsgv(a, m, cb, result) skaclient_putmsgv_and_close(a, m, unixmessage_bits_closenone, cb, result) extern int skaclient_put (skaclient_t *, char const *, size_t, unixmessage_handler_func_t *, void *) ; extern int skaclient_putv (skaclient_t *, struct iovec const *, unsigned int, unixmessage_handler_func_t *, void *) ; /* Writing and flushing */ extern int skaclient_sendmsg_and_close (skaclient_t *, unixmessage_t const *, unsigned char const *, unixmessage_handler_func_t *, void *, tain_t const *, tain_t *) ; #define skaclient_sendmsg_and_close_g(a, m, bits, cb, result, deadline) skaclient_sendmsg_and_close(a, m, bits, cb, result, (deadline), &STAMP) #define skaclient_sendmsg(a, m, cb, result, deadline, stamp) skaclient_sendmsg_and_close(a, m, unixmessage_bits_closenone, cb, result, deadline, stamp) #define skaclient_sendmsg_g(a, m, cb, result, deadline) skaclient_sendmsg(a, m, cb, result, (deadline), &STAMP) extern int skaclient_sendmsgv_and_close (skaclient_t *, unixmessage_v_t const *, unsigned char const *, unixmessage_handler_func_t *, void *, tain_t const *, tain_t *) ; #define skaclient_sendmsgv_and_close_g(a, m, bits, cb, result, deadline) skaclient_sendmsgv_and_close(a, m, bits, cb, result, (deadline), &STAMP) #define skaclient_sendmsgv(a, m, cb, result, deadline, stamp) skaclient_sendmsgv_and_close(a, m, unixmessage_bits_closenone, cb, result, deadline, stamp) #define skaclient_sendmsgv_g(a, m, cb, result, deadline) skaclient_sendmsgv(a, m, cb, result, (deadline), &STAMP) extern int skaclient_send (skaclient_t *, char const *, size_t, unixmessage_handler_func_t *, void *, tain_t const *, tain_t *) ; #define skaclient_send_g(a, s, len, cb, result, deadline) skaclient_send(a, s, len, cb, result, (deadline), &STAMP) extern int skaclient_sendv (skaclient_t *, struct iovec const *, unsigned int, unixmessage_handler_func_t *, void *, tain_t const *, tain_t *) ; #define skaclient_sendv_g(a, v, vlen, cb, result, deadline) skaclient_sendv(a, v, vlen, cb, result, (deadline), &STAMP) /* Helpers for full async */ #define skaclient_sfd(a) unixmessage_receiver_fd(&(a)->syncin) #define skaclient_siswritable(a) (!unixmessage_sender_isempty(&(a)->syncout)) #define skaclient_flush(a) unixmessage_sender_flush(&(a)->syncout) #define skaclient_timed_flush(a, deadline, stamp) unixmessage_sender_timed_flush(&(a)->syncout, deadline, stamp) #define skaclient_timed_flush_g(a, deadline) skaclient_timed_flush(a, (deadline), &STAMP) #define skaclient_supdate(a) unixmessage_handle(&(a)->syncin, (unixmessage_handler_func_t *)&kolbak_call, &(a)->kq) #define skaclient_timed_supdate(a, deadline, stamp) unixmessage_timed_handle(&(a)->syncin, (unixmessage_handler_func_t *)&kolbak_call, &(a)->kq, deadline, stamp) #define skaclient_timed_supdate_g(a, deadline) skaclient_timed_supdate(a, (deadline), &STAMP) extern int skaclient_syncify (skaclient_t *, tain_t const *, tain_t *) ; #define skaclient_fd(a) skaclient_afd(a) #define skaclient_afd(a) unixmessage_receiver_fd(&(a)->asyncin) #define skaclient_update(a, f, p) skaclient_aupdate(a, f, p) #define skaclient_aupdate(a, f, p) unixmessage_handle(&(a)->asyncin, f, p) extern unixmessage_handler_func_t skaclient_default_cb ; /* When asyncout is actually used (skabus...) */ #define skaclient_aiswritable(a) (!unixmessage_sender_isempty(&(a)->asyncout)) #define skaclient_aput_and_close(a, m, bits) unixmessage_put_and_close(&(a)->asyncout, m, bits) #define skaclient_aputv_and_close(a, m, bits) unixmessage_putv_and_close(&(a)->asyncout, m, bits) #define skaclient_aput(a, m) unixmessage_put(&(a)->asyncout, m) #define skaclient_aputv(a, m) unixmessage_putv(&(a)->asyncout, m) #define skaclient_aflush(a) unixmessage_sender_flush(&(a)->asyncout) #define skaclient_timed_aflush(a, deadline, stamp) unixmessage_sender_timed_flush(&(a)->asyncout, deadline, stamp) #define skaclient_timed_aflush_g(a, deadline) skaclient_timed_aflush(a, (deadline), &STAMP) #endif skalibs-2.9.1.0/src/include/skalibs/skalibs.h000066400000000000000000000011321355335115400207560ustar00rootroot00000000000000/* ISC license. */ #ifndef SKALIBS_H #define SKALIBS_H /* This header is heavy! It includes everything in skalibs except: - skalibs/config.h: package configuration - skalibs/sysdeps.h: system-dependent feature test macros - skalibs/nonposix.h: pre-system headers definitions for POSIX extensions - skalibs/posixishard.h: workarounds for failures to respect POSIX */ #include #include #include #include #include #include #include #endif skalibs-2.9.1.0/src/include/skalibs/skamisc.h000066400000000000000000000027011355335115400207630ustar00rootroot00000000000000/* ISC license. */ #ifndef SKAMISC_H #define SKAMISC_H #include #include #include extern stralloc satmp ; extern int skagetln (buffer *, stralloc *, char) ; extern int skagetln_loose (buffer *, stralloc *, char) ; extern int skagetln_nofill (buffer *, stralloc *, char) ; extern int skagetlnsep (buffer *, stralloc *, char const *, size_t) ; extern int skagetlnsep_loose (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) ; extern int sauniquename (stralloc *) ; extern int string_quote (stralloc *, char const *, size_t) ; extern int string_quote_nodelim (stralloc *, char const *, size_t) ; extern int string_quote_nodelim_mustquote (stralloc *, char const *, size_t, char const *, size_t) ; extern int string_unquote (char *, size_t *, char const *, size_t, size_t *) ; extern ssize_t string_unquote_nodelim (char *, char const *, size_t) ; extern int string_unquote_withdelim (char *, size_t *, char const *, size_t, size_t *, char const *, size_t) ; extern int string_format (stralloc *, char const *, char const *, char const *const *) ; #define skaoffsetof(n, s, field) do { s sofoftmp ; *(n) = (unsigned char *)&sofoftmp->field - (unsigned char *)&sofoftmp ; } while (0) #endif skalibs-2.9.1.0/src/include/skalibs/socket.h000066400000000000000000000146661355335115400206360ustar00rootroot00000000000000/* ISC license. */ #ifndef SOCKET_H #define SOCKET_H #include #include #include #include #include #include typedef ssize_t socket_io_func_t (int, char *, size_t, char *, uint16_t *) ; typedef socket_io_func_t *socket_io_func_t_ref ; /* INET and INET6 domain socket operations */ #define socket_tcp() socket_tcp4() #define socket_tcp_b() socket_tcp4_b() #define socket_tcp_nb() socket_tcp4_nb() #define socket_tcp_coe() socket_tcp4_coe() #define socket_tcp_nbcoe() socket_tcp4_nbcoe() #define socket_tcp4() socket_tcp4_nb() #define socket_tcp4_b() socket_tcp4_internal(0) #define socket_tcp4_nb() socket_tcp4_internal(DJBUNIX_FLAG_NB) #define socket_tcp4_coe() socket_tcp4_internal(DJBUNIX_FLAG_COE) #define socket_tcp4_nbcoe() socket_tcp4_internal(DJBUNIX_FLAG_NB|DJBUNIX_FLAG_COE) extern int socket_tcp4_internal (unsigned int) ; #define socket_tcp6() socket_tcp6_nb() #define socket_tcp6_b() socket_tcp6_internal(0) #define socket_tcp6_nb() socket_tcp6_internal(DJBUNIX_FLAG_NB) #define socket_tcp6_coe() socket_tcp6_internal(DJBUNIX_FLAG_COE) #define socket_tcp6_nbcoe() socket_tcp6_internal(DJBUNIX_FLAG_NB|DJBUNIX_FLAG_COE) extern int socket_tcp6_internal (unsigned int) ; #define socket_udp() socket_udp4() #define socket_udp_b() socket_udp4_b() #define socket_udp_nb() socket_udp4_nb() #define socket_udp_coe() socket_udp4_coe() #define socket_udp_nbcoe() socket_udp4_nbcoe() #define socket_udp4() socket_udp4_nb() #define socket_udp4_b() socket_udp4_internal(0) #define socket_udp4_nb() socket_udp4_internal(DJBUNIX_FLAG_NB) #define socket_udp4_coe() socket_udp4_internal(DJBUNIX_FLAG_COE) #define socket_udp4_nbcoe() socket_udp4_internal(DJBUNIX_FLAG_NB|DJBUNIX_FLAG_COE) extern int socket_udp4_internal (unsigned int) ; #define socket_udp6() socket_udp6_nb() #define socket_udp6_b() socket_udp6_internal(0) #define socket_udp6_nb() socket_udp6_internal(DJBUNIX_FLAG_NB) #define socket_udp6_coe() socket_udp6_internal(DJBUNIX_FLAG_COE) #define socket_udp6_nbcoe() socket_udp6_internal(DJBUNIX_FLAG_NB|DJBUNIX_FLAG_COE) extern int socket_udp6_internal (unsigned int) ; extern int socket_waitconn (int, tain_t const *, tain_t *) ; #define socket_waitconn_g(fd, deadline) socket_waitconn(fd, (deadline), &STAMP) extern int socket_deadlineconnstamp4 (int, char const *, uint16_t, tain_t const *, tain_t *) ; #define socket_deadlineconnstamp(s, ip, port, deadline, stamp) socket_deadlineconnstamp4(s, ip, port, deadline, stamp) #define socket_deadlineconnstamp4_g(fd, ip, port, deadline) socket_deadlineconnstamp4(fd, ip, port, (deadline), &STAMP) extern int socket_deadlineconnstamp4_u32 (int, uint32_t, uint16_t, tain_t const *, tain_t *) ; #define socket_deadlineconnstamp4_u32_g(fd, ip, port, deadline) socket_deadlineconnstamp4_u32(fd, ip, port, (deadline), &STAMP) extern int socket_timeoutconn (int, char const *, uint16_t, unsigned int) ; extern int socket_connect4 (int, char const *, uint16_t) ; extern int socket_connect4_u32 (int, uint32_t, uint16_t) ; extern int socket_connected (int) gccattr_const ; extern int socket_bind4 (int, char const *, uint16_t) ; extern int socket_bind4_reuse (int, char const *, uint16_t) ; #define socket_listen(fd, b) ipc_listen(fd, b) extern int socket_connect6 (int, char const *, uint16_t) ; extern int socket_deadlineconnstamp6 (int, char const *, uint16_t, tain_t const *, tain_t *) ; #define socket_deadlineconnstamp6_g(fd, ip6, port, deadline) socket_deadlineconnstamp6(fd, ip6, port, (deadline), &STAMP) extern int socket_bind6 (int, char const *, uint16_t) ; extern int socket_bind6_reuse (int, char const *, uint16_t) ; #define socket_accept4(s, ip, port) socket_accept4_internal(s, ip, (port), 0) #define socket_accept4_nb(s, ip, port) socket_accept4_internal(s, ip, (port), DJBUNIX_FLAG_NB) #define socket_accept4_coe(s, ip, port) socket_accept4_internal(s, ip, (port), DJBUNIX_FLAG_COE) #define socket_accept4_nbcoe(s, ip, port) socket_accept4_internal(s, ip, (port), DJBUNIX_FLAG_NB|DJBUNIX_FLAG_COE) extern int socket_accept4_internal (int, char *, uint16_t *, unsigned int) ; extern socket_io_func_t socket_recv4 ; extern ssize_t socket_send4 (int, char const *, size_t, char const *, uint16_t) ; extern socket_io_func_t socket_ioloop_send4 ; extern int socket_local4 (int, char *, uint16_t *) ; extern int socket_remote4 (int, char *, uint16_t *) ; #define socket_accept6(s, ip6, port) socket_accept6_internal(s, ip6, (port), 0) #define socket_accept6_nb(s, ip6, port) socket_accept6_internal(s, ip6, (port), DJBUNIX_FLAG_NB) #define socket_accept6_coe(s, ip6, port) socket_accept6_internal(s, ip6, (port), DJBUNIX_FLAG_COE) #define socket_accept6_nbcoe(s, ip6, port) socket_accept6_internal(s, ip6, (port), DJBUNIX_FLAG_NB|DJBUNIX_FLAG_COE) extern int socket_accept6_internal (int, char *, uint16_t *, unsigned int) ; extern socket_io_func_t socket_recv6 ; extern ssize_t socket_send6 (int, char const *, size_t, char const *, uint16_t) ; extern socket_io_func_t socket_ioloop_send6 ; extern int socket_local6 (int, char *, uint16_t *) ; extern int socket_remote6 (int, char *, uint16_t *) ; extern int socket_ipoptionskill (int) ; extern int socket_tcpnodelay (int) ; extern void socket_tryreservein (int, unsigned int) ; /* Timed send and recv operations (for dgram sockets) */ extern ssize_t socket_ioloop (int, char *, size_t, char *, uint16_t *, socket_io_func_t_ref, int, tain_t const *, tain_t *) ; #define socket_sendnb4(fd, buf, len, ip4, port, deadline, stamp) socket_ioloop(fd, buf, len, (char *)ip4, &(port), &socket_ioloop_send4, 1, deadline, stamp) #define socket_sendnb4_g(fd, buf, len, ip4, port, deadline) socket_sendnb4(fd, buf, len, ip4, port, (deadline), &STAMP) #define socket_recvnb4(fd, buf, len, ip4, port, deadline, stamp) socket_ioloop(fd, buf, len, ip4, port, &socket_recv4, 0, deadline, stamp) #define socket_recvnb4_g(fd, buf, len, ip4, port, deadline) socket_recvnb4(fd, buf, len, ip4, port, (deadline), &STAMP) #define socket_sendnb6(fd, buf, len, ip6, port, deadline, stamp) socket_ioloop(fd, buf, len, (char *)ip6, &(port), &socket_ioloop_send6, 1, deadline, stamp) #define socket_sendnb6_g(fd, buf, len, ip6, port, deadline) socket_sendnb6(fd, buf, len, ip6, port, (deadline), &STAMP) #define socket_recvnb6(fd, buf, len, ip6, port, deadline, stamp) socket_ioloop(fd, buf, len, ip6, port, &socket_recv6, 0, deadline, stamp) #define socket_recvnb6_g(fd, buf, len, ip6, port, deadline) socket_recvnb6(fd, buf, len, ip6, port, (deadline), &STAMP) #endif skalibs-2.9.1.0/src/include/skalibs/stdcrypto.h000066400000000000000000000003111355335115400213570ustar00rootroot00000000000000/* ISC license. */ #ifndef STDCRYPTO_H #define STDCRYPTO_H #include #include #include #include #include #endif skalibs-2.9.1.0/src/include/skalibs/stddjb.h000066400000000000000000000026111355335115400206030ustar00rootroot00000000000000/* ISC license. */ #ifndef STDDJB_H #define STDDJB_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #endif skalibs-2.9.1.0/src/include/skalibs/stralloc.h000066400000000000000000000027661355335115400211670ustar00rootroot00000000000000/* ISC license. */ #ifndef STRALLOC_H #define STRALLOC_H #include #include typedef struct stralloc_s stralloc, *stralloc_ref ; struct stralloc_s { char *s ; size_t len ; size_t a ; } ; #define STRALLOC_ZERO { 0, 0, 0 } extern stralloc const stralloc_zero ; extern int stralloc_ready_tuned (stralloc *, size_t, size_t, size_t, size_t) ; #define stralloc_ready(sa, n) stralloc_ready_tuned(sa, (n), 8, 1, 8) #define stralloc_readyplus(sa, n) stralloc_ready(sa, (sa)->len + (n)) extern void stralloc_free (stralloc *) ; extern int stralloc_shrink (stralloc *) ; extern int stralloc_copyb (stralloc *, char const *, size_t) ; extern int stralloc_catb (stralloc *, char const *, size_t) ; extern int stralloc_catv (stralloc *, struct iovec const *, unsigned int) ; #define stralloc_copys(sa, s) stralloc_copyb(sa, (s), strlen(s)) #define stralloc_cats(sa, s) stralloc_catb(sa, (s), strlen(s)) #define stralloc_copy(sa1, sa2) stralloc_copyb(sa1, (sa2)->s, (sa2)->len) #define stralloc_cat(sa1, sa2) stralloc_catb(sa1, (sa2)->s, (sa2)->len) extern int stralloc_append (stralloc *, char) ; extern void stralloc_reverse (stralloc *) ; extern void stralloc_reverse_blocks (stralloc *, size_t) ; #define stralloc_0(sa) stralloc_catb(sa, "", 1) extern int stralloc_insertb (stralloc *, size_t, char const *, size_t) ; #define stralloc_inserts(sa, offset, s) stralloc_insertb(sa, offset, (s), strlen(s)) #define stralloc_insert(sa1, offset, sa2) stralloc_insertb(sa1, offset, (sa2)->s, (sa2)->len) #endif skalibs-2.9.1.0/src/include/skalibs/strerr.h000066400000000000000000000154761355335115400206670ustar00rootroot00000000000000/* ISC license. */ #ifndef STRERR_H #define STRERR_H #include extern void strerr_warn (char const *, char const *, char const *, char const *, char const *, char const *, char const *, char const *, char const *, char const *, char const *) ; extern void strerr_die (int, char const *, char const *, char const *, char const *, char const *, char const *, char const *, char const *, char const *, char const *, char const *) gccattr_noreturn ; extern void strerr_warnsys (char const *, char const *, char const *, char const *, char const *, char const *, char const *, char const *, char const *, char const *) ; extern void strerr_diesys (int, char const *, char const *, char const *, char const *, char const *, char const *, char const *, char const *, char const *, char const *) gccattr_noreturn ; #define strerr_warn10(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, se) \ strerr_warn(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, se) #define strerr_warn9(x1, x2, x3, x4, x5, x6, x7, x8, x9, se) \ strerr_warn(x1, x2, x3, x4, x5, x6, x7, x8, x9, 0, se) #define strerr_warn8(x1, x2, x3, x4, x5, x6, x7, x8, se) \ strerr_warn(x1, x2, x3, x4, x5, x6, x7, x8, 0, 0, se) #define strerr_warn7(x1, x2, x3, x4, x5, x6, x7, se) \ strerr_warn(x1, x2, x3, x4, x5, x6, x7, 0, 0, 0, se) #define strerr_warn6(x1, x2, x3, x4, x5, x6, se) \ strerr_warn(x1, x2, x3, x4, x5, x6, 0, 0, 0, 0, se) #define strerr_warn5(x1, x2, x3, x4, x5, se) \ strerr_warn(x1, x2, x3, x4, x5, 0, 0, 0, 0, 0, se) #define strerr_warn4(x1, x2, x3, x4, se) \ strerr_warn(x1, x2, x3, x4, 0, 0, 0, 0, 0, 0, se) #define strerr_warn3(x1, x2, x3, se) \ strerr_warn(x1, x2, x3, 0, 0, 0, 0, 0, 0, 0, se) #define strerr_warn2(x1, x2, se) \ strerr_warn(x1, x2, 0, 0, 0, 0, 0, 0, 0, 0, se) #define strerr_warn1(x1, se) \ strerr_warn(x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, se) #define strerr_warn10sys(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) \ strerr_warnsys(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) #define strerr_warn9sys(x1, x2, x3, x4, x5, x6, x7, x8, x9) \ strerr_warnsys(x1, x2, x3, x4, x5, x6, x7, x8, (x9), 0) #define strerr_warn8sys(x1, x2, x3, x4, x5, x6, x7, x8) \ strerr_warnsys(x1, x2, x3, x4, x5, x6, x7, (x8), 0, 0) #define strerr_warn7sys(x1, x2, x3, x4, x5, x6, x7) \ strerr_warnsys(x1, x2, x3, x4, x5, x6, (x7), 0, 0, 0) #define strerr_warn6sys(x1, x2, x3, x4, x5, x6) \ strerr_warnsys(x1, x2, x3, x4, x5, (x6), 0, 0, 0, 0) #define strerr_warn5sys(x1, x2, x3, x4, x5) \ strerr_warnsys(x1, x2, x3, x4, (x5), 0, 0, 0, 0, 0) #define strerr_warn4sys(x1, x2, x3, x4) \ strerr_warnsys(x1, x2, x3, (x4), 0, 0, 0, 0, 0, 0) #define strerr_warn3sys(x1, x2, x3) \ strerr_warnsys(x1, x2, (x3), 0, 0, 0, 0, 0, 0, 0) #define strerr_warn2sys(x1, x2) \ strerr_warnsys(x1, (x2), 0, 0, 0, 0, 0, 0, 0, 0) #define strerr_warn1sys(x1) \ strerr_warnsys((x1), 0, 0, 0, 0, 0, 0, 0, 0, 0) #define strerr_warn10x(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) \ strerr_warn(x1, x2, x3, x4, x5, x6, x7, x8, x9, (x10), 0) #define strerr_warn9x(x1, x2, x3, x4, x5, x6, x7, x8, x9) \ strerr_warn(x1, x2, x3, x4, x5, x6, x7, x8, (x9), 0, 0) #define strerr_warn8x(x1, x2, x3, x4, x5, x6, x7, x8) \ strerr_warn(x1, x2, x3, x4, x5, x6, x7, (x8), 0, 0, 0) #define strerr_warn7x(x1, x2, x3, x4, x5, x6, x7) \ strerr_warn(x1, x2, x3, x4, x5, x6, (x7), 0, 0, 0, 0) #define strerr_warn6x(x1, x2, x3, x4, x5, x6) \ strerr_warn(x1, x2, x3, x4, x5, (x6), 0, 0, 0, 0, 0) #define strerr_warn5x(x1, x2, x3, x4, x5) \ strerr_warn(x1, x2, x3, x4, (x5), 0, 0, 0, 0, 0, 0) #define strerr_warn4x(x1, x2, x3, x4) \ strerr_warn(x1, x2, x3, (x4), 0, 0, 0, 0, 0, 0, 0) #define strerr_warn3x(x1, x2, x3) \ strerr_warn(x1, x2, (x3), 0, 0, 0, 0, 0, 0, 0, 0) #define strerr_warn2x(x1, x2) \ strerr_warn(x1, (x2), 0, 0, 0, 0, 0, 0, 0, 0, 0) #define strerr_warn1x(x1) \ strerr_warn((x1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) #define strerr_die10(e, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, se) \ strerr_die(e, x1, x2, x3, x4, x5 , x6, x7, x8, x9, x10, se) #define strerr_die9(e, x1, x2, x3, x4, x5, x6, x7, x8, x9, se) \ strerr_die(e, x1, x2, x3, x4, x5, x6, x7, x8, x9, 0, se) #define strerr_die8(e, x1, x2, x3, x4, x5, x6, x7, x8, se) \ strerr_die(e, x1, x2, x3, x4, x5, x6, x7, x8, 0, 0, se) #define strerr_die7(e, x1, x2, x3, x4, x5, x6, x7, se) \ strerr_die(e, x1, x2, x3, x4, x5, x6, x7, 0, 0, 0, se) #define strerr_die6(e, x1, x2, x3, x4, x5, x6, se) \ strerr_die(e, x1, x2, x3, x4, x5, x6, 0, 0, 0, 0, se) #define strerr_die5(e, x1, x2, x3, x4, x5, se) \ strerr_die(e, x1, x2, x3, x4, x5, 0, 0, 0, 0, 0, se) #define strerr_die4(e, x1, x2, x3, x4, se) \ strerr_die(e, x1, x2, x3, x4, 0, 0, 0, 0, 0, 0, se) #define strerr_die3(e, x1, x2, x3, se) \ strerr_die(e, x1, x2, x3, 0, 0, 0, 0, 0, 0, 0, se) #define strerr_die2(e, x1, x2, se) \ strerr_die(e, x1, x2, 0, 0, 0, 0, 0, 0, 0, 0, se) #define strerr_die1(e, x1, se) \ strerr_die(e, x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, se) #define strerr_die10sys(e, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) \ strerr_diesys(e, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) #define strerr_die9sys(e, x1, x2, x3, x4, x5, x6, x7, x8, x9) \ strerr_diesys(e, x1, x2, x3, x4, x5, x6, x7, x8, (x9), 0) #define strerr_die8sys(e, x1, x2, x3, x4, x5, x6, x7, x8) \ strerr_diesys(e, x1, x2, x3, x4, x5, x6, x7, (x8), 0, 0) #define strerr_die7sys(e, x1, x2, x3, x4, x5, x6, x7) \ strerr_diesys(e, x1, x2, x3, x4, x5, x6, (x7), 0, 0, 0) #define strerr_die6sys(e, x1, x2, x3, x4, x5, x6) \ strerr_diesys(e, x1, x2, x3, x4, x5, (x6), 0, 0, 0, 0) #define strerr_die5sys(e, x1, x2, x3, x4, x5) \ strerr_diesys(e, x1, x2, x3, x4, (x5), 0, 0, 0, 0, 0) #define strerr_die4sys(e, x1, x2, x3, x4) \ strerr_diesys(e, x1, x2, x3, (x4), 0, 0, 0, 0, 0, 0) #define strerr_die3sys(e, x1, x2, x3) \ strerr_diesys(e, x1, x2, (x3), 0, 0, 0, 0, 0, 0, 0) #define strerr_die2sys(e, x1, x2) \ strerr_diesys(e, x1, (x2), 0, 0, 0, 0, 0, 0, 0, 0) #define strerr_die1sys(e, x1) \ strerr_diesys(e, (x1), 0, 0, 0, 0, 0, 0, 0, 0, 0) #define strerr_die10x(e, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) \ strerr_die(e, x1, x2, x3, x4, x5, x6, x7, x8, x9, (x10), 0) #define strerr_die9x(e, x1, x2, x3, x4, x5, x6, x7, x8, x9) \ strerr_die(e, x1, x2, x3, x4, x5, x6, x7, x8, (x9), 0, 0) #define strerr_die8x(e, x1, x2, x3, x4, x5, x6, x7, x8) \ strerr_die(e, x1, x2, x3, x4, x5, x6, x7, (x8), 0, 0, 0) #define strerr_die7x(e, x1, x2, x3, x4, x5, x6, x7) \ strerr_die(e, x1, x2, x3, x4, x5, x6, (x7), 0, 0, 0, 0) #define strerr_die6x(e, x1, x2, x3, x4, x5, x6) \ strerr_die(e, x1, x2, x3, x4, x5, (x6), 0, 0, 0, 0, 0) #define strerr_die5x(e, x1, x2, x3, x4, x5) \ strerr_die(e, x1, x2, x3, x4, (x5), 0, 0, 0, 0, 0, 0) #define strerr_die4x(e, x1, x2, x3, x4) \ strerr_die(e, x1, x2, x3, (x4), 0, 0, 0, 0, 0, 0, 0) #define strerr_die3x(e, x1, x2, x3) \ strerr_die(e, x1, x2, (x3), 0, 0, 0, 0, 0, 0, 0, 0) #define strerr_die2x(e, x1, x2) \ strerr_die(e, x1, (x2), 0, 0, 0, 0, 0, 0, 0, 0, 0) #define strerr_die1x(e, x1) \ strerr_die(e, (x1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) #endif skalibs-2.9.1.0/src/include/skalibs/strerr2.h000066400000000000000000000302441355335115400207370ustar00rootroot00000000000000/* ISC license. */ #ifndef STRERR2_H #define STRERR2_H #include extern char const *PROG ; #define strerr_warnw1x(x1) \ strerr_warn3x(PROG, ": warning: ", (x1)) #define strerr_warnw2x(x1, x2) \ strerr_warn4x(PROG, ": warning: ", (x1), x2) #define strerr_warnw3x(x1, x2, x3) \ strerr_warn5x(PROG, ": warning: ", (x1), x2, x3) #define strerr_warnw4x(x1, x2, x3, x4) \ strerr_warn6x(PROG, ": warning: ", (x1), x2, x3, x4) #define strerr_warnw5x(x1, x2, x3, x4, x5) \ strerr_warn7x(PROG, ": warning: ", (x1), x2, x3, x4, x5) #define strerr_warnw6x(x1, x2, x3, x4, x5, x6) \ strerr_warn8x(PROG, ": warning: ", (x1), x2, x3, x4, x5, x6) #define strerr_warnw7x(x1, x2, x3, x4, x5, x6, x7) \ strerr_warn9x(PROG, ": warning: ", (x1), x2, x3, x4, x5, x6, x7) #define strerr_warnw8x(x1, x2, x3, x4, x5, x6, x7, x8) \ strerr_warn10x(PROG, ": warning: ", (x1), x2, x3, x4, x5, x6, x7, x8) #define strerr_warnw1sys(x1) \ strerr_warn4sys(PROG, ": warning: ", (x1), ": ") #define strerr_warnw2sys(x1, x2) \ strerr_warn5sys(PROG, ": warning: ", (x1), (x2), ": ") #define strerr_warnw3sys(x1, x2, x3) \ strerr_warn6sys(PROG, ": warning: ", (x1), x2, (x3), ": ") #define strerr_warnw4sys(x1, x2, x3, x4) \ strerr_warn7sys(PROG, ": warning: ", (x1), x2, x3, (x4), ": ") #define strerr_warnw5sys(x1, x2, x3, x4, x5) \ strerr_warn8sys(PROG, ": warning: ", (x1), x2, x3, x4, (x5), ": ") #define strerr_warnw6sys(x1, x2, x3, x4, x5, x6) \ strerr_warn9sys(PROG, ": warning: ", (x1), x2, x3, x4, x5, (x6), ": ") #define strerr_warnw7sys(x1, x2, x3, x4, x5, x6, x7) \ strerr_warn10sys(PROG, ": warning: ", (x1), x2, x3, x4, x5, x6, (x7), ": ") #define strerr_diew1x(e, x1) \ strerr_die3x(e, PROG, ": warning: ", x1) #define strerr_diew2x(e, x1, x2) \ strerr_die4x(e, PROG, ": warning: ", x1, x2) #define strerr_diew3x(e, x1, x2, x3) \ strerr_die5x(e, PROG, ": warning: ", x1, x2, x3) #define strerr_diew4x(e, x1, x2, x3, x4) \ strerr_die6x(e, PROG, ": warning: ", x1, x2, x3, x4) #define strerr_diew5x(e, x1, x2, x3, x4, x5) \ strerr_die7x(e, PROG, ": warning: ", x1, x2, x3, x4, x5) #define strerr_diew6x(e, x1, x2, x3, x4, x5, x6) \ strerr_die8x(e, PROG, ": warning: ", x1, x2, x3, x4, x5, x6) #define strerr_diew7x(e, x1, x2, x3, x4, x5, x6, x7) \ strerr_die9x(e, PROG, ": warning: ", x1, x2, x3, x4, x5, x6, x7) #define strerr_diew8x(e, x1, x2, x3, x4, x5, x6, x7, x8) \ strerr_die10x(e, PROG, ": warning: ", x1, x2, x3, x4, x5, x6, x7, x8) #define strerr_diew1sys(e, x1) \ strerr_die4sys(e, PROG, ": warning: ", (x1), ": ") #define strerr_diew2sys(e, x1, x2) \ strerr_die5sys(e, PROG, ": warning: ", x1, (x2), ": ") #define strerr_diew3sys(e, x1, x2, x3) \ strerr_die6sys(e, PROG, ": warning: ", x1, x2, (x3), ": ") #define strerr_diew4sys(e, x1, x2, x3, x4) \ strerr_die7sys(e, PROG, ": warning: ", x1, x2, x3, (x4), ": ") #define strerr_diew5sys(e, x1, x2, x3, x4, x5) \ strerr_die8sys(e, PROG, ": warning: ", x1, x2, x3, x4, (x5), ": ") #define strerr_diew6sys(e, x1, x2, x3, x4, x5, x6) \ strerr_die9sys(e, PROG, ": warning: ", x1, x2, x3, x4, x5, (x6), ": ") #define strerr_diew7sys(e, x1, x2, x3, x4, x5, x6, x7) \ strerr_die10sys(e, PROG, ": warning: ", x1, x2, x3, x4, x5, x6, (x7), ": ") #define strerr_dief1x(e, x1) \ strerr_die3x(e, PROG, ": fatal: ", x1) #define strerr_dief2x(e, x1, x2) \ strerr_die4x(e, PROG, ": fatal: ", x1, x2) #define strerr_dief3x(e, x1, x2, x3) \ strerr_die5x(e, PROG, ": fatal: ", x1, x2, x3) #define strerr_dief4x(e, x1, x2, x3, x4) \ strerr_die6x(e, PROG, ": fatal: ", x1, x2, x3, x4) #define strerr_dief5x(e, x1, x2, x3, x4, x5) \ strerr_die7x(e, PROG, ": fatal: ", x1, x2, x3, x4, x5) #define strerr_dief6x(e, x1, x2, x3, x4, x5, x6) \ strerr_die8x(e, PROG, ": fatal: ", x1, x2, x3, x4, x5, x6) #define strerr_dief7x(e, x1, x2, x3, x4, x5, x6, x7) \ strerr_die9x(e, PROG, ": fatal: ", x1, x2, x3, x4, x5, x6, x7) #define strerr_dief8x(e, x1, x2, x3, x4, x5, x6, x7, x8) \ strerr_die10x(e, PROG, ": fatal: ", x1, x2, x3, x4, x5, x6, x7, x8) #define strerr_dief1sys(e, x1) \ strerr_die4sys(e, PROG, ": fatal: ", (x1), ": ") #define strerr_dief2sys(e, x1, x2) \ strerr_die5sys(e, PROG, ": fatal: ", x1, (x2), ": ") #define strerr_dief3sys(e, x1, x2, x3) \ strerr_die6sys(e, PROG, ": fatal: ", x1, x2, (x3), ": ") #define strerr_dief4sys(e, x1, x2, x3, x4) \ strerr_die7sys(e, PROG, ": fatal: ", x1, x2, x3, (x4), ": ") #define strerr_dief5sys(e, x1, x2, x3, x4, x5) \ strerr_die8sys(e, PROG, ": fatal: ", x1, x2, x3, x4, (x5), ": ") #define strerr_dief6sys(e, x1, x2, x3, x4, x5, x6) \ strerr_die9sys(e, PROG, ": fatal: ", x1, x2, x3, x4, x5, (x6), ": ") #define strerr_dief7sys(e, x1, x2, x3, x4, x5, x6, x7) \ strerr_die10sys(e, PROG, ": fatal: ", x1, x2, x3, x4, x5, x6, (x7), ": ") #define strerr_diefu1x(e, x1) \ strerr_die4x(e, PROG, ": fatal: ", "unable to ", x1) #define strerr_diefu2x(e, x1, x2) \ strerr_die5x(e, PROG, ": fatal: ", "unable to ", x1, x2) #define strerr_diefu3x(e, x1, x2, x3) \ strerr_die6x(e, PROG, ": fatal: ", "unable to ", x1, x2, x3) #define strerr_diefu4x(e, x1, x2, x3, x4) \ strerr_die7x(e, PROG, ": fatal: ", "unable to ", x1, x2, x3, x4) #define strerr_diefu5x(e, x1, x2, x3, x4, x5) \ strerr_die8x(e, PROG, ": fatal: ", "unable to ", x1, x2, x3, x4, x5) #define strerr_diefu6x(e, x1, x2, x3, x4, x5, x6) \ strerr_die9x(e, PROG, ": fatal: ", "unable to ", x1, x2, x3, x4, x5, x6) #define strerr_diefu7x(e, x1, x2, x3, x4, x5, x6, x7) \ strerr_die10x(e, PROG, ": fatal: ", "unable to ", x1, x2, x3, x4, x5, x6, x7) #define strerr_diefu1sys(e, x1) \ strerr_die5sys(e, PROG, ": fatal: ", "unable to ", (x1), ": ") #define strerr_diefu2sys(e, x1, x2) \ strerr_die6sys(e, PROG, ": fatal: ", "unable to ", x1, (x2), ": ") #define strerr_diefu3sys(e, x1, x2, x3) \ strerr_die7sys(e, PROG, ": fatal: ", "unable to ", x1, x2, (x3), ": ") #define strerr_diefu4sys(e, x1, x2, x3, x4) \ strerr_die8sys(e, PROG, ": fatal: ", "unable to ", x1, x2, x3, (x4), ": ") #define strerr_diefu5sys(e, x1, x2, x3, x4, x5) \ strerr_die9sys(e, PROG, ": fatal: ", "unable to ", x1, x2, x3, x4, (x5), ": ") #define strerr_diefu6sys(e, x1, x2, x3, x4, x5, x6) \ strerr_die10sys(e, PROG, ": fatal: ", "unable to ", x1, x2, x3, x4, x5, (x6), ": ") #define strerr_warnwu1x(x1) \ strerr_warn4x(PROG, ": warning: ", "unable to ", (x1)) #define strerr_warnwu2x(x1, x2) \ strerr_warn5x(PROG, ": warning: ", "unable to ", (x1), x2) #define strerr_warnwu3x(x1, x2, x3) \ strerr_warn6x(PROG, ": warning: ", "unable to ", (x1), x2, x3) #define strerr_warnwu4x(x1, x2, x3, x4) \ strerr_warn7x(PROG, ": warning: ", "unable to ", (x1), x2, x3, x4) #define strerr_warnwu5x(x1, x2, x3, x4, x5) \ strerr_warn8x(PROG, ": warning: ", "unable to ", (x1), x2, x3, x4, x5) #define strerr_warnwu6x(x1, x2, x3, x4, x5, x6) \ strerr_warn9x(PROG, ": warning: ", "unable to ", (x1), x2, x3, x4, x5, x6) #define strerr_warnwu7x(x1, x2, x3, x4, x5, x6, x7) \ strerr_warn10x(PROG, ": warning: ", "unable to ", (x1), x2, x3, x4, x5, x6, x7) #define strerr_warnwu1sys(x1) \ strerr_warn5sys(PROG, ": warning: ", "unable to ", (x1), ": ") #define strerr_warnwu2sys(x1, x2) \ strerr_warn6sys(PROG, ": warning: ", "unable to ", (x1), (x2), ": ") #define strerr_warnwu3sys(x1, x2, x3) \ strerr_warn7sys(PROG, ": warning: ", "unable to ", (x1), x2, (x3), ": ") #define strerr_warnwu4sys(x1, x2, x3, x4) \ strerr_warn8sys(PROG, ": warning: ", "unable to ", (x1), x2, x3, (x4), ": ") #define strerr_warnwu5sys(x1, x2, x3, x4, x5) \ strerr_warn9sys(PROG, ": warning: ", "unable to ", (x1), x2, x3, x4, (x5), ": ") #define strerr_warnwu6sys(x1, x2, x3, x4, x5, x6) \ strerr_warn10sys(PROG, ": warning: ", "unable to ", (x1), x2, x3, x4, x5, (x6), ": ") #define strerr_diewu1x(e, x1) \ strerr_die4x(e, PROG, ": warning: ", "unable to ", x1) #define strerr_diewu2x(e, x1, x2) \ strerr_die5x(e, PROG, ": warning: ", "unable to ", x1, x2) #define strerr_diewu3x(e, x1, x2, x3) \ strerr_die6x(e, PROG, ": warning: ", "unable to ", x1, x2, x3) #define strerr_diewu4x(e, x1, x2, x3, x4) \ strerr_die7x(e, PROG, ": warning: ", "unable to ", x1, x2, x3, x4) #define strerr_diewu5x(e, x1, x2, x3, x4, x5) \ strerr_die8x(e, PROG, ": warning: ", "unable to ", x1, x2, x3, x4, x5) #define strerr_diewu6x(e, x1, x2, x3, x4, x5, x6) \ strerr_die9x(e, PROG, ": warning: ", "unable to ", x1, x2, x3, x4, x5, x6) #define strerr_diewu7x(e, x1, x2, x3, x4, x5, x6, x7) \ strerr_die10x(e, PROG, ": warning: ", "unable to ", x1, x2, x3, x4, x5, x6, x7) #define strerr_diewu1sys(e, x1) \ strerr_die5sys(e, PROG, ": warning: ", "unable to ", (x1), ": ") #define strerr_diewu2sys(e, x1, x2) \ strerr_die6sys(e, PROG, ": warning: ", "unable to ", x1, (x2), ": ") #define strerr_diewu3sys(e, x1, x2, x3) \ strerr_die7sys(e, PROG, ": warning: ", "unable to ", x1, x2, (x3), ": ") #define strerr_diewu4sys(e, x1, x2, x3, x4) \ strerr_die8sys(e, PROG, ": warning: ", "unable to ", x1, x2, x3, (x4), ": ") #define strerr_diewu5sys(e, x1, x2, x3, x4, x5) \ strerr_die9sys(e, PROG, ": warning: ", "unable to ", x1, x2, x3, x4, (x5), ": ") #define strerr_diewu6sys(e, x1, x2, x3, x4, x5, x6) \ strerr_die10sys(e, PROG, ": warning: ", "unable to ", x1, x2, x3, x4, x5, (x6), ": ") #define strerr_dieusage(e, u) \ strerr_die3x(e, PROG, ": usage: ", u) #define strerr_dienotset(e, x) \ strerr_dief2x(e, (x), " not set") #define strerr_dieinvalid(e, x) \ strerr_dief2x(e, "invalid $", x) #define strerr_dieexec(e, x) \ strerr_diefu2sys(e, "exec ", x) #define strerr_warni1x(x1) \ strerr_warn3x(PROG, ": info: ", (x1)) #define strerr_warni2x(x1, x2) \ strerr_warn4x(PROG, ": info: ", (x1), x2) #define strerr_warni3x(x1, x2, x3) \ strerr_warn5x(PROG, ": info: ", (x1), x2, x3) #define strerr_warni4x(x1, x2, x3, x4) \ strerr_warn6x(PROG, ": info: ", (x1), x2, x3, x4) #define strerr_warni5x(x1, x2, x3, x4, x5) \ strerr_warn7x(PROG, ": info: ", (x1), x2, x3, x4, x5) #define strerr_warni6x(x1, x2, x3, x4, x5, x6) \ strerr_warn8x(PROG, ": info: ", (x1), x2, x3, x4, x5, x6) #define strerr_warni7x(x1, x2, x3, x4, x5, x6, x7) \ strerr_warn9x(PROG, ": info: ", (x1), x2, x3, x4, x5, x6, x7) #define strerr_warni8x(x1, x2, x3, x4, x5, x6, x7, x8) \ strerr_warn10x(PROG, ": info: ", (x1), x2, x3, x4, x5, x6, x7, x8) #define strerr_warni1sys(x1) \ strerr_warn4sys(PROG, ": info: ", (x1), ": ") #define strerr_warni2sys(x1, x2) \ strerr_warn5sys(PROG, ": info: ", (x1), (x2), ": ") #define strerr_warni3sys(x1, x2, x3) \ strerr_warn6sys(PROG, ": info: ", (x1), x2, (x3), ": ") #define strerr_warni4sys(x1, x2, x3, x4) \ strerr_warn7sys(PROG, ": info: ", (x1), x2, x3, (x4), ": ") #define strerr_warni5sys(x1, x2, x3, x4, x5) \ strerr_warn8sys(PROG, ": info: ", (x1), x2, x3, x4, (x5), ": ") #define strerr_warni6sys(x1, x2, x3, x4, x5, x6) \ strerr_warn9sys(PROG, ": info: ", (x1), x2, x3, x4, x5, (x6), ": ") #define strerr_warni7sys(x1, x2, x3, x4, x5, x6, x7) \ strerr_warn10sys(PROG, ": info: ", (x1), x2, x3, x4, x5, x6, (x7), ": ") #define strerr_warnt1x(x1) \ strerr_warn3x(PROG, ": tracing: ", (x1)) #define strerr_warnt2x(x1, x2) \ strerr_warn4x(PROG, ": tracing: ", (x1), x2) #define strerr_warnt3x(x1, x2, x3) \ strerr_warn5x(PROG, ": tracing: ", (x1), x2, x3) #define strerr_warnt4x(x1, x2, x3, x4) \ strerr_warn6x(PROG, ": tracing: ", (x1), x2, x3, x4) #define strerr_warnt5x(x1, x2, x3, x4, x5) \ strerr_warn7x(PROG, ": tracing: ", (x1), x2, x3, x4, x5) #define strerr_warnt6x(x1, x2, x3, x4, x5, x6) \ strerr_warn8x(PROG, ": tracing: ", (x1), x2, x3, x4, x5, x6) #define strerr_warnt7x(x1, x2, x3, x4, x5, x6, x7) \ strerr_warn9x(PROG, ": tracing: ", (x1), x2, x3, x4, x5, x6, x7) #define strerr_warnt8x(x1, x2, x3, x4, x5, x6, x7, x8) \ strerr_warn10x(PROG, ": tracing: ", (x1), x2, x3, x4, x5, x6, x7, x8) #define strerr_warnt1sys(x1) \ strerr_warn4sys(PROG, ": tracing: ", (x1), ": ") #define strerr_warnt2sys(x1, x2) \ strerr_warn5sys(PROG, ": tracing: ", (x1), (x2), ": ") #define strerr_warnt3sys(x1, x2, x3) \ strerr_warn6sys(PROG, ": tracing: ", (x1), x2, (x3), ": ") #define strerr_warnt4sys(x1, x2, x3, x4) \ strerr_warn7sys(PROG, ": tracing: ", (x1), x2, x3, (x4), ": ") #define strerr_warnt5sys(x1, x2, x3, x4, x5) \ strerr_warn8sys(PROG, ": tracing: ", (x1), x2, x3, x4, (x5), ": ") #define strerr_warnt6sys(x1, x2, x3, x4, x5, x6) \ strerr_warn9sys(PROG, ": tracing: ", (x1), x2, x3, x4, x5, (x6), ": ") #define strerr_warnt7sys(x1, x2, x3, x4, x5, x6, x7) \ strerr_warn10sys(PROG, ": tracing: ", (x1), x2, x3, x4, x5, x6, (x7), ": ") #endif skalibs-2.9.1.0/src/include/skalibs/surf.h000066400000000000000000000014241355335115400203110ustar00rootroot00000000000000/* ISC license. */ #ifndef SKALIBS_SURF_H #define SKALIBS_SURF_H #include #include typedef struct SURFSchedule SURFSchedule, *SURFSchedule_ref, **SURFSchedule_ref_ref ; struct SURFSchedule { uint32_t seed[32] ; uint32_t in[12] ; char out[32] ; unsigned int pos ; } ; #define SURFSCHEDULE_ZERO { .seed = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, .in = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, .out = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", .pos = 32 } extern void surf_init (SURFSchedule *, char const *) ; /* 160 chars */ extern void surf (SURFSchedule *, char *, size_t) ; extern void autosurf (char *, size_t) ; extern void autosurf_name (char *, size_t) ; #endif skalibs-2.9.1.0/src/include/skalibs/tai.h000066400000000000000000000130441355335115400201100ustar00rootroot00000000000000/* ISC license. */ #ifndef TAI_H #define TAI_H #include #include #include #include #include typedef struct tai_s tai_t, *tai_t_ref ; struct tai_s { uint64_t x ; } ; #define TAI_ZERO { 0 } #define TAI_MAGIC ((uint64_t)4611686018427387904ULL) #define TAI_EPOCH { TAI_MAGIC + 10UL } #define TAI_INFINITE_RELATIVE { (uint64_t)1 << 60 } #define TAI_INFINITE { TAI_MAGIC + ((uint64_t)1 << 61) } #define tai_sec(t) ((t)->x) extern int tai_u64 (tai_t *, uint64_t) ; #define tai_unix(t, u) tai_u64(t, (TAI_MAGIC + (u))) #define tai_uint(t, u) tai_u64(t, (uint64_t)(u)) extern int tai_now (tai_t *) ; #define tai_relative_from_time(t, u) ((t)->x = (uint64_t)(u), 1) #define tai_from_time(t, u) tai_unix(t, u) #define tai_from_time_sysclock(t, u) tai_from_sysclock(t, (uint64_t)(u) + TAI_MAGIC) extern int time_from_tai_relative (time_t *, tai_t const *) ; extern int time_from_tai (time_t *, tai_t const *) ; extern int time_sysclock_from_tai(time_t *, tai_t const *) ; extern int tai_from_sysclock (tai_t *, uint64_t) ; extern int sysclock_from_tai (uint64_t *, tai_t const *) ; #define tai_approx(t) ((double)(tai_sec(t))) extern int tai_add (tai_t *, tai_t const *, tai_t const *) ; extern int tai_sub (tai_t *, tai_t const *, tai_t const *) ; #define tai_less(t,u) (tai_sec(t) < tai_sec(u)) #define TAI_PACK 8 extern void tai_pack (char *, tai_t const *) ; extern void tai_unpack (char const *, tai_t *) ; extern void tai_pack_little (char *, tai_t const *) ; extern void tai_unpack_little (char const *, tai_t *) ; typedef struct tain_s tain_t, *tain_t_ref ; struct tain_s { tai_t sec ; uint32_t nano ; /* 0..999999999U */ } ; #define TAIN_ZERO { TAI_ZERO, 0 } #define TAIN_EPOCH { TAI_EPOCH, 0 } #define TAIN_INFINITE { TAI_INFINITE, 0 } #define TAIN_INFINITE_RELATIVE { TAI_INFINITE_RELATIVE, 0 } #define TAIN_NANO500 { TAI_ZERO, 500 } extern tain_t STAMP ; /* the global process wallclock */ extern tain_t const tain_zero ; extern tain_t const tain_infinite_relative ; extern tain_t const tain_nano500 ; #define tain_sec(a) ((a)->sec) #define tain_secp(a) (&(a)->sec) #define tain_nano(a) ((a)->nano) extern int tain_relative_from_timeval (tain_t *, struct timeval const *) ; extern int tain_from_timeval (tain_t *, struct timeval const *) ; extern int tain_from_timeval_sysclock (tain_t *, struct timeval const *) ; extern int timeval_from_tain_relative (struct timeval *, tain_t const *) ; extern int timeval_from_tain (struct timeval *, tain_t const *) ; extern int timeval_sysclock_from_tain (struct timeval *, tain_t const *) ; extern int tain_relative_from_timespec (tain_t *, struct timespec const *) ; extern int tain_from_timespec (tain_t *, struct timespec const *) ; extern int tain_from_timespec_sysclock (tain_t *, struct timespec const *) ; extern int timespec_from_tain_relative (struct timespec *, tain_t const *) ; extern int timespec_from_tain (struct timespec *, tain_t const *) ; extern int timespec_sysclock_from_tain (struct timespec *, tain_t const *) ; typedef int tain_clockread_func_t (tain_t *) ; typedef tain_clockread_func_t *tain_clockread_func_t_ref ; extern int tain_from_sysclock (tain_t *, tain_t const *) ; extern int sysclock_from_tain (tain_t *, tain_t const *) ; extern tain_clockread_func_t sysclock_get ; extern tain_clockread_func_t tain_wallclock_read ; #define tain_wallclock_read_g() tain_wallclock_read(&STAMP) extern int tain_stopwatch_init (tain_t *, clock_t, tain_t *) ; extern int tain_stopwatch_read (tain_t *, clock_t, tain_t const *) ; #define tain_stopwatch_read_g(cl, offset) tain_stopwatch_read(&STAMP, (cl), offset) extern tain_clockread_func_t_ref tain_now ; #define tain_now_g() (*tain_now)(&STAMP) #define tain_copynow(t) (*(t) = STAMP) extern tain_clockread_func_t tain_now_set_wallclock ; #define tain_now_set_wallclock_g() tain_now_set_wallclock(&STAMP) extern tain_clockread_func_t tain_now_set_stopwatch ; #define tain_now_set_stopwatch_g() tain_now_set_stopwatch(&STAMP) extern int sysclock_set (tain_t const *) ; extern int tain_setnow (tain_t const *) ; extern double tain_approx (tain_t const *) gccattr_pure ; extern double tain_frac (tain_t const *) gccattr_pure ; extern int tain_from_millisecs (tain_t *, int) ; extern int tain_to_millisecs (tain_t const *) gccattr_pure ; extern int tain_add (tain_t *, tain_t const *, tain_t const *) ; #define tain_add_g(deadline, tto) tain_add(deadline, &STAMP, tto) extern int tain_addsec (tain_t *, tain_t const *, int) ; #define tain_addsec_g(deadline, n) tain_addsec(deadline, &STAMP, n) extern int tain_sub (tain_t *, tain_t const *, tain_t const *) ; extern int tain_less (tain_t const *, tain_t const *) gccattr_pure ; #define tain_future(deadline) tain_less(&STAMP, (deadline)) #define TAIN_PACK 12 extern void tain_pack (char *, tain_t const *) ; extern void tain_unpack (char const *, tain_t *) ; extern void tain_pack_little (char *, tain_t const *) ; extern void tain_unpack_little (char const *, tain_t *) ; #define TAIN_FMT 25 extern size_t tain_fmt (char *, tain_t const *) ; extern size_t tain_scan (char const *, tain_t *) ; #define TAIN_FMTFRAC 19 extern size_t tain_fmtfrac (char *, tain_t const *) ; #define tain_uint(a, u) tain_ulong(a, u) extern int tain_ulong (tain_t *, unsigned long) ; extern void tain_half (tain_t *, tain_t const *) ; #define TIMESTAMP (1 + (TAIN_PACK << 1)) extern size_t timestamp_fmt (char *, tain_t const *) ; extern size_t timestamp_scan (char const *, tain_t *) ; extern int timestamp_r (char *, tain_t *) ; extern int timestamp (char *) ; #define timestamp_g(s) timestamp_fmt((s), &STAMP) #endif skalibs-2.9.1.0/src/include/skalibs/textclient.h000066400000000000000000000156771355335115400215340ustar00rootroot00000000000000/* ISC license. */ #ifndef SKALIBS_TEXTCLIENT_H #define SKALIBS_TEXTCLIENT_H #include #include #include #include #include #include /* This is a simpler, smaller version of skaclient for basic cases: - no fd-passing - no asyncout - no kolbak: client calls are always synchronous - fixed-size buffers included in the client structure */ #define TEXTCLIENT_BUFSIZE 4096 #define TEXTCLIENT_OPTION_WAITPID 0x00000001U /* Server-side functions */ extern int textclient_server_init (textmessage_receiver_t *, textmessage_sender_t *, textmessage_sender_t *, char const *, size_t, char const *, size_t, tain_t const *, tain_t *) ; extern int textclient_server_init_frompipe (textmessage_receiver_t *, textmessage_sender_t *, textmessage_sender_t *, char const *, size_t, char const *, size_t, tain_t const *, tain_t *) ; extern int textclient_server_init_fromsocket (textmessage_receiver_t *, textmessage_sender_t *, textmessage_sender_t *, char const *, size_t, char const *, size_t, tain_t const *, tain_t *) ; #define textclient_server_init_g(in, syncout, asyncout, before, beforelen, after, afterlen, deadline) textclient_server_init(in, syncout, asyncout, before, beforelen, after, afterlen, (deadline), &STAMP) #define textclient_server_init_frompipe_g(in, syncout, asyncout, before, beforelen, after, afterlen, deadline) textclient_server_init_frompipe(in, syncout, asyncout, before, beforelen, after, afterlen, (deadline), &STAMP) #define textclient_server_init_fromsocket_g(in, syncout, asyncout, before, beforelen, after, afterlen, deadline) textclient_server_init_fromsocket(in, syncout, asyncout, before, beforelen, after, afterlen, (deadline), &STAMP) #define textclient_server_01x_init(before, beforelen, after, afterlen, deadline, stamp) textclient_server_init(textmessage_receiver_0, textmessage_sender_1, textmessage_sender_x, before, beforelen, after, afterlen, deadline, stamp) #define textclient_server_01x_init_frompipe(before, beforelen, after, afterlen, deadline, stamp) textclient_server_init_frompipe(textmessage_receiver_0, textmessage_sender_1, textmessage_sender_x, before, beforelen, after, afterlen, deadline, stamp) #define textclient_server_01x_init_fromsocket(before, beforelen, after, afterlen, deadline, stamp) textclient_server_init_fromsocket(textmessage_receiver_0, textmessage_sender_1, textmessage_sender_x, before, beforelen, after, afterlen, deadline, stamp) #define textclient_server_01x_init_g(before, beforelen, after, afterlen, deadline) textclient_server_01x_init(before, beforelen, after, afterlen, (deadline), &STAMP) #define textclient_server_01x_init_frompipe_g(before, beforelen, after, afterlen, deadline) textclient_server_01x_init_frompipe(before, beforelen, after, afterlen, (deadline), &STAMP) #define textclient_server_01x_init_fromsocket_g(before, beforelen, after, afterlen, deadline) textclient_server_01x_init_fromsocket(before, beforelen, after, afterlen, (deadline), &STAMP) /* User structure */ typedef struct textclient_s textclient_t, *textclient_t_ref ; struct textclient_s { textmessage_sender_t syncout ; textmessage_receiver_t syncin ; textmessage_receiver_t asyncin ; pid_t pid ; uint32_t options ; char syncbuf[TEXTCLIENT_BUFSIZE] ; char asyncbuf[TEXTCLIENT_BUFSIZE] ; } ; #define TEXTCLIENT_ZERO { .syncout = TEXTMESSAGE_SENDER_ZERO, .syncin = TEXTMESSAGE_RECEIVER_ZERO, .asyncin = TEXTMESSAGE_RECEIVER_ZERO, .pid = 0, .options = 0 } extern textclient_t const textclient_zero ; /* Starting and ending */ extern void textclient_end (textclient_t *) ; extern int textclient_start (textclient_t *, char const *, uint32_t, char const *, size_t, char const *, size_t, tain_t const *, tain_t *) ; extern int textclient_startf (textclient_t *, char const *const *, char const *const *, uint32_t, char const *, size_t, char const *, size_t, tain_t const *, tain_t *) ; #define textclient_start_g(a, path, options, before, beforelen, after, afterlen, deadline) textclient_start(a, path, options, before, beforelen, after, afterlen, (deadline), &STAMP) #define textclient_startf_g(a, argv, envp, options, before, beforelen, after, afterlen, deadline) textclient_startf_b(a, argv, envp, options, before, beforelen, after, afterlen, (deadline), &STAMP) /* Writing */ #define textclient_put(a, s, len) textmessage_sender_put(&(a)->syncout, s, len) #define textclient_putv(a, v, n) textmessage_sender_putv(&(a)->syncout, v, n) #define textclient_flush(a) textmessage_sender_flush(&(a)->syncout) #define textclient_timed_flush(a, deadline, stamp) textmessage_sender_timed_flush(&(a)->syncout, deadline, stamp) #define textclient_timed_flush_g(a, deadline) textclient_timed_flush(a, (deadline), &STAMP) #define textclient_send(a, s, len) textmessage_send(&(a)->syncout, s, len) #define textclient_sendv(a, v, n) textmessage_sendv(&(a)->syncout, v, n) #define textclient_timed_send(a, s, len, deadline, stamp) textmessage_timed_send(&(a)->syncout, s, len, deadline, stamp) #define textclient_timed_sendv(a, v, n, deadline, stamp) textmessage_timed_sendv(&(a)->syncout, v, n, deadline, stamp) #define textclient_timed_send_g(a, s, len, deadline) textclient_timed_send(a, s, len, (deadline), &STAMP) #define textclient_timed_sendv_g(a, v, n, deadline) textclient_timed_sendv(a, v, n, (deadline), &STAMP) /* Sync reading */ #define textclient_get(a, v) textmessage_receive(&(a)->syncin, v) #define textclient_timed_get(a, v, deadline, stamp) (sanitize_read(textmessage_timed_receive(&(a)->syncin, v, deadline, stamp)) > 0) #define textclient_timed_get_g(a, v, deadline) textclient_timed_get(a, v, (deadline), &STAMP) /* Sync writing+reading */ #define textclient_exchange(a, s, len, ans, deadline, stamp) (textclient_timed_send(a, s, len, deadline, stamp) && textclient_timed_get(a, ans, deadline, stamp)) #define textclient_exchangev(a, v, n, ans, deadline, stamp) (textclient_timed_sendv(a, v, n, deadline, stamp) && textclient_timed_get(a, ans, deadline, stamp)) #define textclient_exchange_g(a, s, len, ans, deadline) textclient_exchange(a, s, len, ans, (deadline), &STAMP) #define textclient_exchangev_g(a, v, n, ans, deadline) textclient_exchangev(a, v, n, ans, (deadline), &STAMP) extern int textclient_command (textclient_t *, char const *, size_t, tain_t const *, tain_t *) ; extern int textclient_commandv (textclient_t *, struct iovec const *, unsigned int, tain_t const *, tain_t *) ; #define textclient_command_g(a, s, len, deadline) textclient_command(a, s, len, (deadline), &STAMP) #define textclient_commandv_g(a, v, n, deadline) textclient_commandv(a, v, n, (deadline), &STAMP) /* Async reading */ #define textclient_fd(a) textmessage_receiver_fd(&(a)->asyncin) #define textclient_update(a, f, p) textmessage_handle(&(a)->asyncin, f, p) #define textclient_timed_update(a, f, p, deadline, stamp) textmessage_timed_handle(&(a)->asyncin, f, p, deadline, stamp) #define textclient_timed_update_g(a, f, p, deadline) textclient_timed_update(a, f, p, (deadline), &STAMP) #endif skalibs-2.9.1.0/src/include/skalibs/textmessage.h000066400000000000000000000102331355335115400216610ustar00rootroot00000000000000/* ISC license. */ #ifndef SKALIBS_TEXTMESSAGE_H #define SKALIBS_TEXTMESSAGE_H #include #include #include #include #include #include #include #include #define TEXTMESSAGE_MAXREADS 128 #define TEXTMESSAGE_MAXLEN 0x01000000U /* Sender */ typedef struct textmessage_sender_s textmessage_sender_t, *textmessage_sender_t_ref ; struct textmessage_sender_s { bufalloc out ; } ; #define TEXTMESSAGE_SENDER_ZERO { BUFALLOC_ZERO } extern textmessage_sender_t const textmessage_sender_zero ; #define TEXTMESSAGE_SENDER_INIT(fd) { 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 textmessage_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) && textmessage_sender_timed_flush(ts, deadline, stamp)) #define textmessage_timed_sendv(ts, v, n, deadline, stamp) (textmessage_putv(ts, v, n) && textmessage_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 { BUFFER_ZERO, STRALLOC_ZERO, 0, 0 } extern textmessage_receiver_t const textmessage_receiver_zero ; #define TEXTMESSAGE_RECEIVER_INIT(fd, buf, len, n) { BUFFER_INIT(&buffer_read, (fd), buf, len), STRALLOC_ZERO, 0, 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, v, deadline) textmessage_timed_receive(tr, v, (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) textmessage_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 skalibs-2.9.1.0/src/include/skalibs/unix-timed.h000066400000000000000000000047531355335115400214250ustar00rootroot00000000000000/* ISC license. */ #ifndef UNIX_TIMED_H #define UNIX_TIMED_H #include #include #include #include #include #include #include /* Timed "blocking" operations (the fd must still be non-blocking) */ extern int timed_flush (void *, initfunc_t_ref, initfunc_t_ref, initfunc_t_ref, tain_t const *, tain_t *) ; #define timed_flush_g(b, getfd, isnonempty, flush, deadline) timed_flush(b, getfd, isnonempty, flush, (deadline_), &STAMP) extern ssize_t timed_get (void *, initfunc_t_ref, getfunc_t_ref, tain_t const *, tain_t *) ; #define timed_get_g (b, getfd, get, deadline) timed_get(b, getfd, get, (deadline), &STAMP) extern ssize_t buffer_timed_fill (buffer *, tain_t const *, tain_t *) ; #define buffer_timed_fill_g(b, deadline) buffer_timed_fill(b, (deadline), &STAMP) extern int bufalloc_timed_flush (bufalloc *, tain_t const *, tain_t *) ; #define bufalloc_timed_flush_g(ba, deadline) bufalloc_timed_flush(ba, (deadline), &STAMP) extern int buffer_timed_flush (buffer *, tain_t const *, tain_t *) ; #define buffer_timed_flush_g(b, deadline) buffer_timed_flush(b, (deadline), &STAMP) extern size_t buffer_timed_get (buffer *, char *, size_t, tain_t const *, tain_t *) ; #define buffer_timed_get_g(b, buf, buflen, deadline) buffer_timed_get(b, buf, buflen, (deadline), &STAMP) extern int timed_getln (buffer *, stralloc *, char, tain_t const *, tain_t *) ; #define timed_getln_g(b, sa, sep, deadline) timed_getln(b, sa, sep, (deadline), &STAMP) extern ssize_t timed_getlnmax (buffer *, char *, size_t, size_t *, char, tain_t const *, tain_t *) ; #define timed_getlnmax_g(b, max, maxlen, len, sep, deadline) timed_getlnmax(b, max, maxlen, len, sep, (deadline), &STAMP) extern int netstring_timed_get (buffer *, stralloc *, tain_t const *, tain_t *) ; #define netstring_timed_get_g(b, sa, deadline) netstring_timed_get(b, sa, (deadline), &STAMP) extern int ipc_timed_send (int, char const *, size_t, tain_t const *, tain_t *) ; #define ipc_timed_send_g(fd, s, len, deadline) ipc_timed_send(fd, s, len, (deadline), &STAMP) extern int ipc_timed_sendv (int, struct iovec const *, unsigned int, tain_t const *, tain_t *) ; #define ipc_timed_sendv_g(fd, v, n, deadline) ipc_timed_sendv(fd, v, n, (deadline), &STAMP) extern ssize_t ipc_timed_recv (int, char *, size_t, char *, tain_t const *, tain_t *) ; #define ipc_timed_recv_g(fd, s, len, path, deadline) ipc_timed_recv(fd, s, len, path, (deadline), &STAMP) #endif skalibs-2.9.1.0/src/include/skalibs/unix-transactional.h000066400000000000000000000047621355335115400231650ustar00rootroot00000000000000/* ISC license. */ #ifndef UNIX_TRANSACTIONAL_H #define UNIX_TRANSACTIONAL_H #include #include #include #include #include /* Transactional/reliable filesystem operations */ extern int open2_at (int, char const *, int) ; extern int open3_at (int, char const *, int, unsigned int) ; extern int access_at (int, char const *, int, unsigned int) ; extern int opengetlnclose (char const *, stralloc *, int) ; extern int open_readat (int, char const *) ; extern int open_readatb (int, char const *) ; extern int open_writeat (int, char const *) ; extern int open_writeatb (int, char const *) ; extern int open_truncat (int, char const *) ; extern int open_truncatb (int, char const *) ; extern int open_appendat (int, char const *) ; extern int open_appendatb (int, char const *) ; extern int stat_at (int, char const *, struct stat *) ; extern int lstat_at (int, char const *, struct stat *) ; extern size_t openreadnclose_at (int, char const *, char *, size_t) ; extern int openslurpclose_at (int, char const *, stralloc *) ; extern int opengetlnclose_at (int, char const *, stralloc *, int) ; extern size_t openwritenclose_at (int, char const *, char const *, size_t) ; extern size_t openwritevnclose_at (int, char const *, struct iovec const *, unsigned int) ; extern int atomic_rm_rf (char const *) ; extern int atomic_rm_rf_tmp (char const *, stralloc *) ; extern int atomic_symlink (char const *, char const *, char const *) ; typedef struct dirdescriptor_s dirdescriptor_t, *dirdescriptor_t_ref ; struct dirdescriptor_s { int fd ; char const *lnkfn ; stralloc new ; } ; #define DIRDESCRIPTOR_ZERO { .fd = 0, .lnkfn = 0, .new = STRALLOC_ZERO } extern int dd_open_read (dirdescriptor_t *, char const *) ; extern int dd_open_write (dirdescriptor_t *, char const *, unsigned int) ; extern void dd_close (dirdescriptor_t *) ; /* after dd_open_read */ extern void dd_cancel (dirdescriptor_t *) ; /* after dd_open_write */ extern int dd_commit (dirdescriptor_t *) ; /* after dd_open_write */ extern int dd_commit_devino (dirdescriptor_t *, dev_t *, ino_t *) ; /* after dd_open_write */ #define dd_openreadnclose(blah, file, s, len) openreadnclose_at((blah)->fd, file, s, len) #define dd_openslurpclose(blah, file, sa) openslurpclose_at((blah)->fd, file, sa) #define dd_opengetlnclose(blah, file, sa, sep) opengetlnclose_at((blah)->fd, file, sa, sep) #define dd_openwritenclose(blah, file, s, len) openwritenclose_at((blah)->fd, file, s, len) #endif skalibs-2.9.1.0/src/include/skalibs/unixconnection.h000066400000000000000000000015731355335115400224020ustar00rootroot00000000000000 /* ISC license. */ #ifndef UNIXCONNECTION_H #define UNIXCONNECTION_H #include typedef struct unixconnection_s unixconnection_t, *unixconnection_t_ref ; struct unixconnection_s { unixmessage_sender_t out ; unixmessage_receiver_t in ; char mainbuf[UNIXMESSAGE_BUFSIZE] ; char auxbuf[UNIXMESSAGE_AUXBUFSIZE] ; } ; #define UNIXCONNECTION_ZERO { .out = UNIXMESSAGE_SENDER_ZERO, .in = UNIXMESSAGE_RECEIVER_ZERO } extern unixconnection_t const unixconnection_zero ; extern void unixconnection_init (unixconnection_t *, int, int) ; extern void unixconnection_init_withclosecb (unixconnection_t *, int, int, unixmessage_sender_closecb_func_t_ref, void *) ; extern void unixconnection_free (unixconnection_t *) ; #define unixconnection_flush(io) unixmessage_sender_flush(&(io)->out) #define unixconnection_receive(io, m) unixmessage_receive(&(io)->in, m) #endif skalibs-2.9.1.0/src/include/skalibs/unixmessage.h000066400000000000000000000140721355335115400216650ustar00rootroot00000000000000/* ISC license. */ #ifndef UNIXMESSAGE_H #define UNIXMESSAGE_H #include #include #include #include #include #include #include #include /* Message */ typedef struct unixmessage_s unixmessage_t, *unixmessage_t_ref ; struct unixmessage_s { char *s ; size_t len ; int *fds ; unsigned int nfds ; } ; #define UNIXMESSAGE_ZERO { .s = 0, .len = 0, .fds = 0, .nfds = 0 } extern unixmessage_t const unixmessage_zero ; extern void unixmessage_drop (unixmessage_t const *) ; typedef struct unixmessage_v_s unixmessage_v_t, *unixmessage_v_t_ref ; struct unixmessage_v_s { struct iovec *v ; unsigned int vlen ; int *fds ; unsigned int nfds ; } ; #define UNIXMESSAGE_V_ZERO { .v = 0, .vlen = 0, .fds = 0, .nfds = 0 } extern unixmessage_v_t const unixmessage_v_zero ; #define UNIXMESSAGE_MAXSIZE (1U << 28) #define UNIXMESSAGE_MAXFDS 255 #define UNIXMESSAGE_BUFSIZE 2048 #define UNIXMESSAGE_AUXBUFSIZE (sizeof(int) * UNIXMESSAGE_MAXFDS + 1) #define UNIXMESSAGE_MAXREADS 128 /* Sender */ typedef void unixmessage_sender_closecb_func_t (int, void *) ; typedef unixmessage_sender_closecb_func_t *unixmessage_sender_closecb_func_t_ref ; typedef struct unixmessage_sender_s unixmessage_sender_t, *unixmessage_sender_t_ref ; struct unixmessage_sender_s { int fd ; stralloc data ; genalloc fds ; /* int */ genalloc offsets ; /* disize */ size_t head ; size_t shorty ; unixmessage_sender_closecb_func_t_ref closecb ; void *closecbdata ; } ; #define UNIXMESSAGE_SENDER_ZERO UNIXMESSAGE_SENDER_INIT(-1) #define UNIXMESSAGE_SENDER_INIT(s) UNIXMESSAGE_SENDER_INIT_WITHCLOSECB((s), &unixmessage_sender_closecb, 0) #define UNIXMESSAGE_SENDER_INIT_WITHCLOSECB(s, f, p) { .fd = (s), .data = STRALLOC_ZERO, .fds = GENALLOC_ZERO, .offsets = GENALLOC_ZERO, .head = 0, .shorty = 0, .closecb = (f), .closecbdata = (p) } extern unixmessage_sender_t const unixmessage_sender_zero ; extern unixmessage_sender_closecb_func_t unixmessage_sender_closecb ; extern void unixmessage_sender_init (unixmessage_sender_t *, int) ; extern void unixmessage_sender_init_withclosecb (unixmessage_sender_t *, int, unixmessage_sender_closecb_func_t_ref, void *) ; extern void unixmessage_sender_free (unixmessage_sender_t *) ; #define unixmessage_sender_fd(b) ((b)->fd) extern int unixmessage_sender_getfd (unixmessage_sender_t const *) gccattr_pure ; #define unixmessage_sender_isempty(b) (!genalloc_len(unsigned int, &(b)->offsets)) extern int unixmessage_put_and_close (unixmessage_sender_t *, unixmessage_t const *, unsigned char const *) ; #define unixmessage_put(b, m) unixmessage_put_and_close(b, m, unixmessage_bits_closenone) extern int unixmessage_putv_and_close (unixmessage_sender_t *, unixmessage_v_t const *, unsigned char const *) ; #define unixmessage_putv(b, m) unixmessage_putv_and_close(b, m, unixmessage_bits_closenone) extern int unixmessage_unput_and_maybe_drop (unixmessage_sender_t *, int) ; #define unixmessage_unput(b) unixmessage_unput_and_maybe_drop((b), 0) #define unixmessage_unput_and_drop(b) unixmessage_unput_and_maybe_drop((b), 1) extern unsigned char const *const unixmessage_bits_closenone ; extern unsigned char const *const unixmessage_bits_closeall ; extern int unixmessage_sender_flush (unixmessage_sender_t *) ; extern int unixmessage_sender_timed_flush (unixmessage_sender_t *, tain_t const *, tain_t *) ; #define unixmessage_sender_timed_flush_g(sender, deadline) unixmessage_sender_timed_flush(sender, (deadline), &STAMP) /* Receiver */ typedef struct unixmessage_receiver_s unixmessage_receiver_t, *unixmessage_receiver_t_ref ; struct unixmessage_receiver_s { int fd ; cbuffer_t mainb ; cbuffer_t auxb ; stralloc maindata ; stralloc auxdata ; uint32_t mainlen ; uint16_t auxlen ; unsigned int fds_ok : 2 ; } ; #define UNIXMESSAGE_RECEIVER_ZERO { .fd = -1, .mainb = CBUFFER_ZERO, .auxb = CBUFFER_ZERO, .maindata = STRALLOC_ZERO, .auxdata = STRALLOC_ZERO, .mainlen = 0, .auxlen = 0, .fds_ok = 3 } #define UNIXMESSAGE_RECEIVER_INIT(d, mains, mainn, auxs, auxn) \ { \ .fd = d, \ .mainb = CBUFFER_INIT(mains, mainn), \ .auxb = CBUFFER_INIT(auxs, auxn), \ .maindata = STRALLOC_ZERO, \ .auxdata = STRALLOC_ZERO, \ .mainlen = 0, \ .auxlen = 0, \ .fds_ok = 3 \ } extern int unixmessage_receiver_init (unixmessage_receiver_t *, int, char *, size_t, char *, size_t) ; extern void unixmessage_receiver_free (unixmessage_receiver_t *) ; #define unixmessage_receiver_fd(b) ((b)->fd) #define unixmessage_receiver_isempty(b) (cbuffer_isempty(&(b)->mainb) && cbuffer_isempty(&(b)->auxb)) #define unixmessage_receiver_isfull(b) (cbuffer_isfull(&(b)->mainb) || cbuffer_isfull(&(b)->auxb)) extern int unixmessage_receiver_hasmsginbuf (unixmessage_receiver_t const *) ; extern int unixmessage_receive (unixmessage_receiver_t *, unixmessage_t *) ; extern int unixmessage_timed_receive (unixmessage_receiver_t *, unixmessage_t *, tain_t const *, tain_t *) ; #define unixmessage_timed_receive_g(receiver, msg, deadline) unixmessage_timed_receive(receiver, msg, (deadline), &STAMP) #define unixmessage_receiver_accept_fds(b) ((b)->fds_ok = 3) #define unixmessage_receiver_refuse_fds(b) ((b)->fds_ok = 1) #define unixmessage_receiver_ignore_fds(b) ((b)->fds_ok = 0) typedef int unixmessage_handler_func_t (unixmessage_t const *, void *) ; typedef unixmessage_handler_func_t *unixmessage_handler_func_t_ref ; extern int unixmessage_handle (unixmessage_receiver_t *, unixmessage_handler_func_t_ref, void *) ; extern int unixmessage_timed_handle (unixmessage_receiver_t *, unixmessage_handler_func_t_ref, void *, tain_t const *, tain_t *) ; #define unixmessage_timed_handle_g(b, f, p, deadline) unixmessage_timed_handle(b, f, p, (deadline), &STAMP) /* Globals */ extern unixmessage_receiver_t unixmessage_receiver_0_ ; #define unixmessage_receiver_0 (&unixmessage_receiver_0_) extern unixmessage_sender_t unixmessage_sender_1_ ; #define unixmessage_sender_1 (&unixmessage_sender_1_) extern unixmessage_sender_t unixmessage_sender_x_ ; #define unixmessage_sender_x (&unixmessage_sender_x_) #endif skalibs-2.9.1.0/src/include/skalibs/unixonacid.h000066400000000000000000000005201355335115400214670ustar00rootroot00000000000000/* ISC license. */ #ifndef UNIXONACID_H #define UNIXONACID_H #include #include #include #include #include #include #include #include #endif skalibs-2.9.1.0/src/include/skalibs/webipc.h000066400000000000000000000050011355335115400205760ustar00rootroot00000000000000/* ISC license. */ #ifndef WEBIPC_H #define WEBIPC_H /* UNIX domain socket functions. "web" stands for William E. Baxter, the original author, who kindly permitted me to modify and release his code as a part of skalibs. It has nothing to do with the World Wide Web. */ #define IPCPATH_MAX 107 #include #include #include #include #define ipc_stream() ipc_stream_nb() #define ipc_stream_b() ipc_stream_internal(0) #define ipc_stream_nb() ipc_stream_internal(DJBUNIX_FLAG_NB) #define ipc_stream_coe() ipc_stream_internal(DJBUNIX_FLAG_COE) #define ipc_stream_nbcoe() ipc_stream_internal(DJBUNIX_FLAG_NB|DJBUNIX_FLAG_COE) extern int ipc_stream_internal (unsigned int) ; #define ipc_datagram() ipc_datagram_nb() #define ipc_datagram_b() ipc_datagram_internal(0) #define ipc_datagram_nb() ipc_datagram_internal(DJBUNIX_FLAG_NB) #define ipc_datagram_coe() ipc_datagram_internal(DJBUNIX_FLAG_COE) #define ipc_datagram_nbcoe() ipc_datagram_internal(DJBUNIX_FLAG_NB|DJBUNIX_FLAG_COE) extern int ipc_datagram_internal (unsigned int) ; #define ipc_pair(sv) ipc_pair_nb(sv) #define ipc_pair_b(sv) ipc_pair_internal((sv), 0) #define ipc_pair_nb(sv) ipc_pair_internal((sv), DJBUNIX_FLAG_NB) #define ipc_pair_coe(sv) ipc_pair_internal((sv), DJBUNIX_FLAG_COE) #define ipc_pair_nbcoe(sv) ipc_pair_internal((sv), DJBUNIX_FLAG_NB|DJBUNIX_FLAG_COE) extern int ipc_pair_internal (int *, unsigned int) ; extern int ipc_bind (int, char const *) ; extern int ipc_bind_reuse (int, char const *) ; extern int ipc_listen (int, int) ; #define ipc_accept(s, path, len, trunc) ipc_accept_internal(s, path, len, (trunc), 0) #define ipc_accept_nb(s, path, len, trunc) ipc_accept_internal(s, path, len, (trunc), DJBUNIX_FLAG_NB) #define ipc_accept_coe(s, path, len, trunc) ipc_accept_internal(s, path, len, (trunc), DJBUNIX_FLAG_COE) #define ipc_accept_nbcoe(s, path, len, trunc) ipc_accept_internal(s, path, len, (trunc), DJBUNIX_FLAG_NB|DJBUNIX_FLAG_COE) extern int ipc_accept_internal (int, char *, size_t, int *, unsigned int) ; #define ipc_eid getpeereid extern int ipc_local (int, char *, size_t, int *) ; extern int ipc_connect (int, char const *) ; extern int ipc_connected (int) ; extern int ipc_timed_connect (int, char const *, tain_t const *, tain_t *) ; #define ipc_timed_connect_g(fd, path, deadline) ipc_timed_connect(fd, path, (deadline), &STAMP) extern ssize_t ipc_send (int, char const *, size_t, char const *) ; extern ssize_t ipc_recv (int, char *, size_t, char *) ; #endif skalibs-2.9.1.0/src/libbiguint/000077500000000000000000000000001355335115400162355ustar00rootroot00000000000000skalibs-2.9.1.0/src/libbiguint/bu_addc.c000066400000000000000000000007721355335115400177700ustar00rootroot00000000000000/* ISC license. */ #include #include #include int bu_addc (uint32_t *c, unsigned int cn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, int carry) { unsigned int i = 0 ; for (; i < cn ; i++) { uint32_t ai = (i < an) ? a[i] : 0 ; uint32_t bi = (i < bn) ? b[i] : 0 ; uint32_t ci = ai + bi + carry ; carry = (carry || bi) && (ci < ai) ; c[i] = ci ; } return carry ? (errno = EOVERFLOW, 0) : 1 ; } skalibs-2.9.1.0/src/libbiguint/bu_addmod.c000066400000000000000000000005121355335115400203150ustar00rootroot00000000000000/* ISC license. */ #include int bu_addmod (uint32_t *c, unsigned int cn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, uint32_t const *m, unsigned int mn) { if (!bu_add(c, cn, a, an, b, bn)) return 0 ; if (bu_cmp(c, cn, m, mn) >= 0) bu_sub(c, cn, c, cn, m, mn) ; return 1 ; } skalibs-2.9.1.0/src/libbiguint/bu_cmp.c000066400000000000000000000005261355335115400176510ustar00rootroot00000000000000/* ISC license. */ #include int bu_cmp (uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn) { an = bu_len(a, an) ; bn = bu_len(b, bn) ; if (an < bn) return -1 ; if (an > bn) return 1 ; while (bn--) { if (a[bn] < b[bn]) return -1 ; if (a[bn] > b[bn]) return 1 ; } return 0 ; } skalibs-2.9.1.0/src/libbiguint/bu_copy.c000066400000000000000000000006151355335115400200430ustar00rootroot00000000000000/* ISC license. */ #include #include #include int bu_copy (uint32_t *b, unsigned int bn, uint32_t const *a, unsigned int an) { unsigned int alen = bu_len(a, an) ; if (bn < alen) { bu_copy_internal(b, a, bn) ; return (errno = EOVERFLOW, 0) ; } bu_copy_internal(b, a, alen) ; bu_zero(b + alen, bn - alen) ; return 1 ; } skalibs-2.9.1.0/src/libbiguint/bu_copy_internal.c000066400000000000000000000002311355335115400217310ustar00rootroot00000000000000/* ISC license. */ #include void bu_copy_internal (uint32_t *b, uint32_t const *a, unsigned int n) { while (n--) b[n] = a[n] ; } skalibs-2.9.1.0/src/libbiguint/bu_div.c000066400000000000000000000011221355335115400176450ustar00rootroot00000000000000/* ISC license. */ #include #include int bu_div (uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, uint32_t *q, unsigned int qn, uint32_t *r, unsigned int rn) { unsigned int alen = bu_len(a, an) ; unsigned int blen = bu_len(b, bn) ; if (!blen) return (errno = EDOM, 0) ; else { uint32_t qq[alen] ; uint32_t rr[alen] ; int qh, rh ; bu_copy_internal(rr, a, alen) ; bu_div_internal(rr, alen, b, blen, qq, alen) ; qh = bu_copy(q, qn, qq, alen) ; rh = bu_copy(r, rn, rr, alen) ; return qh && rh ; } } skalibs-2.9.1.0/src/libbiguint/bu_div_internal.c000066400000000000000000000017511355335115400215510ustar00rootroot00000000000000/* ISC license. */ #include #include /* q = a/b, a = a mod b. Assumes b != 0 and qn >= alen - blen + 1. */ void bu_div_internal (uint32_t *a, unsigned int an, uint32_t const *b, unsigned int bn, uint32_t *q, unsigned int qn) { unsigned int alen = bu_len(a, an) ; unsigned int blen = bu_len(b, bn) ; bu_zero(q, qn) ; if (alen < blen) return ; { uint32_t bb[alen + 1] ; unsigned int i = 1 + ((alen - blen) << 5) ; bu_zero(bb, alen - blen) ; bu_copy_internal(bb + alen - blen, b, blen) ; bb[alen] = 0 ; while (bu_cmp(a, alen, bb, alen+1) >= 0) { bu_slb(bb + alen - blen, blen + 1) ; i++ ; } while (i && (bu_cmp(a, alen, bb, alen+1) < 0)) { bu_srb(bb, alen + 1) ; i-- ; } while (i--) { bu_slb(q, alen - blen + 1) ; if (bu_cmp(a, alen, bb, alen) >= 0) { bu_sub(a, alen, a, alen, bb, alen) ; q[0] |= 1 ; } bu_srb(bb, alen) ; } } } skalibs-2.9.1.0/src/libbiguint/bu_divmod.c000066400000000000000000000016401355335115400203520ustar00rootroot00000000000000/* ISC license. */ #include #include /* q = y/x mod m. */ int bu_divmod (uint32_t *q, unsigned int qn, uint32_t const *y, unsigned int yn, uint32_t const *x, unsigned int xn, uint32_t const *m, unsigned int mn) { unsigned int ylen = bu_len(y, yn) ; unsigned int xlen = bu_len(x, xn) ; unsigned int mlen = bu_len(m, mn) ; unsigned int n = ylen ; if (n < xlen) n = xlen ; if (n < mlen) n = mlen ; if (!n) return (errno = EDOM, 0) ; { uint32_t yy[n] ; uint32_t xx[n] ; uint32_t mm[n] ; bu_gcd(xx, n, x, xlen, m, mlen) ; if ((xx[0] != 1) || (bu_len(xx, n) != 1)) return (errno = EDOM, 0) ; bu_copy_internal(yy, y, ylen) ; bu_zero(yy+ylen, n-ylen) ; bu_copy_internal(xx, x, xlen) ; bu_zero(xx+xlen, n-xlen) ; bu_copy_internal(mm, m, mlen) ; bu_zero(mm+mlen, n-mlen) ; bu_divmod_internal(yy, xx, mm, n) ; return bu_copy(q, qn, yy, n) ; } } skalibs-2.9.1.0/src/libbiguint/bu_divmod_internal.c000066400000000000000000000015761355335115400222560ustar00rootroot00000000000000/* ISC license. */ #include /* u = u/a mod m. a and m must be relatively prime - otherwise, infinite loop. a is not immutable. Original idea: see http://research.sun.com/techrep/2001/abstract-95.html */ void bu_divmod_internal (uint32_t *u, uint32_t *a, uint32_t const *m, unsigned int n) { uint32_t bb[n] ; uint32_t *b = bb ; uint32_t vv[n] ; uint32_t *v = vv ; bu_copy_internal(b, m, n) ; bu_zero(v, n) ; /*** XXX: this iterates like mad, should probably be optimized more */ for (;;) { while (!(a[0] & 1)) { bu_srb(a, n) ; if (u[0] & 1) bu_add(u, n, u, n, m, n) ; bu_srb(u, n) ; } if ((a[0] == 1) && (bu_len(a, n) == 1)) break ; if (bu_cmp(a, n, b, n) < 0) { uint32_t *t = a ; a = b ; b = t ; t = u ; u = v ; v = t ; } bu_add(a, n, a, n, b, n) ; bu_add(u, n, u, n, v, n) ; } } skalibs-2.9.1.0/src/libbiguint/bu_fmt.c000066400000000000000000000005471355335115400176630ustar00rootroot00000000000000/* ISC license. */ #include #include #include size_t bu_fmt (char *s, uint32_t const *x, unsigned int n) { size_t len = 0 ; while (n--) { char fmt[8] ; size_t i = uint32_xfmt(fmt, x[n]) ; memcpy(s+len, "00000000", 8-i) ; memcpy(s+len+8-i, fmt, i) ; len += 8 ; } return len ; } skalibs-2.9.1.0/src/libbiguint/bu_gcd.c000066400000000000000000000013071355335115400176250ustar00rootroot00000000000000/* ISC license. */ #include int bu_gcd (uint32_t *r, unsigned int rn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn) { if (bu_cmp(a, an, b, bn) < 0) { uint32_t const *t = a ; unsigned int tn = an ; a = b ; an = bn ; b = t ; bn = tn ; } { uint32_t trash[an] ; uint32_t aa[an] ; uint32_t bb[an] ; uint32_t *aaa = aa, *bbb = bb ; bu_copy_internal(aa, a, an) ; bu_copy_internal(bb, b, bn) ; bu_zero(bb+bn, an-bn) ; while (bu_len(bbb, an)) { uint32_t *ttt = aaa ; bu_div_internal(aaa, an, bbb, an, trash, an) ; aaa = bbb ; bbb = ttt ; } return bu_copy(r, rn, aaa, an) ; } } skalibs-2.9.1.0/src/libbiguint/bu_invmod.c000066400000000000000000000003501355335115400203610ustar00rootroot00000000000000/* ISC license. */ #include /* x^-1 mod m. */ int bu_invmod (uint32_t *x, unsigned int xn, uint32_t const *m, unsigned int mn) { uint32_t const one = 1 ; return bu_divmod(x, xn, &one, 1, x, xn, m, mn) ; } skalibs-2.9.1.0/src/libbiguint/bu_len.c000066400000000000000000000002401355335115400176410ustar00rootroot00000000000000/* ISC license. */ #include unsigned int bu_len (uint32_t const *a, unsigned int n) { while (n--) if (a[n]) return n+1 ; return 0 ; } skalibs-2.9.1.0/src/libbiguint/bu_mod.c000066400000000000000000000003051355335115400176440ustar00rootroot00000000000000/* ISC license. */ #include int bu_mod (uint32_t *a, unsigned int an, uint32_t const *b, unsigned int bn) { uint32_t q[an] ; return bu_div(a, an, b, bn, q, an, a, an) ; } skalibs-2.9.1.0/src/libbiguint/bu_mul.c000066400000000000000000000013551355335115400176700ustar00rootroot00000000000000/* ISC license. */ #include #include #include /* No Karatsuba. Keep it simple, stupid. */ int bu_mul (uint32_t *x, unsigned int xn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn) { unsigned int alen = bu_len(a, an) ; unsigned int blen = bu_len(b, bn) ; uint32_t c[alen + blen] ; unsigned int i = 0 ; bu_zero(c, alen + blen) ; for (; i < alen ; i++) { uint32_t carry = 0 ; unsigned int j = 0 ; for (; j < blen ; j++) { uint64_t t = a[i] ; t *= b[j] ; t += c[i+j] ; t += carry ; c[i+j] = (uint32_t)t ; carry = (uint32_t)(t >> 32) ; } c[i+j] += carry ; } return bu_copy(x, xn, c, alen+blen) ; } skalibs-2.9.1.0/src/libbiguint/bu_mulmod.c000066400000000000000000000007431355335115400203700ustar00rootroot00000000000000/* ISC license. */ #include /* Nope, no Montgomery either. */ int bu_mulmod (uint32_t *c, unsigned int cn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, uint32_t const *m, unsigned int mn) { unsigned int alen = bu_len(a, an) ; unsigned int blen = bu_len(b, bn) ; uint32_t x[alen+blen] ; if (!bu_mul(x, alen+blen, a, alen, b, blen)) return 0 ; if (!bu_mod(x, alen+blen, m, mn)) return 0 ; return bu_copy(c, cn, x, mn) ; } skalibs-2.9.1.0/src/libbiguint/bu_pack.c000066400000000000000000000002721355335115400200060ustar00rootroot00000000000000/* ISC license. */ #include #include void bu_pack (char *s, uint32_t const *a, unsigned int n) { while (n--) uint32_pack(s + (n<<2), a[n]) ; } skalibs-2.9.1.0/src/libbiguint/bu_pack_big.c000066400000000000000000000003451355335115400206300ustar00rootroot00000000000000/* ISC license. */ #include #include void bu_pack_big (char *s, uint32_t const *a, unsigned int n) { unsigned int i = 0 ; for (; i < n ; i++) uint32_pack_big(s + (i<<2), a[n-1-i]) ; } skalibs-2.9.1.0/src/libbiguint/bu_scan.c000066400000000000000000000005671355335115400200230ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int bu_scan (char const *s, size_t len, uint32_t *x, unsigned int xn, size_t zeron) { size_t n = bitarray_div8(zeron) ; if (xn < n) return (errno = EOVERFLOW, 0) ; bu_scan_internal(s, len, x) ; bu_zero(x + n, xn - n) ; return 1 ; } skalibs-2.9.1.0/src/libbiguint/bu_scan_internal.c000066400000000000000000000006531355335115400217130ustar00rootroot00000000000000/* ISC license. */ #include #include #include void bu_scan_internal (char const *s, size_t len, uint32_t *x) { char fmt[9] = "\0\0\0\0\0\0\0\0" ; size_t i = 0 ; if (len & 7) { memcpy(fmt, s, len & 7) ; uint32_xscan(fmt, x + (len >> 3)) ; } for (; i < (len >> 3) ; i++) { memcpy(fmt, s + len - 8 - (i << 3), 8) ; uint32_xscan(fmt, x + i) ; } } skalibs-2.9.1.0/src/libbiguint/bu_scanlen.c000066400000000000000000000003541355335115400205140ustar00rootroot00000000000000/* ISC license. */ #include #include size_t bu_scanlen (char const *s, size_t *zeron) { size_t n = ucharn_findlen(s) ; *zeron = n ; while (*s == '0') { s++ ; (*zeron)-- ; } return n ; } skalibs-2.9.1.0/src/libbiguint/bu_slbc.c000066400000000000000000000004171355335115400200140ustar00rootroot00000000000000/* ISC license. */ #include int bu_slbc (uint32_t *a, unsigned int n, int carry) { unsigned int i = 0 ; carry = !!carry ; for (; i < n ; i++) { int c = a[i] >> 31 ; a[i] = (a[i] << 1) | carry ; carry = c ; } return carry ; } skalibs-2.9.1.0/src/libbiguint/bu_srbc.c000066400000000000000000000003561355335115400200240ustar00rootroot00000000000000/* ISC license. */ #include int bu_srbc (uint32_t *a, unsigned int n, int carry) { while (n--) { int c = a[n] & 1 ; a[n] = (a[n] >> 1) | (carry ? 0x80000000U : 0) ; carry = c ; } return carry ; } skalibs-2.9.1.0/src/libbiguint/bu_subc.c000066400000000000000000000007721355335115400200310ustar00rootroot00000000000000/* ISC license. */ #include #include #include int bu_subc (uint32_t *c, unsigned int cn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, int carry) { unsigned int i = 0 ; for (; i < cn ; i++) { uint32_t ai = (i < an) ? a[i] : 0 ; uint32_t bi = (i < bn) ? b[i] : 0 ; uint32_t ci = ai - bi - carry ; carry = (carry || bi) && (ci > ai) ; c[i] = ci ; } return carry ? (errno = EOVERFLOW, 0) : 1 ; } skalibs-2.9.1.0/src/libbiguint/bu_submod.c000066400000000000000000000005211355335115400203560ustar00rootroot00000000000000/* ISC license. */ #include #include int bu_submod (uint32_t *c, unsigned int cn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, uint32_t const *m, unsigned int mn) { if (!bu_sub(c, cn, a, an, b, bn) && bu_add(c, cn, c, cn, m, mn)) return (errno = EDOM, 0) ; return 1 ; } skalibs-2.9.1.0/src/libbiguint/bu_unpack.c000066400000000000000000000002771355335115400203560ustar00rootroot00000000000000/* ISC license. */ #include #include void bu_unpack (char const *s, uint32_t *a, unsigned int n) { while (n--) uint32_unpack(s + (n<<2), a + n) ; } skalibs-2.9.1.0/src/libbiguint/bu_unpack_big.c000066400000000000000000000003561355335115400211750ustar00rootroot00000000000000/* ISC license. */ #include #include void bu_unpack_big (char const *s, uint32_t *a, unsigned int n) { unsigned int i = 0 ; for (; i < n ; i++) uint32_unpack_big(s + (i<<2), a + n - 1 - i) ; } skalibs-2.9.1.0/src/libbiguint/bu_zero.c000066400000000000000000000001721355335115400200460ustar00rootroot00000000000000/* ISC license. */ #include void bu_zero (uint32_t *z, unsigned int n) { while (n--) z[n] = 0 ; } skalibs-2.9.1.0/src/libdatastruct/000077500000000000000000000000001355335115400167525ustar00rootroot00000000000000skalibs-2.9.1.0/src/libdatastruct/avlnode-internal.h000066400000000000000000000007571355335115400223760ustar00rootroot00000000000000/* ISC license. */ #ifndef AVLNODE_INTERNAL_H #define AVLNODE_INTERNAL_H #include #include #define avlnode_ufroms(c) ((c) > 0) #define avlnode_sfromu(h) ((h) ? 1 : -1) extern uint32_t avlnode_rotate (avlnode *, uint32_t, uint32_t, int) ; extern uint32_t avlnode_doublerotate (avlnode *, uint32_t, uint32_t, int) ; #define avlnode_rotate_maydouble(s, max, r, h, isdouble) ((isdouble) ? avlnode_doublerotate(s, max, r, h) : avlnode_rotate(s, max, r, h)) #endif skalibs-2.9.1.0/src/libdatastruct/avlnode_delete.c000066400000000000000000000033321355335115400220710ustar00rootroot00000000000000/* ISC license. */ #include #include "avlnode-internal.h" uint32_t avlnode_delete (avlnode *s, uint32_t max, uint32_t *root, void const *k, dtokfunc_t_ref dtok, cmpfunc_t_ref f, void *p) { uint32_t stack[AVLNODE_MAXDEPTH] ; int spin[AVLNODE_MAXDEPTH] ; unsigned int sp = 0 ; uint32_t r = *root ; uint32_t itodel ; for (; r < max ; sp++) { int c = (*f)(k, (*dtok)(s[r].data, p), p) ; if (!c) break ; spin[sp] = avlnode_ufroms(c) ; stack[sp] = r ; r = s[r].child[spin[sp]] ; } if (r >= max) return max ; itodel = r ; if ((s[r].child[0] < max) || (s[r].child[1] < max)) { int subspin = s[r].child[1] < max ; stack[sp] = r ; spin[sp++] = subspin ; r = s[r].child[subspin] ; for (; r < max ; sp++) { stack[sp] = r ; spin[sp] = !subspin ; r = s[r].child[!subspin] ; } r = stack[--sp] ; s[itodel].data = s[r].data ; itodel = s[r].child[subspin] ; if (itodel < max) { s[r].data = s[itodel].data ; stack[sp] = r ; spin[sp++] = subspin ; } else itodel = r ; } r = max ; while (sp--) { s[stack[sp]].child[spin[sp]] = r ; r = stack[sp] ; if (!s[r].balance) goto easyfix ; else if (spin[sp] == avlnode_ufroms(s[r].balance)) s[r].balance = 0 ; else if (!s[s[r].child[!spin[sp]]].balance) goto hardfix ; else r = avlnode_rotate_maydouble(s, max, r, spin[sp], spin[sp] == avlnode_ufroms(s[s[r].child[!spin[sp]]].balance)) ; } *root = r ; return itodel ; easyfix: s[r].balance = -avlnode_sfromu(spin[sp]) ; return itodel ; hardfix: r = avlnode_rotate(s, max, r, spin[sp]) ; if (!sp--) *root = r ; else s[stack[sp]].child[spin[sp]] = r ; return itodel ; } skalibs-2.9.1.0/src/libdatastruct/avlnode_doublerotate.c000066400000000000000000000007421355335115400233220ustar00rootroot00000000000000/* ISC license. */ #include #include "avlnode-internal.h" uint32_t avlnode_doublerotate (avlnode_ref s, uint32_t max, uint32_t i, int h) { uint32_t j = s[i].child[!h] ; uint32_t k = s[j].child[h] ; s[i].child[!h] = s[k].child[h] ; s[j].child[h] = s[k].child[!h] ; s[k].child[!h] = j ; s[k].child[h] = i ; s[h ? i : j].balance = (s[k].balance < 0) ; s[h ? j : i].balance = -(s[k].balance > 0) ; s[k].balance = 0 ; (void)max ; return k ; } skalibs-2.9.1.0/src/libdatastruct/avlnode_extreme.c000066400000000000000000000004351355335115400223010ustar00rootroot00000000000000/* ISC license. */ #include #include int avlnode_extreme (avlnode const *s, uint32_t max, uint32_t r, int h, uint32_t *k) { uint32_t i = avlnode_extremenode(s, max, r, h) ; if (i >= max) return (errno = ESRCH, 0) ; *k = s[i].data ; return 1 ; } skalibs-2.9.1.0/src/libdatastruct/avlnode_extremenode.c000066400000000000000000000003371355335115400231500ustar00rootroot00000000000000/* ISC license. */ #include uint32_t avlnode_extremenode (avlnode const *s, uint32_t max, uint32_t r, int h) { uint32_t oldr = r ; for (; r < max ; oldr = r, r = s[r].child[h]) ; return oldr ; } skalibs-2.9.1.0/src/libdatastruct/avlnode_height.c000066400000000000000000000006471355335115400221050ustar00rootroot00000000000000/* ISC license. */ #include unsigned int avlnode_height (avlnode const *s, uint32_t max, uint32_t r) { if (r >= max) return 0 ; else if (s[r].balance) return 1 + avlnode_height(s, max, s[r].child[s[r].balance > 0]) ; else { unsigned int h1 = avlnode_height(s, max, s[r].child[0]) ; unsigned int h2 = avlnode_height(s, max, s[r].child[1]) ; return 1 + ((h1 > h2) ? h1 : h2) ; } } skalibs-2.9.1.0/src/libdatastruct/avlnode_insertnode.c000066400000000000000000000017241355335115400230040ustar00rootroot00000000000000/* ISC license. */ #include #include "avlnode-internal.h" uint32_t avlnode_insertnode (avlnode *s, uint32_t max, uint32_t r, uint32_t i, dtokfunc_t_ref dtok, cmpfunc_t_ref f, void *p) { uint32_t stack[AVLNODE_MAXDEPTH] ; int spin[AVLNODE_MAXDEPTH] ; unsigned int sp = 0 ; { void const *k = (*dtok)(s[i].data, p) ; for (; r < max ; sp++) { spin[sp] = avlnode_ufroms((*f)(k, (*dtok)(s[r].data, p), p)) ; stack[sp] = r ; r = s[r].child[spin[sp]] ; } } r = i ; while (sp--) { s[stack[sp]].child[spin[sp]] = r ; r = stack[sp] ; if (s[r].balance) goto lastfix ; s[r].balance = avlnode_sfromu(spin[sp]) ; } return r ; lastfix: if (avlnode_ufroms(s[r].balance) != spin[sp]) { s[r].balance = 0 ; return stack[0] ; } r = avlnode_rotate_maydouble(s, max, r, !spin[sp], spin[sp] != spin[sp+1]) ; if (!sp--) return r ; s[stack[sp]].child[spin[sp]] = r ; return stack[0] ; } skalibs-2.9.1.0/src/libdatastruct/avlnode_iter.c000066400000000000000000000015251355335115400215740ustar00rootroot00000000000000/* ISC license. */ #include #include struct avlnode_iter_s { avlnode const *s ; uint32_t max ; uint32_t cut ; avliterfunc_t_ref f ; void *p ; } ; static uint32_t avlnode_iter_rec (struct avlnode_iter_s const *blah, uint32_t r, unsigned int h) { if (r >= blah->max) return blah->max ; { uint32_t res = avlnode_iter_rec(blah, blah->s[r].child[0], h+1) ; if (res != blah->max) return res ; } if (r == blah->cut) return blah->max ; if (!(*blah->f)(blah->s[r].data, h, blah->p)) return r ; return avlnode_iter_rec(blah, blah->s[r].child[1], h+1) ; } uint32_t avlnode_iter_nocancel (avlnode *s, uint32_t max, uint32_t cut, uint32_t r, avliterfunc_t_ref f, void *p) { struct avlnode_iter_s blah = { .s = s, .max = max, .cut = cut, .f = f, .p = p } ; return avlnode_iter_rec(&blah, r, 0) ; } skalibs-2.9.1.0/src/libdatastruct/avlnode_iter_withcancel.c000066400000000000000000000006641355335115400240000ustar00rootroot00000000000000/* ISC license. */ #include #include int avlnode_iter_withcancel (avlnode *tree, uint32_t max, uint32_t root, avliterfunc_t_ref f, avliterfunc_t_ref cancelf, void *stuff) { uint32_t cut = avlnode_iter_nocancel(tree, max, max, root, f, stuff) ; if (cut != max) { int e = errno ; avlnode_iter_nocancel(tree, max, cut, root, cancelf, stuff) ; errno = e ; return 0 ; } return 1 ; } skalibs-2.9.1.0/src/libdatastruct/avlnode_rotate.c000066400000000000000000000006061355335115400221260ustar00rootroot00000000000000/* ISC license. */ #include #include "avlnode-internal.h" uint32_t avlnode_rotate (avlnode *s, uint32_t max, uint32_t i, int h) { uint32_t j = s[i].child[!h] ; s[i].child[!h] = s[j].child[h] ; s[j].child[h] = i ; if (s[j].balance * avlnode_sfromu(h) < 0) s[i].balance = s[j].balance = 0 ; else s[j].balance = avlnode_sfromu(h) ; (void)max ; return j ; } skalibs-2.9.1.0/src/libdatastruct/avlnode_search.c000066400000000000000000000005441355335115400220760ustar00rootroot00000000000000/* ISC license. */ #include #include int avlnode_search (avlnode const *s, uint32_t max, uint32_t r, void const *k, uint32_t *data, dtokfunc_t_ref dtok, cmpfunc_t_ref f, void *p) { uint32_t i = avlnode_searchnode(s, max, r, k, dtok, f, p) ; if (i >= max) return (errno = ESRCH, 0) ; *data = s[i].data ; return 1 ; } skalibs-2.9.1.0/src/libdatastruct/avlnode_searchnode.c000066400000000000000000000005561355335115400227470ustar00rootroot00000000000000/* ISC license. */ #include #include "avlnode-internal.h" uint32_t avlnode_searchnode (avlnode const *s, uint32_t max, uint32_t r, void const *k, dtokfunc_t_ref dtok, cmpfunc_t_ref f, void *p) { while (r < max) { int h = (*f)(k, (*dtok)(s[r].data, p), p) ; if (!h) break ; r = s[r].child[avlnode_ufroms(h)] ; } return r ; } skalibs-2.9.1.0/src/libdatastruct/avlnode_zero.c000066400000000000000000000001361355335115400216050ustar00rootroot00000000000000/* ISC license. */ #include avlnode const avlnode_zero = AVLNODE_ZERO ; skalibs-2.9.1.0/src/libdatastruct/avltree_delete.c000066400000000000000000000007511355335115400221050ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int avltree_delete (avltree *t, void const *k) { uint32_t r = avltree_root(t) ; uint32_t i = avlnode_delete(avltree_nodes(t), avltree_totalsize(t), &r, k, t->dtok, t->kcmp, t->external) ; if (i >= avltree_totalsize(t)) return (errno = ESRCH, 0) ; avltree_setroot(t, r) ; if (!gensetdyn_delete(&t->x, i)) return 0 ; return 1 ; } skalibs-2.9.1.0/src/libdatastruct/avltree_free.c000066400000000000000000000002441355335115400215610ustar00rootroot00000000000000/* ISC license. */ #include #include void avltree_free (avltree *t) { gensetdyn_free(&t->x) ; *t = avltree_zero ; } skalibs-2.9.1.0/src/libdatastruct/avltree_init.c000066400000000000000000000006551355335115400216110ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include void avltree_init (avltree *t, uint32_t base, uint32_t fracnum, uint32_t fracden, dtokfunc_t_ref dtok, cmpfunc_t_ref f, void *p) { gensetdyn_init(&t->x, sizeof(avlnode), base, fracnum, fracden) ; t->root = UINT32_MAX ; t->dtok = dtok ; t->kcmp = f ; t->external = p ; } skalibs-2.9.1.0/src/libdatastruct/avltree_insert.c000066400000000000000000000003101355335115400221360ustar00rootroot00000000000000/* ISC license. */ #include int avltree_insert (avltree *t, uint32_t d) { uint32_t i ; if (!avltree_newnode(t, d, &i)) return 0 ; avltree_insertnode(t, i) ; return 1 ; } skalibs-2.9.1.0/src/libdatastruct/avltree_newnode.c000066400000000000000000000006111355335115400222750ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int avltree_newnode (avltree *t, uint32_t data, uint32_t *i) { if (!gensetdyn_new(&t->x, i)) return 0 ; { avlnode *s = avltree_nodes(t) ; s[*i].data = data ; s[*i].child[0] = s[*i].child[1] = UINT32_MAX ; s[*i].balance = 0 ; } return 1 ; } skalibs-2.9.1.0/src/libdatastruct/avltree_zero.c000066400000000000000000000001361355335115400216170ustar00rootroot00000000000000/* ISC license. */ #include avltree const avltree_zero = AVLTREE_ZERO ; skalibs-2.9.1.0/src/libdatastruct/avltreen_delete.c000066400000000000000000000007531355335115400222650ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int avltreen_delete (avltreen *t, void const *k) { uint32_t r = avltreen_root(t) ; uint32_t i = avlnode_delete(avltreen_nodes(t), avltreen_totalsize(t), &r, k, t->dtok, t->kcmp, t->external) ; if (i >= avltreen_totalsize(t)) return (errno = ESRCH, 0) ; avltreen_setroot(t, r) ; if (!genset_delete(&t->x, i)) return 0 ; return 1 ; } skalibs-2.9.1.0/src/libdatastruct/avltreen_init.c000066400000000000000000000005701355335115400217630ustar00rootroot00000000000000/* ISC license. */ #include #include #include void avltreen_init (avltreen *t, avlnode *storage, uint32_t *freelist, uint32_t size, dtokfunc_t_ref dtok, cmpfunc_t_ref f, void *p) { GENSET_init(&t->x, avlnode, storage, freelist, size) ; t->root = size ; t->dtok = dtok ; t->kcmp = f ; t->external = p ; } skalibs-2.9.1.0/src/libdatastruct/avltreen_insert.c000066400000000000000000000003451355335115400223240ustar00rootroot00000000000000/* ISC license. */ #include int avltreen_insert (avltreen *t, uint32_t d) { uint32_t i = avltreen_newnode(t, d) ; if (i >= avltreen_totalsize(t)) return 0 ; avltreen_insertnode(t, i) ; return 1 ; } skalibs-2.9.1.0/src/libdatastruct/avltreen_newnode.c000066400000000000000000000006111355335115400224530ustar00rootroot00000000000000/* ISC license. */ #include #include #include uint32_t avltreen_newnode (avltreen *t, uint32_t d) { uint32_t i = genset_new(&t->x) ; if (i < avltreen_totalsize(t)) { avlnode *s = avltreen_nodes(t) ; s[i].data = d ; s[i].child[0] = s[i].child[1] = avltreen_totalsize(t) ; s[i].balance = 0 ; } return i ; } skalibs-2.9.1.0/src/libdatastruct/genqdyn-internal.h000066400000000000000000000002511355335115400224000ustar00rootroot00000000000000/* ISC license. */ #ifndef SKALIBS_GENQDYN_INTERNAL_H #define SKALIBS_GENQDYN_INTERNAL_H #include extern void genqdyn_clean (genqdyn *) ; #endif skalibs-2.9.1.0/src/libdatastruct/genqdyn_clean.c000066400000000000000000000003351355335115400217260ustar00rootroot00000000000000/* ISC license. */ #include #include "genqdyn-internal.h" void genqdyn_clean (genqdyn *g) { memmove(g->queue.s, g->queue.s + g->head, g->queue.len - g->head) ; g->queue.len -= g->head ; g->head = 0 ; } skalibs-2.9.1.0/src/libdatastruct/genqdyn_free.c000066400000000000000000000002461355335115400215660ustar00rootroot00000000000000/* ISC license. */ #include #include void genqdyn_free (genqdyn *g) { stralloc_free(&g->queue) ; *g = genqdyn_zero ; } skalibs-2.9.1.0/src/libdatastruct/genqdyn_init.c000066400000000000000000000004111355335115400216020ustar00rootroot00000000000000/* ISC license. */ #include #include void genqdyn_init (genqdyn *g, size_t esize, unsigned int num, unsigned int den) { g->queue = stralloc_zero ; g->esize = esize ; g->head = 0 ; g->num = num ; g->den = den ; } skalibs-2.9.1.0/src/libdatastruct/genqdyn_pop.c000066400000000000000000000004721355335115400214440ustar00rootroot00000000000000/* ISC license. */ #include #include #include "genqdyn-internal.h" int genqdyn_pop (genqdyn *g) { if (g->head >= g->queue.len) return (errno = EINVAL, 0) ; g->head += g->esize ; if (g->den * (g->queue.len - g->head) <= g->num * g->queue.len) genqdyn_clean(g) ; return 1 ; } skalibs-2.9.1.0/src/libdatastruct/genqdyn_push.c000066400000000000000000000003001355335115400216130ustar00rootroot00000000000000/* ISC license. */ #include #include int genqdyn_push (genqdyn *g, void const *p) { return stralloc_catb(&g->queue, (char const *)p, g->esize) ; } skalibs-2.9.1.0/src/libdatastruct/genqdyn_unpush.c000066400000000000000000000003551355335115400221700ustar00rootroot00000000000000/* ISC license. */ #include #include #include int genqdyn_unpush (genqdyn *g) { if (g->queue.len < g->esize) return (errno = EINVAL, 0) ; g->queue.len -= g->esize ; return 1 ; } skalibs-2.9.1.0/src/libdatastruct/genqdyn_zero.c000066400000000000000000000001361355335115400216220ustar00rootroot00000000000000/* ISC license. */ #include genqdyn const genqdyn_zero = GENQDYN_ZERO ; skalibs-2.9.1.0/src/libdatastruct/genset.c000066400000000000000000000011371355335115400204050ustar00rootroot00000000000000/* ISC license. */ #include #include void genset_init (genset *x, void *storage, uint32_t *freelist, uint32_t esize, uint32_t max) { uint32_t i = max ; x->storage = (char *)storage ; x->freelist = freelist ; x->esize = esize ; x->max = max ; x->sp = max ; while (i--) freelist[i] = max - 1 - i ; } uint32_t genset_new (genset *x) { return x->sp ? x->freelist[--x->sp] : (errno = ENOSPC, x->max) ; } int genset_delete (genset *x, uint32_t i) { if ((i >= x->max) || (x->sp >= x->max)) return (errno = EINVAL, 0) ; x->freelist[x->sp++] = i ; return 1 ; } skalibs-2.9.1.0/src/libdatastruct/genset_deepfree.c000066400000000000000000000004221355335115400222400ustar00rootroot00000000000000/* ISC license. */ #include #include static int freeiter (char *s, void *aux) { freefunc_t_ref f = aux ; (*f)((void *)s) ; return 1 ; } void genset_deepfree (genset *g, freefunc_t_ref f) { genset_iter(g, &freeiter, f) ; } skalibs-2.9.1.0/src/libdatastruct/genset_iter_nocancel.c000066400000000000000000000010201355335115400232610ustar00rootroot00000000000000/* ISC license. */ #include #include uint32_t genset_iter_nocancel (genset *g, uint32_t n, iterfunc_t_ref f, void *stuff) { unsigned char bits[bitarray_div8(n)] ; uint32_t i = 0, j = 0, m = genset_n(g) ; bitarray_setn(bits, 0, n) ; for (; i < g->sp ; i++) if (g->freelist[i] < n) bitarray_clear(bits, g->freelist[i]) ; for (i = 0 ; (i < n) && (j < m) ; i++) if (bitarray_peek(bits, i)) { j++ ; if (!(*f)(g->storage + i * g->esize, stuff)) break ; } return i ; } skalibs-2.9.1.0/src/libdatastruct/genset_iter_withcancel.c000066400000000000000000000005571355335115400236360ustar00rootroot00000000000000/* ISC license. */ #include #include #include int genset_iter_withcancel (genset *g, iterfunc_t_ref f, iterfunc_t_ref cancelf, void *stuff) { uint32_t n = genset_iter(g, f, stuff) ; if (n < g->max) { int e = errno ; genset_iter_nocancel(g, n, cancelf, stuff) ; errno = e ; return 0 ; } return 1 ; } skalibs-2.9.1.0/src/libdatastruct/gensetdyn_deepfree.c000066400000000000000000000004641355335115400227610ustar00rootroot00000000000000/* ISC license. */ #include #include static int freeiter (char *s, void *aux) { freefunc_t_ref f = aux ; (*f)((void *)s) ; return 1 ; } void gensetdyn_deepfree (gensetdyn *g, freefunc_t_ref f) { gensetdyn_iter(g, &freeiter, f) ; gensetdyn_free(g) ; } skalibs-2.9.1.0/src/libdatastruct/gensetdyn_delete.c000066400000000000000000000004031355335115400224350ustar00rootroot00000000000000/* ISC license. */ #include #include #include int gensetdyn_delete (gensetdyn *g, uint32_t i) { return (i >= g->storage.len) ? (errno = EINVAL, 0) : genalloc_catb(uint32_t, &g->freelist, &i, 1) ; } skalibs-2.9.1.0/src/libdatastruct/gensetdyn_free.c000066400000000000000000000004141355335115400221160ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include void gensetdyn_free (gensetdyn *g) { stralloc_free(&g->storage) ; genalloc_free(uint32_t, &g->freelist) ; *g = gensetdyn_zero ; } skalibs-2.9.1.0/src/libdatastruct/gensetdyn_init.c000066400000000000000000000005631355335115400221450ustar00rootroot00000000000000/* ISC license. */ #include #include #include void gensetdyn_init (gensetdyn *g, uint32_t esize, uint32_t base, uint32_t fracnum, uint32_t fracden) { g->storage = stralloc_zero ; g->freelist = genalloc_zero ; g->esize = esize ; g->base = base ; g->fracnum = fracnum ; g->fracden = fracden ; } skalibs-2.9.1.0/src/libdatastruct/gensetdyn_iter.c000066400000000000000000000015261355335115400221450ustar00rootroot00000000000000/* ISC license. */ #include #include #include uint32_t gensetdyn_iter_nocancel (gensetdyn *g, uint32_t n, iterfunc_t_ref f, void *stuff) { /* XXX: we may be called by a freeing function, so we cannot alloc - XXX: so pray that the bitarray fits in the stack. */ unsigned char bits[bitarray_div8(g->storage.len) ? bitarray_div8(g->storage.len) : 1] ; size_t i = 0 ; uint32_t j = 0 ; uint32_t *fl = genalloc_s(uint32_t, &g->freelist) ; size_t sp = genalloc_len(uint32_t, &g->freelist) ; bitarray_setn(bits, 0, g->storage.len) ; for (; i < sp ; i++) if (fl[i] < g->storage.len) bitarray_clear(bits, fl[i]) ; for (i = 0 ; (i < g->storage.len) && (j < n) ; i++) if (bitarray_peek(bits, i)) { j++ ; if (!(*f)(gensetdyn_p(g, i), stuff)) break ; } return j ; } skalibs-2.9.1.0/src/libdatastruct/gensetdyn_iter_withcancel.c000066400000000000000000000006371355335115400243500ustar00rootroot00000000000000/* ISC license. */ #include #include #include int gensetdyn_iter_withcancel (gensetdyn *g, iterfunc_t_ref f, iterfunc_t_ref cancelf, void *stuff) { uint32_t n = gensetdyn_iter_nocancel(g, gensetdyn_n(g), f, stuff) ; if (n < gensetdyn_n(g)) { int e = errno ; gensetdyn_iter_nocancel(g, n, cancelf, stuff) ; errno = e ; return 0 ; } return 1 ; } skalibs-2.9.1.0/src/libdatastruct/gensetdyn_new.c000066400000000000000000000006321355335115400217700ustar00rootroot00000000000000/* ISC license. */ #include #include #include int gensetdyn_new (gensetdyn *g, uint32_t *i) { size_t n ; if (!genalloc_len(uint32_t, &g->freelist) && !gensetdyn_readyplus(g, 1)) return 0 ; n = genalloc_len(uint32_t, &g->freelist) ; *i = genalloc_s(uint32_t, &g->freelist)[n-1] ; genalloc_setlen(uint32_t, &g->freelist, n-1) ; return 1 ; } skalibs-2.9.1.0/src/libdatastruct/gensetdyn_ready.c000066400000000000000000000012221355335115400222770ustar00rootroot00000000000000/* ISC license. */ #include #include #include int gensetdyn_ready (gensetdyn *g, uint32_t n) { int wasnull = !g->storage.s ; uint32_t i = g->storage.len ; if (n < i) return 1 ; n += g->base + (n * g->fracnum) / g->fracden ; if (!stralloc_ready_tuned(&g->storage, n * g->esize, 0, 0, 1)) return 0 ; if (!genalloc_ready(uint32_t, &g->freelist, n)) { if (wasnull) stralloc_free(&g->storage) ; return 0 ; } for (; i < n ; i++) { uint32_t j = n - 1 - i + g->storage.len ; genalloc_catb(uint32_t, &g->freelist, &j, 1) ; } g->storage.len = n ; return 1 ; } skalibs-2.9.1.0/src/libdatastruct/gensetdyn_zero.c000066400000000000000000000001461355335115400221560ustar00rootroot00000000000000/* ISC license. */ #include gensetdyn const gensetdyn_zero = GENSETDYN_ZERO ; skalibs-2.9.1.0/src/libposixplz/000077500000000000000000000000001355335115400164645ustar00rootroot00000000000000skalibs-2.9.1.0/src/libposixplz/doublefork.c000066400000000000000000000020701355335115400207630ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include 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 ; } } skalibs-2.9.1.0/src/libposixplz/execvep.c000066400000000000000000000005561355335115400202750ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include "posixplz-internal.h" void execvep (char const *file, char const *const *argv, char const *const *envp, char const *path) { if (strchr(file, '/')) execve(file, (char *const *)argv, (char *const *)envp) ; else execvep_internal(file, argv, envp, path) ; } skalibs-2.9.1.0/src/libposixplz/execvep_internal.c000066400000000000000000000017321355335115400221660ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include void execvep_internal (char const *file, char const *const *argv, char const *const *envp, char const *path) { if (!path) errno = EINVAL ; 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 ; } } skalibs-2.9.1.0/src/libposixplz/execvep_loose.c000066400000000000000000000005351355335115400214730ustar00rootroot00000000000000/* ISC license. */ #include #include #include "posixplz-internal.h" void execvep_loose (char const *file, char const *const *argv, char const *const *envp, char const *path) { if (file[0] == '/') execve(file, (char *const *)argv, (char *const *)envp) ; else execvep_internal(file, argv, envp, path) ; } skalibs-2.9.1.0/src/libposixplz/getpeereid.c000066400000000000000000000021731355335115400207500ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASGETPEEREID /* syscall exists - do nothing */ #else #ifdef SKALIBS_HASSOPEERCRED /* implementation with SO_PEERCRED */ #include #include #include #include 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 #include #include int getpeereid (int s, uid_t *u, gid_t *g) { ucred_t *cred = 0 ; 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 #include int getpeereid (int s, uid_t *uid, gid_t *gid) { (void)s ; *uid = *gid = -1 ; errno = ENOSYS ; return -1 ; } #endif #endif #endif skalibs-2.9.1.0/src/libposixplz/memmem.c000066400000000000000000000144551355335115400201160ustar00rootroot00000000000000/* MIT license. See below. */ #include #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 #include #include 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 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 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); kmem && 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 #include #include static int f (char const *fn, mode_t mode, void *data) { dev_t *devp = data ; mode_t m = umask(0) ; int r = mknod(fn, (mode & 00777) | S_IFBLK, *devp) ; umask(m) ; if (r == -1) return -1 ; r = open_readb(fn) ; if (r == -1) unlink_void(fn) ; return r ; } int mkbtemp (char *s, mode_t mode, dev_t dev) { return mkfiletemp(s, &f, mode, &dev) ; } skalibs-2.9.1.0/src/libposixplz/mkctemp.c000066400000000000000000000007211355335115400202700ustar00rootroot00000000000000/* ISC license. */ #include #include #include static int f (char const *fn, mode_t mode, void *data) { dev_t *devp = data ; mode_t m = umask(0) ; int r = mknod(fn, (mode & 00777) | S_IFCHR, *devp) ; umask(m) ; if (r == -1) return -1 ; r = open_readb(fn) ; if (r == -1) unlink_void(fn) ; return r ; } int mkctemp (char *s, mode_t mode, dev_t dev) { return mkfiletemp(s, &f, mode, &dev) ; } skalibs-2.9.1.0/src/libposixplz/mkfiletemp.c000066400000000000000000000007611355335115400207710ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int mkfiletemp (char *s, createfunc_t_ref f, mode_t mode, void *data) { size_t len = strlen(s) ; size_t xlen = 0 ; int r ; for (; xlen < len ; xlen++) if (s[len - 1 - xlen] != 'X') break ; if (xlen < 6) return (errno = EINVAL, -1) ; do { autosurf_name(s + len - xlen, xlen) ; r = (*f)(s, mode, data) ; } while (r == -1 && errno == EEXIST) ; return r ; } skalibs-2.9.1.0/src/libposixplz/mkhtemp.c000066400000000000000000000002341355335115400202740ustar00rootroot00000000000000/* ISC license. */ #include #include int mkhtemp (char const *src, char *dst) { return mklinktemp(src, dst, &link) ; } skalibs-2.9.1.0/src/libposixplz/mklinktemp.c000066400000000000000000000006461355335115400210110ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include "posixplz-internal.h" static int f (char const *dst, mode_t mode, void *data) { linkarg_t *la = data ; (void)mode ; return (*la->lf)(la->src, dst) ; } int mklinktemp (char const *src, char *dst, linkfunc_t_ref lf) { linkarg_t la = { .lf = lf, .src = src } ; return mkfiletemp(dst, &f, 0600, &la) ; } skalibs-2.9.1.0/src/libposixplz/mkltemp.c000066400000000000000000000002371355335115400203030ustar00rootroot00000000000000/* ISC license. */ #include #include int mkltemp (char const *src, char *dst) { return mklinktemp(src, dst, &symlink) ; } skalibs-2.9.1.0/src/libposixplz/mkptemp.c000066400000000000000000000006051355335115400203060ustar00rootroot00000000000000/* ISC license. */ #include #include #include static int f (char const *fn, mode_t mode, void *data) { mode_t m = umask(0) ; int r = mkfifo(fn, mode) ; umask(m) ; if (r == -1) return -1 ; r = open_readb(fn) ; if (r == -1) unlink_void(fn) ; return r ; } int mkptemp (char *s) { return mkfiletemp(s, &f, 0600, 0) ; } skalibs-2.9.1.0/src/libposixplz/posixplz-internal.h000066400000000000000000000004621355335115400223410ustar00rootroot00000000000000/* ISC license. */ #ifndef POSIXPLZ_INTERNAL_H #define POSIXPLZ_INTERNAL_H typedef struct linkarg_s linkarg_t, *linkarg_t_ref ; struct linkarg_s { linkfunc_t_ref lf ; char const *src ; } ; extern void execvep_internal (char const *, char const *const *, char const *const *, char const *) ; #endif skalibs-2.9.1.0/src/libposixplz/setgroups.c000066400000000000000000000020661355335115400206670ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASSETGROUPS #include #include #include #include #include #include int setgroups_and_gid (gid_t g, size_t n, gid_t const *tab) { size_t i = 1 ; if (!n) return setgroups(1, &g) ; if (tab[0] == g) return setgroups(n, tab) ; for (; i < n ; i++) if (tab[i] == g) break ; if (i < n) { gid_t newtab[n] ; newtab[0] = g ; memcpy(newtab + 1, tab, i * sizeof(gid_t)) ; memcpy(newtab + i + 1, tab + i + 1, (n - i - 1) * sizeof(gid_t)) ; return setgroups(n, newtab) ; } else { gid_t newtab[n+1] ; newtab[0] = g ; memcpy(newtab + 1, tab, n * sizeof(gid_t)) ; return setgroups(n+1, newtab) ; } } int setgroups_with_egid (size_t n, gid_t const *tab) { return setgroups_and_gid(getegid(), n, tab) ; } int skalibs_setgroups (size_t n, gid_t const *tab) { #ifdef SKALIBS_BSD_SUCKS return setgroups_with_egid(n, tab) ; #else return setgroups(n, tab) ; #endif } #endif skalibs-2.9.1.0/src/libposixplz/strnlen.c000066400000000000000000000003671355335115400203230ustar00rootroot00000000000000/* ISC license. */ #include #ifndef SKALIBS_HASSTRNLEN #include #include #include size_t strnlen (char const *s, size_t max) { return byte_chr(s, max, 0) ; } #endif skalibs-2.9.1.0/src/libposixplz/touch.c000066400000000000000000000016201355335115400177510ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASFUTIMENS #include #include #include #include #include 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 #include #include #include 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 #include #include 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 skalibs-2.9.1.0/src/libposixplz/unlink_void.c000066400000000000000000000002631355335115400211520ustar00rootroot00000000000000/* ISC license. */ #include #include #include void unlink_void (char const *file) { int e = errno ; unlink(file) ; errno = e ; } skalibs-2.9.1.0/src/librandom/000077500000000000000000000000001355335115400160545ustar00rootroot00000000000000skalibs-2.9.1.0/src/librandom/autosurf.c000066400000000000000000000005211355335115400200660ustar00rootroot00000000000000/* ISC license. */ #include #include void autosurf (char *s, size_t n) { static SURFSchedule ctx = SURFSCHEDULE_ZERO ; static int need4seed = 1 ; if (need4seed) { char tmp[160] ; random_makeseed(tmp) ; surf_init(&ctx, tmp) ; need4seed = 0 ; } return surf(&ctx, s, n) ; } skalibs-2.9.1.0/src/librandom/autosurf_name.c000066400000000000000000000002721355335115400210710ustar00rootroot00000000000000/* ISC license. */ #include #include "random-internal.h" void autosurf_name (char *s, size_t n) { autosurf(s, n) ; while (n--) s[n] = random_oklist[s[n] & 63] ; } skalibs-2.9.1.0/src/librandom/random-internal.h000066400000000000000000000003061355335115400213160ustar00rootroot00000000000000/* ISC license. */ #ifndef RANDOM_INTERNAL_H #define RANDOM_INTERNAL_H #include extern char const *random_oklist ; extern int random_fd ; extern SURFSchedule surf_here ; #endif skalibs-2.9.1.0/src/librandom/random_char.c000066400000000000000000000002301355335115400204700ustar00rootroot00000000000000/* ISC license. */ #include unsigned char random_char (void) { unsigned char c ; random_string((char *)&c, 1) ; return c ; } skalibs-2.9.1.0/src/librandom/random_finish.c000066400000000000000000000010061355335115400210350ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASARC4RANDOM #include void random_finish () { } #else #ifdef SKALIBS_HASGETRANDOM #include void random_finish () { } #else #ifdef SKALIBS_HASDEVURANDOM #include #include #include "random-internal.h" void random_finish () { fd_close(random_fd) ; random_fd = -1 ; } #else /* default */ #include void random_finish () { } #endif #endif #endif skalibs-2.9.1.0/src/librandom/random_init.c000066400000000000000000000025241355335115400205260ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASARC4RANDOM #include #include #include int random_init () { #ifdef SKALIBS_HASARC4RANDOM_ADDRANDOM char seed[160] ; random_makeseed(seed) ; arc4random_addrandom((unsigned char *)seed, 160) ; #endif return 1 ; } #else #ifdef SKALIBS_HASGETRANDOM #include #include int random_init () { #ifdef SKALIBS_HASDEVURANDOM char seed[160] ; random_makeseed(seed) ; openwritenclose_unsafe("/dev/urandom", seed, 160) ; #endif return 1 ; } #else #include #include #include "random-internal.h" SURFSchedule surf_here = SURFSCHEDULE_ZERO ; #ifdef SKALIBS_HASDEVURANDOM #include #include int random_fd = -1 ; int random_init () { int fd ; char seed[160] ; random_makeseed(seed) ; surf_init(&surf_here, seed) ; openwritenclose_unsafe("/dev/urandom", seed, 160) ; if (random_fd < 0) { fd = open_readb("/dev/urandom") ; if (fd < 0) return 0 ; if (coe(fd) < 0) { fd_close(fd) ; return 0 ; } random_fd = fd ; } return 1 ; } #else /* default */ int random_init () { char seed[160] ; random_makeseed(seed) ; surf_init(&surf_here, seed) ; return 1 ; } #endif #endif #endif skalibs-2.9.1.0/src/librandom/random_makeseed.c000066400000000000000000000020031355335115400213310ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include /* Writes 160 bytes of crap into s. Certainly not cryptographically secure or 100% unpredictable, but we're only using this to help shuffle the entropy of /dev/urandom or to init an internal SURF PRNG. iow: we are CS iff the system's RNG is CS. */ void random_makeseed (char *s) { SHA1Schedule bak = SHA1_INIT() ; { tain_t now ; char tmp[256] ; uint32_t x = getpid() ; uint32_pack(tmp, x) ; x = getppid() ; uint32_pack(tmp + 4, x) ; tain_now(&now) ; tain_pack(tmp + 8, &now) ; sha1_update(&bak, tmp, 8 + TAIN_PACK) ; gethostname(tmp, 256) ; sha1_update(&bak, tmp, 256) ; sha1_final(&bak, tmp) ; sha1_init(&bak) ; sha1_update(&bak, tmp, 20) ; } { char i = 0 ; for (; i < 8 ; i++) { SHA1Schedule ctx = bak ; sha1_update(&ctx, &i, 1) ; sha1_final(&ctx, s + 20*i) ; } } } skalibs-2.9.1.0/src/librandom/random_name.c000066400000000000000000000002771355335115400205060ustar00rootroot00000000000000/* ISC license. */ #include #include "random-internal.h" void random_name (char *s, size_t n) { random_string(s, n) ; while (n--) s[n] = random_oklist[s[n] & 63] ; } skalibs-2.9.1.0/src/librandom/random_oklist.c000066400000000000000000000003131355335115400210620ustar00rootroot00000000000000/* ISC license. */ #include "random-internal.h" static char const random_oklist_[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZghijklmnopqrstuvwxyz-_0123456789abcdef" ; char const *random_oklist = random_oklist_ ; skalibs-2.9.1.0/src/librandom/random_sauniquename.c000066400000000000000000000007231355335115400222550ustar00rootroot00000000000000/* ISC license. */ #include #include #include int random_sauniquename (stralloc *sa, size_t n) { size_t base = sa->len ; int wasnull = !sa->s ; if (!sauniquename(sa)) return 0 ; if (!stralloc_readyplus(sa, n+1)) goto err ; stralloc_catb(sa, ":", 1) ; random_name(sa->s + sa->len, n) ; sa->len += n ; return 1 ; err: if (wasnull) stralloc_free(sa) ; else sa->len = base ; return 0 ; } skalibs-2.9.1.0/src/librandom/random_string.c000066400000000000000000000016041355335115400210670ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASARC4RANDOM #include #include #include void random_string (char *s, size_t n) { arc4random_buf(s, n) ; } #else #ifdef SKALIBS_HASGETRANDOM #include #include void random_string (char *s, size_t n) { while (n) { ssize_t r = getrandom(s, n, 0) ; if (r >= 0) { s += r ; n -= r ; } } } #else #ifdef SKALIBS_HASDEVURANDOM #include #include #include "random-internal.h" void random_string (char *s, size_t n) { size_t r = allread(random_fd, s, n) ; if (r < n) surf(&surf_here, s+r, n-r) ; } #else /* default */ #include #include "random-internal.h" void random_string (char *s, size_t n) { surf(&surf_here, s, n) ; } #endif #endif #endif skalibs-2.9.1.0/src/librandom/random_uint32.c000066400000000000000000000010671355335115400207100ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASARC4RANDOM #include #include #include #include uint32_t random_uint32 (uint32_t n) { return arc4random_uniform(n) ; } #else #include #include uint32_t random_uint32 (uint32_t n) { uint32_t min, x ; if (n < 2) return 0 ; min = -n % n ; for (;;) { char tmp[4] ; random_string(tmp, 4) ; uint32_unpack_big(tmp, &x) ; if (x >= min) break ; } return x % n ; } #endif skalibs-2.9.1.0/src/librandom/random_unsort.c000066400000000000000000000006101355335115400211070ustar00rootroot00000000000000/* ISC license. */ #include #include #include void random_unsort (char *s, size_t n, size_t chunksize) { char tmp[chunksize] ; while (n--) { uint32_t i = random_uint32(n+1) ; memcpy(tmp, s + i * chunksize, chunksize) ; memcpy(s + i * chunksize, s + n * chunksize, chunksize) ; memcpy(s + n * chunksize, tmp, chunksize) ; } } skalibs-2.9.1.0/src/librandom/surf.c000066400000000000000000000025311355335115400172000ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #define ROTATE(x, b) (((x) << (b)) | ((x) >> (32 - (b)))) #define MUSH(i, b) x = t[i] += (((x ^ ctx->seed[i]) + sum) ^ ROTATE(x, b)) static void surfit (SURFSchedule *ctx) { uint32_t t[12] ; uint32_t z[8] ; uint32_t x ; uint32_t sum = 0 ; unsigned int i = 0, loop = 0 ; ; if (!++ctx->in[0] && !++ctx->in[1] && !++ctx->in[2]) ++ctx->in[3] ; for (; i < 12 ; i++) t[i] = ctx->in[i] ^ ctx->seed[12+i] ; for (i = 0 ; i < 8 ; i++) z[i] = ctx->seed[24+i] ; x = t[11] ; for (; loop < 2 ; loop++) { for (i = 0 ; i < 16 ; i++) { sum += 0x9e3779b9 ; MUSH(0, 5) ; MUSH(1, 7) ; MUSH(2, 9) ; MUSH(3, 13) ; MUSH(4, 5) ; MUSH(5, 7) ; MUSH(6, 9) ; MUSH(7, 13) ; MUSH(8, 5) ; MUSH(9, 7) ; MUSH(10, 9) ; MUSH(11, 13) ; } for (i = 0 ; i < 8 ; i++) z[i] ^= t[i+4] ; } for (i = 0 ; i < 8 ; i++) uint32_pack(ctx->out + (i<<2), z[i]) ; } void surf (SURFSchedule *ctx, char *s, size_t n) { { size_t i = 32 - ctx->pos ; if (n < i) i = n ; memcpy(s, ctx->out + ctx->pos, i) ; s += i ; n -= i ; ctx->pos += i ; } while (n > 32) { surfit(ctx) ; memcpy(s, ctx->out, 32) ; s += 32 ; n -= 32 ; } if (!n) return ; surfit(ctx) ; memcpy(s, ctx->out, n) ; ctx->pos = n ; } skalibs-2.9.1.0/src/librandom/surf_init.c000066400000000000000000000005441355335115400202250ustar00rootroot00000000000000/* ISC license. */ #include #include void surf_init (SURFSchedule *ctx, char const *s) { SURFSchedule zero = SURFSCHEDULE_ZERO ; unsigned int i = 4 ; *ctx = zero ; for (; i < 12 ; i++) uint32_unpack(s + (i<<2) - 16, ctx->in + i) ; for (i = 0 ; i < 32 ; i++) uint32_unpack(s + 32 + (i<<2), ctx->seed + i) ; } skalibs-2.9.1.0/src/libstdcrypto/000077500000000000000000000000001355335115400166275ustar00rootroot00000000000000skalibs-2.9.1.0/src/libstdcrypto/md5-internal.h000066400000000000000000000003251355335115400212770ustar00rootroot00000000000000/* ISC license. */ #ifndef MD5_INTERNAL_H #define MD5_INTERNAL_H #include #include extern void md5_transform (uint32_t * /* 4 uint32s */, uint32_t const * /* 16 uint32s */) ; #endif skalibs-2.9.1.0/src/libstdcrypto/md5_final.c000066400000000000000000000014261355335115400206340ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include "md5-internal.h" void md5_final (MD5Schedule *ctx, char *digest /* 16 chars */) { unsigned int count = (ctx->bits[0] >> 3) & 0x3F ; unsigned char *p = ctx->in + count ; *p++ = 0x80; count = 63 - count ; if (count < 8) { memset(p, 0, count) ; uint32_little_endian((char *)ctx->in, 16) ; md5_transform(ctx->buf, (uint32_t *)ctx->in) ; memset(ctx->in, 0, 56) ; } else memset(p, 0, count - 8) ; uint32_little_endian((char *)ctx->in, 14) ; memcpy(ctx->in + 56, &ctx->bits[0], 4) ; memcpy(ctx->in + 60, &ctx->bits[1], 4) ; md5_transform(ctx->buf, (uint32_t *)ctx->in) ; uint32_little_endian((char *)ctx->buf, 4) ; memcpy(digest, ctx->buf, 16) ; } skalibs-2.9.1.0/src/libstdcrypto/md5_init.c000066400000000000000000000003651355335115400205070ustar00rootroot00000000000000/* ISC license. */ #include void md5_init (MD5Schedule *ctx) { ctx->buf[0] = 0x67452301U ; ctx->buf[1] = 0xefcdab89U ; ctx->buf[2] = 0x98badcfeU ; ctx->buf[3] = 0x10325476U ; ctx->bits[0] = 0 ; ctx->bits[1] = 0 ; } skalibs-2.9.1.0/src/libstdcrypto/md5_transform.c000066400000000000000000000075561355335115400215700ustar00rootroot00000000000000/* ISC license. */ #include "md5-internal.h" /* #define F1(x, y, z) (x & y | ~x & z) */ #define F1(x, y, z) (z ^ (x & (y ^ z))) #define F2(x, y, z) F1(z, x, y) #define F3(x, y, z) (x ^ y ^ z) #define F4(x, y, z) (y ^ (x | ~z)) #define MD5STEP(f, w, x, y, z, data, s) \ ( w += f(x, y, z) + data, w = w<>(32-s), w += x ) void md5_transform (uint32_t *buf /* 4 uint32s */, uint32_t const *in /* 16 uint32s */) { uint32_t a = buf[0], b = buf[1], c = buf[2], d = buf[3] ; MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478U, 7) ; MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756U, 12) ; MD5STEP(F1, c, d, a, b, in[2] + 0x242070dbU, 17) ; MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceeeU, 22) ; MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0fafU, 7) ; MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62aU, 12) ; MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613U, 17) ; MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501U, 22) ; MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8U, 7) ; MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7afU, 12) ; MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1U, 17) ; MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7beU, 22) ; MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122U, 7) ; MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193U, 12) ; MD5STEP(F1, c, d, a, b, in[14] + 0xa679438eU, 17) ; MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821U, 22) ; MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562U, 5) ; MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340U, 9) ; MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51U, 14) ; MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aaU, 20) ; MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105dU, 5) ; MD5STEP(F2, d, a, b, c, in[10] + 0x02441453U, 9) ; MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681U, 14) ; MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8U, 20) ; MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6U, 5) ; MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6U, 9) ; MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87U, 14) ; MD5STEP(F2, b, c, d, a, in[8] + 0x455a14edU, 20) ; MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905U, 5) ; MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8U, 9) ; MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9U, 14) ; MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8aU, 20) ; MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942U, 4) ; MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681U, 11) ; MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122U, 16) ; MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380cU, 23) ; MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44U, 4) ; MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9U, 11) ; MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60U, 16) ; MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70U, 23) ; MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6U, 4) ; MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127faU, 11) ; MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085U, 16) ; MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05U, 23) ; MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039U, 4) ; MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5U, 11) ; MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8U, 16) ; MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665U, 23) ; MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244U, 6) ; MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97U, 10) ; MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7U, 15) ; MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039U, 21) ; MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3U, 6) ; MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92U, 10) ; MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47dU, 15) ; MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1U, 21) ; MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4fU, 6) ; MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0U, 10) ; MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314U, 15) ; MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1U, 21) ; MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82U, 6) ; MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235U, 10) ; MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bbU, 15) ; MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391U, 21) ; buf[0] += a ; buf[1] += b ; buf[2] += c ; buf[3] += d ; } skalibs-2.9.1.0/src/libstdcrypto/md5_update.c000066400000000000000000000014761355335115400210320ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include "md5-internal.h" void md5_update (MD5Schedule *ctx, char const *s, size_t len) { uint32_t t = ctx->bits[0] ; if ((ctx->bits[0] = t + (len << 3)) < t) ctx->bits[1]++ ; ctx->bits[1] += len >> 29 ; t = (t >> 3) & 0x3f ; if (t) { unsigned char *p = ctx->in + t ; t = 64 - t ; if (len < t) { memcpy(p, s, len) ; return ; } memcpy(p, s, t) ; uint32_little_endian((char *)ctx->in, 16) ; md5_transform(ctx->buf, (uint32_t *)ctx->in) ; s += t ; len -= t ; } while (len >= 64) { memcpy(ctx->in, s, 64) ; uint32_little_endian((char *)ctx->in, 16) ; md5_transform(ctx->buf, (uint32_t *)ctx->in) ; s += 64 ; len -= 64 ; } memcpy(ctx->in, s, len) ; } skalibs-2.9.1.0/src/libstdcrypto/rc4.c000066400000000000000000000007161355335115400174670ustar00rootroot00000000000000/* ISC license. */ /* Thanks to Thomas Pornin */ #include #include void rc4 (RC4Schedule *r, char const *in, char *out, size_t n) { size_t i = 0 ; for (; i < n ; i++) { unsigned char t ; r->x = T8(r->x + 1) ; t = r->tab[r->x] ; r->y = T8(r->y + t) ; r->tab[r->x] = r->tab[r->y] ; r->tab[r->y] = t ; out[i] = (unsigned char)in[i] ^ T8(r->tab[r->x] + r->tab[r->y]) ; } } skalibs-2.9.1.0/src/libstdcrypto/rc4_init.c000066400000000000000000000011101355335115400204770ustar00rootroot00000000000000/* ISC license. */ /* Thanks to Thomas Pornin */ #include #include void rc4_init (RC4Schedule *r, char const *key, size_t ksize) { size_t j = 0 ; unsigned int i = 0 ; unsigned char c = 0; r->x = r->y = 0 ; for (; i < 256 ; i++) r->tab[i] = i ; for (i = 0 ; i < 256 ; i++) { unsigned char t = r->tab[i] ; c = T8(c + (unsigned char)key[j] + t) ; r->tab[i] = r->tab[c] ; r->tab[c] = t ; if (++j == ksize) j = 0 ; } { char tmp[RC4_THROWAWAY] ; rc4(r, tmp, tmp, RC4_THROWAWAY) ; } } skalibs-2.9.1.0/src/libstdcrypto/sha1-internal.h000066400000000000000000000004211355335115400214430ustar00rootroot00000000000000/* ISC license. */ #ifndef SHA1_INTERNAL_H #define SHA1_INTERNAL_H #include #include extern void sha1_feed (SHA1Schedule *, unsigned char) ; extern void sha1_transform (uint32_t * /* 5 uint32s */, uint32_t const * /* 16 uint32s */) ; #endif skalibs-2.9.1.0/src/libstdcrypto/sha1_feed.c000066400000000000000000000007751355335115400206230ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include "sha1-internal.h" void sha1_feed (SHA1Schedule *ctx, unsigned char inb) { uint32_t tmp ; ctx->in[ctx->b>>2] <<= 8 ; ctx->in[ctx->b>>2] |= T8(inb) ; if (++ctx->b >= 64) { unsigned int i = 0 ; sha1_transform(ctx->buf, ctx->in) ; ctx->b = 0 ; for (i = 0 ; i < 16 ; i++) ctx->in[i] = 0 ; } tmp = ctx->bits[0] ; ctx->bits[0] += 8 ; if (tmp > ctx->bits[0]) ctx->bits[1]++ ; } skalibs-2.9.1.0/src/libstdcrypto/sha1_final.c000066400000000000000000000007021355335115400207770ustar00rootroot00000000000000/* ISC license. */ #include #include #include "sha1-internal.h" void sha1_final (SHA1Schedule *ctx, char *digest) { char pack[8] ; unsigned int i = 0 ; uint32_pack_big(pack, ctx->bits[1]) ; uint32_pack_big(pack+4, ctx->bits[0]) ; sha1_feed(ctx, 0x80) ; while (ctx->b != 56) sha1_feed(ctx, 0) ; sha1_update(ctx, pack, 8) ; for (; i < 5 ; i++) uint32_pack_big(digest + (i<<2), ctx->buf[i]) ; } skalibs-2.9.1.0/src/libstdcrypto/sha1_init.c000066400000000000000000000005261355335115400206550ustar00rootroot00000000000000/* ISC license. */ #include void sha1_init (SHA1Schedule *ctx) { unsigned int i = 16 ; ctx->buf[0] = 0x67452301U ; ctx->buf[1] = 0xefcdab89U ; ctx->buf[2] = 0x98badcfeU ; ctx->buf[3] = 0x10325476U ; ctx->buf[4] = 0xc3d2e1f0U ; ctx->bits[0] = ctx->bits[1] = 0 ; while (i--) ctx->in[i] = 0 ; ctx->b = 0 ; } skalibs-2.9.1.0/src/libstdcrypto/sha1_transform.c000066400000000000000000000020141355335115400217170ustar00rootroot00000000000000/* ISC license. */ #include "sha1-internal.h" #define F1(x, y, z) ((x & y) | ((~x) & z)) #define F2(x, y, z) (x ^ y ^ z) #define F3(x, y, z) ((x & y) | (x & z) | (y & z)) #define F4(x, y, z) (x ^ y ^ z) #define SHA1STEP(f, data) \ { \ uint32_t tmp = e + f(b, c, d) + data + ((a<<5) | (a>>27)); \ e = d ; \ d = c ; \ c = (b<<30) | (b>>2) ; \ b = a ; \ a = tmp ; \ } void sha1_transform (uint32_t *buf, uint32_t const *in) { uint32_t a = buf[0], b = buf[1], c = buf[2], d = buf[3], e = buf[4] ; uint32_t w[80] ; unsigned int i = 0 ; for (; i < 16 ; i++) w[i] = in[i] ; for (; i < 80 ; i++) { w[i] = w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16] ; w[i] = (w[i]<<1) | (w[i]>>31) ; } for (i = 0 ; i < 20 ; i++) SHA1STEP(F1, w[i] + 0x5a827999U) ; for (; i < 40 ; i++) SHA1STEP(F2, w[i] + 0x6ed9eba1U) ; for (; i < 60 ; i++) SHA1STEP(F3, w[i] + 0x8f1bbcdcU) ; for (; i < 80 ; i++) SHA1STEP(F4, w[i] + 0xca62c1d6U) ; buf[0] += a ; buf[1] += b ; buf[2] += c ; buf[3] += d ; buf[4] += e ; } skalibs-2.9.1.0/src/libstdcrypto/sha1_update.c000066400000000000000000000003411355335115400211670ustar00rootroot00000000000000/* ISC license. */ #include #include "sha1-internal.h" void sha1_update (SHA1Schedule *ctx, char const *buf, size_t len) { size_t i = 0 ; for (; i < len ; i++) sha1_feed(ctx, (unsigned char)buf[i]) ; } skalibs-2.9.1.0/src/libstdcrypto/sha256-internal.h000066400000000000000000000003741355335115400216260ustar00rootroot00000000000000/* ISC license. */ #ifndef SHA256_INTERNAL_H #define SHA256_INTERNAL_H #include #include extern void sha256_feed (SHA256Schedule *, unsigned char) ; extern void sha256_transform (uint32_t *, uint32_t const *) ; #endif skalibs-2.9.1.0/src/libstdcrypto/sha256_feed.c000066400000000000000000000010011355335115400207560ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include "sha256-internal.h" void sha256_feed (SHA256Schedule *ctx, unsigned char inb) { uint32_t tmp ; ctx->in[ctx->b>>2] <<= 8 ; ctx->in[ctx->b>>2] |= T8(inb) ; if (++ctx->b >= 64) { unsigned int i = 0 ; sha256_transform(ctx->buf, ctx->in) ; ctx->b = 0 ; for (; i < 16 ; i++) ctx->in[i] = 0 ; } tmp = ctx->bits[0] ; ctx->bits[0] += 8 ; if (tmp > ctx->bits[0]) ctx->bits[1]++ ; } skalibs-2.9.1.0/src/libstdcrypto/sha256_final.c000066400000000000000000000015011355335115400211510ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include "sha256-internal.h" void sha256_final (SHA256Schedule *ctx, char *digest) { unsigned int i = 0 ; unsigned char *p = (unsigned char *)digest ; uint32_t bits[2] = { ctx->bits[0], ctx->bits[1] } ; sha256_feed(ctx, 0x80) ; while (ctx->b != 56) sha256_feed(ctx, 0) ; sha256_feed(ctx, T8(bits[1]>>24)) ; sha256_feed(ctx, T8(bits[1]>>16)) ; sha256_feed(ctx, T8(bits[1]>>8)) ; sha256_feed(ctx, T8(bits[1])) ; sha256_feed(ctx, T8(bits[0]>>24)) ; sha256_feed(ctx, T8(bits[0]>>16)) ; sha256_feed(ctx, T8(bits[0]>>8)) ; sha256_feed(ctx, T8(bits[0])) ; for (; i < 8 ; i++) { *p++ = T8(ctx->buf[i]>>24) ; *p++ = T8(ctx->buf[i]>>16) ; *p++ = T8(ctx->buf[i]>>8) ; *p++ = T8(ctx->buf[i]) ; } } skalibs-2.9.1.0/src/libstdcrypto/sha256_init.c000066400000000000000000000002261355335115400210260ustar00rootroot00000000000000/* ISC license. */ #include void sha256_init (SHA256Schedule *ctx) { SHA256Schedule empty = SHA256_INIT() ; *ctx = empty ; } skalibs-2.9.1.0/src/libstdcrypto/sha256_transform.c000066400000000000000000000040321355335115400220750ustar00rootroot00000000000000/* ISC license. */ #include "sha256-internal.h" #define F1(x, y, z) ((x & y) | ((~x) & z)) #define F2(x, y, z) ((x & y) | (x & z) | (y & z)) #define ROTR(x,n) (((x)>>(n)) | ((x)<<(32-(n)))) #define CAPITALSIGMA0(x) (ROTR(x,2)^ROTR(x,13)^ROTR(x,22)) #define CAPITALSIGMA1(x) (ROTR(x,6)^ROTR(x,11)^ROTR(x,25)) #define SMALLSIGMA0(x) (ROTR(x,7)^ROTR(x,18)^((x)>>3)) #define SMALLSIGMA1(x) (ROTR(x,17)^ROTR(x,19)^((x)>>10)) static uint32_t const sha256_constants[64] = { 0x428a2f98U, 0x71374491U, 0xb5c0fbcfU, 0xe9b5dba5U, 0x3956c25bU, 0x59f111f1U, 0x923f82a4U, 0xab1c5ed5U, 0xd807aa98U, 0x12835b01U, 0x243185beU, 0x550c7dc3U, 0x72be5d74U, 0x80deb1feU, 0x9bdc06a7U, 0xc19bf174U, 0xe49b69c1U, 0xefbe4786U, 0x0fc19dc6U, 0x240ca1ccU, 0x2de92c6fU, 0x4a7484aaU, 0x5cb0a9dcU, 0x76f988daU, 0x983e5152U, 0xa831c66dU, 0xb00327c8U, 0xbf597fc7U, 0xc6e00bf3U, 0xd5a79147U, 0x06ca6351U, 0x14292967U, 0x27b70a85U, 0x2e1b2138U, 0x4d2c6dfcU, 0x53380d13U, 0x650a7354U, 0x766a0abbU, 0x81c2c92eU, 0x92722c85U, 0xa2bfe8a1U, 0xa81a664bU, 0xc24b8b70U, 0xc76c51a3U, 0xd192e819U, 0xd6990624U, 0xf40e3585U, 0x106aa070U, 0x19a4c116U, 0x1e376c08U, 0x2748774cU, 0x34b0bcb5U, 0x391c0cb3U, 0x4ed8aa4aU, 0x5b9cca4fU, 0x682e6ff3U, 0x748f82eeU, 0x78a5636fU, 0x84c87814U, 0x8cc70208U, 0x90befffaU, 0xa4506cebU, 0xbef9a3f7U, 0xc67178f2U } ; void sha256_transform (uint32_t *buf, uint32_t const *in) { uint32_t w[64] ; unsigned int i = 0 ; uint32_t a = buf[0], b = buf[1], c = buf[2], d = buf[3], e = buf[4], f = buf[5], g = buf[6], h = buf[7] ; for (; i < 16 ; i++) w[i] = in[i] ; for (; i < 64 ; i++) w[i] = SMALLSIGMA1(w[i-2]) + w[i-7] + SMALLSIGMA0(w[i-15]) + w[i-16] ; for (i = 0 ; i < 64 ; i++) { uint32_t temp1 = h + CAPITALSIGMA1(e) + F1(e, f, g) + sha256_constants[i] + w[i] ; uint32_t temp2 = CAPITALSIGMA0(a) + F2(a, b, c) ; h = g ; g = f ; f = e ; e = d + temp1 ; d = c ; c = b ; b = a ; a = temp1 + temp2 ; } buf[0] += a ; buf[1] += b ; buf[2] += c ; buf[3] += d ; buf[4] += e ; buf[5] += f ; buf[6] += g ; buf[7] += h ; } skalibs-2.9.1.0/src/libstdcrypto/sha256_update.c000066400000000000000000000003531355335115400213460ustar00rootroot00000000000000/* ISC license. */ #include #include "sha256-internal.h" void sha256_update (SHA256Schedule *ctx, char const *buf, size_t len) { size_t i = 0 ; for (; i < len ; i++) sha256_feed(ctx, (unsigned char)buf[i]) ; } skalibs-2.9.1.0/src/libstdcrypto/sha512-internal.h000066400000000000000000000002771355335115400216230ustar00rootroot00000000000000/* ISC license. */ #ifndef SHA512_INTERNAL_H #define SHA512_INTERNAL_H #include extern void sha512_transform (SHA512Schedule *ctx, unsigned char const *block) ; #endif skalibs-2.9.1.0/src/libstdcrypto/sha512_final.c000066400000000000000000000011401355335115400211430ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include "sha512-internal.h" void sha512_final (SHA512Schedule *ctx, char *digest) { unsigned int i = 0 ; unsigned int pad = ctx->len % 128; ctx->buf[pad++] = 0x80 ; if (pad > 112) { byte_zero(ctx->buf + pad, 128 - pad) ; sha512_transform(ctx, ctx->buf) ; pad = 0 ; } byte_zero(ctx->buf + pad, 120 - pad) ; uint64_pack_big((char *)ctx->buf + 120, ctx->len << 3) ; sha512_transform(ctx, ctx->buf) ; for (; i < 8 ; i++) uint64_pack_big(digest + (i << 3), ctx->h[i]) ; } skalibs-2.9.1.0/src/libstdcrypto/sha512_init.c000066400000000000000000000002261355335115400210210ustar00rootroot00000000000000/* ISC license. */ #include void sha512_init (SHA512Schedule *ctx) { SHA512Schedule empty = SHA512_INIT() ; *ctx = empty ; } skalibs-2.9.1.0/src/libstdcrypto/sha512_transform.c000066400000000000000000000064551355335115400221030ustar00rootroot00000000000000/* ISC license. */ #include #include #include "sha512-internal.h" static uint64_t ror (uint64_t n, unsigned int k) { return (n >> k) | (n << (64 - k)) ; } #undef Ch #undef Maj #undef S0 #undef S1 #undef R0 #undef R1 #define Ch(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) #define Maj(x, y, z) (((x) & (y)) | ((z) & ((x) | (y)))) #define S0(x) (ror((x), 28) ^ ror((x), 34) ^ ror((x), 39)) #define S1(x) (ror((x), 14) ^ ror((x), 18) ^ ror((x), 41)) #define R0(x) (ror((x), 1) ^ ror((x), 8) ^ ((x) >> 7)) #define R1(x) (ror((x), 19) ^ ror((x), 61) ^ ((x) >> 6)) void sha512_transform (SHA512Schedule *ctx, unsigned char const *block) { static uint64_t const K[80] = { 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL, 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL, 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, 0xd807aa98a3030242ULL, 0x12835b0145706fbeULL, 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL, 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL, 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL, 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, 0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL, 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL, 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL, 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL, 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, 0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL, 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL, 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL, 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL, 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, 0xd192e819d6ef5218ULL, 0xd69906245565a910ULL, 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL, 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL, 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL, 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, 0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL, 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL, 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL, 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL, 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, 0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL, 0x113f9804bef90daeULL, 0x1b710b35131c471bULL, 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL, 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL } ; uint64_t w[80] ; uint64_t h[8] ; uint64_t t[2] ; unsigned int i = 0 ; for (; i < 16 ; i++) uint64_unpack_big((char const *)block + (i << 3), w + i) ; for (; i < 80 ; i++) w[i] = R1(w[i-2]) + w[i-7] + R0(w[i-15]) + w[i-16] ; for (i = 0 ; i < 8 ; i++) h[i] = ctx->h[i] ; for (i = 0 ; i < 80 ; i++) { t[0] = h[7] + S1(h[4]) + Ch(h[4], h[5], h[6]) + K[i] + w[i] ; t[1] = S0(h[0]) + Maj(h[0], h[1], h[2]) ; h[7] = h[6] ; h[6] = h[5] ; h[5] = h[4] ; h[4] = h[3] + t[0] ; h[3] = h[2] ; h[2] = h[1] ; h[1] = h[0] ; h[0] = t[0] + t[1] ; } for (i = 0 ; i < 8 ; i++) ctx->h[i] += h[i] ; } skalibs-2.9.1.0/src/libstdcrypto/sha512_update.c000066400000000000000000000010771355335115400213450ustar00rootroot00000000000000/* ISC license. */ #include #include #include "sha512-internal.h" void sha512_update (SHA512Schedule *ctx, char const *buf, size_t len) { unsigned int pad = ctx->len & 0x7fU ; ctx->len += len ; if (pad && len >= 128 - pad) { memcpy((char *)ctx->buf + pad, buf, 128 - pad) ; buf += 128 - pad ; len -= 128 - pad ; pad = 0 ; sha512_transform(ctx, ctx->buf) ; } while (len >= 128) { sha512_transform(ctx, (unsigned char const *)buf) ; buf += 128 ; len -= 128 ; } memcpy((char *)ctx->buf + pad, buf, len) ; } skalibs-2.9.1.0/src/libstddjb/000077500000000000000000000000001355335115400160465ustar00rootroot00000000000000skalibs-2.9.1.0/src/libstddjb/alarm-internal.h000066400000000000000000000002371355335115400211270ustar00rootroot00000000000000/* ISC license. */ #ifndef ALARM_INTERNAL_H #define ALARM_INTERNAL_H #ifdef SKALIBS_HASTIMER #include extern timer_t timer_here ; #endif #endif skalibs-2.9.1.0/src/libstddjb/alarm_deadline.c000066400000000000000000000020741355335115400211360ustar00rootroot00000000000000/* ISC license. */ #include #include #include #ifdef SKALIBS_HASTIMER #include #include #include #include "alarm-internal.h" #undef MYCLOCK #ifdef SKALIBS_HASCLOCKMON # define MYCLOCK CLOCK_MONOTONIC #else # define MYCLOCK CLOCK_REALTIME #endif int alarm_deadline (tain_t const *deadline) { struct itimerspec it = { .it_interval = { .tv_sec = 0, .tv_nsec = 0 } } ; struct sigevent se = { .sigev_notify = SIGEV_SIGNAL, .sigev_signo = SIGALRM, .sigev_value = { .sival_int = 0 }, .sigev_notify_function = 0, .sigev_notify_attributes = 0 } ; if (!timespec_from_tain(&it.it_value, deadline)) return 0 ; if (timer_create(MYCLOCK, &se, &timer_here) < 0) return 0 ; if (timer_settime(timer_here, TIMER_ABSTIME, &it, 0) < 0) { int e = errno ; timer_delete(timer_here) ; errno = e ; return 0 ; } return 1 ; } #else int alarm_deadline (tain_t const *deadline) { tain_t tto ; tain_now(&tto) ; tain_sub(&tto, deadline, &tto) ; return alarm_timeout(&tto) ; } #endif skalibs-2.9.1.0/src/libstddjb/alarm_disable.c000066400000000000000000000013201355335115400207650ustar00rootroot00000000000000/* ISC license. */ #include #include #ifdef SKALIBS_HASTIMER #include #include "alarm-internal.h" timer_t timer_here ; void alarm_disable () { struct itimerspec stopit = { .it_value = { .tv_sec = 0, .tv_nsec = 0 }, .it_interval = { .tv_sec = 0, .tv_nsec = 0 } } ; timer_settime(timer_here, 0, &stopit, 0) ; timer_delete(timer_here) ; } #else #ifdef SKALIBS_HASITIMER #include void alarm_disable () { struct itimerval stopit = { .it_value = { .tv_sec = 0, .tv_usec = 0 }, .it_interval = { .tv_sec = 0, .tv_usec = 0 } } ; setitimer(ITIMER_REAL, &stopit, 0) ; } #else #include void alarm_disable () { alarm(0) ; } #endif #endif skalibs-2.9.1.0/src/libstddjb/alarm_milliseconds.c000066400000000000000000000025551355335115400220620ustar00rootroot00000000000000/* ISC license. */ #include #include #ifdef SKALIBS_HASTIMER #include #include #include #include "alarm-internal.h" #undef MYCLOCK #ifdef SKALIBS_HASCLOCKMON # define MYCLOCK CLOCK_MONOTONIC #else # define MYCLOCK CLOCK_REALTIME #endif int alarm_milliseconds (unsigned int t) { struct itimerspec it = { .it_interval = { .tv_sec = 0, .tv_nsec = 0 }, .it_value = { .tv_sec = t / 1000, .tv_nsec = 1000000 * (t % 1000) } } ; struct sigevent se = { .sigev_notify = SIGEV_SIGNAL, .sigev_signo = SIGALRM, .sigev_value = { .sival_int = 0 }, .sigev_notify_function = 0, .sigev_notify_attributes = 0 } ; if (timer_create(MYCLOCK, &se, &timer_here) < 0) return 0 ; if (timer_settime(timer_here, 0, &it, 0) < 0) { int e = errno ; timer_delete(timer_here) ; errno = e ; return 0 ; } return 1 ; } #else #ifdef SKALIBS_HASITIMER #include int alarm_milliseconds (unsigned int t) { struct itimerval it = { .it_interval = { .tv_sec = 0, .tv_usec = 0 }, .it_value = { .tv_sec = t / 1000, .tv_usec = 1000 * (t % 1000) } } ; if (setitimer(ITIMER_REAL, &it, 0) < 0) return 0 ; return 1 ; } #else #include #include int alarm_milliseconds (unsigned int t) { if (t > UINT_MAX - 999) return 0 ; t = (t + 999) / 1000 ; alarm(t) ; return 1 ; } #endif #endif skalibs-2.9.1.0/src/libstddjb/alarm_timeout.c000066400000000000000000000026471355335115400210650ustar00rootroot00000000000000/* ISC license. */ #include #include #include #ifdef SKALIBS_HASTIMER #include #include #include #include "alarm-internal.h" #undef MYCLOCK #ifdef SKALIBS_HASCLOCKMON # define MYCLOCK CLOCK_MONOTONIC #else # define MYCLOCK CLOCK_REALTIME #endif int alarm_timeout (tain_t const *tto) { struct itimerspec it = { .it_interval = { .tv_sec = 0, .tv_nsec = 0 } } ; struct sigevent se = { .sigev_notify = SIGEV_SIGNAL, .sigev_signo = SIGALRM, .sigev_value = { .sival_int = 0 }, .sigev_notify_function = 0, .sigev_notify_attributes = 0 } ; if (!timespec_from_tain_relative(&it.it_value, tto)) return 0 ; if (timer_create(MYCLOCK, &se, &timer_here) < 0) return 0 ; if (timer_settime(timer_here, 0, &it, 0) < 0) { int e = errno ; timer_delete(timer_here) ; errno = e ; return 0 ; } return 1 ; } #else #ifdef SKALIBS_HASITIMER #include int alarm_timeout (tain_t const *tto) { struct itimerval it = { .it_interval = { .tv_sec = 0, .tv_usec = 0 } } ; if (!timeval_from_tain_relative(&it.it_value, tto)) return 0 ; if (setitimer(ITIMER_REAL, &it, 0) < 0) return 0 ; return 1 ; } #else #include #include int alarm_timeout (tain_t const *tto) { int t = tain_to_millisecs(tto) ; if (t < 0 || t > INT_MAX - 999) return 0 ; t = (t + 999) / 1000 ; alarm(t) ; return 1 ; } #endif #endif skalibs-2.9.1.0/src/libstddjb/alloc.c000066400000000000000000000001741355335115400173060ustar00rootroot00000000000000/* ISC license. */ #include #include void *alloc (size_t n) { return malloc(n ? n : 1) ; } skalibs-2.9.1.0/src/libstddjb/alloc_realloc.c000066400000000000000000000003241355335115400210040ustar00rootroot00000000000000/* ISC license. */ #include #include int alloc_realloc (void **x, size_t n) { void *y = n ? realloc(*x, n) : (free(*x), alloc(0)) ; if (!y) return 0 ; *x = y ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/allread.c000066400000000000000000000002321355335115400176130ustar00rootroot00000000000000/* ISC license. */ #include size_t allread (int fd, char *buf, size_t len) { return allreadwrite(&fd_read, fd, buf, len) ; } skalibs-2.9.1.0/src/libstddjb/allreadv.c000066400000000000000000000003041355335115400200010ustar00rootroot00000000000000/* ISC license. */ #include #include size_t allreadv (int fd, struct iovec const *v, unsigned int vlen) { return allreadwritev(&fd_readv, fd, v, vlen) ; } skalibs-2.9.1.0/src/libstddjb/allreadwrite.c000066400000000000000000000005561355335115400206770ustar00rootroot00000000000000/* ISC license. */ #include #include size_t allreadwrite (iofunc_t_ref op, int fd, char *buf, size_t len) { size_t written = 0 ; while (len) { ssize_t w = (*op)(fd, buf, len) ; if (w <= 0) { if (!w) errno = 0 ; break ; } written += w ; buf += w ; len -= w ; } return written ; } skalibs-2.9.1.0/src/libstddjb/allreadwritev.c000066400000000000000000000007471355335115400210670ustar00rootroot00000000000000/* ISC license. */ #include #include #include size_t allreadwritev (iovfunc_t_ref op, int fd, struct iovec const *v, unsigned int vlen) { size_t written = 0 ; struct iovec vv[vlen ? vlen : 1] ; unsigned int i = vlen ; while (i--) vv[i] = v[i] ; while (siovec_len(vv, vlen)) { ssize_t w = (*op)(fd, vv, vlen) ; if (w <= 0) break ; w = siovec_seek(vv, vlen, w) ; written += w ; } return written ; } skalibs-2.9.1.0/src/libstddjb/allwrite.c000066400000000000000000000003271355335115400200370ustar00rootroot00000000000000/* ISC license. */ #include #include size_t allwrite (int fd, char const *buf, size_t len) { return allreadwrite((iofunc_t_ref)&fd_write, fd, (char *)buf, len) ; } skalibs-2.9.1.0/src/libstddjb/allwritev.c000066400000000000000000000003061355335115400202220ustar00rootroot00000000000000/* ISC license. */ #include #include size_t allwritev (int fd, struct iovec const *v, unsigned int vlen) { return allreadwritev(&fd_writev, fd, v, vlen) ; } skalibs-2.9.1.0/src/libstddjb/baprintf.c000066400000000000000000000004261355335115400200210ustar00rootroot00000000000000/* ISC license. */ #include #include #include int baprintf (bufalloc *ba, char const *format, ...) { va_list args ; int r ; va_start(args, format) ; r = vbaprintf(ba, format, args) ; va_end(args) ; return r ; } skalibs-2.9.1.0/src/libstddjb/bitarray_and.c000066400000000000000000000003311355335115400206460ustar00rootroot00000000000000/* ISC license. */ #include void bitarray_and (unsigned char *c, unsigned char const *a, unsigned char const *b, size_t n) { size_t i = bitarray_div8(n) ; while (i--) c[i] = a[i] & b[i] ; } skalibs-2.9.1.0/src/libstddjb/bitarray_clearsetn.c000066400000000000000000000011551355335115400220710ustar00rootroot00000000000000/* ISC license. */ #include void bitarray_clearsetn (unsigned char *s, size_t a, size_t b, int h) { if (!b) return ; b += a ; if ((a >> 3) == ((b-1) >> 3)) { unsigned char mask = (1 << (a & 7)) - 1 ^ (1 << 1 + (b-1 & 7)) - 1 ; if (h) s[a>>3] |= mask ; else s[a>>3] &= ~mask ; } else { unsigned char mask = ~((1 << (a & 7)) - 1) ; size_t i = (a>>3) + 1 ; if (h) s[a>>3] |= mask ; else s[a>>3] &= ~mask ; mask = h ? 0xff : 0x00 ; for (; i < b>>3 ; i++) s[i] = mask ; mask = (1 << (b & 7)) - 1 ; if (h) s[b>>3] |= mask ; else s[b>>3] &= ~mask ; } } skalibs-2.9.1.0/src/libstddjb/bitarray_count.c000066400000000000000000000010571355335115400212420ustar00rootroot00000000000000/* ISC license. */ #include #define B0(n) n, n+1, n+1, n+2 #define B1(n) B0(n), B0(n+1), B0(n+1), B0(n+2) #define B2(n) B1(n), B1(n+1), B1(n+1), B1(n+2) #define B3(n) B2(n), B2(n+1), B2(n+1), B2(n+2) size_t bitarray_countones (unsigned char const *c, size_t n) { static unsigned char const table[256] = { B3(0) } ; size_t len = bitarray_div8(n) ; size_t total = 0 ; size_t i = 0 ; if (n & 7) len-- ; for (; i < len ; i++) total += table[c[i]] ; if (n & 7) total += table[c[i] & ((1 << (n & 7)) - 1)] ; return total ; } skalibs-2.9.1.0/src/libstddjb/bitarray_firstclear.c000066400000000000000000000005001355335115400222400ustar00rootroot00000000000000/* ISC license. */ #include size_t bitarray_firstclear (unsigned char const *s, size_t max) { size_t n = bitarray_div8(max) ; size_t i = 0 ; for (; i < n ; i++) if (s[i] != 0xffU) break ; if (i == n) return max ; i <<= 3 ; while ((i < max) && bitarray_peek(s, i)) i++ ; return i ; } skalibs-2.9.1.0/src/libstddjb/bitarray_firstclear_skip.c000066400000000000000000000006101355335115400232700ustar00rootroot00000000000000/* ISC license. */ #include size_t bitarray_firstclear_skip (unsigned char const *s, size_t max, size_t skip) { size_t i = bitarray_div8(skip) ; size_t j = i << 3 > max ? max : i << 3 ; if (i && s[i-1] != 0xffU) { while ((skip < j) && bitarray_peek(s, skip)) skip++ ; if (skip < j) return skip ; } return j + bitarray_firstclear(s + i, max - j) ; } skalibs-2.9.1.0/src/libstddjb/bitarray_firstset.c000066400000000000000000000004661355335115400217600ustar00rootroot00000000000000/* ISC license. */ #include size_t bitarray_firstset (unsigned char const *s, size_t max) { size_t n = bitarray_div8(max) ; size_t i = 0 ; for (; i < n ; i++) if (s[i]) break ; if (i == n) return max ; i <<= 3 ; while ((i < max) && !bitarray_peek(s, i)) i++ ; return i ; } skalibs-2.9.1.0/src/libstddjb/bitarray_firstset_skip.c000066400000000000000000000005741355335115400230060ustar00rootroot00000000000000/* ISC license. */ #include size_t bitarray_firstset_skip (unsigned char const *s, size_t max, size_t skip) { size_t i = bitarray_div8(skip) ; size_t j = i << 3 > max ? max : i << 3 ; if (i && s[i-1]) { while ((skip < j) && !bitarray_peek(s, skip)) skip++ ; if (skip < j) return skip ; } return j + bitarray_firstset(s + i, max - j) ; } skalibs-2.9.1.0/src/libstddjb/bitarray_not.c000066400000000000000000000006151355335115400207110ustar00rootroot00000000000000/* ISC license. */ #include void bitarray_not (unsigned char *s, size_t a, size_t b) { if (!b) return ; b += a ; if ((a >> 3) == ((b-1) >> 3)) s[a>>3] ^= ((1 << (a & 7)) - 1) ^ ((a << (b & 7)) - 1) ; else { size_t i = (a>>3) + 1 ; s[a>>3] ^= ~((1 << (a & 7)) - 1) ; for (; i < (b>>3) ; i++) s[i] = ~s[i] ; s[b>>3] ^= (1 << (b & 7)) - 1 ; } } skalibs-2.9.1.0/src/libstddjb/bitarray_or.c000066400000000000000000000003301355335115400205230ustar00rootroot00000000000000/* ISC license. */ #include void bitarray_or (unsigned char *c, unsigned char const *a, unsigned char const *b, size_t n) { size_t i = bitarray_div8(n) ; while (i--) c[i] = a[i] | b[i] ; } skalibs-2.9.1.0/src/libstddjb/bitarray_testandpoke.c000066400000000000000000000003751355335115400224350ustar00rootroot00000000000000/* ISC license. */ #include int bitarray_testandpoke (unsigned char *s, size_t n, int h) { unsigned char mask = 1 << (n & 7) ; unsigned char c = s[n>>3] ; s[n>>3] = h ? c | mask : c & ~mask ; return (c & mask) ? 1 : 0 ; } skalibs-2.9.1.0/src/libstddjb/bitarray_xor.c000066400000000000000000000003311355335115400207140ustar00rootroot00000000000000/* ISC license. */ #include void bitarray_xor (unsigned char *c, unsigned char const *a, unsigned char const *b, size_t n) { size_t i = bitarray_div8(n) ; while (i--) c[i] = a[i] ^ b[i] ; } skalibs-2.9.1.0/src/libstddjb/bprintf.c000066400000000000000000000004161355335115400176570ustar00rootroot00000000000000/* ISC license. */ #include #include #include int bprintf (buffer *b, char const *format, ...) { va_list args ; int r ; va_start(args, format) ; r = vbprintf(b, format, args) ; va_end(args) ; return r ; } skalibs-2.9.1.0/src/libstddjb/bufalloc_1.c000066400000000000000000000002331355335115400202170ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include bufalloc bufalloc_1_ = BUFALLOC_INIT(&fd_write, 1) ; skalibs-2.9.1.0/src/libstddjb/bufalloc_2.c000066400000000000000000000002331355335115400202200ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include bufalloc bufalloc_2_ = BUFALLOC_INIT(&fd_write, 2) ; skalibs-2.9.1.0/src/libstddjb/bufalloc_clean.c000066400000000000000000000003471355335115400211470ustar00rootroot00000000000000/* ISC license. */ #include #include void bufalloc_clean (bufalloc *ba) { if (ba->p) { memmove(ba->x.s, ba->x.s + ba->p, ba->x.len - ba->p) ; ba->x.len -= ba->p ; ba->p = 0 ; } } skalibs-2.9.1.0/src/libstddjb/bufalloc_flush.c000066400000000000000000000004431355335115400212030ustar00rootroot00000000000000/* ISC license. */ #include #include #include int bufalloc_flush (bufalloc *ba) { ba->p += allreadwrite((iofunc_t_ref)ba->op, ba->fd, ba->x.s + ba->p, ba->x.len - ba->p) ; bufalloc_clean(ba) ; return !ba->x.len ; } skalibs-2.9.1.0/src/libstddjb/bufalloc_getfd.c000066400000000000000000000001721355335115400211520ustar00rootroot00000000000000/* ISC license. */ #include int bufalloc_getfd (bufalloc const *ba) { return bufalloc_fd(ba) ; } skalibs-2.9.1.0/src/libstddjb/bufalloc_getlen.c000066400000000000000000000001771355335115400213440ustar00rootroot00000000000000/* ISC license. */ #include size_t bufalloc_getlen (bufalloc const *ba) { return bufalloc_len(ba) ; } skalibs-2.9.1.0/src/libstddjb/bufalloc_init.c000066400000000000000000000003611355335115400210240ustar00rootroot00000000000000/* ISC license. */ #include #include void bufalloc_init (bufalloc *ba, ssize_t (*op)(int, char const *, size_t), int fd) { ba->x = stralloc_zero ; ba->op = op ; ba->fd = fd ; ba->p = 0 ; } skalibs-2.9.1.0/src/libstddjb/buffer_0.c000066400000000000000000000003101355335115400176740ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include static char buf[BUFFER_INSIZE] ; buffer buffer_0_ = BUFFER_INIT(&fd_readv, 0, buf, BUFFER_INSIZE) ; skalibs-2.9.1.0/src/libstddjb/buffer_0f1.c000066400000000000000000000002611355335115400201300ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include static char buf[BUFFER_INSIZE] ; buffer buffer_0f1_ = BUFFER_INIT(&buffer_flush1read, 0, buf, BUFFER_INSIZE) ; skalibs-2.9.1.0/src/libstddjb/buffer_0small.c000066400000000000000000000003311355335115400207300ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include static char buf[BUFFER_INSIZE_SMALL] ; buffer buffer_0small_ = BUFFER_INIT(&fd_readv, 0, buf, BUFFER_INSIZE_SMALL) ; skalibs-2.9.1.0/src/libstddjb/buffer_1.c000066400000000000000000000003131355335115400177000ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include static char buf[BUFFER_OUTSIZE] ; buffer buffer_1_ = BUFFER_INIT(&fd_writev, 1, buf, BUFFER_OUTSIZE) ; skalibs-2.9.1.0/src/libstddjb/buffer_1small.c000066400000000000000000000003341355335115400207340ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include static char buf[BUFFER_OUTSIZE_SMALL] ; buffer buffer_1small_ = BUFFER_INIT(&fd_writev, 1, buf, BUFFER_OUTSIZE_SMALL) ; skalibs-2.9.1.0/src/libstddjb/buffer_2.c000066400000000000000000000003131355335115400177010ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include static char buf[BUFFER_ERRSIZE] ; buffer buffer_2_ = BUFFER_INIT(&fd_writev, 2, buf, BUFFER_ERRSIZE) ; skalibs-2.9.1.0/src/libstddjb/buffer_fill.c000066400000000000000000000005121355335115400204670ustar00rootroot00000000000000/* ISC license. */ #include #include #include ssize_t buffer_fill (buffer *b) { struct iovec v[2] ; ssize_t r ; if (buffer_isfull(b)) return (errno = ENOBUFS, -1) ; buffer_wpeek(b, v) ; r = (*b->op)(b->fd, v, 2) ; if (r <= 0) return r ; buffer_wseek(b, r) ; return r ; } skalibs-2.9.1.0/src/libstddjb/buffer_flush.c000066400000000000000000000005561355335115400206720ustar00rootroot00000000000000/* ISC license. */ #include #include #include int buffer_flush (buffer *b) { for (;;) { struct iovec v[2] ; ssize_t r ; buffer_rpeek(b, v) ; if (!v[0].iov_len && !v[1].iov_len) break ; r = (*b->op)(b->fd, v, 2) ; if (r <= 0) return 0 ; cbuffer_RSEEK(&b->c, r) ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/buffer_flush1read.c000066400000000000000000000003771355335115400216100ustar00rootroot00000000000000/* ISC license. */ #include #include #include ssize_t buffer_flush1read (int fd, struct iovec const *v, unsigned int n) { if (!buffer_flush(buffer_1)) return -1 ; return fd_readv(fd, v, n) ; } skalibs-2.9.1.0/src/libstddjb/buffer_get.c000066400000000000000000000004361355335115400203250ustar00rootroot00000000000000/* ISC license. */ #include #include ssize_t buffer_get (buffer *b, char *s, size_t len) { size_t w = 0 ; int r = buffer_getall(b, s, len, &w) ; return r == -1 ? errno == EPIPE ? (errno = 0, w) : -1 : !r ? (errno = EWOULDBLOCK, -1) : w ; } skalibs-2.9.1.0/src/libstddjb/buffer_getall.c000066400000000000000000000006321355335115400210140ustar00rootroot00000000000000/* ISC license. */ #include #include #include int buffer_getall (buffer *b, char *buf, size_t len, size_t *w) { if (*w > len) return (errno = EINVAL, -1) ; for (;;) { ssize_t r ; *w += buffer_getnofill(b, buf + *w, len - *w) ; if (*w >= len) break ; r = sanitize_read(buffer_fill(b)) ; if (r <= 0) return r ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/buffer_getallnf.c000066400000000000000000000004131355335115400213350ustar00rootroot00000000000000/* ISC license. */ #include #include int buffer_getallnofill (buffer *b, char *s, size_t len) { size_t r = buffer_getnofill(b, s, len) ; if (r < len) { buffer_unget(b, r) ; return (errno = ENOBUFS, 0) ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/buffer_getfd.c000066400000000000000000000001601355335115400206310ustar00rootroot00000000000000/* ISC license. */ #include int buffer_getfd (buffer const *b) { return buffer_fd(b) ; } skalibs-2.9.1.0/src/libstddjb/buffer_getlen.c000066400000000000000000000001651355335115400210230ustar00rootroot00000000000000/* ISC license. */ #include size_t buffer_getlen (buffer const *b) { return buffer_len(b) ; } skalibs-2.9.1.0/src/libstddjb/buffer_getv.c000066400000000000000000000004331355335115400205100ustar00rootroot00000000000000/* ISC license. */ #include #include #include ssize_t buffer_getv (buffer *b, struct iovec const *v, unsigned int n) { size_t w = 0 ; ssize_t r = unsanitize_read(buffer_getvall(b, v, n, &w)) ; return r <= 0 ? r : w ; } skalibs-2.9.1.0/src/libstddjb/buffer_getvall.c000066400000000000000000000012711355335115400212020ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int buffer_getvall (buffer *b, struct iovec const *v, unsigned int n, size_t *written) { size_t len = siovec_len(v, n) ; struct iovec vv[n ? n : 1] ; if (*written > len) return (errno = EINVAL, -1) ; { unsigned int i = n ; while (i--) vv[i] = v[i] ; } siovec_seek(vv, n, *written) ; for (;;) { ssize_t r ; size_t w = buffer_getvnofill(b, vv, n) ; *written += w ; if (*written >= len) break ; siovec_seek(vv, n, w) ; r = sanitize_read(buffer_fill(b)) ; if (r <= 0) return r ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/buffer_getvallnf.c000066400000000000000000000005331355335115400215260ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int buffer_getvallnofill (buffer *b, struct iovec const *v, unsigned int n) { size_t r = buffer_getvnofill(b, v, n) ; if (r < siovec_len(v, n)) { buffer_unget(b, r) ; return (errno = ENOBUFS, 0) ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/buffer_init.c000066400000000000000000000004121355335115400205030ustar00rootroot00000000000000/* ISC license. */ #include #include #include int buffer_init (buffer *b, iovfunc_t_ref op, int fd, char *s, size_t len) { if (!cbuffer_init(&b->c, s, len)) return 0 ; b->fd = fd ; b->op = op ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/buffer_put.c000066400000000000000000000002761355335115400203600ustar00rootroot00000000000000/* ISC license. */ #include ssize_t buffer_put (buffer *b, char const *s, size_t len) { size_t w = 0 ; if (!buffer_putall(b, s, len, &w)) return -1 ; return w ; } skalibs-2.9.1.0/src/libstddjb/buffer_putall.c000066400000000000000000000005741355335115400210520ustar00rootroot00000000000000/* ISC license. */ #include #include int buffer_putall (buffer *b, char const *s, size_t len, size_t *written) { if (*written > len) return (errno = EINVAL, 0) ; for (;;) { *written += buffer_putnoflush(b, s + *written, len - *written) ; if (*written >= len) return 1 ; buffer_flush(b) ; if (buffer_isfull(b)) return 0 ; } } skalibs-2.9.1.0/src/libstddjb/buffer_putallnf.c000066400000000000000000000004241355335115400213700ustar00rootroot00000000000000/* ISC license. */ #include #include int buffer_putallnoflush (buffer *b, char const *s, size_t len) { ssize_t r = buffer_putnoflush(b, s, len) ; if (r < len) { buffer_unput(b, r) ; return (errno = ENOBUFS, 0) ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/buffer_putflush.c000066400000000000000000000003441355335115400214160ustar00rootroot00000000000000/* ISC license. */ #include ssize_t buffer_putflush (buffer *b, char const *s, size_t len) { ssize_t r = buffer_put(b, s, len) ; if (r < 0) return -1 ; if (!buffer_flush(b)) return -1 ; return r ; } skalibs-2.9.1.0/src/libstddjb/buffer_puts.c000066400000000000000000000002371355335115400205400ustar00rootroot00000000000000/* ISC license. */ #include #include ssize_t buffer_puts (buffer *b, char const *s) { return buffer_put(b, s, strlen(s)) ; } skalibs-2.9.1.0/src/libstddjb/buffer_putsall.c000066400000000000000000000002571355335115400212330ustar00rootroot00000000000000/* ISC license. */ #include #include int buffer_putsall (buffer *b, char const *s, size_t *w) { return buffer_putall(b, s, strlen(s), w) ; } skalibs-2.9.1.0/src/libstddjb/buffer_putsallflush.c000066400000000000000000000002711355335115400222710ustar00rootroot00000000000000/* ISC license. */ #include #include int buffer_putsallflush (buffer *b, char const *s, size_t *w) { return buffer_putallflush(b, s, strlen(s), w) ; } skalibs-2.9.1.0/src/libstddjb/buffer_putsallnoflush.c000066400000000000000000000002571355335115400226320ustar00rootroot00000000000000/* ISC license. */ #include #include int buffer_putsallnoflush (buffer *b, char const *s) { return buffer_putallnoflush(b, s, strlen(s)) ; } skalibs-2.9.1.0/src/libstddjb/buffer_putsflush.c000066400000000000000000000002511355335115400215760ustar00rootroot00000000000000/* ISC license. */ #include #include ssize_t buffer_putsflush (buffer *b, char const *s) { return buffer_putflush(b, s, strlen(s)) ; } skalibs-2.9.1.0/src/libstddjb/buffer_putsnoflush.c000066400000000000000000000002541355335115400221360ustar00rootroot00000000000000/* ISC license. */ #include #include size_t buffer_putsnoflush (buffer *b, char const *s) { return buffer_putnoflush(b, s, strlen(s)) ; } skalibs-2.9.1.0/src/libstddjb/buffer_putv.c000066400000000000000000000003331355335115400205400ustar00rootroot00000000000000/* ISC license. */ #include #include ssize_t buffer_putv (buffer *b, struct iovec const *v, unsigned int n) { size_t w = 0 ; return buffer_putvall(b, v, n, &w) ? (ssize_t)w : -1 ; } skalibs-2.9.1.0/src/libstddjb/buffer_putvall.c000066400000000000000000000011141355335115400212270ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int buffer_putvall (buffer *b, struct iovec const *v, unsigned int n, size_t *written) { size_t len = siovec_len(v, n) ; size_t w = n ; struct iovec vv[n ? n : 1] ; if (*written > len) return (errno = EINVAL, 0) ; while (w--) vv[w] = v[w] ; w = *written ; for (;;) { siovec_seek(vv, n, w) ; w = buffer_putvnoflush(b, vv, n) ; *written += w ; if (*written >= len) return 1 ; buffer_flush(b) ; if (buffer_isfull(b)) return 0 ; } } skalibs-2.9.1.0/src/libstddjb/buffer_putvallnf.c000066400000000000000000000005351355335115400215610ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int buffer_putvallnoflush (buffer *b, struct iovec const *v, unsigned int n) { size_t r = buffer_putvnoflush(b, v, n) ; if (r < siovec_len(v, n)) { buffer_unput(b, r) ; return (errno = ENOBUFS, 0) ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/buffer_putvflush.c000066400000000000000000000004051355335115400216020ustar00rootroot00000000000000/* ISC license. */ #include #include ssize_t buffer_putvflush (buffer *b, struct iovec const *v, unsigned int n) { ssize_t r = buffer_putv(b, v, n) ; if (r < 0) return -1 ; if (!buffer_flush(b)) return -1 ; return r ; } skalibs-2.9.1.0/src/libstddjb/byte_chr.c000066400000000000000000000002721355335115400200120ustar00rootroot00000000000000/* ISC license. */ #include #include size_t byte_chr (char const *s, size_t n, int c) { void *p = memchr(s, c, n) ; return p ? (char *)p - s : n ; } skalibs-2.9.1.0/src/libstddjb/byte_count.c000066400000000000000000000002571355335115400203710ustar00rootroot00000000000000/* ISC license. */ #include size_t byte_count (char const *s, size_t len, char b) { size_t n = 0 ; while (len--) if (*s++ == b) n++ ; return n ; } skalibs-2.9.1.0/src/libstddjb/byte_in.c000066400000000000000000000003751355335115400176500ustar00rootroot00000000000000/* ISC license. */ #include #include size_t byte_in (char const *s, size_t n, char const *sep, size_t len) { char const *t = s ; while (n--) { if (memchr(sep, *t, len)) break ; ++t ; } return t - s ; } skalibs-2.9.1.0/src/libstddjb/byte_rchr.c000066400000000000000000000003121355335115400201670ustar00rootroot00000000000000/* ISC license. */ #include size_t byte_rchr (char const *s, size_t n, int c) { size_t i = n ; char ch = c ; s += n ; while (i--) if (*--s == ch) return i ; return n ; } skalibs-2.9.1.0/src/libstddjb/byte_search.c000066400000000000000000000004411355335115400205010ustar00rootroot00000000000000/* ISC license. */ #include #include #include 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 ; } skalibs-2.9.1.0/src/libstddjb/byte_zzero.c000066400000000000000000000010511355335115400204030ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASEXPLICIT_BZERO #include #include #include #include void byte_zzero (char *s, size_t n) { explicit_bzero(s, n) ; } #else #include #include #include void _byte_zzero_hook (char *, size_t) gccattr_weak ; gccattr_weak void _byte_zzero_hook (char *s, size_t n) { } void byte_zzero (char *s, size_t n) { memset(s, 0, n) ; _byte_zzero_hook(s, n) ; } #endif skalibs-2.9.1.0/src/libstddjb/case_lowerb.c000066400000000000000000000003231355335115400204750ustar00rootroot00000000000000/* ISC license. */ #include void case_lowerb (char *s, size_t len) { unsigned char const d = 'a' - 'A' ; while (len--) { if (('A' <= *s) && (*s <= 'Z')) *s += d ; ++s ; } } skalibs-2.9.1.0/src/libstddjb/case_lowers.c000066400000000000000000000003041355335115400205150ustar00rootroot00000000000000/* ISC license. */ #include void case_lowers (char *s) { unsigned char const d = 'a' - 'A' ; while (*s) { if (('A' <= *s) && (*s <= 'Z')) *s += d ; ++s ; } } skalibs-2.9.1.0/src/libstddjb/case_startb.c000066400000000000000000000003551355335115400205070ustar00rootroot00000000000000/* ISC license. */ #include #include #include int case_startb (char const *s, size_t slen, char const *t) { size_t tlen = strlen(t) ; return slen < tlen ? 0 : !strncasecmp(s, t, tlen) ; } skalibs-2.9.1.0/src/libstddjb/case_str.c000066400000000000000000000012211355335115400200110ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASSTRCASESTR #include #include #include size_t case_str (char const *haystack, char const *needle) { char *p = strcasestr(haystack, needle) ; return p ? p - haystack : strlen(haystack) ; } #else #include #include #include size_t case_str (char const *haystack, char const *needle) { size_t nlen = strlen(needle) ; char const *p = haystack ; if (!nlen) return 0 ; for (; *p ; p++) if (!strncasecmp(p, needle, nlen)) return p - haystack ; return strlen(haystack) ; } #endif skalibs-2.9.1.0/src/libstddjb/case_upperb.c000066400000000000000000000003231355335115400205000ustar00rootroot00000000000000/* ISC license. */ #include void case_upperb (char *s, size_t len) { unsigned char const d = 'a' - 'A' ; while (len--) { if (('a' <= *s) && (*s <= 'z')) *s -= d ; ++s ; } } skalibs-2.9.1.0/src/libstddjb/case_uppers.c000066400000000000000000000003041355335115400205200ustar00rootroot00000000000000/* ISC license. */ #include void case_uppers (char *s) { unsigned char const d = 'a' - 'A' ; while (*s) { if (('a' <= *s) && (*s <= 'z')) *s -= d ; ++s ; } } skalibs-2.9.1.0/src/libstddjb/cbuffer_get.c000066400000000000000000000004341355335115400204660ustar00rootroot00000000000000/* ISC license. */ #include #include #include size_t cbuffer_get (cbuffer_t *b, char *s, size_t len) { struct iovec v[2] ; size_t w ; cbuffer_rpeek(b, v) ; w = siovec_gather(v, 2, s, len) ; return cbuffer_RSEEK(b, w) ; } skalibs-2.9.1.0/src/libstddjb/cbuffer_getv.c000066400000000000000000000004641355335115400206570ustar00rootroot00000000000000/* ISC license. */ #include #include #include size_t cbuffer_getv (cbuffer_t *b, struct iovec const *v, unsigned int n) { struct iovec vsrc[2] ; size_t w ; cbuffer_rpeek(b, vsrc) ; w = siovec_deal(v, n, vsrc, 2) ; return cbuffer_RSEEK(b, w) ; } skalibs-2.9.1.0/src/libstddjb/cbuffer_init.c000066400000000000000000000003471355335115400206550ustar00rootroot00000000000000/* ISC license. */ #include #include int cbuffer_init (cbuffer_t *b, char *s, size_t len) { if (len < 2) return (errno = EINVAL, 0) ; b->x = s ; b->a = len ; b->p = b->n = 0 ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/cbuffer_put.c000066400000000000000000000004431355335115400205170ustar00rootroot00000000000000/* ISC license. */ #include #include #include size_t cbuffer_put (cbuffer_t *b, char const *s, size_t len) { struct iovec v[2] ; size_t w ; cbuffer_wpeek(b, v) ; w = siovec_scatter(v, 2, s, len) ; return cbuffer_WSEEK(b, w) ; } skalibs-2.9.1.0/src/libstddjb/cbuffer_putv.c000066400000000000000000000004671355335115400207130ustar00rootroot00000000000000/* ISC license. */ #include #include #include size_t cbuffer_putv (cbuffer_t *b, struct iovec const *v, unsigned int n) { struct iovec vdest[2] ; size_t w ; cbuffer_wpeek(b, vdest) ; w = siovec_deal(vdest, 2, v, n) ; return cbuffer_WSEEK(b, w) ; } skalibs-2.9.1.0/src/libstddjb/cbuffer_rpeek.c000066400000000000000000000005651355335115400210220ustar00rootroot00000000000000/* ISC license. */ #include #include void cbuffer_rpeek (cbuffer_t const *b, struct iovec *v) { v[0].iov_base = b->x + b->p ; if (b->n >= b->p) { v[0].iov_len = b->n - b->p ; v[1].iov_base = 0 ; v[1].iov_len = 0 ; } else { v[0].iov_len = b->a - b->p ; v[1].iov_base = b->x ; v[1].iov_len = b->n ; } } skalibs-2.9.1.0/src/libstddjb/cbuffer_rseek.c000066400000000000000000000003041355335115400210140ustar00rootroot00000000000000/* ISC license. */ #include size_t cbuffer_rseek (cbuffer_t *b, size_t len) { size_t max = cbuffer_len(b) ; if (len > max) len = max ; return cbuffer_RSEEK(b, len) ; } skalibs-2.9.1.0/src/libstddjb/cbuffer_unget.c000066400000000000000000000003121355335115400210240ustar00rootroot00000000000000/* ISC license. */ #include size_t cbuffer_unget (cbuffer_t *b, size_t len) { size_t max = cbuffer_available(b) ; if (len > max) len = max ; return cbuffer_UNGET(b, len) ; } skalibs-2.9.1.0/src/libstddjb/cbuffer_unput.c000066400000000000000000000003041355335115400210560ustar00rootroot00000000000000/* ISC license. */ #include size_t cbuffer_unput (cbuffer_t *b, size_t len) { size_t max = cbuffer_len(b) ; if (len > max) len = max ; return cbuffer_UNPUT(b, len) ; } skalibs-2.9.1.0/src/libstddjb/cbuffer_wpeek.c000066400000000000000000000006401355335115400210210ustar00rootroot00000000000000/* ISC license. */ #include #include void cbuffer_wpeek (cbuffer_t const *b, struct iovec *v) { size_t last = (b->a - 1 + b->p) % b->a ; v[0].iov_base = b->x + b->n ; if (last >= b->n) { v[0].iov_len = last - b->n ; v[1].iov_base = 0 ; v[1].iov_len = 0 ; } else { v[0].iov_len = b->a - b->n ; v[1].iov_base = b->x ; v[1].iov_len = last ; } } skalibs-2.9.1.0/src/libstddjb/cbuffer_wseek.c000066400000000000000000000003131355335115400210210ustar00rootroot00000000000000/* ISC license. */ #include size_t cbuffer_wseek (cbuffer_t *b, size_t len) { size_t max = cbuffer_available(b) ; if (len > max) len = max ; return cbuffer_WSEEK(b, len) ; } skalibs-2.9.1.0/src/libstddjb/cdb_findnext.c000066400000000000000000000027701355335115400206470ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include static int match (struct cdb *c, char const *key, unsigned int len, uint32_t pos) { char buf[1024] ; while (len > 0) { unsigned int n = 1024 ; if (n > len) n = len ; if (cdb_read(c, buf, n, pos) < 0) return -1 ; if (memcmp(buf, key, n)) return 0 ; pos += n ; key += n ; len -= n ; } return 1 ; } int cdb_findnext (struct cdb *c, char const *key, unsigned int len) { char buf[8] ; uint32_t pos ; uint32_t u ; if (!c->loop) { u = cdb_hash(key, len) ; if (cdb_read(c, buf, 8, (u << 3) & 2047) < 0) return -1 ; uint32_unpack(buf + 4, &c->hslots) ; if (!c->hslots) return 0 ; uint32_unpack(buf, &c->hpos) ; c->khash = u ; u >>= 8 ; u %= c->hslots ; u <<= 3 ; c->kpos = c->hpos + u ; } while (c->loop < c->hslots) { if (cdb_read(c, buf, 8, c->kpos) < 0) return -1 ; uint32_unpack(buf + 4, &pos) ; if (!pos) return 0 ; c->loop++ ; c->kpos += 8 ; if (c->kpos == c->hpos + (c->hslots << 3)) c->kpos = c->hpos ; uint32_unpack(buf, &u) ; if (u == c->khash) { if (cdb_read(c, buf, 8, pos) < 0) return -1 ; uint32_unpack(buf, &u) ; if (u == len) switch (match(c, key, len, pos + 8)) { case -1: return -1 ; case 1: uint32_unpack(buf + 4, &c->dlen) ; c->dpos = pos + 8 + len ; return 1 ; } } } return 0 ; } skalibs-2.9.1.0/src/libstddjb/cdb_free.c000066400000000000000000000002471355335115400177460ustar00rootroot00000000000000/* ISC license. */ #include #include extern void cdb_free (struct cdb *c) { if (c->map) munmap(c->map, c->size) ; *c = cdb_zero ; } skalibs-2.9.1.0/src/libstddjb/cdb_hash.c000066400000000000000000000004341355335115400177460ustar00rootroot00000000000000/* ISC license. */ #include uint32_t cdb_hashadd (uint32_t h, unsigned char c) { h += (h << 5) ; return h ^ c ; } uint32_t cdb_hash (char const *buf, unsigned int len) { uint32_t h = CDB_HASHSTART ; while (len--) h = cdb_hashadd(h, *buf++) ; return h ; } skalibs-2.9.1.0/src/libstddjb/cdb_init_map.c000066400000000000000000000011041355335115400206160ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include int cdb_init_map (struct cdb *c, int fd, int domap) { if (domap) { struct stat st ; char *map ; if (fstat(fd, &st) < 0) return 0 ; if (st.st_size > UINT32_MAX) return (errno = EOVERFLOW, 0) ; map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0) ; if (map == MAP_FAILED) return 0 ; c->fd = -fd-2 ; c->map = map ; c->size = st.st_size ; } else c->fd = fd ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/cdb_make.c000066400000000000000000000065561355335115400177530ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include #include int cdb_make_start (struct cdb_make *c, int fd) { c->hplist = genalloc_zero ; c->pos = 2048 ; buffer_init(&c->b, &buffer_write, fd, c->buf, BUFFER_OUTSIZE) ; if (lseek(fd, c->pos, SEEK_SET) < 0) return -1 ; return 0 ; } static int posplus (struct cdb_make *c, uint32_t len) { uint32_t newpos = c->pos + len ; if (newpos < len) return (errno = ENOMEM, 0) ; c->pos = newpos ; return 1 ; } static inline int cdb_make_addend (struct cdb_make *c, unsigned int keylen, unsigned int datalen, uint32_t h) { diuint32 blah = { .left = h, .right = c->pos } ; return genalloc_append(diuint32, &c->hplist, &blah) && posplus(c, 8) && posplus(c, keylen) && posplus(c, datalen) ; } static inline ssize_t cdb_make_addbegin (struct cdb_make *c, unsigned int keylen, unsigned int datalen) { char buf[8] ; uint32_pack(buf, (uint32_t)keylen) ; uint32_pack(buf + 4, (uint32_t)datalen) ; return buffer_put(&c->b, buf, 8) ; } int cdb_make_add (struct cdb_make *c, char const *key, unsigned int keylen, char const *data, unsigned int datalen) { if (cdb_make_addbegin(c, keylen, datalen) < 0 || buffer_put(&c->b, key, keylen) < 0 || buffer_put(&c->b, data, datalen) < 0 || !cdb_make_addend(c, keylen, datalen, cdb_hash(key, keylen))) { genalloc_free(diuint32, &c->hplist) ; return -1 ; } return 0 ; } int cdb_make_finish (struct cdb_make *c) { uint32_t count[256] ; uint32_t start[256] ; char final[2048] ; unsigned int size = 1 ; unsigned int n = genalloc_len(diuint32, &c->hplist) ; unsigned int i = 0 ; diuint32 *hp = genalloc_s(diuint32, &c->hplist) ; for (; i < 256 ; i++) count[i] = 0 ; for (i = 0 ; i < n ; i++) ++count[hp[i].left & 255] ; { uint32_t u = 0 ; for (i = 0 ; i < 256 ; i++) start[i] = u += count[i] ; /* bounded by n */ for (i = 0 ; i < 256 ; i++) { u = count[i] << 1 ; if (u > size) size = u ; } size += n ; /* no overflow possible up to now */ u = 0xffffffffUL ; u /= sizeof(diuint32) ; if (size > u) return (errno = ENOMEM, -1) ; } i = n ; { diuint32 split[size] ; while (i--) split[--start[hp[i].left & 255]] = hp[i] ; genalloc_free(diuint32, &c->hplist) ; hp = split + n ; for (i = 0 ; i < 256 ; ++i) { char buf[8] ; uint32_t k = count[i] ; uint32_t len = k << 1 ; /* no overflow possible */ diuint32 *p = split + start[i] ; unsigned int j = 0 ; uint32_pack(final + (i << 3), c->pos) ; uint32_pack(final + (i << 3) + 4, len) ; for (; j < len ; j++) hp[j].left = hp[j].right = 0 ; for (j = 0 ; j < k ; j++) { uint32_t where = (p->left >> 8) % len ; while (hp[where].right) if (++where == len) where = 0 ; hp[where] = *p++ ; } for (j = 0 ; j < len ; j++) { uint32_pack(buf, hp[j].left) ; uint32_pack(buf + 4, hp[j].right) ; if (buffer_put(&c->b, buf, 8) < 0) return -1 ; if (!posplus(c, 8)) return -1 ; } } } if (!buffer_flush(&c->b)) return -1 ; if (lseek(buffer_fd(&c->b), 0, SEEK_SET) < 0) return -1 ; if (buffer_putflush(&c->b, final, 2048) < 0) return -1 ; return 0 ; } skalibs-2.9.1.0/src/libstddjb/cdb_mapfile.c000066400000000000000000000004371355335115400204430ustar00rootroot00000000000000/* ISC license. */ #include #include int cdb_mapfile (struct cdb *c, char const *file) { int fd = open_readb(file) ; if (fd < 0) return 0 ; if (!cdb_init_map(c, fd, 1)) { fd_close(fd) ; return 0 ; } fd_close(fd) ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/cdb_nextkey.c000066400000000000000000000011171355335115400205110ustar00rootroot00000000000000/* ISC license. */ #include #include int cdb_nextkey (struct cdb *c, uint32_t *kpos) { char buf[8] ; uint32_t eod, klen ; if (cdb_read(c, buf, 4, 0) < 0) return -1 ; uint32_unpack(buf, &eod) ; if (eod < 8 || eod - 8 < *kpos) return 0 ; c->kpos = *kpos + 8 ; if (c->kpos < *kpos) return -1 ; /* wraparound */ cdb_findstart(c) ; c->hslots = 1 ; if (cdb_read(c, buf, 8, *kpos) < 0) return -1 ; uint32_unpack(buf, &klen) ; uint32_unpack(buf + 4, &c->dlen) ; c->dpos = c->kpos + klen ; *kpos += 8 + klen + c->dlen ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/cdb_read.c000066400000000000000000000010111355335115400177260ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include int cdb_read (struct cdb *c, char *buf, unsigned int len, uint32_t pos) { if (c->map) { if ((pos > c->size) || (c->size - pos < len)) return (errno = EPROTO, -1) ; memcpy(buf, c->map + pos, len) ; } else { if (lseek(c->fd, pos, SEEK_SET) < 0) return -1 ; if (allread(c->fd, buf, len) < len) return -1 ; } return 0 ; } skalibs-2.9.1.0/src/libstddjb/cdb_successor.c000066400000000000000000000005251355335115400210350ustar00rootroot00000000000000/* ISC license. */ #include #include int cdb_successor (struct cdb *c, char const *key, unsigned int klen) { uint32_t kpos ; if (key) { int r = cdb_find(c, key, klen) ; if (r < 1) return r ; kpos = c->dpos + c->dlen ; } else cdb_traverse_init(c, &kpos) ; return cdb_nextkey(c, &kpos) ; } skalibs-2.9.1.0/src/libstddjb/cdb_zero.c000066400000000000000000000001251355335115400177770ustar00rootroot00000000000000/* ISC license. */ #include struct cdb const cdb_zero = CDB_ZERO ; skalibs-2.9.1.0/src/libstddjb/child_spawn.c000066400000000000000000000105461355335115400205130ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include #include #include #include #include #include #include #ifdef SKALIBS_HASPOSIXSPAWN #include #include #include #else #include #include #endif #include #include #include #include /* If n = 0 : child's stdin and stdout are the same as the parent's If n >= 1 : pipes between parent and child. Parent reads on even ones, writes on odd ones. */ pid_t child_spawn (char const *prog, char const *const *argv, char const *const *envp, int *fds, unsigned int n) { #ifdef SKALIBS_HASPOSIXSPAWN posix_spawn_file_actions_t actions ; posix_spawnattr_t attr ; #else int syncpipe[2] ; #endif int p[n ? n : 1][2] ; pid_t pid ; int e ; size_t m = sizeof(SKALIBS_CHILD_SPAWN_FDS_ENVVAR) ; unsigned int i = 0 ; char modifs[m + 1 + n * UINT_FMT] ; memcpy(modifs, SKALIBS_CHILD_SPAWN_FDS_ENVVAR "=", sizeof(SKALIBS_CHILD_SPAWN_FDS_ENVVAR)) ; for (; i < n ; i++) if (pipe(p[i]) < 0) { e = errno ; goto errpi ; } for (i = 0 ; i < n ; i++) if ((ndelay_on(p[i][i & 1]) < 0) || (coe(p[i][i & 1]) < 0)) { e = errno ; goto errp ; } for (i = 2 ; i < n ; i++) { m += uint_fmt(modifs + m, p[i][!(i & 1)]) ; if (i+1 < n) modifs[m++] = ',' ; } modifs[m++] = 0 ; #ifdef SKALIBS_HASPOSIXSPAWN e = posix_spawnattr_init(&attr) ; if (e) goto errsp ; { sigset_t set ; sigemptyset(&set) ; e = posix_spawnattr_setsigmask(&attr, &set) ; if (e) goto errattr ; e = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK) ; if (e) goto errattr ; } e = posix_spawn_file_actions_init(&actions) ; if (e) goto errattr ; if (n >= 2 && p[1][0]) { e = posix_spawn_file_actions_adddup2(&actions, p[1][0], 0) ; if (e) goto erractions ; e = posix_spawn_file_actions_addclose(&actions, p[1][0]) ; if (e) goto erractions ; } if (n && p[0][1] != 1) { e = posix_spawn_file_actions_adddup2(&actions, p[0][1], 1) ; if (e) goto erractions ; e = posix_spawn_file_actions_addclose(&actions, p[0][1]) ; if (e) goto erractions ; } { int haspath = !!getenv("PATH") ; size_t envlen = env_len(envp) ; char const *newenv[envlen + 2] ; if (!env_merge(newenv, envlen+2, envp, envlen, modifs, m)) goto erractions ; if (!haspath && (setenv("PATH", SKALIBS_DEFAULTPATH, 0) < 0)) { e = errno ; goto erractions ; } e = posix_spawnp(&pid, prog, &actions, &attr, (char *const *)argv, (char *const *)newenv) ; if (!haspath) unsetenv("PATH") ; if (e) goto erractions ; } posix_spawn_file_actions_destroy(&actions) ; posix_spawnattr_destroy(&attr) ; #else if (pipe(syncpipe) < 0) { e = errno ; goto errp ; } if (coe(syncpipe[1]) < 0) { e = errno ; goto errsp ; } pid = fork() ; if (pid < 0) { e = errno ; goto errsp ; } else if (!pid) { size_t len = strlen(PROG) ; char name[len + 9] ; memcpy(name, PROG, len) ; memcpy(name + len, " (child)", 9) ; PROG = name ; fd_close(syncpipe[0]) ; if (n >= 2) { if (fd_move2(0, p[1][0], 1, p[0][1]) < 0) goto syncdie ; } else if (n) { if (fd_move(1, p[0][1]) < 0) goto syncdie ; } sig_blocknone() ; pathexec_r_name(prog, argv, envp, env_len(envp), modifs, m) ; syncdie: { char c = errno ; fd_write(syncpipe[1], &c, 1) ; } _exit(127) ; } fd_close(syncpipe[1]) ; { char c ; syncpipe[1] = fd_read(syncpipe[0], &c, 1) ; if (syncpipe[1]) { if (syncpipe[1] < 0) e = errno ; else { kill(pid, SIGKILL) ; e = c ; } wait_pid(pid, &syncpipe[1]) ; goto errsp0 ; } } fd_close(syncpipe[0]) ; #endif for (i = n ; i ; i--) { fd_close(p[i-1][i & 1]) ; fds[i-1] = p[i-1][!(i & 1)] ; } return pid ; #ifdef SKALIBS_HASPOSIXSPAWN erractions: posix_spawn_file_actions_destroy(&actions) ; errattr: posix_spawnattr_destroy(&attr) ; #endif errsp: #ifndef SKALIBS_HASPOSIXSPAWN fd_close(syncpipe[1]) ; errsp0: fd_close(syncpipe[0]) ; #endif errp: i = n ; errpi: while (i--) { fd_close(p[i][1]) ; fd_close(p[i][0]) ; } errno = e ; return 0 ; } skalibs-2.9.1.0/src/libstddjb/child_spawn0.c000066400000000000000000000037331355335115400205730ustar00rootroot00000000000000/* ISC license. */ #include #include #ifdef SKALIBS_HASPOSIXSPAWN #include #include #include #include pid_t child_spawn0 (char const *prog, char const *const *argv, char const *const *envp) { posix_spawnattr_t attr ; int e ; pid_t pid ; int haspath = !!getenv("PATH") ; e = posix_spawnattr_init(&attr) ; if (e) goto err ; { sigset_t set ; sigemptyset(&set) ; e = posix_spawnattr_setsigmask(&attr, &set) ; if (e) goto errattr ; e = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK) ; if (e) goto errattr ; } if (!haspath && (setenv("PATH", SKALIBS_DEFAULTPATH, 0) < 0)) { e = errno ; goto errattr ; } e = posix_spawnp(&pid, prog, 0, &attr, (char *const *)argv, (char *const *)envp) ; if (!haspath) unsetenv("PATH") ; posix_spawnattr_destroy(&attr) ; if (e) goto err ; return pid ; errattr: posix_spawnattr_destroy(&attr) ; err: errno = e ; return 0 ; } #else #include #include #include #include #include #include pid_t child_spawn0 (char const *prog, char const *const *argv, char const *const *envp) { int e ; int p[2] ; pid_t pid ; if (pipecoe(p) < 0) return 0 ; pid = fork() ; if (pid < 0) { fd_close(p[1]) ; fd_close(p[0]) ; return 0 ; } if (!pid) { size_t len = strlen(PROG) ; char name[len + 9] ; memcpy(name, PROG, len) ; memcpy(name + len, " (child)", 9) ; PROG = name ; fd_close(p[0]) ; sig_blocknone() ; pathexec_run(prog, argv, envp) ; e = errno ; fd_write(p[1], (char *)&e, sizeof(e)) ; _exit(127) ; } fd_close(p[1]) ; p[1] = fd_read(p[0], (char *)&e, sizeof(e)) ; if (p[1] < 0) { fd_close(p[0]) ; return 0 ; } fd_close(p[0]) ; if (p[1] == sizeof(e)) { wait_pid(pid, &p[0]) ; errno = e ; return 0 ; } return pid ; } #endif skalibs-2.9.1.0/src/libstddjb/child_spawn1_internal.c000066400000000000000000000062161355335115400224670ustar00rootroot00000000000000/* ISC license. */ #include #include #include #ifdef SKALIBS_HASPOSIXSPAWN #include #include #include #include #include pid_t child_spawn1_internal (char const *prog, char const *const *argv, char const *const *envp, int *p, int to) { posix_spawn_file_actions_t actions ; posix_spawnattr_t attr ; int e ; pid_t pid ; int haspath = !!getenv("PATH") ; if (coe(p[!(to & 1)]) < 0) { e = errno ; goto err ; } e = posix_spawnattr_init(&attr) ; if (e) goto err ; { sigset_t set ; sigemptyset(&set) ; e = posix_spawnattr_setsigmask(&attr, &set) ; if (e) goto errattr ; e = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK) ; if (e) goto errattr ; } e = posix_spawn_file_actions_init(&actions) ; if (e) goto errattr ; if (p[to & 1] != to & 1) { e = posix_spawn_file_actions_adddup2(&actions, p[to & 1], to & 1) ; if (e) goto erractions ; e = posix_spawn_file_actions_addclose(&actions, p[to & 1]) ; if (e) goto erractions ; } if (to & 2) { e = posix_spawn_file_actions_adddup2(&actions, to & 1, !(to & 1)) ; if (e) goto erractions ; } if (!haspath && (setenv("PATH", SKALIBS_DEFAULTPATH, 0) < 0)) { e = errno ; goto erractions ; } e = posix_spawnp(&pid, prog, &actions, &attr, (char *const *)argv, (char *const *)envp) ; if (!haspath) unsetenv("PATH") ; posix_spawn_file_actions_destroy(&actions) ; posix_spawnattr_destroy(&attr) ; fd_close(p[to & 1]) ; if (e) goto errp ; return pid ; erractions: posix_spawn_file_actions_destroy(&actions) ; errattr: posix_spawnattr_destroy(&attr) ; err: fd_close(p[to & 1]) ; errp: fd_close(p[!(to & 1)]) ; errno = e ; return 0 ; } #else #include #include #include #include #include pid_t child_spawn1_internal (char const *prog, char const *const *argv, char const *const *envp, int *p, int to) { int e ; int syncp[2] ; pid_t pid ; if (coe(p[0]) < 0 || pipecoe(syncp) < 0) { fd_close(p[1]) ; fd_close(p[0]) ; return 0 ; } pid = fork() ; if (pid < 0) { fd_close(syncp[1]) ; fd_close(syncp[0]) ; fd_close(p[1]) ; fd_close(p[0]) ; return 0 ; } if (!pid) { size_t len = strlen(PROG) ; char name[len + 9] ; memcpy(name, PROG, len) ; memcpy(name + len, " (child)", 9) ; PROG = name ; fd_close(syncp[0]) ; fd_close(p[!(to & 1)]) ; if (fd_move(to & 1, p[to & 1]) < 0) goto err ; if ((to & 2) && (fd_copy(!(to & 1), to & 1) < 0)) goto err ; sig_blocknone() ; pathexec_run(prog, argv, envp) ; err: e = errno ; fd_write(syncp[1], (char *)&e, sizeof(e)) ; _exit(127) ; } fd_close(syncp[1]) ; fd_close(p[to & 1]) ; syncp[1] = fd_read(syncp[0], (char *)&e, sizeof(e)) ; if (syncp[1] < 0) { fd_close(syncp[0]) ; fd_close(p[!(to & 1)]) ; return 0 ; } fd_close(syncp[0]) ; if (syncp[1] == sizeof(e)) { fd_close(p[!(to & 1)]) ; wait_pid(pid, &syncp[1]) ; errno = e ; return 0 ; } return pid ; } #endif skalibs-2.9.1.0/src/libstddjb/child_spawn1_pipe.c000066400000000000000000000006011355335115400216000ustar00rootroot00000000000000/* ISC license. */ #include #include #include "djbunix-internal.h" pid_t child_spawn1_pipe (char const *prog, char const *const *argv, char const *const *envp, int *fd, int to) { pid_t pid ; int p[2] ; if (pipe(p) < 0) return 0 ; pid = child_spawn1_internal(prog, argv, envp, p, !!to) ; if (!pid) return 0 ; *fd = p[!to] ; return pid ; } skalibs-2.9.1.0/src/libstddjb/child_spawn1_socket.c000066400000000000000000000006041355335115400221360ustar00rootroot00000000000000/* ISC license. */ #include #include #include "djbunix-internal.h" pid_t child_spawn1_socket (char const *prog, char const *const *argv, char const *const *envp, int *fd) { pid_t pid ; int p[2] ; if (ipc_pair_b(p) < 0) return 0 ; pid = child_spawn1_internal(prog, argv, envp, p, 3) ; if (!pid) return 0 ; *fd = p[0] ; return pid ; } skalibs-2.9.1.0/src/libstddjb/child_spawn2.c000066400000000000000000000067541355335115400206030ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include #include #include #include #include #include #ifdef SKALIBS_HASPOSIXSPAWN #include #include #include #else #include #include #include #include #endif #include pid_t child_spawn2 (char const *prog, char const *const *argv, char const *const *envp, int *fds) { #ifdef SKALIBS_HASPOSIXSPAWN posix_spawn_file_actions_t actions ; posix_spawnattr_t attr ; #else int syncpipe[2] ; #endif int p[2][2] ; pid_t pid ; int e ; if (pipe(p[0]) < 0) return 0 ; if (ndelay_on(p[0][0]) < 0 || coe(p[0][0]) < 0 || pipe(p[1]) < 0) { e = errno ; goto errp ; } if (ndelay_on(p[1][1]) < 0 || coe(p[1][1]) < 0) { e = errno ; goto errp1 ; } #ifdef SKALIBS_HASPOSIXSPAWN e = posix_spawnattr_init(&attr) ; if (e) goto errsp ; { sigset_t set ; sigemptyset(&set) ; e = posix_spawnattr_setsigmask(&attr, &set) ; if (e) goto errattr ; e = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK) ; if (e) goto errattr ; } e = posix_spawn_file_actions_init(&actions) ; if (e) goto errattr ; if (p[1][0] != fds[0]) { e = posix_spawn_file_actions_adddup2(&actions, p[1][0], fds[0]) ; if (e) goto erractions ; e = posix_spawn_file_actions_addclose(&actions, p[1][0]) ; if (e) goto erractions ; } if (p[0][1] != fds[1]) { e = posix_spawn_file_actions_adddup2(&actions, p[0][1], fds[1]) ; if (e) goto erractions ; e = posix_spawn_file_actions_addclose(&actions, p[0][1]) ; if (e) goto erractions ; } { int haspath = !!getenv("PATH") ; if (!haspath && (setenv("PATH", SKALIBS_DEFAULTPATH, 0) < 0)) { e = errno ; goto erractions ; } e = posix_spawnp(&pid, prog, &actions, &attr, (char *const *)argv, (char *const *)envp) ; if (!haspath) unsetenv("PATH") ; if (e) goto erractions ; } posix_spawn_file_actions_destroy(&actions) ; posix_spawnattr_destroy(&attr) ; #else if (pipe(syncpipe) < 0) { e = errno ; goto errp1 ; } if (coe(syncpipe[1]) < 0) { e = errno ; goto errsp ; } pid = fork() ; if (pid < 0) { e = errno ; goto errsp ; } else if (!pid) { size_t len = strlen(PROG) ; char name[len + 9] ; memcpy(name, PROG, len) ; memcpy(name + len, " (child)", 9) ; PROG = name ; fd_close(syncpipe[0]) ; if (fd_move2(fds[0], p[1][0], fds[1], p[0][1]) < 0) goto syncdie ; sig_blocknone() ; pathexec_run(prog, argv, envp) ; syncdie: { char c = errno ; fd_write(syncpipe[1], &c, 1) ; } _exit(127) ; } fd_close(syncpipe[1]) ; { char c ; syncpipe[1] = fd_read(syncpipe[0], &c, 1) ; if (syncpipe[1]) { if (syncpipe[1] < 0) e = errno ; else { kill(pid, SIGKILL) ; e = c ; } wait_pid(pid, &syncpipe[1]) ; goto errsp0 ; } } fd_close(syncpipe[0]) ; #endif fd_close(p[0][1]) ; fds[0] = p[0][0] ; fd_close(p[1][0]) ; fds[1] = p[1][1] ; return pid ; #ifdef SKALIBS_HASPOSIXSPAWN erractions: posix_spawn_file_actions_destroy(&actions) ; errattr: posix_spawnattr_destroy(&attr) ; #endif errsp: #ifndef SKALIBS_HASPOSIXSPAWN fd_close(syncpipe[1]) ; errsp0: fd_close(syncpipe[0]) ; #endif errp1: fd_close(p[1][1]) ; fd_close(p[1][0]) ; errp: fd_close(p[0][1]) ; fd_close(p[0][0]) ; errno = e ; return 0 ; } skalibs-2.9.1.0/src/libstddjb/child_spawn3.c000066400000000000000000000101161355335115400205670ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include #include #include #include #include #include #ifdef SKALIBS_HASPOSIXSPAWN #include #include #include #else #include #include #include #endif #include #include #include #include pid_t child_spawn3 (char const *prog, char const *const *argv, char const *const *envp, int *fds) { #ifdef SKALIBS_HASPOSIXSPAWN posix_spawn_file_actions_t actions ; posix_spawnattr_t attr ; #else int syncpipe[2] ; #endif int p[3][2] ; pid_t pid ; int e ; size_t m = sizeof(SKALIBS_CHILD_SPAWN_FDS_ENVVAR) ; char modifs[sizeof(SKALIBS_CHILD_SPAWN_FDS_ENVVAR) + UINT_FMT] = SKALIBS_CHILD_SPAWN_FDS_ENVVAR "=" ; if (pipe(p[0]) < 0 || ndelay_on(p[0][0]) < 0 || coe(p[0][0]) < 0) return 0 ; if (pipe(p[1]) < 0 || ndelay_on(p[1][1]) < 0 || coe(p[1][1]) < 0) goto errp0 ; if (pipe(p[2]) < 0 || ndelay_on(p[2][0]) < 0 || coe(p[2][0]) < 0) goto errp1 ; m += uint_fmt(modifs + sizeof(SKALIBS_CHILD_SPAWN_FDS_ENVVAR), p[2][1]) ; modifs[m++] = 0 ; #ifdef SKALIBS_HASPOSIXSPAWN e = posix_spawnattr_init(&attr) ; if (e) goto errp2 ; { sigset_t set ; sigemptyset(&set) ; e = posix_spawnattr_setsigmask(&attr, &set) ; if (e) goto errattr ; e = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK) ; if (e) goto errattr ; } e = posix_spawn_file_actions_init(&actions) ; if (e) goto errattr ; if (p[1][0] != fds[0]) { e = posix_spawn_file_actions_adddup2(&actions, p[1][0], fds[0]) ; if (e) goto erractions ; e = posix_spawn_file_actions_addclose(&actions, p[1][0]) ; if (e) goto erractions ; } if (p[0][1] != fds[1]) { e = posix_spawn_file_actions_adddup2(&actions, p[0][1], fds[1]) ; if (e) goto erractions ; e = posix_spawn_file_actions_addclose(&actions, p[0][1]) ; if (e) goto erractions ; } { int haspath = !!getenv("PATH") ; size_t envlen = env_len(envp) ; char const *newenv[envlen + 2] ; if (!env_merge(newenv, envlen+2, envp, envlen, modifs, m)) goto erractions ; if (!haspath && (setenv("PATH", SKALIBS_DEFAULTPATH, 0) < 0)) { e = errno ; goto erractions ; } e = posix_spawnp(&pid, prog, &actions, &attr, (char *const *)argv, (char *const *)newenv) ; if (!haspath) unsetenv("PATH") ; if (e) goto erractions ; } posix_spawn_file_actions_destroy(&actions) ; posix_spawnattr_destroy(&attr) ; #else if (pipe(syncpipe) < 0) { e = errno ; goto errp2 ; } if (coe(syncpipe[1]) < 0) { e = errno ; goto errsp ; } pid = fork() ; if (pid < 0) { e = errno ; goto errsp ; } else if (!pid) { size_t len = strlen(PROG) ; char name[len + 9] ; memcpy(name, PROG, len) ; memcpy(name + len, " (child)", 9) ; PROG = name ; fd_close(syncpipe[0]) ; if (fd_move2(fds[0], p[1][0], fds[1], p[0][1]) < 0) goto syncdie ; sig_blocknone() ; pathexec_r_name(prog, argv, envp, env_len(envp), modifs, m) ; syncdie: { char c = errno ; fd_write(syncpipe[1], &c, 1) ; } _exit(127) ; } fd_close(syncpipe[1]) ; { char c ; syncpipe[1] = fd_read(syncpipe[0], &c, 1) ; if (syncpipe[1]) { if (syncpipe[1] < 0) e = errno ; else { kill(pid, SIGKILL) ; e = c ; } wait_pid(pid, &syncpipe[1]) ; goto errsp0 ; } } fd_close(syncpipe[0]) ; #endif fd_close(p[2][1]) ; fd_close(p[1][0]) ; fd_close(p[0][1]) ; fds[0] = p[0][0] ; fds[1] = p[1][1] ; fds[2] = p[2][0] ; return pid ; #ifdef SKALIBS_HASPOSIXSPAWN erractions: posix_spawn_file_actions_destroy(&actions) ; errattr: posix_spawnattr_destroy(&attr) ; #endif #ifndef SKALIBS_HASPOSIXSPAWN errsp: fd_close(syncpipe[1]) ; errsp0: fd_close(syncpipe[0]) ; #endif errp2: fd_close(p[2][1]) ; fd_close(p[2][0]) ; errp1: fd_close(p[1][1]) ; fd_close(p[1][0]) ; errp0: fd_close(p[0][1]) ; fd_close(p[0][0]) ; return 0 ; } skalibs-2.9.1.0/src/libstddjb/coe.c000066400000000000000000000003171355335115400167610ustar00rootroot00000000000000/* ISC license. */ #include #include int coe (int fd) { int flags = fcntl(fd, F_GETFD, 0) ; if (flags < 0) return -1 ; return fcntl(fd, F_SETFD, flags | FD_CLOEXEC) ; } skalibs-2.9.1.0/src/libstddjb/deepsleepuntil.c000066400000000000000000000003511355335115400212330ustar00rootroot00000000000000/* ISC license. */ #include #include void deepsleepuntil (tain_t const *deadline, tain_t *stamp) { iopause_fd x ; while (tain_less(stamp, deadline)) iopause_stamp(&x, 0, deadline, stamp) ; } skalibs-2.9.1.0/src/libstddjb/dir_close.c000066400000000000000000000003331355335115400201540ustar00rootroot00000000000000/* ISC license. */ #include #include void dir_close (DIR *dir) { int e = errno ; for (;;) { if (closedir(dir) == 0) break ; if (errno != EINTR) break ; } errno = e ; } skalibs-2.9.1.0/src/libstddjb/dir_fd.c000066400000000000000000000004561355335115400174460ustar00rootroot00000000000000/* ISC license. */ #include #include #include #ifdef SKALIBS_HASDIRFD int dir_fd (DIR *dir) { return dirfd(dir) ; } #else /* Pokes at the internals of DIR - no choice here */ int dir_fd (DIR *dir) { return dir->dd_fd ; } #endif skalibs-2.9.1.0/src/libstddjb/djbtime-internal.h000066400000000000000000000005101355335115400214430ustar00rootroot00000000000000/* ISC license. */ #ifndef DJBTIME_INTERNAL_H #define DJBTIME_INTERNAL_H #include extern unsigned int const leapsecs_table_len ; extern uint64_t const *const leapsecs_table ; extern void leapsecs_add (uint64_t *, int) ; extern int leapsecs_sub (uint64_t *) ; extern int skalibs_tzisright (void) ; #endif skalibs-2.9.1.0/src/libstddjb/djbunix-internal.h000066400000000000000000000003251355335115400214740ustar00rootroot00000000000000/* ISC license. */ #ifndef DJBUNIX_INTERNAL_H #define DJBUNIX_INTERNAL_H #include extern pid_t child_spawn1_internal (char const *, char const *const *, char const *const *, int *, int) ; #endif skalibs-2.9.1.0/src/libstddjb/env_addmodif.c000066400000000000000000000006231355335115400206320ustar00rootroot00000000000000/* ISC license. */ #include #include #include int env_addmodif (stralloc *sa, char const *s, char const *t) { size_t oldlen = sa->len ; if (!s) return 1 ; if (!stralloc_cats(sa, s)) return 0 ; if ((t && (!stralloc_catb(sa, "=", 1) || !stralloc_cats(sa, t))) || !stralloc_0(sa)) { sa->len = oldlen ; return 0 ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/env_dump.c000066400000000000000000000023441355335115400200320ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include #include #include /* XXX: breaks layering, but really openat() should be supported everywhere */ #include #define SUFFIX ":envdump:XXXXXX" int env_dump (char const *dir, mode_t mode, char const *const *envp) { int fd ; size_t dirlen = strlen(dir) ; char tmpdir[dirlen + sizeof(SUFFIX)] ; memcpy(tmpdir, dir, dirlen) ; memcpy(tmpdir + dirlen, SUFFIX, sizeof(SUFFIX)) ; if (!mkdtemp(tmpdir)) return 0 ; fd = open_read(tmpdir) ; if (fd == -1) goto err ; for (; *envp ; envp++) { size_t len = str_chr(*envp, '=') ; size_t vallen = strlen(*envp + len + 1) ; char fn[len + 1] ; memcpy(fn, *envp, len) ; fn[len] = 0 ; len = openwritenclose_at(fd, fn, *envp + len + 1, vallen) ; if (len < vallen) goto cerr ; } fd_close(fd) ; if (chmod(tmpdir, mode) == -1) goto err ; if (rename(tmpdir, dir) == -1) goto err ; return 1 ; cerr: fd_close(fd) ; err: { int e = errno ; rm_rf(tmpdir) ; errno = e ; } return 0 ; } skalibs-2.9.1.0/src/libstddjb/env_get.c000066400000000000000000000002041355335115400176350ustar00rootroot00000000000000/* ISC license. */ #include #include char const *env_get (char const *s) { return getenv(s) ; } skalibs-2.9.1.0/src/libstddjb/env_get2.c000066400000000000000000000005451355335115400177270ustar00rootroot00000000000000/* ISC license. */ #include #include #include char const *env_get2 (char const *const *envp, char const *s) { size_t len, i ; if (!s) return 0 ; len = strlen(s) ; for (i = 0 ; envp[i] ; ++i) if (str_start(envp[i], s) && (envp[i][len] == '=')) return envp[i] + len + 1 ; return 0 ; } skalibs-2.9.1.0/src/libstddjb/env_len.c000066400000000000000000000002131355335115400176340ustar00rootroot00000000000000/* ISC license. */ #include size_t env_len (char const *const *e) { size_t i = 0 ; while (*e++) i++ ; return i ; } skalibs-2.9.1.0/src/libstddjb/env_make.c000066400000000000000000000004651355335115400200040ustar00rootroot00000000000000/* ISC license. */ #include #include #include int env_make (char const **v, size_t argc, char const *s, size_t len) { while (argc--) { size_t n = strlen(s) + 1 ; if (n > len) return (errno = EINVAL, 0) ; *v++ = s ; s += n ; len -= n ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/env_merge.c000066400000000000000000000014051355335115400201610ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include size_t env_merge (char const **v, size_t vmax, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) { size_t n = byte_count(modifs, modiflen, '\0') ; size_t vlen = envlen ; size_t i = 0 ; if (envlen + n + 1 > vmax) return (errno = ENAMETOOLONG, 0) ; for (; i < envlen ; i++) v[i] = envp[i] ; for (i = 0 ; i < modiflen ; i += strlen(modifs + i) + 1) { size_t split = str_chr(modifs + i, '=') ; size_t j = 0 ; for (; j < vlen ; j++) if (!strncmp(modifs + i, v[j], split+1)) break ; if (j < vlen) v[j] = v[--vlen] ; if (modifs[i + split]) v[vlen++] = modifs + i ; } v[vlen++] = 0 ; return vlen ; } skalibs-2.9.1.0/src/libstddjb/env_string.c000066400000000000000000000005371355335115400203750ustar00rootroot00000000000000/* ISC license. */ #include #include int env_string (stralloc *sa, char const *const *envp, size_t envlen) { size_t salen = sa->len ; size_t i = 0 ; for (; i < envlen ; i++) { if (!stralloc_cats(sa, envp[i]) || !stralloc_0(sa)) { sa->len = salen ; return 0 ; } } return 1 ; } skalibs-2.9.1.0/src/libstddjb/envalloc_0.c000066400000000000000000000002701355335115400202330ustar00rootroot00000000000000/* ISC license. */ #include #include int envalloc_0 (genalloc *v) { char const *z = 0 ; return genalloc_append(char const *, v, &z) ; } skalibs-2.9.1.0/src/libstddjb/envalloc_make.c000066400000000000000000000010121355335115400210040ustar00rootroot00000000000000/* ISC license. */ #include #include #include int envalloc_make (genalloc *v, size_t argc, char const *s, size_t len) { int wasnull = !v->s ; if (!genalloc_readyplus(char const *, v, argc+1)) return 0 ; if (!env_make(genalloc_s(char const *, v) + genalloc_len(char const *, v), argc, s, len)) { if (wasnull) genalloc_free(char const *, v) ; return 0 ; } genalloc_setlen(char const *, v, genalloc_len(char const *, v) + argc) ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/envalloc_merge.c000066400000000000000000000010711355335115400211730ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int envalloc_merge (genalloc *v, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) { size_t n = envlen + 1 + byte_count(modifs, modiflen, '\0') ; if (!genalloc_readyplus(char const *, v, n)) return 0 ; n = env_merge(genalloc_s(char const *, v) + genalloc_len(char const *, v), n, envp, envlen, modifs, modiflen) ; genalloc_setlen(char const *, v, genalloc_len(char const *, v) + n) ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/envalloc_uniq.c000066400000000000000000000014131355335115400210500ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int envalloc_uniq (genalloc *v, char delim) { unsigned int m = 0 ; size_t i = 0 ; for (; i < genalloc_len(char const *, v) ; i++) { size_t j = i+1 ; char const *s = genalloc_s(char const *, v)[i] ; size_t n = str_chr(s, delim) ; if (delim && !s[n]) return (errno = EINVAL, -1) ; for (; j < genalloc_len(char const *, v) ; j++) { char const **p = genalloc_s(char const *, v) ; if (!strncmp(s, p[j], n)) { size_t len = genalloc_len(char const *, v) - 1 ; genalloc_setlen(char const *, v, len) ; p[j] = p[len] ; m++ ; } } } return m ; } skalibs-2.9.1.0/src/libstddjb/envdir.c000066400000000000000000000037611355335115400175100ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include #define MAXVARSIZE 4095 int envdir_internal (char const *path, stralloc *modifs, unsigned int options, char nullis) { char buf[MAXVARSIZE + 1] ; unsigned int n = 0 ; size_t pathlen = strlen(path) ; size_t modifbase = modifs->len ; int wasnull = !modifs->s ; DIR *dir ; if (!nullis) return (errno = EINVAL, -1) ; dir = opendir(path) ; if (!dir) return -1 ; for (;;) { direntry *d ; size_t len ; ssize_t r ; errno = 0 ; d = readdir(dir) ; if (!d) break ; if (d->d_name[0] == '.') continue ; len = strlen(d->d_name) ; if (str_chr(d->d_name, '=') < len) continue ; { char tmp[pathlen + len + 2] ; memcpy(tmp, path, pathlen) ; tmp[pathlen] = '/' ; memcpy(tmp + pathlen + 1, d->d_name, len + 1) ; r = openreadnclose(tmp, buf, MAXVARSIZE) ; } if (r < 0) { if (errno == ENOENT) errno = EIDRM ; goto err ; } else if (r > 0) { if (options & SKALIBS_ENVDIR_VERBATIM) { if (!(options & SKALIBS_ENVDIR_NOCHOMP) && (buf[r-1] == '\n')) r-- ; } else { r = byte_chr(buf, r, '\n') ; if (!(options & SKALIBS_ENVDIR_NOCHOMP)) { while (r--) if ((buf[r] != ' ') && (buf[r] != '\t') && (buf[r] != '\r')) break ; r++ ; } } { size_t i = 0 ; for (; i < (size_t)r ; i++) if (!buf[i]) buf[i] = nullis ; } buf[r++] = 0 ; if (!env_addmodif(modifs, d->d_name, buf)) goto err ; } else if (!env_addmodif(modifs, d->d_name, 0)) goto err ; n++ ; } if (errno) goto err ; dir_close(dir) ; return n ; err: { int e = errno ; dir_close(dir) ; if (wasnull) stralloc_free(modifs) ; else modifs->len = modifbase ; errno = e ; return -1 ; } } skalibs-2.9.1.0/src/libstddjb/error_isalready.c000066400000000000000000000003521355335115400214000ustar00rootroot00000000000000/* ISC license. */ #include #include #include int error_isalready (int e) { return e == EALREADY || e == EINPROGRESS #ifdef SKALIBS_BSD_SUCKS || e == EADDRINUSE #endif ; } skalibs-2.9.1.0/src/libstddjb/error_temp.c000066400000000000000000000021631355335115400203720ustar00rootroot00000000000000/* ISC license. */ #include #include int error_temp (int e) { if (error_isagain(e)) return 1 ; switch (e) { case 0 : case EINTR : case ENOMEM : case ETXTBSY : case EIO : case ETIMEDOUT : case ENOBUFS : #ifdef EDEADLK case EDEADLK : #endif #ifdef EBUSY case EBUSY : #endif #ifdef ENFILE case ENFILE : #endif #ifdef EFBIG case EFBIG : #endif #ifdef ENOSPC case ENOSPC : #endif #ifdef ENETDOWN case ENETDOWN : #endif #ifdef ENETUNREACH case ENETUNREACH : #endif #ifdef ENETRESET case ENETRESET : #endif #ifdef ECONNABORTED case ECONNABORTED : #endif #ifdef ECONNRESET case ECONNRESET : #endif #ifdef ETOOMANYREFS case ETOOMANYREFS : #endif #ifdef ECONNREFUSED case ECONNREFUSED : #endif #ifdef EHOSTDOWN case EHOSTDOWN : #endif #ifdef EHOSTUNREACH case EHOSTUNREACH : #endif #ifdef EPROCLIM case EPROCLIM : #endif #ifdef EUSERS case EUSERS : #endif #ifdef EDQUOT case EDQUOT : #endif #ifdef ESTALE case ESTALE : #endif #ifdef ENOLCK case ENOLCK : #endif return 1 ; default : return 0 ; } } skalibs-2.9.1.0/src/libstddjb/fd_cat.c000066400000000000000000000007121355335115400174320ustar00rootroot00000000000000/* ISC license. */ #include #include #include int fd_cat (int from, int to) { iobuffer b ; size_t n = 0 ; if (!iobuffer_init(&b, from, to)) return -1 ; for (;;) { ssize_t r = iobuffer_fill(&b) ; if (r < 0) goto err ; else if (!r) break ; if (!iobuffer_flush(&b)) goto err ; n += r ; } iobuffer_finish(&b) ; return n ; err: iobuffer_finish(&b) ; return -1 ; } skalibs-2.9.1.0/src/libstddjb/fd_catn.c000066400000000000000000000014541355335115400176140ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include size_t fd_catn (int from, int to, size_t n) { size_t w = 0 ; if (n >= IOBUFFER_SIZE) { iobuffer b ; if (!iobuffer_init(&b, from, to)) return 0 ; while (n >= IOBUFFER_SIZE) { ssize_t r = iobuffer_fill(&b) ; if (r <= 0) { iobuffer_finish(&b) ; if (!r) errno = EPIPE ; return w ; } if (!iobuffer_flush(&b)) { iobuffer_finish(&b) ; return w ; } n -= r ; w += r ; } iobuffer_finish(&b) ; } { char buf[n] ; size_t r = allread(from, buf, n) ; size_t v = 0 ; if (r) v = allwrite(to, buf, r) ; w += v ; } return w ; } skalibs-2.9.1.0/src/libstddjb/fd_chdir.c000066400000000000000000000003141355335115400177520ustar00rootroot00000000000000/* ISC license. */ #include #include #include int fd_chdir (int d) { int r ; do r = fchdir(d) ; while ((r == -1) && (errno == EINTR)) ; return r ; } skalibs-2.9.1.0/src/libstddjb/fd_chmod.c000066400000000000000000000005051355335115400177550ustar00rootroot00000000000000/* ISC license. */ /* OpenBSD manages to bork the fchmod declaration */ #include #include #include #include int fd_chmod (int fd, unsigned int mode) { int r ; do r = fchmod(fd, (mode_t)mode) ; while ((r == -1) && (errno == EINTR)) ; return r ; } skalibs-2.9.1.0/src/libstddjb/fd_chown.c000066400000000000000000000003561355335115400200050ustar00rootroot00000000000000/* ISC license. */ #include #include #include int fd_chown (int fd, uid_t uid, gid_t gid) { int r ; do r = fchown(fd, uid, gid) ; while ((r == -1) && (errno == EINTR)) ; return r ; } skalibs-2.9.1.0/src/libstddjb/fd_close.c000066400000000000000000000003001355335115400177610ustar00rootroot00000000000000/* ISC license. */ #include #include #include void fd_close (int fd) { int e = errno ; while (close(fd) < 0 && errno == EINTR) ; errno = e ; } skalibs-2.9.1.0/src/libstddjb/fd_copy.c000066400000000000000000000004131355335115400176330ustar00rootroot00000000000000/* ISC license. */ #include #include #include int fd_copy (int to, int from) { int r ; if (to == from) return (errno = EINVAL, -1) ; do r = dup2(from, to) ; while ((r == -1) && (errno == EINTR)) ; return r ; } skalibs-2.9.1.0/src/libstddjb/fd_copy2.c000066400000000000000000000005361355335115400177230ustar00rootroot00000000000000/* ISC license. */ #include #include int fd_copy2 (int to1, int from1, int to2, int from2) { if ((to1 == from2) || (to2 == from1)) return (errno = EINVAL, -1) ; if (fd_copy(to1, from1) == -1) return -1 ; if (fd_copy(to2, from2) == -1) { if (to1 != from1) fd_close(to1) ; return -1 ; } return 0 ; } skalibs-2.9.1.0/src/libstddjb/fd_ensure_open.c000066400000000000000000000006501355335115400212060ustar00rootroot00000000000000/* ISC license. */ #include #include #include int fd_ensure_open (int fd, int w) { int dummy ; if (fcntl(fd, F_GETFD, &dummy) < 0) { int newfd ; if (errno != EBADF) return 0 ; newfd = open2("/dev/null", w ? O_WRONLY : O_RDONLY) ; if (newfd < 0) return 0 ; if (fd_move(fd, newfd) < 0) { fd_close(newfd) ; return 0 ; } } return 1 ; } skalibs-2.9.1.0/src/libstddjb/fd_move.c000066400000000000000000000004431355335115400176320ustar00rootroot00000000000000/* ISC license. */ #include #include #include int fd_move (int to, int from) { int r ; if (to == from) return 0 ; do r = dup2(from, to) ; while ((r == -1) && (errno == EINTR)) ; if (r < 0) return r ; fd_close(from) ; return 0 ; } skalibs-2.9.1.0/src/libstddjb/fd_move2.c000066400000000000000000000014431355335115400177150ustar00rootroot00000000000000/* ISC license. */ #include #include #include int fd_move2 (int to1, int from1, int to2, int from2) { int tmp = from2 ; if (to1 == from1) return fd_move(to2, from2) ; if (to2 == from2) return fd_move(to1, from1) ; if (from1 == from2) return (to1 == to2) ? fd_move(to1, from1) : (errno = EINVAL, -1) ; if (to1 == to2) return (errno = EINVAL, -1) ; if (from2 == to1) { tmp = dup(from2) ; if (tmp == -1) return -1 ; } if (fd_copy(to1, from1) == -1) { if (from2 != tmp) fd_close(tmp) ; return -1 ; } if (fd_copy(to2, tmp) == -1) { int e = errno ; fd_close(to1) ; if (from2 != tmp) fd_move(from2, tmp) ; errno = e ; return -1 ; } if (from1 != to2) fd_close(from1) ; fd_close(tmp) ; return 0 ; } skalibs-2.9.1.0/src/libstddjb/fd_read.c000066400000000000000000000003651355335115400176020ustar00rootroot00000000000000/* ISC license. */ #include #include #include ssize_t fd_read (int fd, char *buf, size_t len) { ssize_t r ; do r = read(fd, buf, len) ; while ((r == -1) && (errno == EINTR)) ; return r ; } skalibs-2.9.1.0/src/libstddjb/fd_readv.c000066400000000000000000000004121355335115400177610ustar00rootroot00000000000000/* ISC license. */ #include #include #include ssize_t fd_readv (int fd, struct iovec const *v, unsigned int vlen) { ssize_t r ; do r = readv(fd, v, vlen) ; while ((r == -1) && (errno == EINTR)) ; return r ; } skalibs-2.9.1.0/src/libstddjb/fd_recv.c000066400000000000000000000004241355335115400176220ustar00rootroot00000000000000/* ISC license. */ #include #include #include ssize_t fd_recv (int fd, char *buf, size_t len, unsigned int flags) { ssize_t r ; do r = recv(fd, buf, len, flags) ; while ((r == -1) && (errno == EINTR)) ; return r ; } skalibs-2.9.1.0/src/libstddjb/fd_send.c000066400000000000000000000004321355335115400176130ustar00rootroot00000000000000/* ISC license. */ #include #include #include ssize_t fd_send (int fd, char const *buf, size_t len, unsigned int flags) { ssize_t r ; do r = send(fd, buf, len, flags) ; while ((r == -1) && (errno == EINTR)) ; return r ; } skalibs-2.9.1.0/src/libstddjb/fd_sync.c000066400000000000000000000003141355335115400176350ustar00rootroot00000000000000/* ISC license. */ #include #include #include int fd_sync (int fd) { int r ; do r = fsync(fd) ; while ((r == -1) && (errno == EINTR)) ; return r ; } skalibs-2.9.1.0/src/libstddjb/fd_write.c000066400000000000000000000003751355335115400200220ustar00rootroot00000000000000/* ISC license. */ #include #include #include ssize_t fd_write (int fd, char const *buf, size_t len) { ssize_t r ; do r = write(fd, buf, len) ; while ((r == -1) && (errno == EINTR)) ; return r ; } skalibs-2.9.1.0/src/libstddjb/fd_writev.c000066400000000000000000000004141355335115400202020ustar00rootroot00000000000000/* ISC license. */ #include #include #include ssize_t fd_writev (int fd, struct iovec const *v, unsigned int vlen) { ssize_t r ; do r = writev(fd, v, vlen) ; while ((r == -1) && (errno == EINTR)) ; return r ; } skalibs-2.9.1.0/src/libstddjb/filecopy_suffix.c000066400000000000000000000011041355335115400214040ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int filecopy_suffix (char const *src, char const *dst, unsigned int mode, char const *suffix) { size_t dstlen = strlen(dst) ; size_t suffixlen = strlen(suffix) ; char tmp[dstlen + suffixlen + 1] ; memcpy(tmp, dst, dstlen) ; memcpy(tmp + dstlen, suffix, suffixlen + 1) ; if (!filecopy_unsafe(src, tmp, mode)) return 0 ; if (rename(tmp, dst) < 0) { int e = errno ; unlink(tmp) ; errno = e ; return 0 ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/filecopy_unsafe.c000066400000000000000000000006611355335115400213700ustar00rootroot00000000000000/* ISC license. */ #include #include int filecopy_unsafe (char const *src, char const *dst, unsigned int mode) { int d ; int s = open2(src, O_RDONLY) ; if (s < 0) return 0 ; d = open3(dst, O_WRONLY | O_CREAT | O_TRUNC, mode) ; if (d < 0) goto errs ; if (fd_cat(s, d) < 0) goto errd ; fd_close(d) ; fd_close(s) ; return 1 ; errd: fd_close(d) ; errs: fd_close(s) ; return 0 ; } skalibs-2.9.1.0/src/libstddjb/fmtscan-internal.h000066400000000000000000000042331355335115400214660ustar00rootroot00000000000000/* ISC license. */ #ifndef FMTSCAN_INTERNAL_H #define FMTSCAN_INTERNAL_H #include #include #include #include #include #include #define SCANB0(bits) \ size_t uint##bits##0_scan_base (char const *s, uint##bits##_t *u, uint8_t base) \ { \ size_t pos = uint##bits##_scan_base(s, u, base) ; \ if (!pos) return (errno = EINVAL, 0) ; \ if (!s[pos]) return pos ; \ errno = fmtscan_num(s[pos], base) < base ? ERANGE : EINVAL ; \ return 0 ; \ } \ #define SCANS0(bits) \ size_t int##bits##0_scan_base (char const *s, int##bits##_t *d, uint8_t base) \ { \ size_t pos = int##bits##_scan(s, d) ; \ if (!pos) return (errno = EINVAL, 0) ; \ if (!s[pos]) return pos ; \ errno = (fmtscan_num(s[pos], base) < base) ? ERANGE : EINVAL ; \ return 0 ; \ } \ #define SCANL(bits) \ size_t uint##bits##_scanlist (uint##bits##_t *tab, size_t max, char const *s, size_t *num) \ { \ size_t i = 0, len = 0 ; \ for (; s[len] && (i < max) ; i++) \ { \ size_t w = uint##bits##_scan(s + len, tab + i) ; \ if (!w) break ; \ len += w ; \ while (memchr(",:; \t\r\n", s[len], 7)) len++ ; \ } \ *num = i ; \ return len ; \ } \ #define SCANSL(bits) \ size_t int##bits##_scanlist (int##bits##_t *tab, size_t max, char const *s, size_t *num) \ { \ size_t i = 0, len = 0 ; \ for (; s[len] && (i < max) ; i++) \ { \ size_t w = int##bits##_scan(s + len, tab + i) ; \ if (!w) break ; \ len += w ; \ while (memchr(",:; \t\r\n", s[len], 7)) len++ ; \ } \ *num = i ; \ return len ; \ } \ #define FMTL(bits) \ static uint64_t get (void const *tab, size_t i) \ { \ return ((uint##bits##_t const *)tab)[i] ; \ } \ size_t uint##bits##_fmtlist (char *s, uint##bits##_t const *tab, size_t n) \ { \ return uint64_fmtlist_generic(s, tab, n, 10, &get) ; \ } \ #define FMTSL(bits) \ size_t int##bits##_fmtlist (char *s, int##bits##_t const *tab, size_t n) \ { \ size_t i = 0, len = 0 ; \ for (; i < n ; i++) \ { \ size_t w = int##bits##_fmt(s, tab[i]) ; \ len += w ; \ if (s) s += w ; \ if (i < n-1) { len++ ; if (s) *s++ = ',' ; } \ } \ return len ; \ } \ #endif skalibs-2.9.1.0/src/libstddjb/fmtscan_asc.c000066400000000000000000000003101355335115400204650ustar00rootroot00000000000000/* ISC license. */ #include unsigned char fmtscan_asc (unsigned char c) { static char const *tab = "0123456789abcdefghijklmnopqrstuvwxyz" ; return (c >= 36) ? 0 : tab[c] ; } skalibs-2.9.1.0/src/libstddjb/fmtscan_num.c000066400000000000000000000005541355335115400205300ustar00rootroot00000000000000/* ISC license. */ #include unsigned char fmtscan_num (unsigned char c, unsigned char n) { return ((c < '0') || (n > 36)) ? n : (n <= 10) ? (c - '0' <= n) ? c - '0' : n : (c - '0' <= 9) ? c - '0' : (c < 'A') ? n : (c - 'A' < n - 10) ? c - 'A' + 10 : (c < 'a') ? n : (c - 'a' < n - 10) ? c - 'a' + 10 : n ; } skalibs-2.9.1.0/src/libstddjb/genalloc_deepfree.c000066400000000000000000000004231355335115400216340ustar00rootroot00000000000000/* ISC license. */ #include #include void genalloc_deepfree_size (genalloc *g, freefunc_t_ref f, size_t size) { size_t len = g->len / size ; size_t i = 0 ; for (; i < len ; i++) (*f)(g->s + i * size) ; stralloc_free(g) ; } skalibs-2.9.1.0/src/libstddjb/genwrite_flush_bufalloc.c000066400000000000000000000002561355335115400231110ustar00rootroot00000000000000/* ISC license. */ #include #include int genwrite_flush_bufalloc (void *target) { return bufalloc_flush((bufalloc *)target) ; } skalibs-2.9.1.0/src/libstddjb/genwrite_flush_buffer.c000066400000000000000000000002461355335115400225720ustar00rootroot00000000000000/* ISC license. */ #include #include int genwrite_flush_buffer (void *target) { return buffer_flush((buffer *)target) ; } skalibs-2.9.1.0/src/libstddjb/genwrite_flush_stralloc.c000066400000000000000000000002001355335115400231320ustar00rootroot00000000000000/* ISC license. */ #include int genwrite_flush_stralloc (void *target) { (void)target ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/genwrite_put_bufalloc.c000066400000000000000000000003741355335115400226010ustar00rootroot00000000000000/* ISC license. */ #include #include #include ssize_t genwrite_put_bufalloc (void *target, char const *s, size_t len) { return bufalloc_put((bufalloc *)target, s, len) ? (ssize_t)len : -1 ; } skalibs-2.9.1.0/src/libstddjb/genwrite_put_buffer.c000066400000000000000000000003111355335115400222520ustar00rootroot00000000000000/* ISC license. */ #include #include ssize_t genwrite_put_buffer (void *target, char const *s, size_t len) { return buffer_put((buffer *)target, s, len) ; } skalibs-2.9.1.0/src/libstddjb/genwrite_put_stralloc.c000066400000000000000000000003351355335115400226320ustar00rootroot00000000000000/* ISC license. */ #include #include ssize_t genwrite_put_stralloc (void *target, char const *s, size_t len) { return stralloc_catb((stralloc *)target, s, len) ? len : -1 ; } skalibs-2.9.1.0/src/libstddjb/genwrite_stderr.c000066400000000000000000000002151355335115400214170ustar00rootroot00000000000000/* ISC license. */ #include #include genwrite_t genwrite_stderr = GENWRITE_BUFFER_INIT(buffer_2) ; skalibs-2.9.1.0/src/libstddjb/genwrite_stdout.c000066400000000000000000000002151355335115400214360ustar00rootroot00000000000000/* ISC license. */ #include #include genwrite_t genwrite_stdout = GENWRITE_BUFFER_INIT(buffer_1) ; skalibs-2.9.1.0/src/libstddjb/getlnmax.c000066400000000000000000000013101355335115400200240ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int getlnmax (buffer *b, char *d, size_t max, size_t *w, char sep) { if (max < *w) return (errno = EINVAL, -1) ; for (;;) { struct iovec v[2] ; size_t len = buffer_len(b) ; size_t pos ; ssize_t r ; buffer_rpeek(b, v) ; if (len > max - *w) len = max - *w ; pos = siovec_bytechr(v, 2, sep) ; if (pos > len) pos = len ; r = pos < len ; pos += r ; buffer_getnofill(b, d + *w, pos) ; *w += pos ; if (*w >= max) return (errno = ERANGE, -1) ; if (r) return 1 ; r = buffer_fill(b) ; if (r <= 0) return r ; } } skalibs-2.9.1.0/src/libstddjb/getlnmaxsep.c000066400000000000000000000013501355335115400205400ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int getlnmaxsep (buffer *b, char *d, size_t max, size_t *w, char const *sep, size_t seplen) { if (max < *w) return (errno = EINVAL, -1) ; for (;;) { struct iovec v[2] ; size_t len = buffer_len(b) ; size_t pos ; ssize_t r ; buffer_rpeek(b, v) ; if (len > max - *w) len = max - *w ; pos = siovec_bytein(v, 2, sep, seplen) ; if (pos > len) pos = len ; r = pos < len ; pos += r ; buffer_getnofill(b, d + *w, pos) ; *w += pos ; if (*w >= max) return (errno = ERANGE, -1) ; if (r) return 1 ; r = buffer_fill(b) ; if (r <= 0) return r ; } } skalibs-2.9.1.0/src/libstddjb/hiercopy.c000066400000000000000000000002551355335115400200360ustar00rootroot00000000000000/* ISC license. */ #include #include int hiercopy (char const *src, char const *dst) { return hiercopy_tmp(src, dst, &satmp) ; } skalibs-2.9.1.0/src/libstddjb/hiercopy_tmp.c000066400000000000000000000052751355335115400207250ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include #include static int dircopy (char const *src, char const *dst, mode_t mode, stralloc *tmp) { size_t tmpbase = tmp->len ; size_t maxlen = 0 ; { DIR *dir = opendir(src) ; if (!dir) return 0 ; for (;;) { direntry *d ; size_t n ; errno = 0 ; d = readdir(dir) ; if (!d) break ; if (d->d_name[0] == '.') if (((d->d_name[1] == '.') && !d->d_name[2]) || !d->d_name[1]) continue ; n = strlen(d->d_name) ; if (n > maxlen) maxlen = n ; if (!stralloc_catb(tmp, d->d_name, n+1)) break ; } if (errno) { int e = errno ; dir_close(dir) ; errno = e ; goto err ; } dir_close(dir) ; } if (mkdir(dst, S_IRWXU) < 0) { struct stat st ; if (errno != EEXIST) goto err ; if (stat(dst, &st) < 0) goto err ; if (!S_ISDIR(st.st_mode)) { errno = ENOTDIR ; goto err ; } } { size_t srclen = strlen(src) ; size_t dstlen = strlen(dst) ; size_t i = tmpbase ; char srcbuf[srclen + maxlen + 2] ; char dstbuf[dstlen + maxlen + 2] ; memcpy(srcbuf, src, srclen) ; memcpy(dstbuf, dst, dstlen) ; srcbuf[srclen] = '/' ; dstbuf[dstlen] = '/' ; while (i < tmp->len) { size_t n = strlen(tmp->s + i) + 1 ; memcpy(srcbuf + srclen + 1, tmp->s + i, n) ; memcpy(dstbuf + dstlen + 1, tmp->s + i, n) ; i += n ; hiercopy_tmp(srcbuf, dstbuf, tmp) ; } } if (chmod(dst, mode) < 0) goto err ; tmp->len = tmpbase ; return 1 ; err: tmp->len = tmpbase ; return 0 ; } int hiercopy_tmp (char const *src, char const *dst, stralloc *tmp) { struct stat st ; if (lstat(src, &st) < 0) return 0 ; if (S_ISREG(st.st_mode)) { if (!filecopy_unsafe(src, dst, st.st_mode)) return 0 ; } else if (S_ISDIR(st.st_mode)) { if (!dircopy(src, dst, st.st_mode, tmp)) return 0 ; } else if (S_ISFIFO(st.st_mode)) { if (mkfifo(dst, st.st_mode) < 0) return 0 ; } else if (S_ISLNK(st.st_mode)) { size_t tmpbase = tmp->len ; if (sareadlink(tmp, src) < 0) return 0 ; if (!stralloc_0(tmp) || symlink(tmp->s + tmpbase, dst) < 0) { tmp->len = tmpbase ; return 0 ; } tmp->len = tmpbase ; } else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) || S_ISSOCK(st.st_mode)) { if (mknod(dst, st.st_mode, st.st_rdev) < 0) return 0 ; } else return (errno = ENOTSUP, 0) ; lchown(dst, st.st_uid, st.st_gid) ; if (!S_ISLNK(st.st_mode)) chmod(dst, st.st_mode) ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/int160_scan.c000066400000000000000000000001321355335115400202330ustar00rootroot00000000000000/* ISC license. */ #include #include "fmtscan-internal.h" SCANS0(16) skalibs-2.9.1.0/src/libstddjb/int16_fmtlist.c000066400000000000000000000001311355335115400207100ustar00rootroot00000000000000/* ISC license. */ #include "fmtscan-internal.h" #include FMTSL(16) skalibs-2.9.1.0/src/libstddjb/int16_scan.c000066400000000000000000000004541355335115400201620ustar00rootroot00000000000000/* ISC license. */ #include #include #include "fmtscan-internal.h" size_t int16_scan_base (char const *s, int16_t *d, uint8_t base) { int64_t dd ; size_t pos = int64_scan_base_max(s, &dd, base, UINT16_MAX) ; if (pos) *d = (uint16_t)dd ; return pos ; } skalibs-2.9.1.0/src/libstddjb/int16_scanlist.c000066400000000000000000000001321355335115400210470ustar00rootroot00000000000000/* ISC license. */ #include "fmtscan-internal.h" #include SCANSL(16) skalibs-2.9.1.0/src/libstddjb/int320_scan.c000066400000000000000000000001321355335115400202310ustar00rootroot00000000000000/* ISC license. */ #include #include "fmtscan-internal.h" SCANS0(32) skalibs-2.9.1.0/src/libstddjb/int32_fmtlist.c000066400000000000000000000001311355335115400207060ustar00rootroot00000000000000/* ISC license. */ #include "fmtscan-internal.h" #include FMTSL(32) skalibs-2.9.1.0/src/libstddjb/int32_scan.c000066400000000000000000000004531355335115400201570ustar00rootroot00000000000000/* ISC license. */ #include #include #include "fmtscan-internal.h" size_t int32_scan_base (char const *s, int32_t *d, uint8_t base) { int64_t dd ; size_t pos = int64_scan_base_max(s, &dd, base, UINT32_MAX) ; if (pos) *d = (int32_t)dd ; return pos ; } skalibs-2.9.1.0/src/libstddjb/int32_scanlist.c000066400000000000000000000001321355335115400210450ustar00rootroot00000000000000/* ISC license. */ #include "fmtscan-internal.h" #include SCANSL(32) skalibs-2.9.1.0/src/libstddjb/int640_scan.c000066400000000000000000000001321355335115400202360ustar00rootroot00000000000000/* ISC license. */ #include #include "fmtscan-internal.h" SCANS0(64) skalibs-2.9.1.0/src/libstddjb/int64_fmt_generic.c000066400000000000000000000004121355335115400215150ustar00rootroot00000000000000/* ISC license. */ #include size_t int64_fmt_generic (char *fmt, int64_t d, uint8_t base) { if (d >= 0) return uint64_fmt_generic(fmt, (uint64_t)d, base) ; if (fmt) *fmt++ = '-' ; return 1 + uint64_fmt_generic(fmt, -(uint64_t)d, base) ; } skalibs-2.9.1.0/src/libstddjb/int64_fmtlist.c000066400000000000000000000001311355335115400207130ustar00rootroot00000000000000/* ISC license. */ #include "fmtscan-internal.h" #include FMTSL(64) skalibs-2.9.1.0/src/libstddjb/int64_scan.c000066400000000000000000000003121355335115400201560ustar00rootroot00000000000000/* ISC license. */ #include #include "fmtscan-internal.h" size_t int64_scan_base (char const *s, int64_t *d, uint8_t base) { return int64_scan_base_max(s, d, base, INT64_MAX) ; } skalibs-2.9.1.0/src/libstddjb/int64_scan_base_max.c000066400000000000000000000010021355335115400220120ustar00rootroot00000000000000/* ISC license. */ #include #include "fmtscan-internal.h" size_t int64_scan_base_max (char const *s, int64_t *d, uint8_t base, uint64_t max) { if (s[0] == '-') { uint64_t u ; size_t pos = uint64_scan_base_max(s+1, &u, base, max+1) ; return pos ? (*d = -u, 1 + pos) : 0 ; } else if (s[0] == '+') { size_t pos = uint64_scan_base_max(s+1, (uint64_t *)d, base, max) ; return pos ? 1 + pos : 0 ; } else return uint64_scan_base_max(s, (uint64_t *)d, base, max) ; } skalibs-2.9.1.0/src/libstddjb/int64_scanlist.c000066400000000000000000000001321355335115400210520ustar00rootroot00000000000000/* ISC license. */ #include "fmtscan-internal.h" #include SCANSL(64) skalibs-2.9.1.0/src/libstddjb/iobuffer_fill.c000066400000000000000000000004321355335115400210200ustar00rootroot00000000000000/* ISC license. */ #include #include ssize_t iobuffer_fill (iobuffer_ref b) { if (b->isk) { ssize_t r = iobufferk_fill(&b->x.k) ; if (r >= 0 || errno != ENOSYS || !iobuffer_salvage(b)) return r ; } return iobufferu_fill(&b->x.u) ; } skalibs-2.9.1.0/src/libstddjb/iobuffer_flush.c000066400000000000000000000004161355335115400212150ustar00rootroot00000000000000/* ISC license. */ #include #include int iobuffer_flush (iobuffer *b) { if (b->isk) { if (iobufferk_flush(&b->x.k)) return 1 ; if (errno != ENOSYS || !iobuffer_salvage(b)) return 0 ; } return iobufferu_flush(&b->x.u) ; } skalibs-2.9.1.0/src/libstddjb/iobuffer_init.c000066400000000000000000000005561355335115400210440ustar00rootroot00000000000000/* ISC license. */ #include int iobuffer_init (iobuffer *b, int fdin, int fdout) { if (!iobufferk_init(&b->x.k, fdin, fdout)) goto user ; if (!iobufferk_isworking(&b->x.k)) goto fk ; b->isk = 1 ; return 1 ; fk: iobufferk_finish(&b->x.k) ; user: if (!iobufferu_init(&b->x.u, fdin, fdout)) return 0 ; b->isk = 0 ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/iobuffer_kfromu.c000066400000000000000000000012271355335115400214000ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASSPLICE #include #include #include #include #include int iobuffer_kfromu (iobufferk *k, iobufferu *u) { struct iovec v[2] ; ssize_t r ; buffer_rpeek(&u->b[0], v) ; r = vmsplice(k->p[1], v, 2, 0) ; if (r < 0) return 0 ; k->n += r ; buffer_rseek(&u->b[0], r) ; u->b[1].c.p = u->b[0].c.p ; return iobufferu_isempty(u) ; } #else #include #include int iobuffer_kfromu (iobufferk *k, iobufferu *u) { (void)k ; (void)u ; return (errno = ENOSYS, 0) ; } #endif skalibs-2.9.1.0/src/libstddjb/iobuffer_salvage.c000066400000000000000000000005531355335115400215200ustar00rootroot00000000000000/* ISC license. */ #include int iobuffer_salvage (iobuffer *b) { iobufferu u ; if (!b->isk) return 1 ; if (!iobufferu_init(&u, b->x.k.fd[0], b->x.k.fd[1])) return 0 ; if (!iobuffer_ufromk(&u, &b->x.k)) goto err ; iobufferk_finish(&b->x.k) ; b->x.u = u ; b->isk = 0 ; return 1 ; err: iobufferu_finish(&u) ; return 0 ; } skalibs-2.9.1.0/src/libstddjb/iobuffer_ufromk.c000066400000000000000000000011051355335115400213730ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASSPLICE #include #include int iobuffer_ufromk (iobufferu *u, iobufferk *k) { int in = u->b[0].fd ; u->b[0].fd = k->p[0] ; while (k->n) { ssize_t r = iobufferu_fill(u) ; if (r <= 0) goto err ; k->n -= r ; } u->b[0].fd = in ; return 1 ; err: u->b[0].fd = in ; return 0 ; } #else #include #include int iobuffer_ufromk (iobufferu *u, iobufferk *k) { (void)u ; (void)k ; return (errno = ENOSYS, 0) ; } #endif skalibs-2.9.1.0/src/libstddjb/iobufferk_fill.c000066400000000000000000000024031355335115400211730ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASSPLICE #include #include #include #include static ssize_t iobufferk_tee (iobufferk *k) { ssize_t r = tee(k->fd[0], k->fd[1], IOBUFFERK_SIZE - k->n, k->nb & 1 ? SPLICE_F_NONBLOCK : 0) ; if (r > 0) k->n += r ; return r ; } static ssize_t iobufferk_splice (iobufferk *k) { ssize_t r = splice(k->fd[0], 0, k->fd[1], 0, IOBUFFERK_SIZE, k->nb ? SPLICE_F_NONBLOCK : 0) ; if (r > 0) k->n += r ; if ((r < 0) && (errno == EINVAL)) errno = ENOSYS ; return r ; } static ssize_t iobufferk_fill_3 (iobufferk *k) { ssize_t r = splice(k->fd[0], 0, k->p[1], 0, IOBUFFERK_SIZE - k->n, k->nb & 1 ? SPLICE_F_NONBLOCK : 0) ; if (r > 0) k->n += r ; if ((r < 0) && (errno == EINVAL)) errno = ENOSYS ; return r ; } iobufferk_input_func_t_ref const iobufferk_fill_f[4] = { &iobufferk_tee, &iobufferk_splice, &iobufferk_splice, &iobufferk_fill_3 } ; #else #include #include static ssize_t iobufferk_inosys (iobufferk *k) { (void)k ; return (errno = ENOSYS, -1) ; } iobufferk_input_func_t_ref const iobufferk_fill_f[4] = { &iobufferk_inosys, &iobufferk_inosys, &iobufferk_inosys, &iobufferk_inosys } ; #endif skalibs-2.9.1.0/src/libstddjb/iobufferk_finish.c000066400000000000000000000013371355335115400215320ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASSPLICE #include #include static void iobufferk_nop (iobufferk *k) { (void)k ; } static void iobufferk_finish_0 (iobufferk *k) { fd_close(k->p[1]) ; } static void iobufferk_finish_3 (iobufferk *k) { fd_close(k->p[1]) ; fd_close(k->p[0]) ; } iobufferk_finish_func_t_ref const iobufferk_finish_f[4] = { &iobufferk_finish_0, &iobufferk_nop, &iobufferk_nop, &iobufferk_finish_3 } ; #else #include static void iobufferk_nop (iobufferk *k) { (void)k ; } iobufferk_finish_func_t_ref const iobufferk_finish_f[4] = { &iobufferk_nop, &iobufferk_nop, &iobufferk_nop, &iobufferk_nop } ; #endif skalibs-2.9.1.0/src/libstddjb/iobufferk_flush.c000066400000000000000000000023061355335115400213700ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASSPLICE #include #include #include #include static int iobufferk_flush_0 (iobufferk *k) { while (k->n) { ssize_t r = splice(k->fd[0], 0, k->p[1], 0, k->n, 0) ; if (r < 0) return 0 ; else if (!r) break ; k->n -= r ; } return 1 ; } static int fakeflush (iobufferk *k) { k->n = 0 ; return 1 ; } static int iobufferk_flush_3 (iobufferk *k) { while (k->n) { ssize_t r = splice(k->p[0], 0, k->fd[1], 0, k->n, SPLICE_F_MORE | (k->nb & 2 ? SPLICE_F_NONBLOCK : 0)) ; if (r < 0) { if (errno == EINVAL) errno = ENOSYS ; return 0 ; } else if (!r) return (errno = EPIPE, 0) ; k->n -= r ; } return 1 ; } iobufferk_output_func_t_ref const iobufferk_flush_f[4] = { &iobufferk_flush_0, &fakeflush, &fakeflush, &iobufferk_flush_3 } ; #else #include #include static int iobufferk_onosys (iobufferk *k) { (void)k ; return (errno = ENOSYS, -1) ; } iobufferk_output_func_t_ref const iobufferk_flush_f[4] = { &iobufferk_onosys, &iobufferk_onosys, &iobufferk_onosys, &iobufferk_onosys } ; #endif skalibs-2.9.1.0/src/libstddjb/iobufferk_init.c000066400000000000000000000027121355335115400212130ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASSPLICE #include #include #include #include static int iobufferk_init_0 (iobufferk *k) { int fd = open_write("/dev/null") ; if (fd < 0) return 0 ; if (coe(fd) < 0) { fd_close(fd) ; return 0 ; } k->p[0] = -1 ; k->p[1] = fd ; return 1 ; } static int iobufferk_nofd (iobufferk *k) { k->p[0] = k->p[1] = -1 ; return 1 ; } static int iobufferk_init_3 (iobufferk *k) { return (pipenbcoe(k->p) >= 0) ; } static iobufferk_output_func_t_ref iobufferk_init_f[4] = { &iobufferk_init_0, &iobufferk_nofd, &iobufferk_nofd, &iobufferk_init_3 } ; int iobufferk_init (iobufferk *k, int fdin, int fdout) { iobufferk tmp ; struct stat st ; int r ; if (fstat(fdin, &st) < 0) return 0 ; r = fcntl(fdin, F_GETFL) ; if (r < 0) return 0 ; tmp.type = !S_ISFIFO(st.st_mode) ; tmp.nb = !!(r & O_NONBLOCK) ; if (fstat(fdout, &st) < 0) return 0 ; r = fcntl(fdout, F_GETFL) ; if (r < 0) return 0 ; tmp.type |= (!S_ISFIFO(st.st_mode) << 1) ; tmp.nb |= (r & O_NONBLOCK) ? 2 : 0 ; tmp.fd[0] = fdin ; tmp.fd[1] = fdout ; tmp.n = 0 ; if (!(*iobufferk_init_f[tmp.type])(&tmp)) return 0 ; *k = tmp ; return 1 ; } #else #include #include int iobufferk_init (iobufferk *k, int fdin, int fdout) { (void)k ; (void)fdin ; (void)fdout ; return (errno = ENOSYS, 0) ; } #endif skalibs-2.9.1.0/src/libstddjb/iobufferk_isworking.c000066400000000000000000000013711355335115400222640ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASSPLICE #include #include #include #include int iobufferk_isworking (iobufferk *k) { /* for now splice() with a length of 0 returns 0 no matter what, so this */ /* test is useless. splice() should test the underlying filesystems even */ /* if the length is 0. */ # if 0 int e = errno ; if (splice(k->fd[0], 0, k->p[1], 0, 0, 0) < 0) goto no ; if (splice(k->p[0], 0, k->fd[1], 0, 0, 0) < 0) goto no ; errno = e ; return 1 ; no: errno = e ; return 0 ; # else (void)k ; return 1 ; # endif } #else #include int iobufferk_isworking (iobufferk *k) { (void)k ; return 0 ; } #endif skalibs-2.9.1.0/src/libstddjb/iobufferu_fill.c000066400000000000000000000003121355335115400212020ustar00rootroot00000000000000/* ISC license. */ #include #include ssize_t iobufferu_fill (iobufferu *b) { ssize_t r = buffer_fill(&b->b[0]) ; b->b[1].c.n = b->b[0].c.n ; return r ; } skalibs-2.9.1.0/src/libstddjb/iobufferu_finish.c000066400000000000000000000002161355335115400215370ustar00rootroot00000000000000/* ISC license. */ #include #include void iobufferu_finish (iobufferu *b) { alloc_free(b->buf) ; } skalibs-2.9.1.0/src/libstddjb/iobufferu_flush.c000066400000000000000000000003041355335115400213760ustar00rootroot00000000000000/* ISC license. */ #include #include int iobufferu_flush (iobufferu *b) { int r = buffer_flush(&b->b[1]) ; b->b[0].c.p = b->b[1].c.p ; return r ; } skalibs-2.9.1.0/src/libstddjb/iobufferu_init.c000066400000000000000000000006321355335115400212240ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int iobufferu_init (iobufferu *b, int fdin, int fdout) { char *x = alloc(IOBUFFERU_SIZE) ; if (!x) return 0 ; b->buf = x ; buffer_init(&b->b[0], &fd_readv, fdin, x, IOBUFFERU_SIZE) ; buffer_init(&b->b[1], &fd_writev, fdout, x, IOBUFFERU_SIZE) ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/iopause.c000066400000000000000000000005461355335115400176640ustar00rootroot00000000000000/* ISC license. */ #include #include #ifdef SKALIBS_HASPPOLL iopause_func_t_ref const iopause_ = &iopause_ppoll ; #else #include #ifdef SKALIBS_FLAG_PREFERSELECT iopause_func_t_ref const iopause_ = &iopause_select ; #else iopause_func_t_ref const iopause_ = &iopause_poll ; #endif #endif skalibs-2.9.1.0/src/libstddjb/iopause_poll.c000066400000000000000000000006711355335115400207110ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int iopause_poll (iopause_fd *x, unsigned int len, tain_t const *deadline, tain_t const *stamp) { int millisecs = 0 ; if (!deadline) millisecs = -1 ; else if (tain_less(stamp, deadline)) { tain_t t ; tain_sub(&t, deadline, stamp) ; millisecs = tain_to_millisecs(&t) ; } return poll(x, len, millisecs) ; } skalibs-2.9.1.0/src/libstddjb/iopause_ppoll.c000066400000000000000000000016321355335115400210670ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASPPOLL #include #include #include #include #include #include int iopause_ppoll (iopause_fd *x, unsigned int len, tain_t const *deadline, tain_t const *stamp) { struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 } ; if (deadline && tain_less(stamp, deadline)) { tain_t delta ; tain_sub(&delta, deadline, stamp) ; if (!timespec_from_tain_relative(&ts, &delta)) { if (errno != EOVERFLOW) return -1 ; else deadline = 0 ; } } return ppoll(x, len, deadline ? &ts : 0, 0) ; } #else #include #include int iopause_ppoll (iopause_fd *x, unsigned int len, tain_t const *deadline, tain_t const *stamp) { (void)x ; (void)len ; (void)deadline ; (void)stamp ; return (errno = ENOSYS, -1) ; } #endif skalibs-2.9.1.0/src/libstddjb/iopause_select.c000066400000000000000000000031751355335115400212240ustar00rootroot00000000000000/* ISC license. */ #include #include /* Solaris... */ #include #include #include #include int iopause_select (iopause_fd *x, unsigned int len, tain_t const *deadline, tain_t const *stamp) { struct timeval tv = { .tv_sec = 0, .tv_usec = 0 } ; int nfds = 0 ; fd_set rfds, wfds, xfds ; int r ; FD_ZERO(&rfds) ; FD_ZERO(&wfds) ; FD_ZERO(&xfds) ; if (deadline && tain_less(stamp, deadline)) { tain_t delta ; tain_sub(&delta, deadline, stamp) ; if (!timeval_from_tain_relative(&tv, &delta)) { if (errno != EOVERFLOW) return -1 ; else deadline = 0 ; } } { unsigned int i = 0 ; for (; i < len ; i++) { x[i].revents = 0 ; if (x[i].fd >= 0) { if (x[i].fd >= FD_SETSIZE) return (errno = EMFILE, -1) ; if (x[i].fd >= nfds) nfds = x[i].fd + 1 ; if (x[i].events & IOPAUSE_READ) FD_SET(x[i].fd, &rfds) ; if (x[i].events & IOPAUSE_WRITE) FD_SET(x[i].fd, &wfds) ; if (x[i].events & IOPAUSE_EXCEPT) FD_SET(x[i].fd, &xfds) ; } } } r = select(nfds, &rfds, &wfds, &xfds, deadline ? &tv : 0) ; if (r > 0) { unsigned int i = 0 ; for (; i < len ; i++) if (x[i].fd >= 0) { if ((x[i].events & IOPAUSE_READ) && FD_ISSET(x[i].fd, &rfds)) x[i].revents |= IOPAUSE_READ ; if ((x[i].events & IOPAUSE_WRITE) && FD_ISSET(x[i].fd, &wfds)) x[i].revents |= IOPAUSE_WRITE ; if ((x[i].events & IOPAUSE_EXCEPT) && FD_ISSET(x[i].fd, &xfds)) x[i].revents |= IOPAUSE_EXCEPT ; } } return r ; } skalibs-2.9.1.0/src/libstddjb/iopause_stamp.c000066400000000000000000000006131355335115400210630ustar00rootroot00000000000000/* ISC license. */ #include #include #include int iopause_stamp (iopause_fd *x, unsigned int n, tain_t const *deadline, tain_t *stamp) { int r ; do { r = iopause(x, n, deadline, stamp) ; if (stamp) { int e = errno ; tain_now(stamp) ; errno = e ; } } while ((r < 0) && (errno == EINTR)) ; return r ; } skalibs-2.9.1.0/src/libstddjb/ip46_scan.c000066400000000000000000000004341355335115400200010ustar00rootroot00000000000000/* ISC license. */ #include #include size_t ip46full_scan (char const *s, ip46full_t *ip) { size_t len = ip6_scan(s, ip->ip) ; if (len) ip->is6 = 1 ; else { len = ip4_scan(s, ip->ip) ; if (len) ip->is6 = 0 ; } return len ; } skalibs-2.9.1.0/src/libstddjb/ip46_scanlist.c000066400000000000000000000010201355335115400206650ustar00rootroot00000000000000/* ISC license. */ #include #include #include size_t ip46full_scanlist (ip46full_t *out, size_t max, char const *s, size_t *num) { size_t n = 0, w = 0 ; for (; s[w] && (n < max) ; n++) { ip46full_t z ; size_t i = ip6_scan(s + w, z.ip) ; if (i) z.is6 = 1 ; else { i = ip4_scan(s + w, z.ip) ; if (!i) break ; z.is6 = 0 ; } out[n] = z ; w += i ; while (memchr(",; \t\r\n", s[w], 6)) w++ ; } *num = n ; return w ; } skalibs-2.9.1.0/src/libstddjb/ip4_fmt.c000066400000000000000000000005461355335115400175610ustar00rootroot00000000000000/* ISC license. */ #include #include size_t ip4_fmt (char *s, char const *ip) { size_t len = 0 ; unsigned int j = 0 ; for (; j < 4 ; j++) { size_t i = uint32_fmt(s, (unsigned char)ip[j]) ; len += i ; if (s) s += i ; if (j == 3) break ; if (s) *s++ = '.' ; ++len ; } return len ; } skalibs-2.9.1.0/src/libstddjb/ip4_fmtu32.c000066400000000000000000000003061355335115400201050ustar00rootroot00000000000000/* ISC license. */ #include #include size_t ip4_fmtu32 (char *s, uint32_t ip) { char pack[4] ; uint32_pack_big(pack, ip) ; return ip4_fmt(s, pack) ; } skalibs-2.9.1.0/src/libstddjb/ip4_scan.c000066400000000000000000000006361355335115400177170ustar00rootroot00000000000000/* ISC license. */ #include #include size_t ip4_scan (char const *s, char *ip) { size_t len = 0 ; unsigned int j = 0 ; for (; j < 4 ; j++) { unsigned int u ; size_t i = uint_scan(s, &u) ; if (!i) return 0 ; ip[j] = (char)u ; s += i ; len += i ; if (j == 3) break ; if (*s != '.') return 0 ; ++s ; ++len ; } return len ; } skalibs-2.9.1.0/src/libstddjb/ip4_scanlist.c000066400000000000000000000005601355335115400206070ustar00rootroot00000000000000/* ISC license. */ #include #include size_t ip4_scanlist (char *out, size_t max, char const *s, size_t *num) { size_t n = 0, w = 0 ; for (; s[w] && (n < max) ; n++) { size_t i = ip4_scan(s + w, out + (n << 2)) ; if (!i) break ; w += i ; while (memchr(",:; \t\r\n", s[w], 7)) w++ ; } *num = n ; return w ; } skalibs-2.9.1.0/src/libstddjb/ip4_scanlist_u32.c000066400000000000000000000005641355335115400213040ustar00rootroot00000000000000/* ISC license. */ #include #include size_t ip4_scanlist_u32 (uint32_t *out, size_t max, char const *s, size_t *num) { size_t n = 0, w = 0 ; for (; s[w] && (n < max) ; n++) { size_t i = ip4_scanu32(s + w, out + n) ; if (!i) break ; w += i ; while (memchr(",:; \t\r\n", s[w], 7)) w++ ; } *num = n ; return w ; } skalibs-2.9.1.0/src/libstddjb/ip4_scanu32.c000066400000000000000000000003511355335115400202430ustar00rootroot00000000000000/* ISC license. */ #include #include size_t ip4_scanu32 (char const *s, uint32_t *ip) { char pack[4] ; size_t r = ip4_scan(s, pack) ; if (r) uint32_unpack_big(pack, ip) ; return r ; } skalibs-2.9.1.0/src/libstddjb/ip6_fmt.c000066400000000000000000000031101355335115400175510ustar00rootroot00000000000000/* ISC license. */ #include #include #define px(c) ((j || (c)) ? (*s++ = fmtscan_asc(c), 1) : 0) static inline size_t xfmt16 (char *s, char const *key) { size_t j = 0 ; j += px((unsigned char)key[0] >> 4) ; j += px((unsigned char)key[0] & 15) ; j += px((unsigned char)key[1] >> 4) ; j += px((unsigned char)key[1] & 15) ; return j ? j : (*s = '0', 1) ; } static inline unsigned int find_colcol (char const *key, unsigned int *pos) { diuint z[4] = { DIUINT_ZERO, DIUINT_ZERO, DIUINT_ZERO, DIUINT_ZERO } ; unsigned int j = 0 ; unsigned int max = 0 ; int iszero = 0 ; unsigned int i = 0 ; for ( ; i < 8 ; i++) { if (key[i<<1] || key[(i<<1)+1]) { if (iszero) { iszero = 0 ; z[j].right = i - z[j].left ; if (z[j].right > max) max = z[j].right ; j++ ; } } else { if (!iszero) { iszero = 1 ; z[j].left = i ; } } } if (iszero) { z[j].right = 8 - z[j].left ; if (z[j].right > max) max = z[j].right ; j++ ; } if (max >= 2) for (i = 0 ; i < j ; i++) if (z[i].right == max) return (*pos = z[i].left, max) ; return 0 ; } size_t ip6_fmt (char *s, char const *ip6) { size_t w = 0 ; unsigned int pos = 8 ; unsigned int len = find_colcol(ip6, &pos) ; unsigned int i = 0 ; for (; i < 8 ; i++) { if (i == pos) { if (!i) s[w++] = ':' ; s[w++] = ':' ; i += len-1 ; } else { w += xfmt16(s + w, ip6 + (i<<1)) ; if (i < 7) s[w++] = ':' ; } } return w ; } skalibs-2.9.1.0/src/libstddjb/ip6_scan.c000066400000000000000000000025651355335115400177240ustar00rootroot00000000000000/* ISC license. */ #include #include #include size_t ip6_scan (char const *s, char *ip6) { static const unsigned char class[256] = "2222222222222222222222222222222222222222222222220000000000122222200000022222222222222222222222222000000222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222" ; static const unsigned char table[5][3] = { "\024#\005", "\024\"\005", "\024\005\006", "\005\002\005", "\024\t\016" } ; uint16_t tmp[8] = { 0, 0, 0, 0, 0, 0, 0, 0 } ; size_t i = 0 ; unsigned int pos = 8, j = 0, state = 0 ; while (state < 5) { unsigned char c = table[state][class[(unsigned char)s[i]] - '0'] ; state = c & 7 ; if (c & 0x20) { if (pos < 8) state = 5 ; else pos = j ; } if (c & 0x10) { if (tmp[j] & 0xf000) state = 5 ; else tmp[j] = (tmp[j] << 4) + fmtscan_num(s[i], 16) ; } if (c & 0x08) if ((++j > 7) && (state < 5)) state = 5 ; i++ ; } if (((pos < 8) && (j > 6)) || ((pos == 8) && (j < 8))) state = 5 ; if (state == 5) return (errno = EINVAL, 0) ; for (state = j ; state > pos ; state--) tmp[state - j + 7] = tmp[state - 1] ; for (; state < pos + 8 - j ; state++) tmp[state] = 0 ; for (j = 0 ; j < 8 ; j++) uint16_pack_big(ip6 + (j<<1), tmp[j]) ; return i - 1 ; } skalibs-2.9.1.0/src/libstddjb/ip6_scanlist.c000066400000000000000000000006321355335115400206110ustar00rootroot00000000000000/* ISC license. */ #include #include size_t ip6_scanlist (char *out, size_t max, char const *s, size_t *num) { size_t n = 0, w = 0 ; for (; s[w] && (n < max) ; n++) { char ip[16] ; size_t i = ip6_scan(s + w, ip) ; if (!i) break ; memcpy(out + (n << 4), ip, 16) ; w += i ; while (memchr(",; \t\r\n", s[w], 6)) w++ ; } *num = n ; return w ; } skalibs-2.9.1.0/src/libstddjb/ipc_accept.c000066400000000000000000000022751355335115400203120ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include #include int ipc_accept_internal (int s, char *p, size_t l, int *trunc, unsigned int options) { struct sockaddr_un sa ; socklen_t dummy = sizeof sa ; int fd ; memset(&sa, 0, dummy) ; do #ifdef SKALIBS_HASACCEPT4 fd = accept4(s, (struct sockaddr *)&sa, &dummy, ((options & DJBUNIX_FLAG_NB) ? SOCK_NONBLOCK : 0) | ((options & DJBUNIX_FLAG_COE) ? SOCK_CLOEXEC : 0)) ; #else fd = accept(s, (struct sockaddr *)&sa, &dummy) ; #endif while ((fd == -1) && (errno == EINTR)) ; if (fd == -1) return -1 ; #ifndef SKALIBS_HASACCEPT4 if ((((options & DJBUNIX_FLAG_NB) ? ndelay_on(fd) : ndelay_off(fd)) < 0) || (((options & DJBUNIX_FLAG_COE) ? coe(fd) : uncoe(fd)) < 0)) { fd_close(fd) ; return -1 ; } #endif if (p) { dummy = byte_chr(sa.sun_path, dummy, 0) ; *trunc = 1 ; if (!l) return fd ; if (l < (dummy + 1)) dummy = l - 1 ; else *trunc = 0 ; memcpy(p, sa.sun_path, dummy) ; p[dummy] = 0 ; } return fd ; } skalibs-2.9.1.0/src/libstddjb/ipc_bind.c000066400000000000000000000007451355335115400177670ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include int ipc_bind (int s, char const *p) { struct sockaddr_un sa ; size_t l = strlen(p) ; if (l > IPCPATH_MAX) return (errno = EPROTO, -1) ; memset(&sa, 0, sizeof sa) ; sa.sun_family = AF_UNIX ; memcpy(sa.sun_path, p, l+1) ; return bind(s, (struct sockaddr *)&sa, sizeof sa) ; } skalibs-2.9.1.0/src/libstddjb/ipc_bind_reuse.c000066400000000000000000000004501355335115400211630ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int ipc_bind_reuse (int s, char const *p) { unsigned int opt = 1 ; setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof opt) ; unlink(p) ; return ipc_bind(s, p) ; } skalibs-2.9.1.0/src/libstddjb/ipc_connect.c000066400000000000000000000010761355335115400205020ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include int ipc_connect (int s, char const *p) { struct sockaddr_un sa ; size_t l = strlen(p) ; if (l > IPCPATH_MAX) return (errno = EPROTO, 0) ; memset(&sa, 0, sizeof sa) ; sa.sun_family = AF_UNIX ; memcpy(sa.sun_path, p, l+1) ; if (connect(s, (struct sockaddr *)&sa, sizeof sa) == -1) { if (errno == EINTR) errno = EINPROGRESS ; return 0 ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/ipc_connected.c000066400000000000000000000005741355335115400210150ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int ipc_connected (int s) { struct sockaddr_un sa ; socklen_t dummy = sizeof sa ; if (getpeername(s, (struct sockaddr *)&sa, &dummy) == -1) { char ch ; fd_read(s, &ch, 1) ; return 0 ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/ipc_dgram.c000066400000000000000000000003611355335115400201370ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int ipc_datagram_internal (unsigned int flags) { return socket_internal(AF_UNIX, SOCK_DGRAM, 0, flags) ; } skalibs-2.9.1.0/src/libstddjb/ipc_listen.c000066400000000000000000000002561355335115400203460ustar00rootroot00000000000000/* ISC license. */ #include #include #include int ipc_listen (int s, int backlog) { return listen(s, backlog) ; } skalibs-2.9.1.0/src/libstddjb/ipc_local.c000066400000000000000000000011201355335115400201310ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include int ipc_local (int s, char *p, size_t l, int *trunc) { struct sockaddr_un sa ; socklen_t dummy = sizeof sa ; memset(&sa, 0, sizeof sa) ; if (getsockname(s, (struct sockaddr *)&sa, &dummy) == -1) return -1 ; dummy = byte_chr(sa.sun_path, dummy, 0) ; *trunc = 1 ; if (!l) return 0 ; if (l < (dummy + 1)) dummy = l - 1 ; else *trunc = 0 ; memcpy(p, sa.sun_path, dummy) ; p[dummy] = 0 ; return 0 ; } skalibs-2.9.1.0/src/libstddjb/ipc_pair.c000066400000000000000000000003771355335115400200070ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int ipc_pair_internal (int *sv, unsigned int flags) { return socketpair_internal(AF_UNIX, SOCK_STREAM, 0, flags, sv) ; } skalibs-2.9.1.0/src/libstddjb/ipc_recv.c000066400000000000000000000015061355335115400200060ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include ssize_t ipc_recv (int fd, char *s, size_t len, char *path) { struct sockaddr_un sa = { .sun_family = AF_UNIX } ; socklen_t total = sizeof sa ; char tmp[len] ; ssize_t r ; do r = recvfrom(fd, tmp, len, 0, (struct sockaddr *)&sa, &total) ; while ((r == -1) && (errno == EINTR)) ; if (r < 0) return r ; if (sa.sun_family != AF_UNIX) return (errno = EPROTO, -1) ; if (path) { if (total == sizeof(sa_family_t)) path[0] = 0 ; else { size_t l = strlen(sa.sun_path) ; if (l > IPCPATH_MAX) return (errno = EPROTO, -1) ; memcpy(path, sa.sun_path, l+1) ; } } memcpy(s, tmp, r) ; return r ; } skalibs-2.9.1.0/src/libstddjb/ipc_send.c000066400000000000000000000010341355335115400177740ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include ssize_t ipc_send (int fd, char const *s, size_t len, char const *path) { struct sockaddr_un sa ; size_t l = strlen(path) ; if (l > IPCPATH_MAX) return (errno = EPROTO, -1) ; memset(&sa, 0, sizeof sa) ; sa.sun_family = AF_UNIX ; memcpy(sa.sun_path, path, l+1) ; return sendto(fd, s, len, 0, (struct sockaddr *)&sa, sizeof sa) ; } skalibs-2.9.1.0/src/libstddjb/ipc_stream.c000066400000000000000000000003601355335115400203370ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int ipc_stream_internal (unsigned int flags) { return socket_internal(AF_UNIX, SOCK_STREAM, 0, flags) ; } skalibs-2.9.1.0/src/libstddjb/ipc_timed_connect.c000066400000000000000000000012471355335115400216640ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int ipc_timed_connect (int s, char const *path, tain_t const *deadline, tain_t *stamp) { if (!ipc_connect(s, path)) { iopause_fd x = { s, IOPAUSE_WRITE, 0 } ; if (!error_isagain(errno) && !error_isalready(errno)) return 0 ; for (;;) { int r = iopause_stamp(&x, 1, deadline, stamp) ; if (r < 0) return 0 ; else if (!r) return (errno = ETIMEDOUT, 0) ; else if (x.revents & IOPAUSE_EXCEPT) return 0 ; else if (x.revents & IOPAUSE_WRITE) break ; } if (!ipc_connected(s)) return 0 ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/leapsecs_add.c000066400000000000000000000004771355335115400206310ustar00rootroot00000000000000/* ISC license. */ #include #include "djbtime-internal.h" void leapsecs_add (uint64_t *t, int hit) { uint64_t u = *t - !!hit ; unsigned int i = 0 ; for (; i < leapsecs_table_len ; i++) { if (u < leapsecs_table[i]) break ; if (!hit || (leapsecs_table[i] < u)) ++u ; } *t = u ; } skalibs-2.9.1.0/src/libstddjb/leapsecs_sub.c000066400000000000000000000005551355335115400206670ustar00rootroot00000000000000/* ISC license. */ #include #include "djbtime-internal.h" int leapsecs_sub (uint64_t *t) { uint64_t u = *t ; uint64_t d = 0 ; unsigned int i = 0 ; int hit = 0 ; for (; i < leapsecs_table_len ; i++) { if (u < leapsecs_table[i]) break ; if (u == leapsecs_table[i]) hit = 1 ; else d++ ; } *t = u - d ; return hit ; } skalibs-2.9.1.0/src/libstddjb/leapsecs_table.c000066400000000000000000000017501355335115400211630ustar00rootroot00000000000000/* ISC license. */ /* This file has been generated by ./tools/make-leapsecs_table */ #include #include #include "djbtime-internal.h" unsigned int const leapsecs_table_len = 27 ; static uint64_t const leapsecs_table_[27] = { TAI_MAGIC + 78796800, TAI_MAGIC + 94694401, TAI_MAGIC + 126230402, TAI_MAGIC + 157766403, TAI_MAGIC + 189302404, TAI_MAGIC + 220924805, TAI_MAGIC + 252460806, TAI_MAGIC + 283996807, TAI_MAGIC + 315532808, TAI_MAGIC + 362793609, TAI_MAGIC + 394329610, TAI_MAGIC + 425865611, TAI_MAGIC + 489024012, TAI_MAGIC + 567993613, TAI_MAGIC + 631152014, TAI_MAGIC + 662688015, TAI_MAGIC + 709948816, TAI_MAGIC + 741484817, TAI_MAGIC + 773020818, TAI_MAGIC + 820454419, TAI_MAGIC + 867715220, TAI_MAGIC + 915148821, TAI_MAGIC + 1136073622, TAI_MAGIC + 1230768023, TAI_MAGIC + 1341100824, TAI_MAGIC + 1435708825, TAI_MAGIC + 1483228826 } ; uint64_t const *const leapsecs_table = leapsecs_table_ ; skalibs-2.9.1.0/src/libstddjb/localtm_fmt.c000066400000000000000000000007541355335115400205210ustar00rootroot00000000000000/* ISC license. */ #include #include #include size_t localtm_fmt (char *s, struct tm const *l) { char *p = s ; p += uint_fmt(p, 1900 + l->tm_year) ; *p++ = '-' ; uint0_fmt(p, 1 + l->tm_mon, 2) ; p += 2 ; *p++ = '-' ; uint0_fmt(p, l->tm_mday, 2) ; p += 2 ; *p++ = ' ' ; uint0_fmt(p, l->tm_hour, 2) ; p += 2 ; *p++ = ':' ; uint0_fmt(p, l->tm_min, 2) ; p += 2 ; *p++ = ':' ; uint0_fmt(p, l->tm_sec, 2) ; p += 2 ; return p - s ; } skalibs-2.9.1.0/src/libstddjb/localtm_from_ltm64.c000066400000000000000000000011111355335115400217100ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include int localtm_from_ltm64 (struct tm *l, uint64_t uu, int tzh) { time_t u ; if (uu < TAI_MAGIC) return (errno = EINVAL, 0) ; uu -= TAI_MAGIC ; #if SKALIBS_SIZEOFTIME != 8 if (uu > 0xFFFFFFFFUL) return (errno = EOVERFLOW, 0) ; #endif u = (time_t)uu - !!(tzh & 2) ; if (tzh & 1 ? !localtime_r(&u, l) : !gmtime_r(&u, l)) return 0 ; if (tzh & 2) l->tm_sec++ ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/localtm_from_sysclock.c000066400000000000000000000003661355335115400226070ustar00rootroot00000000000000/* ISC license. */ #include #include #include int localtm_from_sysclock (struct tm *l, uint64_t u, int tz) { if (!ltm64_from_sysclock(&u)) return 0 ; return localtm_from_ltm64(l, u, !!tz) ; } skalibs-2.9.1.0/src/libstddjb/localtm_from_tai.c000066400000000000000000000004151355335115400215250ustar00rootroot00000000000000/* ISC license. */ #include #include #include int localtm_from_tai (struct tm *l, tai_t const *t, int tz) { uint64_t u ; int h = ltm64_from_tai(&u, t) ; return h ? localtm_from_ltm64(l, u, !!tz | (h & 2)) : 0 ; } skalibs-2.9.1.0/src/libstddjb/localtm_from_utc.c000066400000000000000000000003541355335115400215450ustar00rootroot00000000000000/* ISC license. */ #include #include #include int localtm_from_utc (struct tm *l, uint64_t u, int tz) { if (!ltm64_from_utc(&u)) return 0 ; return localtm_from_ltm64(l, u, !!tz) ; } skalibs-2.9.1.0/src/libstddjb/localtm_scan.c000066400000000000000000000022721355335115400206540ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include size_t localtm_scan (char const *s, struct tm *l) { struct tm ll = { .tm_isdst = -1 } ; size_t n = 0 ; unsigned int u ; size_t i = uint_scan(s+n, &u) ; if (!i) goto fail ; n += i ; if (u < 1900) goto fail ; u -= 1900 ; ll.tm_year = u ; if (s[n++] != '-') goto fail ; i = uint_scan(s+n, &u) ; if (!i) goto fail ; n += i ; if (!u || (u > 12)) goto fail ; u-- ; ll.tm_mon = u ; if (s[n++] != '-') goto fail ; i = uint_scan(s+n, &u) ; if (!i) goto fail ; n += i ; if (!u || (u > 31)) goto fail ; ll.tm_mday = u ; if ((s[n] != ' ') && (s[n] != 'T')) goto fail ; n++ ; i = uint_scan(s+n, &u) ; if (!i) goto fail ; n += i ; if (u > 23) goto fail ; ll.tm_hour = u ; if (s[n++] != ':') goto fail ; i = uint_scan(s+n, &u) ; if (!i) goto fail ; n += i ; if (u > 59) goto fail ; ll.tm_min = u ; if (s[n++] != ':') goto fail ; i = uint_scan(s+n, &u) ; if (!i) goto fail ; n += i ; if (u > 60) goto fail ; ll.tm_sec = u ; if (mktime(&ll) == (time_t)-1) goto fail ; *l = ll ; return n ; fail: return (errno = EINVAL, 0) ; } skalibs-2.9.1.0/src/libstddjb/localtmn_fmt.c000066400000000000000000000003731355335115400206740ustar00rootroot00000000000000/* ISC license. */ #include #include size_t localtmn_fmt (char *s, localtmn_t const *l) { char *p = s ; p += localtm_fmt(p, &l->tm) ; *p++ = '.' ; uint320_fmt(p, l->nano, 9) ; p += 9 ; return p - s ; } skalibs-2.9.1.0/src/libstddjb/localtmn_from_sysclock.c000066400000000000000000000004101355335115400227530ustar00rootroot00000000000000/* ISC license. */ #include #include int localtmn_from_sysclock (localtmn_t *l, tain_t const *a, int tz) { struct tm t ; if (!localtm_from_sysclock(&t, a->sec.x, tz)) return 0 ; l->tm = t ; l->nano = a->nano ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/localtmn_from_tain.c000066400000000000000000000004031355335115400220560ustar00rootroot00000000000000/* ISC license. */ #include #include int localtmn_from_tain (localtmn_t *l, tain_t const *a, int tz) { struct tm t ; if (!localtm_from_tai(&t, tain_secp(a), tz)) return 0 ; l->tm = t ; l->nano = a->nano ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/localtmn_scan.c000066400000000000000000000005611355335115400210310ustar00rootroot00000000000000/* ISC license. */ #include #include size_t localtmn_scan (char const *s, localtmn_t *l) { localtmn_t m ; size_t n = localtm_scan(s, &m.tm) ; if (!n) return 0 ; s += n ; if (*s++ != '.') m.nano = 0 ; else { size_t b = uint32_scan(s, &m.nano) ; if (!b) return 0 ; n += b ; } *l = m ; return n ; } skalibs-2.9.1.0/src/libstddjb/lock_ex.c000066400000000000000000000007671355335115400176500ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASFLOCK #include #include #include #include int lock_ex (int fd) { int r ; do r = flock(fd, LOCK_EX) ; while ((r == -1) && (errno == EINTR)) ; return r ; } #else #include #include #include int lock_ex (int fd) { int r ; do r = lockf(fd, F_LOCK, 0) ; while ((r == -1) && (errno == EINTR)) ; return r ; } #endif skalibs-2.9.1.0/src/libstddjb/lock_exnb.c000066400000000000000000000010751355335115400201610ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASFLOCK #include #include #include #include int lock_exnb (int fd) { int r ; do r = flock(fd, LOCK_EX | LOCK_NB) ; while ((r == -1) && (errno == EINTR)) ; return r ; } #else #include #include #include int lock_exnb (int fd) { int r ; do r = lockf(fd, F_TLOCK, 0) ; while ((r == -1) && (errno == EINTR)) ; if ((r == -1) && (errno == EACCES)) errno = EAGAIN ; return r ; } #endif skalibs-2.9.1.0/src/libstddjb/lock_sh.c000066400000000000000000000007671355335115400176460ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASFLOCK #include #include #include #include int lock_sh (int fd) { int r ; do r = flock(fd, LOCK_SH) ; while ((r == -1) && (errno == EINTR)) ; return r ; } #else #include #include #include int lock_sh (int fd) { int r ; do r = lockf(fd, F_LOCK, 0) ; while ((r == -1) && (errno == EINTR)) ; return r ; } #endif skalibs-2.9.1.0/src/libstddjb/lock_shnb.c000066400000000000000000000010751355335115400201570ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASFLOCK #include #include #include #include int lock_shnb (int fd) { int r ; do r = flock(fd, LOCK_SH | LOCK_NB) ; while ((r == -1) && (errno == EINTR)) ; return r ; } #else #include #include #include int lock_shnb (int fd) { int r ; do r = lockf(fd, F_TLOCK, 0) ; while ((r == -1) && (errno == EINTR)) ; if ((r == -1) && (errno == EACCES)) errno = EAGAIN ; return r ; } #endif skalibs-2.9.1.0/src/libstddjb/lock_un.c000066400000000000000000000007701355335115400176500ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASFLOCK #include #include #include #include int lock_un (int fd) { int r ; do r = flock(fd, LOCK_UN) ; while ((r == -1) && (errno == EINTR)) ; return r ; } #else #include #include #include int lock_un (int fd) { int r ; do r = lockf(fd, F_ULOCK, 0) ; while ((r == -1) && (errno == EINTR)) ; return r ; } #endif skalibs-2.9.1.0/src/libstddjb/lock_unx.c000066400000000000000000000002201355335115400200260ustar00rootroot00000000000000/* ISC license. */ #include #include void lock_unx (int fd) { int e = errno ; lock_un(fd) ; errno = e ; } skalibs-2.9.1.0/src/libstddjb/lolprintf.c000066400000000000000000000004141355335115400202220ustar00rootroot00000000000000/* ISC license. */ #include #include #include int lolprintf (char const *format, ...) { va_list args ; int r ; va_start(args, format) ; r = vbprintf(buffer_1, format, args) ; va_end(args) ; return r ; } skalibs-2.9.1.0/src/libstddjb/ltm64_from_localtm.c000066400000000000000000000004701355335115400217170ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int ltm64_from_localtm (uint64_t *uu, struct tm const *l) { struct tm ll = *l ; time_t u = mktime(&ll) ; if (u == (time_t)-1) return (errno = EINVAL, 0) ; *uu = TAI_MAGIC + u ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/ltm64_from_sysclock.c000066400000000000000000000005121355335115400221130ustar00rootroot00000000000000/* ISC license. */ #include #include #ifdef SKALIBS_FLAG_CLOCKISTAI #include int ltm64_from_sysclock (uint64_t *u) { tai_t t = { .x = *u + 10U } ; return ltm64_from_tai(u, &t) ; } #else int ltm64_from_sysclock (uint64_t *u) { return ltm64_from_utc(u) ; } #endif skalibs-2.9.1.0/src/libstddjb/ltm64_from_tai.c000066400000000000000000000004301355335115400210350ustar00rootroot00000000000000/* ISC license. */ #include #include "djbtime-internal.h" int ltm64_from_tai (uint64_t *u, tai_t const *t) { switch (skalibs_tzisright()) { case 1 : *u = t->x - 10U ; return 1 ; case 0 : return utc_from_tai(u, t) ; default : return 0 ; } } skalibs-2.9.1.0/src/libstddjb/ltm64_from_utc.c000066400000000000000000000004131355335115400210540ustar00rootroot00000000000000/* ISC license. */ #include #include #include "djbtime-internal.h" int ltm64_from_utc (uint64_t *u) { switch (skalibs_tzisright()) { case 1 : leapsecs_add(u, 0) ; case 0 : return 1 ; default : return 0 ; } } skalibs-2.9.1.0/src/libstddjb/ndelay_off.c000066400000000000000000000003061355335115400203170ustar00rootroot00000000000000/* ISC license. */ #include #include int ndelay_off (int fd) { int got = fcntl(fd, F_GETFL) ; return (got == -1) ? -1 : fcntl(fd, F_SETFL, got & ~O_NONBLOCK) ; } skalibs-2.9.1.0/src/libstddjb/ndelay_on.c000066400000000000000000000003041355335115400201570ustar00rootroot00000000000000/* ISC license. */ #include #include int ndelay_on (int fd) { int got = fcntl(fd, F_GETFL) ; return (got == -1) ? -1 : fcntl(fd, F_SETFL, got | O_NONBLOCK) ; } skalibs-2.9.1.0/src/libstddjb/netstring_append.c000066400000000000000000000007501355335115400215600ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int netstring_appendb (stralloc *sa, char const *s, size_t len) { char fmt[UINT64_FMT] ; size_t n = uint64_fmt(fmt, len) ; if (!stralloc_readyplus(sa, len + n + 2)) return 0 ; fmt[n] = ':' ; memcpy(sa->s + sa->len, fmt, n+1) ; memcpy(sa->s + sa->len + n+1, s, len) ; sa->s[sa->len + n+1 + len] = ',' ; sa->len += n + 2 + len ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/netstring_appendv.c000066400000000000000000000013141355335115400217430ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include int netstring_appendv (stralloc *sa, struct iovec const *v, unsigned int n) { char fmt[UINT64_FMT] ; size_t len = 0, pos ; unsigned int i = 0 ; for (; i < n ; i++) len += v[i].iov_len ; pos = uint64_fmt(fmt, len) ; if (!stralloc_readyplus(sa, len + pos + 2)) return 0 ; fmt[pos] = ':' ; memcpy(sa->s + sa->len, fmt, pos+1) ; sa->len += pos+1 ; for (i = 0 ; i < n ; i++) { memcpy(sa->s + sa->len, v[i].iov_base, v[i].iov_len) ; sa->len += v[i].iov_len ; } sa->s[sa->len++] = ',' ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/netstring_decode.c000066400000000000000000000011171355335115400215320ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include ssize_t netstring_decode (stralloc *sa, char const *s, size_t len) { uint64_t nlen ; size_t pos ; if (!len) return 0 ; pos = uint64_scan(s, &nlen) ; if (pos >= len) return (errno = EINVAL, -1) ; if (s[pos] != ':') return (errno = EINVAL, -1) ; s += pos+1 ; len -= pos+1 ; if (len <= nlen) return (errno = EINVAL, -1) ; if (s[nlen] != ',') return (errno = EINVAL, -1) ; if (!stralloc_catb(sa, s, nlen)) return -1 ; return pos + nlen + 2 ; } skalibs-2.9.1.0/src/libstddjb/netstring_encode.c000066400000000000000000000007041355335115400215450ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int netstring_encode (stralloc *sa, char const *s, size_t len) { char fmt[UINT64_FMT] ; size_t pos = uint64_fmt(fmt, len) ; if (!stralloc_readyplus(sa, pos + len + 2)) return 0 ; stralloc_catb(sa, fmt, pos) ; stralloc_catb(sa, ":", 1) ; stralloc_catb(sa, s, len) ; stralloc_catb(sa, ",", 1) ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/netstring_get.c000066400000000000000000000025511355335115400210710ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include int netstring_okeof (buffer *b, size_t w) { return (errno == EPIPE) && !w && buffer_isempty(b) ? (errno = 0, 1) : 0 ; } int netstring_get (buffer *b, stralloc *sa, size_t *state) { if (!*state) { size_t n ; size_t len ; char buf[SIZE_FMT] ; if (b->c.a < SIZE_FMT+1) return (errno = EINVAL, -1) ; for (;;) { ssize_t r ; len = buffer_getnofill(b, buf, SIZE_FMT) ; n = byte_chr(buf, len, ':') ; /* XXX: accepts :, as a valid netstring */ if (n >= SIZE_FMT) { buffer_unget(b, len) ; return (errno = EPROTO, -1) ; } if (n < len) break ; buffer_unget(b, len) ; r = sanitize_read(buffer_fill(b)) ; if (r <= 0) return r ; } buffer_unget(b, len - n - 1) ; if (!n || n != size_scan(buf, &len)) return (errno = EPROTO, -1) ; if (!stralloc_readyplus(sa, len + 1)) return -1 ; *state = len + 1 ; } { size_t w = 0 ; int r = buffer_getall(b, sa->s + sa->len, *state, &w) ; sa->len += w ; *state -= w ; if (r <= 0) return r ; } return (sa->s[--sa->len] == ',') ? 1 : (errno = EPROTO, -1) ; } skalibs-2.9.1.0/src/libstddjb/netstring_put.c000066400000000000000000000015211355335115400211160ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int netstring_put (buffer *b, char const *s, size_t len, size_t *written) { char fmt[UINT64_FMT] ; size_t n = uint64_fmt(fmt, len) ; if (*written > len + n + 2) return (errno = EINVAL, 0) ; fmt[n] = ':' ; if (*written < n + 1) { size_t w = *written ; int r = buffer_putall(b, fmt, n+1, &w) ; if (r < 0) return (*written = w, 0) ; *written = n+1 ; } if (*written < n+1 + len) { size_t w = *written - (n+1) ; int r = buffer_putall(b, s, len, &w) ; *written = w + (n+1) ; if (r < 0) return (*written = n+1 + w, 0) ; *written = n+1 + len ; } { size_t w = 0 ; int r = buffer_putall(b, ",", 1, &w) ; if (r < 0) return 0 ; } *written = 0 ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/ntp_from_tain.c000066400000000000000000000011241355335115400210470ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int ntp_from_tain (uint64_t *u, tain_t const *a) { uint64_t secs, frac ; if (!utc_from_tai(&secs, tain_secp(a))) return 0 ; secs += NTP_OFFSET ; if (secs < TAI_MAGIC + 2147483648UL) goto ifail ; secs -= TAI_MAGIC ; if (secs >= ((uint64)3 << 31)) goto ifail ; secs &= (secs < ((uint64)1 << 32)) ? 0xFFFFFFFFUL : 0x7FFFFFFFUL ; frac = ((uint64)a->nano << 32) / 1000000000UL ; *u = (secs << 32) + frac ; return 1 ; ifail: errno = EINVAL ; return 0 ; } skalibs-2.9.1.0/src/libstddjb/open2.c000066400000000000000000000003741355335115400172410ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int open2 (char const *s, unsigned int flags) { int r ; do r = open(s, flags) ; while ((r == -1) && (errno == EINTR)) ; return r ; } skalibs-2.9.1.0/src/libstddjb/open3.c000066400000000000000000000004251355335115400172370ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int open3 (char const *s, unsigned int flags, unsigned int mode) { int r ; do r = open(s, flags, mode) ; while ((r == -1) && (errno == EINTR)) ; return r ; } skalibs-2.9.1.0/src/libstddjb/open_append.c000066400000000000000000000003171355335115400205030ustar00rootroot00000000000000/* ISC license. */ #include #include #include int open_append (char const *fn) { return open3(fn, O_WRONLY | O_NONBLOCK | O_APPEND | O_CREAT, 0666) ; } skalibs-2.9.1.0/src/libstddjb/open_create.c000066400000000000000000000003041355335115400204730ustar00rootroot00000000000000/* ISC license. */ #include #include #include int open_create (char const *fn) { return open3(fn, O_WRONLY | O_NONBLOCK | O_CREAT, 0666) ; } skalibs-2.9.1.0/src/libstddjb/open_excl.c000066400000000000000000000003131355335115400201630ustar00rootroot00000000000000/* ISC license. */ #include #include #include int open_excl (char const *fn) { return open3(fn, O_WRONLY | O_CREAT | O_EXCL | O_NONBLOCK, 0666) ; } skalibs-2.9.1.0/src/libstddjb/open_read.c000066400000000000000000000002621355335115400201460ustar00rootroot00000000000000/* ISC license. */ #include #include #include int open_read (char const *fn) { return open2(fn, O_RDONLY | O_NONBLOCK) ; } skalibs-2.9.1.0/src/libstddjb/open_readb.c000066400000000000000000000003361355335115400203120ustar00rootroot00000000000000/* ISC license. */ #include int open_readb (char const *fn) { int fd = open_read(fn) ; if (fd < 0) return -1 ; if (ndelay_off(fd) < 0) { fd_close(fd) ; return -1 ; } return fd ; } skalibs-2.9.1.0/src/libstddjb/open_trunc.c000066400000000000000000000003151355335115400203650ustar00rootroot00000000000000/* ISC license. */ #include #include #include int open_trunc (char const *fn) { return open3(fn, O_WRONLY | O_NONBLOCK | O_TRUNC | O_CREAT, 0666) ; } skalibs-2.9.1.0/src/libstddjb/open_write.c000066400000000000000000000002631355335115400203660ustar00rootroot00000000000000/* ISC license. */ #include #include #include int open_write (char const *fn) { return open2(fn, O_WRONLY | O_NONBLOCK) ; } skalibs-2.9.1.0/src/libstddjb/openb_read.c000066400000000000000000000002461355335115400203120ustar00rootroot00000000000000/* ISC license. */ #include #include #include int openb_read (char const *fn) { return open2(fn, O_RDONLY) ; } skalibs-2.9.1.0/src/libstddjb/openreadfileclose.c000066400000000000000000000012001355335115400216660ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int openreadfileclose (char const *file, stralloc *sa, size_t limit) { size_t n ; int fd = open_readb(file) ; if (fd < 0) return 0 ; { struct stat st ; if (fstat(fd, &st) < 0) goto err ; n = st.st_size ; } if (limit && (limit < n)) n = limit ; if (!stralloc_ready_tuned(sa, sa->len + n, 0, 0, 1)) goto err ; { size_t r = allread(fd, sa->s + sa->len, n) ; sa->len += r ; if (r < n) goto err ; } fd_close(fd) ; return 1 ; err: fd_close(fd) ; return 0 ; } skalibs-2.9.1.0/src/libstddjb/openreadnclose.c000066400000000000000000000011761355335115400212200ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include static ssize_t readnclose (int fd, char *s, size_t n) { size_t r ; errno = 0 ; r = allread(fd, s, n) ; if (errno) { fd_close(fd) ; return -1 ; } fd_close(fd) ; if (r < n) errno = EPIPE ; return r ; } ssize_t openreadnclose (char const *file, char *s, size_t n) { int fd = open_readb(file) ; return fd < 0 ? fd : readnclose(fd, s, n) ; } ssize_t openreadnclose_nb (char const *file, char *s, size_t n) { int fd = open_read(file) ; return fd < 0 ? fd : readnclose(fd, s, n) ; } skalibs-2.9.1.0/src/libstddjb/openslurpclose.c000066400000000000000000000003731355335115400212720ustar00rootroot00000000000000/* ISC license. */ #include #include int openslurpclose (stralloc *sa, char const *fn) { int r ; int fd = open_readb(fn) ; if (fd == -1) return 0 ; r = slurp(sa, fd) ; fd_close(fd) ; return r ; } skalibs-2.9.1.0/src/libstddjb/openwritenclose.c000066400000000000000000000015461355335115400214400ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #define SUFFIX ":skalibs-openwritenclose:XXXXXX" int openwritenclose_internal (char const *fn, char const *s, size_t n, dev_t *dev, ino_t *ino, int dosync) { dev_t tmpdev ; ino_t tmpino ; size_t fnlen = strlen(fn) ; int fd ; char tmp[fnlen + sizeof(SUFFIX)] ; memcpy(tmp, fn, fnlen) ; memcpy(tmp + fnlen, SUFFIX, sizeof(SUFFIX)) ; fd = mkstemp(tmp) ; if (fd < 0) return 0 ; if (!writenclose_unsafe_internal(fd, s, n, dev ? &tmpdev : 0, ino ? &tmpino : 0, dosync)) goto failclose ; if (rename(tmp, fn) < 0) goto fail ; if (dev) *dev = tmpdev ; if (ino) *ino = tmpino ; return 1 ; failclose: fd_close(fd) ; fail: { int e = errno ; unlink(tmp) ; errno = e ; } return 0 ; } skalibs-2.9.1.0/src/libstddjb/openwritenclose_suffix.c000066400000000000000000000013561355335115400230230ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int openwritenclose_suffix_internal (char const *fn, char const *s, size_t n, dev_t *dev, ino_t *ino, int dosync, char const *suffix) { dev_t tmpdev ; ino_t tmpino ; size_t len = strlen(fn) ; size_t suffixlen = strlen(suffix) ; char tmp[len + suffixlen + 1] ; memcpy(tmp, fn, len) ; memcpy(tmp + len, suffix, suffixlen + 1) ; if (!openwritenclose_unsafe_internal(tmp, s, n, dev ? &tmpdev : 0, ino ? &tmpino : 0, dosync)) return 0 ; if (rename(tmp, fn) < 0) { int e = errno ; unlink(tmp) ; errno = e ; return 0 ; } if (dev) *dev = tmpdev ; if (ino) *ino = tmpino ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/openwritenclose_unsafe.c000066400000000000000000000006641355335115400230010ustar00rootroot00000000000000/* ISC license. */ #include #include #include int openwritenclose_unsafe_internal (char const *fn, char const *s, size_t len, dev_t *dev, ino_t *ino, int dosync) { int fd = open_trunc(fn) ; if (fd < 0) return 0 ; if (!writenclose_unsafe_internal(fd, s, len, dev, ino, dosync)) { int e = errno ; fd_close(fd) ; unlink(fn) ; errno = e ; return 0 ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/openwritevnclose.c000066400000000000000000000016221355335115400216210ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #define SUFFIX ":skalibs-openwritevnclose:XXXXXX" int openwritevnclose_internal (char const *fn, struct iovec const *v, unsigned int vlen, dev_t *dev, ino_t *ino, int dosync) { dev_t tmpdev ; ino_t tmpino ; size_t fnlen = strlen(fn) ; int fd ; char tmp[fnlen + sizeof(SUFFIX)] ; memcpy(tmp, fn, fnlen) ; memcpy(tmp + fnlen, SUFFIX, sizeof(SUFFIX)) ; fd = mkstemp(tmp) ; if (fd < 0) return 0 ; if (!writevnclose_unsafe_internal(fd, v, vlen, dev ? &tmpdev : 0, ino ? &tmpino : 0, dosync)) goto failclose ; if (rename(tmp, fn) < 0) goto fail ; if (dev) *dev = tmpdev ; if (ino) *ino = tmpino ; return 1 ; failclose: fd_close(fd) ; fail: { int e = errno ; unlink(tmp) ; errno = e ; } return 0 ; } skalibs-2.9.1.0/src/libstddjb/openwritevnclose_suffix.c000066400000000000000000000014231355335115400232040ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include int openwritevnclose_suffix_internal (char const *fn, struct iovec const *v, unsigned int n, dev_t *dev, ino_t *ino, int dosync, char const *suffix) { dev_t tmpdev ; ino_t tmpino ; size_t len = strlen(fn) ; size_t suffixlen = strlen(suffix) ; char tmp[len + suffixlen + 1] ; memcpy(tmp, fn, len) ; memcpy(tmp + len, suffix, suffixlen + 1) ; if (!openwritevnclose_unsafe_internal(tmp, v, n, dev ? &tmpdev : 0, ino ? &tmpino : 0, dosync)) return 0 ; if (rename(tmp, fn) < 0) { int e = errno ; unlink(tmp) ; errno = e ; return 0 ; } if (dev) *dev = tmpdev ; if (ino) *ino = tmpino ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/openwritevnclose_unsafe.c000066400000000000000000000007751355335115400231720ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int openwritevnclose_unsafe_internal (char const *fn, struct iovec const *v, unsigned int vlen, dev_t *dev, ino_t *ino, int dosync) { int fd = open_trunc(fn) ; if (fd < 0) return 0 ; if (!writevnclose_unsafe_internal(fd, v, vlen, dev, ino, dosync)) { int e = errno ; fd_close(fd) ; unlink(fn) ; errno = e ; return 0 ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/path_canonicalize.c000066400000000000000000000026761355335115400217000ustar00rootroot00000000000000/* ISC license. */ #include #include #include static unsigned char cclass (char c) { switch (c) { case 0 : return 0 ; case '/' : return 1 ; case '.' : return 2 ; default : return 3 ; } } /* out must be at least strlen(in) + 2 bytes */ size_t path_canonicalize (char *out, char const *in, int check) { static unsigned char const table[4][4] = { { 0x04, 0x00, 0x12, 0x11 }, { 0x04, 0x50, 0x11, 0x11 }, { 0x24, 0x20, 0x13, 0x11 }, { 0xa4, 0xa0, 0x11, 0x11 } } ; int isabsolute = in[0] == '/' ; size_t j = 0 ; unsigned int depth = 0 ; unsigned char state = 0 ; if (isabsolute) *out++ = *in++ ; while (state < 4) { char c = *in++ ; unsigned char what = table[state][cclass(c)] ; state = what & 0x07 ; if (what & 0x80) { if (depth) { depth-- ; j -= 3 ; if (check) { struct stat st ; out[j] = 0 ; if (stat(out - isabsolute, &st) < 0) return 0 ; if (!S_ISDIR(st.st_mode)) return (errno = ENOTDIR, 0) ; } } else if (!isabsolute) { out[j++] = '/' ; out[j++] = '.' ; } } if (what & 0x40) depth++ ; if (what & 0x20) while (j && out[j-1] != '/') j-- ; if (what & 0x10) out[j++] = c ; } if (j && out[j-1] == '/') j-- ; if (!j && !isabsolute) out[j++] = '.' ; out[j] = 0 ; return j + isabsolute ; } skalibs-2.9.1.0/src/libstddjb/pathexec.c000066400000000000000000000003721355335115400200150ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include #include void pathexec (char const *const *argv) { pathexec_fromenv(argv, (char const **)environ, env_len((char const **)environ)) ; } skalibs-2.9.1.0/src/libstddjb/pathexec0.c000066400000000000000000000002411355335115400200700ustar00rootroot00000000000000/* ISC license. */ #include #include void pathexec0 (char const *const *argv) { if (!argv[0]) _exit(0) ; pathexec(argv) ; } skalibs-2.9.1.0/src/libstddjb/pathexec0_run.c000066400000000000000000000003211355335115400207530ustar00rootroot00000000000000/* ISC license. */ #include #include void pathexec0_run (char const *const *argv, char const *const *envp) { if (!argv[0]) _exit(0) ; pathexec_run(argv[0], argv, envp) ; } skalibs-2.9.1.0/src/libstddjb/pathexec_fromenv.c000066400000000000000000000006251355335115400215520ustar00rootroot00000000000000/* ISC license. */ #include #include #include static stralloc plus = STRALLOC_ZERO ; int pathexec_env (char const *s, char const *t) /* historic, bad name */ { return env_addmodif(&plus, s, t) ; } void pathexec_fromenv (char const *const *argv, char const *const *envp, size_t envlen) { pathexec_r(argv, envp, envlen, plus.s, plus.len) ; } skalibs-2.9.1.0/src/libstddjb/pathexec_r.c000066400000000000000000000003601355335115400203330ustar00rootroot00000000000000/* ISC license. */ #include void pathexec_r (char const *const *argv, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) { pathexec_r_name(argv[0], argv, envp, envlen, modifs, modiflen) ; } skalibs-2.9.1.0/src/libstddjb/pathexec_r_name.c000066400000000000000000000006471355335115400213430ustar00rootroot00000000000000/* ISC license. */ #include #include #include void pathexec_r_name (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) { size_t n = envlen + 1 + byte_count(modifs, modiflen, '\0') ; char const *v[n] ; if (env_merge(v, n, envp, envlen, modifs, modiflen)) pathexec_run(file, argv, v) ; } skalibs-2.9.1.0/src/libstddjb/pathexec_run.c000066400000000000000000000005171355335115400207020ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include void pathexec_run (char const *file, char const *const *argv, char const *const *envp) { char const *path = getenv("PATH") ; if (!path) path = SKALIBS_DEFAULTPATH ; execvep(file, argv, envp, path) ; } skalibs-2.9.1.0/src/libstddjb/pipe_internal.c000066400000000000000000000014471355335115400210510ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASPIPE2 #include #include #include #include int pipe_internal (int *p, unsigned int flags) { return pipe2(p, ((flags & DJBUNIX_FLAG_COE) ? O_CLOEXEC : 0) | ((flags & DJBUNIX_FLAG_NB) ? O_NONBLOCK : 0)) ; } #else #include #include int pipe_internal (int *p, unsigned int flags) { int pi[2] ; if (pipe(pi) < 0) return -1 ; if (flags & DJBUNIX_FLAG_COE) if ((coe(pi[0]) < 0) || (coe(pi[1]) < 0)) goto err ; if (flags & DJBUNIX_FLAG_NB) if ((ndelay_on(pi[0]) < 0) || (ndelay_on(pi[1]) < 0)) goto err ; p[0] = pi[0] ; p[1] = pi[1] ; return 0 ; err: { fd_close(pi[1]) ; fd_close(pi[0]) ; } return -1 ; } #endif skalibs-2.9.1.0/src/libstddjb/prog.c000066400000000000000000000001411355335115400171550ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include char const *PROG = "(none)" ; skalibs-2.9.1.0/src/libstddjb/rm_rf.c000066400000000000000000000002541355335115400173200ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include int rm_rf (char const *filename) { return rm_rf_tmp(filename, &satmp) ; } skalibs-2.9.1.0/src/libstddjb/rm_rf_in_tmp.c000066400000000000000000000041721355335115400206710ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include static int rmstarindir (DIR *dir, stralloc *tmp, size_t ipos) /* WARNING: closes dir */ { size_t tmpbase = tmp->len ; for (;;) { direntry *d ; errno = 0 ; d = readdir(dir) ; if (!d) break ; if (d->d_name[0] == '.') if (((d->d_name[1] == '.') && (d->d_name[2] == 0)) || (d->d_name[1] == 0)) continue ; if (!stralloc_cats(tmp, d->d_name) || !stralloc_0(tmp)) goto closeanderr ; } if (errno) goto closeanderr ; dir_close(dir) ; { size_t tmpstop = tmp->len ; size_t fnbase = strlen(tmp->s + ipos) ; size_t i = tmpbase ; if (!stralloc_readyplus(tmp, fnbase+1)) goto err ; stralloc_catb(tmp, tmp->s + ipos, fnbase) ; stralloc_catb(tmp, "/", 1) ; fnbase = tmp->len ; for (; i < tmpstop ; i += tmp->len - fnbase) { size_t n = strlen(tmp->s + i) ; tmp->len = fnbase ; if (!stralloc_readyplus(tmp, n+1)) goto err ; stralloc_catb(tmp, tmp->s + i, n+1) ; if (rm_rf_in_tmp(tmp, tmpstop) == -1) goto err ; } } tmp->len = tmpbase ; return 0 ; closeanderr: { int e = errno ; dir_close(dir) ; errno = e ; } err: tmp->len = tmpbase ; return -1 ; } int rm_rf_in_tmp (stralloc *tmp, size_t ipos) { if (unlink(tmp->s + ipos) == 0) return 0 ; if (errno == ENOENT) return 0 ; if ((errno != EISDIR) && (errno != EPERM)) return -1 ; { int h = (errno == EPERM) ; DIR *dir = opendir(tmp->s + ipos) ; if (!dir) { if (h && (errno == ENOTDIR)) errno = EPERM ; return -1 ; } if (rmstarindir(dir, tmp, ipos) == -1) return -1 ; } return rmdir(tmp->s + ipos) ; } int rmstar_tmp (char const *dirname, stralloc *tmp) { size_t tmpbase = tmp->len ; if (!stralloc_cats(tmp, dirname)) return -1 ; if (!stralloc_0(tmp)) goto err ; { DIR *dir = opendir(dirname) ; if (!dir) goto err ; if (rmstarindir(dir, tmp, tmpbase) == -1) goto err ; } tmp->len = tmpbase ; return 0 ; err: tmp->len = tmpbase ; return -1 ; } skalibs-2.9.1.0/src/libstddjb/rm_rf_tmp.c000066400000000000000000000005741355335115400202050ustar00rootroot00000000000000/* ISC license. */ #include #include int rm_rf_tmp (char const *filename, stralloc *tmp) { size_t tmpbase = tmp->len ; if (!stralloc_cats(tmp, filename)) return -1 ; if (!stralloc_0(tmp)) goto err ; if (rm_rf_in_tmp(tmp, tmpbase) == -1) goto err ; tmp->len = tmpbase ; return 0 ; err: tmp->len = tmpbase ; return -1 ; } skalibs-2.9.1.0/src/libstddjb/rmstar.c000066400000000000000000000002541355335115400175230ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include int rmstar (char const *dirname) { return rmstar_tmp(dirname, &satmp) ; } skalibs-2.9.1.0/src/libstddjb/sabasename.c000066400000000000000000000007051355335115400203130ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int sabasename (stralloc *sa, char const *s, size_t len) { if (!len) return stralloc_catb(sa, ".", 1) ; while (len && (s[len-1] == '/')) len-- ; if (!len) return stralloc_catb(sa, "/", 1) ; { size_t i = byte_rchr(s, len, '/') ; i = (i == len) ? 0 : i+1 ; return stralloc_catb(sa, s + i, len - i) ; } } skalibs-2.9.1.0/src/libstddjb/sadirname.c000066400000000000000000000010201355335115400201460ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int sadirname (stralloc *sa, char const *s, size_t len) { if (!len) return stralloc_catb(sa, ".", 1) ; while (len && (s[len-1] == '/')) len-- ; if (!len) return stralloc_catb(sa, "/", 1) ; { size_t i = byte_rchr(s, len, '/') ; return (i == len) ? stralloc_catb(sa, ".", 1) : (i == 0) ? stralloc_catb(sa, "/", 1) : stralloc_catb(sa, s, i) ; } } skalibs-2.9.1.0/src/libstddjb/sagetcwd.c000066400000000000000000000007441355335115400200200ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int sagetcwd (stralloc *sa) { size_t n = 128 ; int wasnull = !sa->s ; for (;;) { if (!stralloc_readyplus(sa, n)) goto err ; if (getcwd(sa->s + sa->len, n)) break ; if (errno != ERANGE) goto err ; n += 128 ; } sa->len += strlen(sa->s + sa->len) ; return 0 ; err: if (wasnull) stralloc_free(sa) ; return -1 ; } skalibs-2.9.1.0/src/libstddjb/sagethostname.c000066400000000000000000000010121355335115400210460ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int sagethostname (stralloc *sa) { size_t n = 128 ; int wasnull = !sa->s ; for (;;) { if (!stralloc_readyplus(sa, n)) goto err ; sa->s[sa->len + n - 2] = 0 ; if (gethostname(sa->s + sa->len, n) == -1) goto err ; if (!sa->s[sa->len + n - 2]) break ; n += 128 ; } sa->len += strlen(sa->s + sa->len) ; return 0 ; err: if (wasnull) stralloc_free(sa) ; return -1 ; } skalibs-2.9.1.0/src/libstddjb/sanitize_read.c000066400000000000000000000003631355335115400210350ustar00rootroot00000000000000/* ISC license. */ #include #include #include ssize_t sanitize_read (ssize_t r) { return r == -1 ? error_isagain(errno) ? (errno = 0, 0) : -1 : !r ? (errno = EPIPE, -1) : r ; } skalibs-2.9.1.0/src/libstddjb/sareadlink.c000066400000000000000000000007371355335115400203360ustar00rootroot00000000000000/* ISC license. */ #include #include #include int sareadlink (stralloc *sa, char const *path) { size_t n = 128 ; int wasnull = !sa->s ; ssize_t r ; for (;;) { if (!stralloc_readyplus(sa, n)) goto err ; r = readlink(path, sa->s + sa->len, n) ; if (r < 0) goto err ; if ((size_t)r < n) break ; n += 128 ; } sa->len += r ; return 0 ; err: if (wasnull) stralloc_free(sa) ; return -1 ; } skalibs-2.9.1.0/src/libstddjb/sarealpath.c000066400000000000000000000013751355335115400203440ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int sarealpath (stralloc *sa, char const *path) { if (sa->s) { #ifdef PATH_MAX if (!stralloc_readyplus(sa, PATH_MAX)) return -1 ; if (!realpath(path, sa->s + sa->len)) return -1 ; sa->len += strlen(sa->s + sa->len) ; #else char *p = realpath(path, 0) ; if (!p) return -1 ; if (!stralloc_cats(sa, p) || !stralloc_0(sa)) { free(p) ; return -1 ; } free(p) ; #endif } else { char *p = realpath(path, 0) ; if (!p) return -1 ; sa->s = p ; /* XXX: incompatible with alloc() interposition */ sa->len = strlen(p) ; sa->a = sa->len + 1 ; } return 0 ; } skalibs-2.9.1.0/src/libstddjb/satmp.c000066400000000000000000000001611355335115400173340ustar00rootroot00000000000000/* ISC license. */ #include #include stralloc satmp = STRALLOC_ZERO ; skalibs-2.9.1.0/src/libstddjb/sauniquename.c000066400000000000000000000012371355335115400207100ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include int sauniquename (stralloc *sa) { size_t base = sa->len ; int wasnull = !sa->s ; if (!stralloc_readyplus(sa, TIMESTAMP + PID_FMT + 131)) return 0 ; sa->s[base] = ':' ; timestamp(sa->s + base + 1) ; sa->s[base + 1 + TIMESTAMP] = ':' ; sa->len = base + 2 + TIMESTAMP ; sa->len += pid_fmt(sa->s + sa->len, getpid()) ; sa->s[sa->len++] = ':' ; if (sagethostname(sa) < 0) goto err ; return 1 ; err: if (wasnull) stralloc_free(sa) ; else sa->len = base ; return 0 ; } skalibs-2.9.1.0/src/libstddjb/selfpipe-internal.h000066400000000000000000000006041355335115400216400ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #ifndef SELFPIPE_INTERNAL_H #define SELFPIPE_INTERNAL_H #include #include extern sigset_t selfpipe_caught ; #ifdef SKALIBS_HASSIGNALFD extern int selfpipe_fd ; #else #include extern int selfpipe[2] ; #define selfpipe_fd selfpipe[0] extern struct skasigaction const selfpipe_ssa ; #endif #endif skalibs-2.9.1.0/src/libstddjb/selfpipe_finish.c000066400000000000000000000014161355335115400213630ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #ifdef SKALIBS_HASSIGNALFD #include #include #include "selfpipe-internal.h" #include void selfpipe_finish (void) { sigprocmask(SIG_UNBLOCK, &selfpipe_caught, 0) ; sigemptyset(&selfpipe_caught) ; fd_close(selfpipe_fd) ; selfpipe_fd = -1 ; } #else #include #include #include #include #include #include "selfpipe-internal.h" #include void selfpipe_finish (void) { sig_restoreto(&selfpipe_caught, SKALIBS_NSIG-1) ; sigemptyset(&selfpipe_caught) ; fd_close(selfpipe[1]) ; fd_close(selfpipe[0]) ; selfpipe[0] = selfpipe[1] = -1 ; } #endif skalibs-2.9.1.0/src/libstddjb/selfpipe_init.c000066400000000000000000000010621355335115400210430ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include #include #include "selfpipe-internal.h" #include #ifdef SKALIBS_HASSIGNALFD #include #else #include #endif int selfpipe_init (void) { if (selfpipe_fd >= 0) return (errno = EBUSY, -1) ; sigemptyset(&selfpipe_caught) ; #ifdef SKALIBS_HASSIGNALFD selfpipe_fd = signalfd(-1, &selfpipe_caught, SFD_NONBLOCK | SFD_CLOEXEC) ; #else if (pipenbcoe(selfpipe) < 0) return -1 ; #endif return selfpipe_fd ; } skalibs-2.9.1.0/src/libstddjb/selfpipe_internal.c000066400000000000000000000010441355335115400217140ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include #include "selfpipe-internal.h" sigset_t selfpipe_caught ; #ifdef SKALIBS_HASSIGNALFD int selfpipe_fd = -1 ; #else #include #include #include int selfpipe[2] = { -1, -1 } ; static void selfpipe_trigger (int s) { unsigned char c = (unsigned char)s ; fd_write(selfpipe[1], (char *)&c, 1) ; } struct skasigaction const selfpipe_ssa = { &selfpipe_trigger, SKASA_NOCLDSTOP | SKASA_MASKALL } ; #endif skalibs-2.9.1.0/src/libstddjb/selfpipe_read.c000066400000000000000000000010711355335115400210130ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include #include "selfpipe-internal.h" #include #ifdef SKALIBS_HASSIGNALFD #include int selfpipe_read (void) { struct signalfd_siginfo buf ; ssize_t r = sanitize_read(fd_read(selfpipe_fd, (char *)&buf, sizeof(struct signalfd_siginfo))) ; return (r <= 0) ? r : buf.ssi_signo ; } #else int selfpipe_read (void) { char c ; ssize_t r = sanitize_read((fd_read(selfpipe_fd, &c, 1))) ; return (r <= 0) ? r : c ; } #endif skalibs-2.9.1.0/src/libstddjb/selfpipe_trap.c000066400000000000000000000017151355335115400210530ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include #include #include "selfpipe-internal.h" #include #ifdef SKALIBS_HASSIGNALFD #include int selfpipe_trap (int sig) { sigset_t ss = selfpipe_caught ; sigset_t old ; if (selfpipe_fd < 0) return (errno = EBADF, -1) ; if ((sigaddset(&ss, sig) < 0) || (sigprocmask(SIG_BLOCK, &ss, &old) < 0)) return -1 ; if (signalfd(selfpipe_fd, &ss, SFD_NONBLOCK | SFD_CLOEXEC) < 0) { int e = errno ; sigprocmask(SIG_SETMASK, &old, 0) ; errno = e ; return -1 ; } selfpipe_caught = ss ; return 0 ; } #else #include int selfpipe_trap (int sig) { if (selfpipe_fd < 0) return (errno = EBADF, -1) ; if (sig_catcha(sig, &selfpipe_ssa) < 0) return -1 ; if (sigaddset(&selfpipe_caught, sig) < 0) { int e = errno ; sig_restore(sig) ; errno = e ; return -1 ; } return 0 ; } #endif skalibs-2.9.1.0/src/libstddjb/selfpipe_trapset.c000066400000000000000000000024631355335115400215700ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASSIGNALFD #include #include #include #include #include "selfpipe-internal.h" int selfpipe_trapset (sigset_t const *set) { sigset_t old ; if (selfpipe_fd < 0) return (errno = EBADF, -1) ; if (sigprocmask(SIG_SETMASK, set, &old) < 0) return -1 ; if (signalfd(selfpipe_fd, set, SFD_NONBLOCK | SFD_CLOEXEC) < 0) { int e = errno ; sigprocmask(SIG_SETMASK, &old, 0) ; errno = e ; return -1 ; } selfpipe_caught = *set ; return 0 ; } #else #include #include #include #include #include #include #include "selfpipe-internal.h" int selfpipe_trapset (sigset_t const *set) { unsigned int i = 1 ; if (selfpipe_fd < 0) return (errno = EBADF, -1) ; for (; i < SKALIBS_NSIG ; i++) { int h = sigismember(set, i) ; if (h < 0) continue ; if (h) { if (sig_catcha(i, &selfpipe_ssa) < 0) break ; } else if (sigismember(&selfpipe_caught, i)) { if (sig_restore(i) < 0) break ; } } if (i < SKALIBS_NSIG) { int e = errno ; sig_restoreto(set, i) ; errno = e ; return -1 ; } selfpipe_caught = *set ; return 0 ; } #endif skalibs-2.9.1.0/src/libstddjb/selfpipe_untrap.c000066400000000000000000000022411355335115400214110ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include #include #include "selfpipe-internal.h" #include #ifdef SKALIBS_HASSIGNALFD #include int selfpipe_untrap (int sig) { sigset_t ss = selfpipe_caught ; sigset_t blah ; int r = sigismember(&selfpipe_caught, sig) ; if (selfpipe_fd < 0) return (errno = EBADF, -1) ; if (r < 0) return -1 ; if (!r) return (errno = EINVAL, -1) ; if ((sigdelset(&ss, sig) < 0) || (signalfd(selfpipe_fd, &ss, SFD_NONBLOCK | SFD_CLOEXEC) < 0)) return -1 ; sigemptyset(&blah) ; sigaddset(&blah, sig) ; if (sigprocmask(SIG_UNBLOCK, &blah, 0) < 0) { int e = errno ; signalfd(selfpipe_fd, &selfpipe_caught, SFD_NONBLOCK | SFD_CLOEXEC) ; errno = e ; return -1 ; } selfpipe_caught = ss ; return 0 ; } #else #include int selfpipe_untrap (int sig) { int r = sigismember(&selfpipe_caught, sig) ; if (selfpipe_fd < 0) return (errno = EBADF, -1) ; if (r < 0) return -1 ; if (!r) return (errno = EINVAL, -1) ; if (sig_restore(sig) < 0) return -1 ; sigdelset(&selfpipe_caught, sig) ; return 0 ; } #endif skalibs-2.9.1.0/src/libstddjb/sgetopt.c000066400000000000000000000011101355335115400176700ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #undef SUBGETOPT_SHORT #include #include int sgetopt_r (int argc, char const *const *argv, char const *opts, subgetopt_t *o) { int c = subgetopt_r(argc, argv, opts, o) ; if (o->err && ((c == '?') || (c == ':'))) { buffer_puts(buffer_2, o->prog ? o->prog : argv[0]) ; buffer_put(buffer_2, ": ", 2) ; buffer_puts(buffer_2, ((c == '?') && argv[o->ind] && (o->ind < argc)) ? "illegal option" : "option requires an argument") ; buffer_putflush(buffer_2, "\n", 1) ; } return c ; } skalibs-2.9.1.0/src/libstddjb/sig-internal.h000066400000000000000000000003511355335115400206120ustar00rootroot00000000000000/* ISC license. */ #ifndef SIG_INTERNAL #define SIG_INTERNAL typedef struct sigtable_s sigtable_t, *sigtable_t_ref ; struct sigtable_s { int number ; char const *name ; } ; extern sigtable_t const skalibs_sigtable[] ; #endif skalibs-2.9.1.0/src/libstddjb/sig0_scan.c000066400000000000000000000011231355335115400200550ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include static size_t sig0_scan_norec (char const *s, int *sig) { int r = sig_number(s) ; if (r) { *sig = r ; return strlen(s) ; } { unsigned int u ; size_t len = uint0_scan(s, &u) ; if (len) *sig = u ; return len ; } } size_t sig0_scan (char const *s, int *sig) { size_t len = sig0_scan_norec(s, sig) ; if (len) return len ; if (!strncasecmp(s, "SIG", 3)) { len = sig0_scan_norec(s+3, sig) ; if (len) return 3+len ; } return 0 ; } skalibs-2.9.1.0/src/libstddjb/sig_block.c000066400000000000000000000002771355335115400201540ustar00rootroot00000000000000/* ISC license. */ #include #include void sig_block (int sig) { sigset_t ss ; sigemptyset(&ss) ; sigaddset(&ss, sig) ; sigprocmask(SIG_BLOCK, &ss, 0) ; } skalibs-2.9.1.0/src/libstddjb/sig_blocknone.c000066400000000000000000000002521355335115400210250ustar00rootroot00000000000000/* ISC license. */ #include #include void sig_blocknone (void) { sigset_t ss ; sigemptyset(&ss) ; sigprocmask(SIG_SETMASK, &ss, 0) ; } skalibs-2.9.1.0/src/libstddjb/sig_blockset.c000066400000000000000000000002231355335115400206570ustar00rootroot00000000000000/* ISC license. */ #include #include void sig_blockset (sigset_t const *set) { sigprocmask(SIG_SETMASK, set, 0) ; } skalibs-2.9.1.0/src/libstddjb/sig_catch.c000066400000000000000000000003301355335115400201320ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include int sig_catch (int sig, skasighandler_t_ref f) { struct skasigaction ssa = { f, SKASA_MASKALL | SKASA_NOCLDSTOP } ; return sig_catcha(sig, &ssa) ; } skalibs-2.9.1.0/src/libstddjb/sig_name.c000066400000000000000000000003651355335115400200000ustar00rootroot00000000000000/* ISC license. */ #include #include "sig-internal.h" char const *sig_name (int sig) { sigtable_t const *p = skalibs_sigtable ; for (; p->number ; p++) if (sig == p->number) break ; return p->number ? p->name : "???" ; } skalibs-2.9.1.0/src/libstddjb/sig_number.c000066400000000000000000000004031355335115400203410ustar00rootroot00000000000000/* ISC license. */ #include #include #include "sig-internal.h" int sig_number (char const *name) { sigtable_t const *p = skalibs_sigtable ; for (; p->name ; p++) if (!strcasecmp(name, p->name)) break ; return p->number ; } skalibs-2.9.1.0/src/libstddjb/sig_pause.c000066400000000000000000000002251355335115400201700ustar00rootroot00000000000000/* ISC license. */ #include #include void sig_pause (void) { sigset_t ss ; sigemptyset(&ss) ; sigsuspend(&ss) ; } skalibs-2.9.1.0/src/libstddjb/sig_push.c000066400000000000000000000003261355335115400200340ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include int sig_push (int sig, skasighandler_t_ref f) { struct skasigaction ssa = { f, SKASA_MASKALL | SKASA_NOCLDSTOP } ; return sig_pusha(sig, &ssa) ; } skalibs-2.9.1.0/src/libstddjb/sig_restoreto.c000066400000000000000000000004361355335115400211050ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include void sig_restoreto (sigset_t const *set, unsigned int n) { unsigned int i = 1 ; for (; i <= n ; i++) { int h = sigismember(set, i) ; if (h < 0) continue ; if (h) sig_restore(i) ; } } skalibs-2.9.1.0/src/libstddjb/sig_shield.c000066400000000000000000000005131355335115400203230ustar00rootroot00000000000000/* ISC license. */ #include #include void sig_shield (void) { sigset_t ss ; sigemptyset(&ss) ; sigaddset(&ss, SIGTERM) ; sigaddset(&ss, SIGQUIT) ; sigaddset(&ss, SIGABRT) ; sigaddset(&ss, SIGINT) ; sigaddset(&ss, SIGPIPE) ; sigaddset(&ss, SIGHUP) ; sigprocmask(SIG_BLOCK, &ss, 0) ; } skalibs-2.9.1.0/src/libstddjb/sig_stack.c000066400000000000000000000015031355335115400201600ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include static struct skasigaction skasigstack[SKALIBS_NSIG-1][SIGSTACKSIZE] ; static unsigned int sigsp[SKALIBS_NSIG-1] ; int sig_pusha (int sig, struct skasigaction const *ssa) { if ((sig <= 0) || (sig >= SKALIBS_NSIG)) return (errno = EINVAL, -1) ; if (sigsp[sig-1] >= SIGSTACKSIZE) return (errno = ENOBUFS, -1) ; if (skasigaction(sig, ssa, &skasigstack[sig-1][sigsp[sig-1]]) == -1) return -1 ; return ++sigsp[sig-1] ; } int sig_pop (int sig) { if ((sig <= 0) || (sig >= SKALIBS_NSIG)) return (errno = EINVAL, -1) ; if (!sigsp[sig-1]) return (errno = EFAULT, -1); if (skasigaction(sig, &skasigstack[sig-1][sigsp[sig-1]-1], 0) == -1) return -1 ; return --sigsp[sig-1] ; } skalibs-2.9.1.0/src/libstddjb/sig_table.c000066400000000000000000000025451355335115400201510ustar00rootroot00000000000000 /* ISC license. */ #include #include "sig-internal.h" sigtable_t const skalibs_sigtable[] = { { SIGABRT, "ABRT" }, { SIGALRM, "ALRM" }, { SIGBUS, "BUS" }, { SIGCHLD, "CHLD" }, { SIGCONT, "CONT" }, { SIGFPE, "FPE" }, { SIGHUP, "HUP" }, { SIGILL, "ILL" }, { SIGINT, "INT" }, { SIGKILL, "KILL" }, { SIGPIPE, "PIPE" }, { SIGQUIT, "QUIT" }, { SIGSEGV, "SEGV" }, { SIGSTOP, "STOP" }, { SIGTERM, "TERM" }, { SIGTSTP, "TSTP" }, { SIGTTIN, "TTIN" }, { SIGTTOU, "TTOU" }, { SIGUSR1, "USR1" }, { SIGUSR2, "USR2" }, #ifdef SIGPOLL { SIGPOLL, "POLL" }, #endif #ifdef SIGPROF { SIGPROF, "PROF" }, #endif #ifdef SIGSYS { SIGSYS, "SYS" }, #endif #ifdef SIGTRAP { SIGTRAP, "TRAP" }, #endif #ifdef SIGURG { SIGURG, "URG" }, #endif #ifdef SIGVTALRM { SIGVTALRM, "VTALRM" }, #endif #ifdef SIGXCPU { SIGXCPU, "XCPU" }, #endif #ifdef SIGXFSZ { SIGXFSZ, "XFSZ" }, #endif #ifdef SIGIOT { SIGIOT, "IOT" }, #endif #ifdef SIGEMT { SIGEMT, "EMT" }, #endif #ifdef SIGSTKFLT { SIGSTKFLT, "STKFLT" }, #endif #ifdef SIGCLD { SIGCLD, "CLD" }, #endif #ifdef SIGWINCH { SIGWINCH, "WINCH" }, #endif #ifdef SIGIO { SIGIO, "IO" }, #endif #ifdef SIGINFO { SIGINFO, "INFO" }, #endif #ifdef SIGLOST { SIGLOST, "LOST" }, #endif #ifdef SIGPWR { SIGPWR, "PWR" }, #endif #ifdef SIGUNUSED { SIGUNUSED, "UNUSED" }, #endif { 0, 0 } } ; skalibs-2.9.1.0/src/libstddjb/sig_unblock.c000066400000000000000000000003031355335115400205050ustar00rootroot00000000000000/* ISC license. */ #include #include void sig_unblock (int sig) { sigset_t ss ; sigemptyset(&ss) ; sigaddset(&ss, sig) ; sigprocmask(SIG_UNBLOCK, &ss, 0) ; } skalibs-2.9.1.0/src/libstddjb/sig_unshield.c000066400000000000000000000005171355335115400206720ustar00rootroot00000000000000/* ISC license. */ #include #include void sig_unshield (void) { sigset_t ss ; sigemptyset(&ss) ; sigaddset(&ss, SIGTERM) ; sigaddset(&ss, SIGQUIT) ; sigaddset(&ss, SIGABRT) ; sigaddset(&ss, SIGINT) ; sigaddset(&ss, SIGPIPE) ; sigaddset(&ss, SIGHUP) ; sigprocmask(SIG_UNBLOCK, &ss, 0) ; } skalibs-2.9.1.0/src/libstddjb/sigfpe.c000066400000000000000000000001731355335115400174700ustar00rootroot00000000000000/* ISC license. */ #include #include int sigfpe (void) { return raise(SIGFPE) == 0 ; } skalibs-2.9.1.0/src/libstddjb/sigsegv.c000066400000000000000000000001751355335115400176640ustar00rootroot00000000000000/* ISC license. */ #include #include int sigsegv (void) { return raise(SIGSEGV) == 0 ; } skalibs-2.9.1.0/src/libstddjb/siovec_bytechr.c000066400000000000000000000005751355335115400212310ustar00rootroot00000000000000/* ISC license. */ #include #include #include size_t siovec_bytechr (struct iovec const *v, unsigned int n, char c) { size_t w = 0 ; unsigned int i = 0 ; for (; i < n ; i++) { size_t pos = byte_chr((char const *)v[i].iov_base, v[i].iov_len, c) ; w += pos ; if (pos < v[i].iov_len) break ; } return w ; } skalibs-2.9.1.0/src/libstddjb/siovec_bytein.c000066400000000000000000000006351355335115400210600ustar00rootroot00000000000000/* ISC license. */ #include #include #include size_t siovec_bytein (struct iovec const *v, unsigned int n, char const *sep, size_t seplen) { size_t w = 0 ; unsigned int i = 0 ; for (; i < n ; i++) { size_t pos = byte_in((char const *)v[i].iov_base, v[i].iov_len, sep, seplen) ; w += pos ; if (pos < v[i].iov_len) break ; } return w ; } skalibs-2.9.1.0/src/libstddjb/siovec_deal.c000066400000000000000000000012461355335115400204720ustar00rootroot00000000000000/* ISC license. */ #include #include #include size_t siovec_deal (struct iovec const *vj, unsigned int nj, struct iovec const *vi, unsigned int ni) { size_t w = 0 ; size_t wi = 0 ; size_t wj = 0 ; unsigned int i = 0 ; unsigned int j = 0 ; while (i < ni && j < nj) { size_t tor = vi[i].iov_len - wi ; size_t tow = vj[j].iov_len - wj ; size_t len = tor < tow ? tor : tow ; memmove((char *)vj[j].iov_base + wj, (char const *)vi[i].iov_base + wi, len) ; wi += len ; wj += len ; w += len ; if (wi >= vi[i].iov_len) { wi = 0 ; i++ ; } if (wj >= vj[j].iov_len) { wj = 0 ; j++ ; } } return w ; } skalibs-2.9.1.0/src/libstddjb/siovec_gather.c000066400000000000000000000006151355335115400210360ustar00rootroot00000000000000/* ISC license. */ #include #include #include size_t siovec_gather (struct iovec const *v, unsigned int n, char *s, size_t max) { size_t w = 0 ; unsigned int i = 0 ; for (; i < n && w < max ; i++) { size_t len = v[i].iov_len ; if (len > max - w) len = max - w ; memmove(s + w, v[i].iov_base, len) ; w += len ; } return w ; } skalibs-2.9.1.0/src/libstddjb/siovec_len.c000066400000000000000000000003041355335115400203350ustar00rootroot00000000000000/* ISC license. */ #include #include size_t siovec_len (struct iovec const *v, unsigned int n) { size_t w = 0 ; while (n--) w += v[n].iov_len ; return w ; } skalibs-2.9.1.0/src/libstddjb/siovec_scatter.c000066400000000000000000000006551355335115400212350ustar00rootroot00000000000000/* ISC license. */ #include #include #include size_t siovec_scatter (struct iovec const *v, unsigned int n, char const *s, size_t len) { size_t w = 0 ; unsigned int i = 0 ; for (; i < n && w < len ; i++) { size_t chunklen = v[i].iov_len ; if (w + chunklen > len) chunklen = len - w ; memmove(v[i].iov_base, s + w, chunklen) ; w += chunklen ; } return w ; } skalibs-2.9.1.0/src/libstddjb/siovec_search.c000066400000000000000000000017631355335115400210360ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include 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 ; } skalibs-2.9.1.0/src/libstddjb/siovec_seek.c000066400000000000000000000007601355335115400205140ustar00rootroot00000000000000/* ISC license. */ #include #include #include size_t siovec_seek (struct iovec *v, unsigned int n, size_t len) { size_t w = 0 ; unsigned int i = 0 ; for (; i < n ; i++) { if (len < v[i].iov_len) break ; w += v[i].iov_len ; len -= v[i].iov_len ; v[i].iov_base = 0 ; v[i].iov_len = 0 ; } if (i < n) { v[i].iov_base = (char *)v[i].iov_base + len ; v[i].iov_len -= len ; w += len ; } return w ; } skalibs-2.9.1.0/src/libstddjb/siovec_trunc.c000066400000000000000000000005641355335115400207220ustar00rootroot00000000000000/* ISC license. */ #include #include unsigned int siovec_trunc (struct iovec *v, unsigned int n, size_t len) { size_t w = siovec_len(v, n) ; unsigned int i = n ; if (w < len) return n ; len = w - len ; while (len && i--) { w = len > v[i].iov_len ? v[i].iov_len : len ; v[i].iov_len -= w ; len -= w ; } return i ; } skalibs-2.9.1.0/src/libstddjb/skagetln.c000066400000000000000000000006451355335115400200270ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int skagetln (buffer *b, stralloc *sa, char sep) { size_t start = sa->len ; for (;;) { ssize_t r = skagetln_nofill(b, sa, sep) ; if (r) return r ; r = buffer_fill(b) ; if (r < 0) return r ; if (!r) return (sa->s && (sa->len > start)) ? (errno = EPIPE, -1) : 0 ; } } skalibs-2.9.1.0/src/libstddjb/skagetln_loose.c000066400000000000000000000005111355335115400212200ustar00rootroot00000000000000/* ISC license. */ #include #include #include int skagetln_loose (buffer *b, stralloc *sa, char sep) { int e = errno ; int r = skagetln(b, sa, sep) ; if (r >= 0) return r ; if (errno != EPIPE) return -1 ; if (!stralloc_0(sa)) return -1 ; return (errno = e, 3) ; } skalibs-2.9.1.0/src/libstddjb/skagetln_nofill.c000066400000000000000000000007461355335115400213740ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int skagetln_nofill (buffer *b, stralloc *sa, char sep) { struct iovec v[2] ; size_t pos ; int r ; buffer_rpeek(b, v) ; pos = siovec_bytechr(v, 2, sep) ; 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 ; return r ; } skalibs-2.9.1.0/src/libstddjb/skagetlnmaxsep.c000066400000000000000000000014471355335115400212460ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include 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 ; } } skalibs-2.9.1.0/src/libstddjb/skagetlnsep.c000066400000000000000000000013301355335115400205270ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include int skagetlnsep (buffer *b, stralloc *sa, 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 ; r = buffer_fill(b) ; if (r < 0) return r ; if (!r) return (sa->s && (sa->len > start)) ? (errno = EPIPE, -1) : 0 ; } } skalibs-2.9.1.0/src/libstddjb/skagetlnsep_loose.c000066400000000000000000000005551355335115400217400ustar00rootroot00000000000000/* ISC license. */ #include #include #include int skagetlnsep_loose (buffer *b, stralloc *sa, char const *sep, size_t seplen) { int e = errno ; int r = skagetlnsep(b, sa, sep, seplen) ; if (r >= 0) return r ; if (errno != EPIPE) return -1 ; if (!stralloc_0(sa)) return -1 ; return (errno = e, 3) ; } skalibs-2.9.1.0/src/libstddjb/skalibs_tzisright.c000066400000000000000000000004331355335115400217510ustar00rootroot00000000000000/* ISC license. */ #include #include "djbtime-internal.h" int skalibs_tzisright () { static int tzisright = -1 ; if (tzisright < 0) { struct tm tm ; time_t t = 78796800 ; if (localtime_r(&t, &tm)) tzisright = tm.tm_sec == 60 ; } return tzisright ; } skalibs-2.9.1.0/src/libstddjb/skasig_dfl.c000066400000000000000000000002621355335115400203200ustar00rootroot00000000000000/* ISC license. */ #include #include struct skasigaction const SKASIG_DFL = { SIG_DFL, 0 } ; struct skasigaction const SKASIG_IGN = { SIG_IGN, 0 } ; skalibs-2.9.1.0/src/libstddjb/skasigaction.c000066400000000000000000000015551355335115400206770ustar00rootroot00000000000000/* ISC license. */ #include #include #include int skasigaction (int sig, struct skasigaction const *new, struct skasigaction *old) { struct sigaction sanew, saold ; if (((new->flags & SKASA_MASKALL) ? sigfillset(&sanew.sa_mask) : sigemptyset(&sanew.sa_mask)) == -1) return -1 ; sanew.sa_handler = new->handler ; sanew.sa_flags = (new->flags & SKASA_NOCLDSTOP) ? SA_NOCLDSTOP : 0 ; #ifndef SKALIBS_FLAG_PREFERSELECT sanew.sa_flags |= SA_RESTART ; #endif if (sigaction(sig, &sanew, &saold) < 0) return -1 ; if (old) { int r = sigismember(&saold.sa_mask, (sig == SIGTERM) ? SIGPIPE : SIGTERM) ; if (r < 0) return -1 ; old->flags = 0 ; if (r) old->flags |= SKASA_MASKALL ; if (saold.sa_flags & SA_NOCLDSTOP) old->flags |= SKASA_NOCLDSTOP ; old->handler = saold.sa_handler ; } return 0 ; } skalibs-2.9.1.0/src/libstddjb/slurp.c000066400000000000000000000011711355335115400173570ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #define N 4096 int slurp (stralloc *sa, int fd) { size_t salen = sa->len ; int wasnull = !sa->s ; for (;;) { ssize_t r ; if (!stralloc_readyplus(sa, N)) break ; r = fd_read(fd, sa->s + sa->len, N) ; switch (r) { case -1: goto err ; case 0: stralloc_shrink(sa) ; return 1 ; default: sa->len += r ; } } err: if (wasnull) stralloc_free(sa) ; else { sa->len = salen ; stralloc_shrink(sa) ; } return 0 ; } skalibs-2.9.1.0/src/libstddjb/socket_accept4.c000066400000000000000000000020331355335115400211030ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include #include int socket_accept4_internal (int s, char *ip, uint16_t *port, unsigned int options) { struct sockaddr_in sa ; socklen_t dummy = sizeof sa ; int fd ; do #ifdef SKALIBS_HASACCEPT4 fd = accept4(s, (struct sockaddr *)&sa, &dummy, ((options & DJBUNIX_FLAG_NB) ? SOCK_NONBLOCK : 0) | ((options & DJBUNIX_FLAG_COE) ? SOCK_CLOEXEC : 0)) ; #else fd = accept(s, (struct sockaddr *)&sa, &dummy) ; #endif while ((fd < 0) && (errno == EINTR)) ; if (fd < 0) return -1 ; #ifndef SKALIBS_HASACCEPT4 if ((((options & DJBUNIX_FLAG_NB) ? ndelay_on(fd) : ndelay_off(fd)) < 0) || (((options & DJBUNIX_FLAG_COE) ? coe(fd) : uncoe(fd)) < 0)) { fd_close(fd) ; return -1 ; } #endif memcpy(ip, &sa.sin_addr.s_addr, 4) ; uint16_unpack_big((char *)&sa.sin_port, port) ; return fd ; } skalibs-2.9.1.0/src/libstddjb/socket_accept4_u32.c000066400000000000000000000004661355335115400216040ustar00rootroot00000000000000/* ISC license. */ #include #include int socket_accept4_internal_u32 (int s, uint32_t *ip, uint16_t *port, unsigned int options) { char pack[4] ; int fd = socket_accept4_internal(s, pack, port, options) ; if (fd >= 0) uint32_unpack_big(pack, ip) ; return fd ; } skalibs-2.9.1.0/src/libstddjb/socket_accept6.c000066400000000000000000000024341355335115400211120ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include #include #include #ifdef SKALIBS_IPV6_ENABLED int socket_accept6_internal (int s, char *ip6, uint16_t *port, unsigned int options) { struct sockaddr_in6 sa ; socklen_t dummy = sizeof sa ; int fd ; do #ifdef SKALIBS_HASACCEPT4 fd = accept4(s, (struct sockaddr *)&sa, &dummy, ((options & DJBUNIX_FLAG_NB) ? SOCK_NONBLOCK : 0) | ((options & DJBUNIX_FLAG_COE) ? SOCK_CLOEXEC : 0)) ; #else fd = accept(s, (struct sockaddr *)&sa, &dummy) ; #endif while ((fd < 0) && (errno == EINTR)) ; if (fd < 0) return -1 ; #ifndef SKALIBS_HASACCEPT4 if ((((options & DJBUNIX_FLAG_NB) ? ndelay_on(fd) : ndelay_off(fd)) < 0) || (((options & DJBUNIX_FLAG_COE) ? coe(fd) : uncoe(fd)) < 0)) { fd_close(fd) ; return -1 ; } #endif memcpy(ip6, sa.sin6_addr.s6_addr, 16) ; uint16_unpack_big((char *)&sa.sin6_port, port) ; return fd ; } #else int socket_accept6_internal (int s, char *ip6, uint16_t *port, unsigned int options) { (void)s ; (void)ip6 ; (void)port ; (void)options ; return (errno = ENOSYS, -1) ; } #endif skalibs-2.9.1.0/src/libstddjb/socket_bind4.c000066400000000000000000000007331355335115400205650ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include int socket_bind4 (int s, char const *ip, uint16_t port) { struct sockaddr_in sa ; memset(&sa, 0, sizeof sa) ; sa.sin_family = AF_INET ; uint16_big_endian((char *)&port, 1) ; sa.sin_port = port ; memcpy(&sa.sin_addr.s_addr, ip, 4) ; return bind(s, (struct sockaddr *)&sa, sizeof sa) ; } skalibs-2.9.1.0/src/libstddjb/socket_bind4r.c000066400000000000000000000004621355335115400207460ustar00rootroot00000000000000/* ISC license. */ #include #include #include int socket_bind4_reuse (int s, char const *ip, uint16_t port) { static unsigned int const opt = 1 ; setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof opt) ; return socket_bind4(s, ip, port) ; } skalibs-2.9.1.0/src/libstddjb/socket_bind6.c000066400000000000000000000012641355335115400205670ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include #ifdef SKALIBS_IPV6_ENABLED int socket_bind6 (int s, char const *ip6, uint16_t port) { struct sockaddr_in6 sa ; memset(&sa, 0, sizeof sa) ; sa.sin6_family = AF_INET6 ; uint16_pack_big((char *)&sa.sin6_port, port) ; memcpy(sa.sin6_addr.s6_addr, ip6, 16) ; return bind(s, (struct sockaddr *)&sa, sizeof sa) ; } #else int socket_bind6 (int s, char const *ip6, uint16_t port) { (void)s ; (void)ip6 ; (void)port ; return (errno = ENOSYS, -1) ; } #endif skalibs-2.9.1.0/src/libstddjb/socket_bind6r.c000066400000000000000000000004641355335115400207520ustar00rootroot00000000000000/* ISC license. */ #include #include #include int socket_bind6_reuse (int s, char const *ip6, uint16_t port) { static unsigned int const opt = 1 ; setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof opt) ; return socket_bind6(s, ip6, port) ; } skalibs-2.9.1.0/src/libstddjb/socket_conn4.c000066400000000000000000000011631355335115400206040ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include int socket_connect4 (int s, char const *ip, uint16_t port) { struct sockaddr_in sa ; int r ; memset(&sa, 0, sizeof sa) ; sa.sin_family = AF_INET ; uint16_big_endian((char *)&port, 1) ; sa.sin_port = port ; memcpy(&sa.sin_addr.s_addr, ip, 4) ; do r = connect(s, (struct sockaddr *)&sa, sizeof sa) ; while ((r == -1) && (errno == EINTR)) ; if ((r == -1) && (errno == EALREADY)) errno = EINPROGRESS ; return r ; } skalibs-2.9.1.0/src/libstddjb/socket_conn4_u32.c000066400000000000000000000003461355335115400212770ustar00rootroot00000000000000/* ISC license. */ #include #include int socket_connect4_u32 (int s, uint32_t ip, uint16_t port) { char pack[4] ; uint32_pack_big(pack, ip) ; return socket_connect4(s, pack, port) ; } skalibs-2.9.1.0/src/libstddjb/socket_conn6.c000066400000000000000000000014731355335115400206120ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include #ifdef SKALIBS_IPV6_ENABLED int socket_connect6 (int s, char const *ip6, uint16_t port) { struct sockaddr_in6 sa ; int r ; memset(&sa, 0, sizeof sa) ; sa.sin6_family = AF_INET6 ; uint16_pack_big((char *)&sa.sin6_port,port) ; memcpy(sa.sin6_addr.s6_addr, ip6, 16) ; do r = connect(s, (struct sockaddr *)&sa, sizeof sa) ; while ((r == -1) && (errno == EINTR)) ; if ((r == -1) && (errno == EALREADY)) errno = EINPROGRESS ; return r ; } #else int socket_connect6 (int s, char const *ip6, uint16_t port) { (void)s ; (void)ip6 ; (void)port ; return (errno = ENOSYS, -1) ; } #endif skalibs-2.9.1.0/src/libstddjb/socket_connected.c000066400000000000000000000006031355335115400215230ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int socket_connected (int s) { struct sockaddr_in sa ; socklen_t dummy = sizeof sa ; if (getpeername(s, (struct sockaddr *)&sa, &dummy) == -1) { char ch ; fd_read(s, &ch, 1) ; return 0 ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/socket_deadlineconnstamp4.c000066400000000000000000000006241355335115400233400ustar00rootroot00000000000000/* ISC license. */ #include #include #include int socket_deadlineconnstamp (int s, char const *ip, uint16_t port, tain_t const *deadline, tain_t *stamp) { int e = errno ; if (socket_connect4(s, ip, port) >= 0) return 1 ; if (!error_isagain(errno) && !error_isalready(errno)) return 0 ; errno = e ; return socket_waitconn(s, deadline, stamp) ; } skalibs-2.9.1.0/src/libstddjb/socket_deadlineconnstamp46.c000066400000000000000000000006611355335115400234270ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int socket_deadlineconnstamp46 (int s, ip46_t const *i, uint16_t port, tain_t const *deadline, tain_t *stamp) { int e = errno ; if (socket_connect46(s, i, port) >= 0) return 1 ; if (!error_isagain(errno) && !error_isalready(errno)) return 0 ; errno = e ; return socket_waitconn(s, deadline, stamp) ; } skalibs-2.9.1.0/src/libstddjb/socket_deadlineconnstamp4_u32.c000066400000000000000000000004621355335115400240310ustar00rootroot00000000000000/* ISC license. */ #include #include int socket_deadlineconnstamp4_u32 (int s, uint32_t ip, uint16_t port, tain_t const *deadline, tain_t *stamp) { char pack[4] ; uint32_pack_big(pack, ip) ; return socket_deadlineconnstamp4(s, pack, port, deadline, stamp) ; } skalibs-2.9.1.0/src/libstddjb/socket_deadlineconnstamp6.c000066400000000000000000000006251355335115400233430ustar00rootroot00000000000000/* ISC license. */ #include #include #include int socket_deadlineconnstamp6 (int s, char const *ip, uint16_t port, tain_t const *deadline, tain_t *stamp) { int e = errno ; if (socket_connect6(s, ip, port) >= 0) return 1 ; if (!error_isagain(errno) && !error_isalready(errno)) return 0 ; errno = e ; return socket_waitconn(s, deadline, stamp) ; } skalibs-2.9.1.0/src/libstddjb/socket_delay.c000066400000000000000000000004351355335115400206620ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int socket_tcpnodelay (int s) { static int const opt = TCP_NODELAY ; return setsockopt(s, IPPROTO_TCP, 1, &opt, sizeof(int)) ; } skalibs-2.9.1.0/src/libstddjb/socket_internal.c000066400000000000000000000013421355335115400213760ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #ifdef SKALIBS_HASACCEPT4 int socket_internal (int domain, int type, int protocol, unsigned int flags) { return socket(domain, type | ((flags & DJBUNIX_FLAG_NB) ? SOCK_NONBLOCK : 0) | ((flags & DJBUNIX_FLAG_COE) ? SOCK_CLOEXEC : 0), protocol) ; } #else int socket_internal (int domain, int type, int protocol, unsigned int flags) { int s = socket(domain, type, protocol) ; if (s == -1) return -1 ; if ((((flags & DJBUNIX_FLAG_NB) ? ndelay_on(s) : ndelay_off(s)) < 0) || (((flags & DJBUNIX_FLAG_COE) ? coe(s) : uncoe(s)) < 0)) { fd_close(s) ; return -1 ; } return s ; } #endif skalibs-2.9.1.0/src/libstddjb/socket_ioloop.c000066400000000000000000000013711355335115400210650ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include ssize_t socket_ioloop (int s, char *buf, size_t len, char *ip, uint16_t *port, socket_io_func_t_ref f, int w, tain_t const *deadline, tain_t *stamp) { iopause_fd x = { .fd = s, .events = w ? IOPAUSE_WRITE : IOPAUSE_READ, .revents = 0 } ; for (;;) { ssize_t r = iopause_stamp(&x, 1, deadline, stamp) ; if (r < 0) return -1 ; if (!r) return (errno = ETIMEDOUT, -1) ; if (x.revents & IOPAUSE_EXCEPT) return (errno = EIO, -1) ; if (x.revents & x.events) { r = (*f)(s, buf, len, ip, port) ; if (r < 0) { if (!error_isagain(errno)) return -1 ; } else return r ; } } } skalibs-2.9.1.0/src/libstddjb/socket_ioloop_send4.c000066400000000000000000000002701355335115400221570ustar00rootroot00000000000000/* ISC license. */ #include ssize_t socket_ioloop_send4 (int fd, char *s, size_t len, char *ip, uint16_t *port) { return socket_send4(fd, s, len, ip, *port) ; } skalibs-2.9.1.0/src/libstddjb/socket_ioloop_send6.c000066400000000000000000000002701355335115400221610ustar00rootroot00000000000000/* ISC license. */ #include ssize_t socket_ioloop_send6 (int fd, char *s, size_t len, char *ip, uint16_t *port) { return socket_send6(fd, s, len, ip, *port) ; } skalibs-2.9.1.0/src/libstddjb/socket_local4.c000066400000000000000000000007231355335115400207420ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include int socket_local4 (int s, char *ip, uint16_t *port) { struct sockaddr_in sa ; socklen_t dummy = sizeof sa ; if (getsockname(s, (struct sockaddr *)&sa, &dummy) == -1) return -1 ; memcpy(ip, &sa.sin_addr.s_addr, 4) ; uint16_unpack_big((char *)&sa.sin_port, port) ; return 0 ; } skalibs-2.9.1.0/src/libstddjb/socket_local46.c000066400000000000000000000016301355335115400210260ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #ifdef SKALIBS_IPV6_ENABLED int socket_local46 (int s, ip46_t *ip, uint16_t *port) { struct sockaddr_storage sa ; socklen_t dummy = sizeof sa ; if (getsockname(s, (struct sockaddr *)&sa, &dummy) < 0) return -1 ; if (sa.ss_family == AF_INET6) { struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)&sa ; memcpy(ip->ip, sa6->sin6_addr.s6_addr, 16) ; uint16_unpack_big((char *)&sa6->sin6_port, port) ; ip->is6 = 1 ; } else if (sa.ss_family == AF_INET) { struct sockaddr_in *sa4 = (struct sockaddr_in *)&sa ; memcpy(ip->ip, &sa4->sin_addr.s_addr, 4) ; uint16_unpack_big((char *)&sa4->sin_port, port) ; ip->is6 = 0 ; } else return (errno = EAFNOSUPPORT, -1) ; return 0 ; } #endif skalibs-2.9.1.0/src/libstddjb/socket_local6.c000066400000000000000000000012621355335115400207430ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #ifdef SKALIBS_IPV6_ENABLED int socket_local6 (int s, char *ip, uint16_t *port) { struct sockaddr_in6 sa ; socklen_t dummy = sizeof sa ; if (getsockname(s, (struct sockaddr *)&sa, &dummy) == -1) return -1 ; memcpy(ip, sa.sin6_addr.s6_addr, 16) ; uint16_unpack_big((char *)&sa.sin6_port, port) ; return 0 ; } #else #include int socket_local6 (int s, char *ip, uint16_t *port) { (void)s ; (void)ip ; (void)port ; return (errno = ENOSYS, -1) ; } #endif skalibs-2.9.1.0/src/libstddjb/socket_recv4.c000066400000000000000000000011041355335115400206010ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include ssize_t socket_recv4 (int s, char *buf, size_t len, char *ip, uint16_t *port) { struct sockaddr_in sa ; socklen_t dummy = sizeof sa ; ssize_t r ; do r = recvfrom(s, buf, len, 0, (struct sockaddr *)&sa, &dummy) ; while ((r == -1) && (errno == EINTR)) ; if (r == -1) return -1 ; memcpy(ip, &sa.sin_addr, 4) ; uint16_unpack_big((char *)&sa.sin_port, port) ; return r ; } skalibs-2.9.1.0/src/libstddjb/socket_recv6.c000066400000000000000000000015201355335115400206050ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include #ifdef SKALIBS_IPV6_ENABLED ssize_t socket_recv6 (int s, char *buf, size_t len, char *ip6, uint16_t *port) { struct sockaddr_in6 sa ; socklen_t dummy = sizeof sa ; ssize_t r ; do r = recvfrom(s, buf, len, 0, (struct sockaddr *)&sa, &dummy) ; while ((r == -1) && (errno == EINTR)) ; if (r == -1) return -1 ; memcpy(ip6, sa.sin6_addr.s6_addr, 16) ; uint16_unpack_big((char *)&sa.sin6_port, port) ; return r ; } #else ssize_t socket_recv6 (int s, char *buf, size_t len, char *ip6, uint16_t *port) { (void)s ; (void)buf ; (void)len ; (void)ip6 ; (void)port ; return (errno = ENOSYS, -1) ; } #endif skalibs-2.9.1.0/src/libstddjb/socket_remote4.c000066400000000000000000000007241355335115400211440ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include int socket_remote4 (int s, char *ip, uint16_t *port) { struct sockaddr_in sa ; socklen_t dummy = sizeof sa ; if (getpeername(s, (struct sockaddr *)&sa, &dummy) == -1) return -1 ; memcpy(ip, &sa.sin_addr.s_addr, 4) ; uint16_unpack_big((char *)&sa.sin_port, port) ; return 0 ; } skalibs-2.9.1.0/src/libstddjb/socket_remote46.c000066400000000000000000000016311355335115400212300ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #ifdef SKALIBS_IPV6_ENABLED int socket_remote46 (int s, ip46_t *ip, uint16_t *port) { struct sockaddr_storage sa ; socklen_t dummy = sizeof sa ; if (getpeername(s, (struct sockaddr *)&sa, &dummy) < 0) return -1 ; if (sa.ss_family == AF_INET6) { struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)&sa ; memcpy(ip->ip, sa6->sin6_addr.s6_addr, 16) ; uint16_unpack_big((char *)&sa6->sin6_port, port) ; ip->is6 = 1 ; } else if (sa.ss_family == AF_INET) { struct sockaddr_in *sa4 = (struct sockaddr_in *)&sa ; memcpy(ip->ip, &sa4->sin_addr.s_addr, 4) ; uint16_unpack_big((char *)&sa4->sin_port, port) ; ip->is6 = 0 ; } else return (errno = EAFNOSUPPORT, -1) ; return 0 ; } #endif skalibs-2.9.1.0/src/libstddjb/socket_remote6.c000066400000000000000000000012631355335115400211450ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include #ifdef SKALIBS_IPV6_ENABLED int socket_remote6 (int s, char *ip, uint16_t *port) { struct sockaddr_in6 sa ; socklen_t dummy = sizeof sa ; if (getpeername(s, (struct sockaddr *)&sa, &dummy) == -1) return -1 ; memcpy(ip, sa.sin6_addr.s6_addr, 16) ; uint16_unpack_big((char *)&sa.sin6_port, port) ; return 0 ; } #else int socket_remote6 (int s, char *ip, uint16_t *port) { (void)s ; (void)ip ; (void)port ; return (errno = ENOSYS, -1) ; } #endif skalibs-2.9.1.0/src/libstddjb/socket_send4.c000066400000000000000000000011151355335115400205750ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include ssize_t socket_send4 (int s, char const *buf, size_t len, char const *ip, uint16_t port) { struct sockaddr_in sa ; ssize_t r ; memset(&sa, 0, sizeof sa) ; sa.sin_family = AF_INET ; uint16_pack_big((char *)&sa.sin_port, port) ; memcpy(&sa.sin_addr, ip, 4) ; do r = sendto(s, buf, len, 0, (struct sockaddr *)&sa, sizeof sa) ; while ((r == -1) && (errno == EINTR)) ; return r ; } skalibs-2.9.1.0/src/libstddjb/socket_send6.c000066400000000000000000000015461355335115400206070ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include #ifdef SKALIBS_IPV6_ENABLED ssize_t socket_send6 (int s, char const *buf, size_t len, char const *ip6, uint16_t port) { struct sockaddr_in6 sa ; ssize_t r ; memset(&sa, 0, sizeof sa) ; sa.sin6_family = AF_INET6 ; uint16_pack_big((char *)&sa.sin6_port, port) ; memcpy(sa.sin6_addr.s6_addr, ip6, 16) ; do r = sendto(s, buf, len, 0, (struct sockaddr *)&sa, sizeof sa) ; while ((r == -1) && (errno == EINTR)) ; return r ; } #else ssize_t socket_send6 (int s, char const *buf, size_t len, char const *ip6, uint16_t port) { (void)s ; (void)buf ; (void)len ; (void)ip6 ; (void)port ; return (errno = ENOSYS, -1) ; } #endif skalibs-2.9.1.0/src/libstddjb/socket_tcp4.c000066400000000000000000000003541355335115400204360ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int socket_tcp4_internal (unsigned int flags) { return socket_internal(AF_INET, SOCK_STREAM, 0, flags) ; } skalibs-2.9.1.0/src/libstddjb/socket_tcp6.c000066400000000000000000000012201355335115400204310ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #ifdef SKALIBS_IPV6_ENABLED int socket_tcp6_internal (unsigned int flags) { int fd = socket_internal(AF_INET6, SOCK_STREAM, 0, flags) ; if (fd < 0) return fd ; { int option = 1 ; if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &option, sizeof(option)) < 0) { fd_close(fd) ; return -1 ; } } return fd ; } #else int socket_tcp6_internal (unsigned int flags) { (void)flags ; return (errno = ENOSYS, -1) ; } #endif skalibs-2.9.1.0/src/libstddjb/socket_timeoutconn.c000066400000000000000000000005031355335115400221240ustar00rootroot00000000000000/* ISC license. */ #include #include int socket_timeoutconn (int s, char const *ip, uint16_t port, unsigned int timeout) { tain_t stamp, deadline ; tain_now(&stamp) ; tain_addsec(&deadline, &stamp, timeout) ; return socket_deadlineconnstamp4(s, ip, port, &deadline, &stamp) ; } skalibs-2.9.1.0/src/libstddjb/socket_tryr.c000066400000000000000000000004441355335115400205640ustar00rootroot00000000000000/* ISC license. */ #include #include #include void socket_tryreservein (int s, unsigned int size) { while (size >= 1024) { if (!setsockopt(s, SOL_SOCKET, SO_RCVBUF, &size, sizeof size)) return ; size -= (size >> 5) ; } } skalibs-2.9.1.0/src/libstddjb/socket_udp4.c000066400000000000000000000003531355335115400204370ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int socket_udp4_internal (unsigned int flags) { return socket_internal(AF_INET, SOCK_DGRAM, 0, flags) ; } skalibs-2.9.1.0/src/libstddjb/socket_udp6.c000066400000000000000000000012171355335115400204410ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #ifdef SKALIBS_IPV6_ENABLED int socket_udp6_internal (unsigned int flags) { int fd = socket_internal(AF_INET6, SOCK_DGRAM, 0, flags) ; if (fd < 0) return fd ; { int option = 1 ; if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &option, sizeof(option)) < 0) { fd_close(fd) ; return -1 ; } } return fd ; } #else int socket_udp6_internal (unsigned int flags) { (void)flags ; return (errno = ENOSYS, -1) ; } #endif skalibs-2.9.1.0/src/libstddjb/socket_waitconn.c000066400000000000000000000010711355335115400214030ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int socket_waitconn (int s, tain_t const *deadline, tain_t *stamp) { iopause_fd x = { s, IOPAUSE_WRITE, 0 } ; for (;;) { int r = iopause_stamp(&x, 1, deadline, stamp) ; if (r < 0) return 0 ; if (!r) return (errno = ETIMEDOUT, 0) ; if (x.revents & IOPAUSE_WRITE) break ; if (x.revents & IOPAUSE_EXCEPT) { fd_write(s, "", 1) ; /* sets errno */ return 0 ; } } return socket_connected(s) ; } skalibs-2.9.1.0/src/libstddjb/socketpair_internal.c000066400000000000000000000021621355335115400222530ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #ifdef SKALIBS_HASACCEPT4 int socketpair_internal (int domain, int type, int protocol, unsigned int flags, int *sv) { return socketpair(domain, type | ((flags & DJBUNIX_FLAG_NB) ? SOCK_NONBLOCK : 0) | ((flags & DJBUNIX_FLAG_COE) ? SOCK_CLOEXEC : 0), protocol, sv) ; } #else int socketpair_internal (int domain, int type, int protocol, unsigned int flags, int *sv) { int fd[2] ; if (socketpair(domain, type, protocol, fd) < 0) return -1 ; if (flags & DJBUNIX_FLAG_NB) { if (ndelay_on(fd[0]) < 0) goto err ; if (ndelay_on(fd[1]) < 0) goto err ; } else { if (ndelay_off(fd[0]) < 0) goto err ; if (ndelay_off(fd[1]) < 0) goto err ; } if (flags & DJBUNIX_FLAG_COE) { if (coe(fd[0]) < 0) goto err ; if (coe(fd[1]) < 0) goto err ; } else { if (uncoe(fd[0]) < 0) goto err ; if (uncoe(fd[1]) < 0) goto err ; } sv[0] = fd[0] ; sv[1] = fd[1] ; return 0 ; err: fd_close(fd[1]) ; fd_close(fd[0]) ; return -1 ; } #endif skalibs-2.9.1.0/src/libstddjb/stamp.c000066400000000000000000000001331355335115400173330ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include tain_t STAMP = TAIN_EPOCH ; skalibs-2.9.1.0/src/libstddjb/str_chr.c000066400000000000000000000002541355335115400176570ustar00rootroot00000000000000/* ISC license. */ #include #include size_t str_chr (char const *s, int c) { char *p = strchr(s, c) ; return p ? p - s : strlen(s) ; } skalibs-2.9.1.0/src/libstddjb/str_fmt.c000066400000000000000000000002271355335115400176710ustar00rootroot00000000000000/* ISC license. */ #include #include size_t str_fmt (char *d, char const *s) { return strn_fmt(d, s, strlen(s)) ; } skalibs-2.9.1.0/src/libstddjb/str_rchr.c000066400000000000000000000002571355335115400200440ustar00rootroot00000000000000/* ISC license. */ #include #include size_t str_rchr (char const *s, int c) { char *p = strrchr(s, c) ; return p ? p - s : strlen(s) ; } skalibs-2.9.1.0/src/libstddjb/str_start.c000066400000000000000000000002341355335115400202360ustar00rootroot00000000000000/* ISC license. */ #include #include int str_start (char const *s, char const *t) { return !strncmp(s, t, strlen(t)) ; } skalibs-2.9.1.0/src/libstddjb/str_strn.c000066400000000000000000000006301355335115400200670ustar00rootroot00000000000000/* ISC license. */ #include #include size_t str_strn (char const *haystack, size_t hlen, char const *needle, size_t nlen) { char haystack2[hlen+1] ; char needle2[nlen+1] ; char *p ; memcpy(haystack2, haystack, hlen) ; haystack2[hlen] = 0 ; memcpy(needle2, needle, nlen) ; needle2[nlen] = 0 ; p = strstr(haystack2, needle2) ; return p ? p - haystack2 : hlen ; } skalibs-2.9.1.0/src/libstddjb/stralloc_append.c000066400000000000000000000002061355335115400213620ustar00rootroot00000000000000/* ISC license. */ #include int stralloc_append (stralloc *sa, char c) { return stralloc_catb(sa, &c, 1) ; } skalibs-2.9.1.0/src/libstddjb/stralloc_catb.c000066400000000000000000000003631355335115400210300ustar00rootroot00000000000000/* ISC license. */ #include #include int stralloc_catb (stralloc *sa, char const *s, size_t n) { if (!stralloc_readyplus(sa, n)) return 0 ; memmove(sa->s + sa->len, s, n) ; sa->len += n ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/stralloc_catv.c000066400000000000000000000006351355335115400210560ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int stralloc_catv (stralloc *sa, struct iovec const *v, unsigned int n) { unsigned int i = 0 ; if (!stralloc_readyplus(sa, siovec_len(v, n))) return 0 ; for ( ; i < n ; i++) { memmove(sa->s + sa->len, v[i].iov_base, v[i].iov_len) ; sa->len += v[i].iov_len ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/stralloc_copyb.c000066400000000000000000000003451355335115400212330ustar00rootroot00000000000000/* ISC license. */ #include #include int stralloc_copyb (stralloc *sa, char const *s, size_t n) { if (!stralloc_ready(sa, n)) return 0 ; memmove(sa->s, s, n) ; sa->len = n ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/stralloc_free.c000066400000000000000000000002421355335115400210340ustar00rootroot00000000000000/* ISC license. */ #include #include void stralloc_free (stralloc *sa) { alloc_free(sa->s) ; *sa = stralloc_zero ; } skalibs-2.9.1.0/src/libstddjb/stralloc_insertb.c000066400000000000000000000006161355335115400215660ustar00rootroot00000000000000/* ISC license. */ #include #include #include int stralloc_insertb (stralloc *sa, size_t offset, char const *s, size_t n) { if (offset > sa->len) return (errno = EINVAL, 0) ; if (!stralloc_readyplus(sa, n)) return 0 ; memmove(sa->s + offset + n, sa->s + offset, sa->len - offset) ; sa->len += n ; memmove(sa->s + offset, s, n) ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/stralloc_ready_tuned.c000066400000000000000000000010231355335115400224140ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int stralloc_ready_tuned (stralloc *sa, size_t n, size_t base, size_t a, size_t b) { size_t t ; if (!b) return (errno = EINVAL, 0) ; t = n + base + a * n / b ; if (t < n) return (errno = ERANGE, 0) ; if (!sa->s) { sa->s = alloc(t) ; if (!sa->s) return 0 ; sa->a = t ; } else if (n > sa->a) { if (!alloc_re((void **)&sa->s, sa->a, t)) return 0 ; sa->a = t ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/stralloc_reverse.c000066400000000000000000000004171355335115400215720ustar00rootroot00000000000000/* ISC license. */ #include #include void stralloc_reverse (stralloc *sa) { size_t i = 0 ; for (; i < sa->len >> 1 ; i++) { char tmp = sa->s[i] ; sa->s[i] = sa->s[sa->len - 1 - i] ; sa->s[sa->len - 1 - i] = tmp ; } } skalibs-2.9.1.0/src/libstddjb/stralloc_reverse_blocks.c000066400000000000000000000006221355335115400231250ustar00rootroot00000000000000/* ISC license. */ #include #include void stralloc_reverse_blocks (stralloc *sa, size_t size) { size_t n = sa->len / (size << 1) ; size_t i = 0 ; char tmp[size] ; for (; i < n ; i++) { size_t k = sa->len - (i + 1) * size ; memcpy(tmp, sa->s + i * size, size) ; memcpy(sa->s + i * size, sa->s + k, size) ; memcpy(sa->s + k, tmp, size) ; } } skalibs-2.9.1.0/src/libstddjb/stralloc_shrink.c000066400000000000000000000003661355335115400214200ustar00rootroot00000000000000/* ISC license. */ #include #include int stralloc_shrink (stralloc *sa) { if (sa->a > sa->len) { if (!alloc_re((void **)&sa->s, sa->a, sa->len)) return 0 ; sa->a = sa->len ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/stralloc_zero.c000066400000000000000000000001421355335115400210710ustar00rootroot00000000000000/* ISC license. */ #include stralloc const stralloc_zero = STRALLOC_ZERO ; skalibs-2.9.1.0/src/libstddjb/strerr.c000066400000000000000000000022601355335115400175330ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include #include #include void strerr_warn (char const *x1, char const *x2, char const *x3, char const *x4, char const *x5, char const *x6, char const *x7, char const *x8, char const *x9, char const *x10, char const *se) { int e = errno ; if (x1) buffer_puts(buffer_2, x1) ; if (x2) buffer_puts(buffer_2, x2) ; if (x3) buffer_puts(buffer_2, x3) ; if (x4) buffer_puts(buffer_2, x4) ; if (x5) buffer_puts(buffer_2, x5) ; if (x6) buffer_puts(buffer_2, x6) ; if (x7) buffer_puts(buffer_2, x7) ; if (x8) buffer_puts(buffer_2, x8) ; if (x9) buffer_puts(buffer_2, x9) ; if (x10) buffer_puts(buffer_2, x10) ; if (se) buffer_puts(buffer_2, se) ; buffer_putflush(buffer_2, "\n", 1) ; errno = e ; } void strerr_die (int e, char const *x1, char const *x2, char const *x3, char const *x4, char const *x5, char const *x6, char const *x7, char const *x8, char const *x9, char const *x10, char const *se) { strerr_warn(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, se) ; _exit(e) ; /* No, OpenBSD, this noreturn function does NOT return. Please learn what _exit() does. */ } skalibs-2.9.1.0/src/libstddjb/strerr_sys.c000066400000000000000000000013541355335115400204340ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include #include #include void strerr_warnsys (char const *x1, char const *x2, char const *x3, char const *x4, char const *x5, char const *x6, char const *x7, char const *x8, char const *x9, char const *x10) { strerr_warn(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, strerror(errno)) ; } void strerr_diesys (int e, char const *x1, char const *x2, char const *x3, char const *x4, char const *x5, char const *x6, char const *x7, char const *x8, char const *x9, char const *x10) { strerr_warnsys(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) ; _exit(e) ; /* No, OpenBSD, this noreturn function does NOT return. Please learn what _exit() does. */ } skalibs-2.9.1.0/src/libstddjb/string_format.c000066400000000000000000000023511355335115400210710ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int string_format (stralloc *sa, char const *vars, char const *format, char const *const *args) { static unsigned char const tab[2][4] = { "1442", "4833" } ; char class[256] = "3222222222222222222222222222222222222022222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222" ; size_t varlen = strlen(vars) ; size_t base = sa->len ; size_t state = 0 ; int wasnull = !sa->s ; for (; state < varlen ; state++) if (class[(unsigned char)vars[state]] == '2') class[(unsigned char)vars[state]] = '1' ; else return (errno = EINVAL, 0) ; for (state = 0 ; state < 2 ; format++) { unsigned char c = tab[state][class[(unsigned char)(*format)] - '0'] ; state = c & 3 ; if (c & 4) if (!stralloc_catb(sa, format, 1)) goto err ; if (c & 8) if (!stralloc_cats(sa, args[byte_chr(vars, varlen, *format)])) goto err ; } if (state == 2) return 1 ; errno = EINVAL ; err: if (wasnull) stralloc_free(sa) ; else sa->len = base ; return 0 ; } skalibs-2.9.1.0/src/libstddjb/string_quote.c000066400000000000000000000006271355335115400207420ustar00rootroot00000000000000/* ISC license. */ #include #include int string_quote (stralloc *sa, char const *s, size_t len) { size_t base = sa->len ; int wasnull = !sa->s ; if (!stralloc_catb(sa, "\"", 1)) return 0 ; if (!string_quote_nodelim(sa, s, len) || !stralloc_catb(sa, "\"", 1)) { if (wasnull) stralloc_free(sa) ; else sa->len = base ; return 0 ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/string_quote_nodelim.c000066400000000000000000000003521355335115400224440ustar00rootroot00000000000000/* ISC license. */ #include #include #include int string_quote_nodelim (stralloc *sa, char const *s, size_t len) { return string_quote_nodelim_mustquote(sa, s, len, "\"", 1) ; } skalibs-2.9.1.0/src/libstddjb/string_quote_nodelim_mustquote.c000066400000000000000000000032001355335115400245650ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int string_quote_nodelim_mustquote (stralloc *sa, char const *s, size_t len, char const *delim, size_t delimlen) { char class[256] = "dddddddaaaaaaaddddddddddddddddddcccccccccccccccceeeeeeeeeeccccccccccccccccccccccccccccccccccbcccceeeeeecccccccecccececececcccccddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" ; size_t base = sa->len ; size_t i = 0 ; int wasnull = !sa->s ; for (; i < delimlen ; i++) if (class[(unsigned char)delim[i]] == 'c') class[(unsigned char)delim[i]] = 'b' ; else return (errno = EINVAL, 0) ; for (i = 0 ; i < len ; i++) { switch (class[(unsigned char)s[i]]) { case 'a' : { static char const tab[7] = "abtnvfr" ; char fmt[2] = "\\" ; fmt[1] = tab[s[i] - 7] ; if (!stralloc_catb(sa, fmt, 2)) goto err ; break ; } case 'b' : { char fmt[2] = "\\" ; fmt[1] = s[i] ; if (!stralloc_catb(sa, fmt, 2)) goto err ; break ; } case 'c' : case 'e' : { if (!stralloc_catb(sa, s+i, 1)) goto err ; break ; } case 'd' : { char fmt[5] = "\\0x" ; ucharn_fmt(fmt+3, s+i, 1) ; if (!stralloc_catb(sa, fmt, 5)) goto err ; break ; } default : errno = EFAULT ; goto err ; /* can't happen */ } } return 1 ; err: if (wasnull) stralloc_free(sa) ; else sa->len = base ; return 0 ; } skalibs-2.9.1.0/src/libstddjb/string_unquote.c000066400000000000000000000007441355335115400213050ustar00rootroot00000000000000/* ISC license. */ #include #include #include int string_unquote (char *d, size_t *w, char const *s, size_t len, size_t *r) { if (!len-- || (*s++ != '"')) return (errno = EINVAL, 0) ; { size_t rr, ww ; char tmp[len ? len : 1] ; if (!string_unquote_withdelim(tmp, &ww, s, len, &rr, "\"", 1)) return 0 ; if (rr == len) return (errno = EPIPE, 0) ; memcpy(d, tmp, ww) ; *w = ww ; *r = rr + 2 ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/string_unquote_nodelim.c000066400000000000000000000003761355335115400230150ustar00rootroot00000000000000/* ISC license. */ #include #include ssize_t string_unquote_nodelim (char *d, char const *s, size_t len) { size_t rr, ww ; if (!string_unquote_withdelim(d, &ww, s, len, &rr, 0, 0)) return -1 ; return (ssize_t)ww ; } skalibs-2.9.1.0/src/libstddjb/string_unquote_withdelim.c000066400000000000000000000043531355335115400233530ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #define PUSH0 0x40 #define PUSH 0x20 #define PUSHSPEC 0x10 #define STORE 0x08 #define CALC 0x04 #define SYNTAXERROR 0x02 #define BROKENPIPE 0x01 int string_unquote_withdelim (char *d, size_t *w, char const *s, size_t len, size_t *r, char const *delim, size_t delimlen) { static unsigned char const actions[5][9] = { { 0, 0, PUSH, PUSH, PUSH, PUSH, PUSH, PUSH, 0 }, { PUSH, PUSH, 0, PUSH, PUSHSPEC, PUSH, PUSHSPEC, PUSH, BROKENPIPE }, { PUSH0, PUSH0, PUSH0|PUSH, 0, PUSH0|PUSH, PUSH0|PUSH, PUSH0|PUSH, PUSH0|PUSH, PUSH0 }, { SYNTAXERROR, SYNTAXERROR, STORE, SYNTAXERROR, STORE, STORE, SYNTAXERROR, SYNTAXERROR, BROKENPIPE }, { SYNTAXERROR, SYNTAXERROR, CALC, SYNTAXERROR, CALC, CALC, SYNTAXERROR, SYNTAXERROR, BROKENPIPE } } ; static unsigned char const states[5][9] = { { 1, 5, 0, 0, 0, 0, 0, 0, 5 }, { 0, 0, 2, 0, 0, 0, 0, 0, 6 }, { 1, 5, 0, 3, 0, 0, 0, 0, 5 }, { 6, 6, 4, 6, 4, 4, 6, 6, 6 }, { 6, 6, 0, 6, 0, 0, 6, 6, 6 } } ; unsigned char class[256] = "7777777777777777777777777777777777777777777777772555555555777777777777777777777777777777777707777445554777777767776767673777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" ; size_t i = 0 ; unsigned char store = 0 ; unsigned char state = 0 ; for (; i < delimlen ; i++) if (class[(unsigned char)delim[i]] == '7') class[(unsigned char)delim[i]] = '1' ; else return (errno = EINVAL, 0) ; *w = 0 ; for (i = 0 ; state < 5 ; i++) { unsigned char c = i < len ? class[(unsigned char)s[i]] - '0' : 8 ; unsigned char action = actions[state][c] ; state = states[state][c] ; if (action & PUSH0) d[(*w)++] = 0 ; if (action & PUSH) d[(*w)++] = s[i] ; if (action & PUSHSPEC) d[(*w)++] = 7 + byte_chr("abtnvfr", 7, s[i]) ; if (action & STORE) store = fmtscan_num(s[i], 16) << 4 ; if (action & CALC) d[(*w)++] = store | fmtscan_num(s[i], 16) ; if (action & SYNTAXERROR) errno = EPROTO ; if (action & BROKENPIPE) errno = EPIPE ; } *r = i - 1 ; return (state == 5) ; } skalibs-2.9.1.0/src/libstddjb/strn_fmt.c000066400000000000000000000007151355335115400200510ustar00rootroot00000000000000/* ISC license. */ #include #include size_t strn_fmt (char *blah, char const *s, size_t len) { char *d = blah ; size_t i ; for (i = 0 ; i < len ; i++) if ((s[i] >= 32) && ((unsigned char)s[i] < 127)) *d++ = s[i] ; else { *d++ = '\\' ; *d++ = '0' ; *d++ = 'x' ; if ((unsigned char)s[i] < 16) *d++ = '0' ; d += uint_xfmt(d, (unsigned char)s[i]) ; } return d - blah ; } skalibs-2.9.1.0/src/libstddjb/subgetopt.c000066400000000000000000000023431355335115400202300ustar00rootroot00000000000000/* ISC license. */ #undef SUBGETOPT_SHORT #include int subgetopt_r (int argc, char const *const *argv, char const *opts, subgetopt_t *o) { o->arg = 0 ; if ((o->ind >= argc) || !argv[o->ind]) return -1 ; if (o->pos && !argv[o->ind][o->pos]) { o->ind++ ; o->pos = 0 ; if ((o->ind >= argc) || !argv[o->ind]) return -1 ; } if (!o->pos) { if (argv[o->ind][0] != '-') return -1 ; else { char c ; o->pos++ ; c = argv[o->ind][1] ; if (c == '-') o->ind++ ; if (!c || (c == '-')) { o->pos = 0 ; return -1 ; } } } { char c = argv[o->ind][o->pos++] ; char const *s = opts ; char retnoarg = (*s == ':') ? (s++, ':') : '?' ; while (*s) { if (c == *s) { if (s[1] == ':') { o->arg = argv[o->ind++] + o->pos ; o->pos = 0 ; if (!*o->arg) { o->arg = argv[o->ind] ; if ((o->ind >= argc) || !o->arg) { o->problem = c ; return retnoarg ; } o->ind++ ; } } return c ; } if (*++s == ':') s++ ; } o->problem = c ; } return '?' ; } skalibs-2.9.1.0/src/libstddjb/subgetopt_here.c000066400000000000000000000001611355335115400212270ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include subgetopt_t subgetopt_here = SUBGETOPT_ZERO ; skalibs-2.9.1.0/src/libstddjb/sysclock_from_localtm.c000066400000000000000000000004411355335115400226010ustar00rootroot00000000000000/* ISC license. */ #include #include #include int sysclock_from_localtm (uint64_t *uu, struct tm const *l) { uint64_t u ; if (!ltm64_from_localtm(&u, l)) return 0 ; if (!sysclock_from_ltm64(&u)) return 0 ; *uu = u ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/sysclock_from_localtmn.c000066400000000000000000000003211355335115400227540ustar00rootroot00000000000000/* ISC license. */ #include int sysclock_from_localtmn (tain_t *a, localtmn_t const *l) { if (!sysclock_from_localtm(&a->sec.x, &l->tm)) return 0 ; a->nano = l->nano ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/sysclock_from_ltm64.c000066400000000000000000000005441355335115400221200ustar00rootroot00000000000000/* ISC license. */ #include #include #include #ifdef SKALIBS_FLAG_CLOCKISTAI int sysclock_from_ltm64 (uint64_t *u) { tai_t t ; if (!tai_from_ltm64(&t, *u)) return 0 ; *u = t.x - 10U ; return 1 ; } #else int sysclock_from_ltm64 (uint64_t *u) { return utc_from_sysclock(u) ; } #endif skalibs-2.9.1.0/src/libstddjb/sysclock_from_tai.c000066400000000000000000000006111355335115400217220ustar00rootroot00000000000000/* ISC license. */ #include #include #include #ifdef SKALIBS_FLAG_CLOCKISTAI int sysclock_from_tai (uint64_t *u, tai_t const *t) { if (t->x < 10U) return (errno = EINVAL, 0) ; *u = t->x - 10U ; return 1 ; } #else #include int sysclock_from_tai (uint64_t *u, tai_t const *t) { return utc_from_tai(u, t) ; } #endif skalibs-2.9.1.0/src/libstddjb/sysclock_from_tain.c000066400000000000000000000003031355335115400220760ustar00rootroot00000000000000 /* ISC license. */ #include int sysclock_from_tain (tain_t *u, tain_t const *t) { if (!sysclock_from_tai(&u->sec.x, &t->sec)) return 0 ; u->nano = t->nano ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/sysclock_from_utc.c000066400000000000000000000006261355335115400217460ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #ifdef SKALIBS_FLAG_CLOCKISTAI int sysclock_from_utc (uint64_t *u) { tai_t t ; if (!tai_from_utc(&t, *u)) return 0 ; if (t.x < 10) return (errno = EINVAL, 0) ; *u = t.x - 10 ; return 1 ; } #else int sysclock_from_utc (uint64_t *u) { (void)u ; return 1 ; } #endif skalibs-2.9.1.0/src/libstddjb/sysclock_get.c000066400000000000000000000011261355335115400207030ustar00rootroot00000000000000/* ISC license. */ #include #include #ifdef SKALIBS_HASCLOCKRT #include int sysclock_get (tain_t *a) { tain_t aa ; struct timespec now ; if (clock_gettime(CLOCK_REALTIME, &now) < 0) return 0 ; if (!tain_from_timespec(&aa, &now)) return 0 ; tain_add(a, &aa, &tain_nano500) ; return 1 ; } #else #include int sysclock_get (tain_t *a) { tain_t aa ; struct timeval now ; if (gettimeofday(&now, 0) < 0) return 0 ; if (!tain_from_timeval(&aa, &now)) return 0 ; tain_add(a, &aa, &tain_nano500) ; return 1 ; } #endif skalibs-2.9.1.0/src/libstddjb/sysclock_set.c000066400000000000000000000015331355335115400207210ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #ifndef SKALIBS_HASCLOCKRT # ifndef SKALIBS_HASSETTIMEOFDAY # error "neither clockrt nor settimeofday sysdeps are present. How do your set your system clock?" # endif #endif #ifdef SKALIBS_HASCLOCKRT #include #include int sysclock_set (tain_t const *a) { struct timespec now ; tain_t aa ; tain_add(&aa, a, &tain_nano500) ; if (!timespec_from_tain(&now, &aa)) return 0 ; if (clock_settime(CLOCK_REALTIME, &now) < 0) return 0 ; return 1 ; } #else #include #include #include int sysclock_set (tain_t const *a) { struct timeval now ; tain_t aa ; tain_add(&aa, a, &tain_nano500) ; if (!timeval_from_tain(&now, &aa)) return 0 ; if (settimeofday(&now, 0) < 0) return 0 ; return 1 ; } #endif skalibs-2.9.1.0/src/libstddjb/tai_add.c000066400000000000000000000002151355335115400175750ustar00rootroot00000000000000/* ISC license. */ #include int tai_add (tai_t *t, tai_t const *u, tai_t const *v) { t->x = u->x + v->x ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/tai_from_localtm.c000066400000000000000000000003641355335115400215300ustar00rootroot00000000000000/* ISC license. */ #include #include #include int tai_from_localtm (tai_t *t, struct tm const *l) { uint64_t u ; if (!ltm64_from_localtm(&u, l)) return 0 ; return tai_from_ltm64(t, u) ; } skalibs-2.9.1.0/src/libstddjb/tai_from_ltm64.c000066400000000000000000000004211355335115400210350ustar00rootroot00000000000000/* ISC license. */ #include #include "djbtime-internal.h" int tai_from_ltm64 (tai_t *t, uint64_t u) { switch (skalibs_tzisright()) { case 1 : return tai_u64(t, u + 10U) ; case 0 : return tai_from_utc(t, u) ; default : return 0 ; } } skalibs-2.9.1.0/src/libstddjb/tai_from_sysclock.c000066400000000000000000000005231355335115400217240ustar00rootroot00000000000000/* ISC license. */ #include #include #include #ifdef SKALIBS_FLAG_CLOCKISTAI int tai_from_sysclock (tai_t *t, uint64_t u) { return tai_u64(t, u + 10U) ; } #else #include int tai_from_sysclock (tai_t *t, uint64_t u) { return tai_from_utc(t, u) ; } #endif skalibs-2.9.1.0/src/libstddjb/tai_from_utc.c000066400000000000000000000003131355335115400206620ustar00rootroot00000000000000/* ISC license. */ #include #include #include "djbtime-internal.h" int tai_from_utc (tai_t *t, uint64_t u) { leapsecs_add(&u, 0) ; return tai_u64(t, u + 10) ; } skalibs-2.9.1.0/src/libstddjb/tai_now.c000066400000000000000000000003151355335115400176510ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include int tai_now (tai_t *t) { time_t u = time(0) ; if (u == (time_t)-1) return 0 ; return tai_from_time_sysclock(t, u) ; } skalibs-2.9.1.0/src/libstddjb/tai_pack.c000066400000000000000000000002311355335115400177610ustar00rootroot00000000000000/* ISC license. */ #include #include void tai_pack (char *s, tai_t const *t) { uint64_pack_big(s, tai_sec(t)) ; } skalibs-2.9.1.0/src/libstddjb/tai_pack_little.c000066400000000000000000000002341355335115400213410ustar00rootroot00000000000000/* ISC license. */ #include #include void tai_pack_little (char *s, tai_t const *t) { uint64_pack(s, tai_sec(t)) ; } skalibs-2.9.1.0/src/libstddjb/tai_sub.c000066400000000000000000000002151355335115400176360ustar00rootroot00000000000000/* ISC license. */ #include int tai_sub (tai_t *t, tai_t const *u, tai_t const *v) { t->x = u->x - v->x ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/tai_u64.c000066400000000000000000000003771355335115400174740ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int tai_u64 (tai_t *t, uint64_t u) { if (u & ((uint64_t)1 << 63)) return (errno = EOVERFLOW, 0) ; t->x = u ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/tai_unpack.c000066400000000000000000000002301355335115400203230ustar00rootroot00000000000000/* ISC license. */ #include #include void tai_unpack (char const *s, tai_t *t) { uint64_unpack_big(s, &t->x) ; } skalibs-2.9.1.0/src/libstddjb/tai_unpack_little.c000066400000000000000000000002331355335115400217030ustar00rootroot00000000000000/* ISC license. */ #include #include void tai_unpack_little (char const *s, tai_t *t) { uint64_unpack(s, &t->x) ; } skalibs-2.9.1.0/src/libstddjb/tain_add.c000066400000000000000000000004171355335115400177570ustar00rootroot00000000000000/* ISC license. */ #include int tain_add (tain_t *t, tain_t const *u, tain_t const *v) { t->sec.x = u->sec.x + v->sec.x ; t->nano = u->nano + v->nano ; if (t->nano > 999999999U) { t->sec.x++ ; t->nano -= 1000000000U ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/tain_addsec.c000066400000000000000000000005351355335115400204530ustar00rootroot00000000000000/* ISC license. */ #include #include int tain_addsec (tain_t *b, tain_t const *a, int c) { if (c >= 0) { tai_t t = { .x = (uint64_t)c } ; tai_add(&b->sec, &a->sec, &t) ; } else { tai_t t = { .x = (uint64_t)-c } ; tai_sub(&b->sec, &a->sec, &t) ; } b->nano = a->nano ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/tain_approx.c000066400000000000000000000002051355335115400205330ustar00rootroot00000000000000/* ISC license. */ #include double tain_approx (tain_t const *t) { return tai_approx(&t->sec) + tain_frac(t) ; } skalibs-2.9.1.0/src/libstddjb/tain_fmt.c000066400000000000000000000003241355335115400200120ustar00rootroot00000000000000/* ISC license. */ #include #include size_t tain_fmt (char *s, tain_t const *a) { char pack[TAIN_PACK] ; tain_pack(pack, a) ; return ucharn_fmt(s, pack, TAIN_PACK) ; } skalibs-2.9.1.0/src/libstddjb/tain_frac.c000066400000000000000000000001661355335115400201430ustar00rootroot00000000000000/* ISC license. */ #include double tain_frac (tain_t const *t) { return t->nano * 0.000000001 ; } skalibs-2.9.1.0/src/libstddjb/tain_from_localtmn.c000066400000000000000000000003341355335115400220610ustar00rootroot00000000000000/* ISC license. */ #include int tain_from_localtmn (tain_t *a, localtmn_t const *l) { tai_t t ; if (!tai_from_localtm(&t, &l->tm)) return 0 ; a->sec = t ; a->nano = l->nano ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/tain_from_millisecs.c000066400000000000000000000004031355335115400222310ustar00rootroot00000000000000/* ISC license. */ #include #include int tain_from_millisecs (tain_t *a, int millisecs) { if (millisecs < 0) return (errno = EINVAL, 0) ; a->sec.x = millisecs / 1000 ; a->nano = (millisecs % 1000) * 1000000U ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/tain_from_ntp.c000066400000000000000000000006521355335115400210540ustar00rootroot00000000000000/* ISC license. */ #include #include #include int tain_from_ntp (tain_t *a, uint64_t u) { tai_t secs = { .x = u >> 32 } ; if (secs.x <= 0x7FFFFFFFUL) secs.x |= ((uint64_t)1 << 32) ; secs.x += TAI_MAGIC ; secs.x -= NTP_OFFSET ; if (!tai_from_utc(&secs, secs.x)) return 0 ; a->sec = secs ; a->nano = ((u & 0xFFFFFFFFUL) * 1000000000) >> 32 ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/tain_from_sysclock.c000066400000000000000000000003011355335115400220740ustar00rootroot00000000000000/* ISC license. */ #include int tain_from_sysclock (tain_t *a, tain_t const *u) { if (!tai_from_sysclock(&a->sec, u->sec.x)) return 0 ; a->nano = u->nano ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/tain_from_timespec.c000066400000000000000000000003371355335115400220640ustar00rootroot00000000000000/* ISC license. */ #include #include int tain_from_timespec (tain_t *t, struct timespec const *ts) { if (!tai_from_time(&t->sec, ts->tv_sec)) return 0 ; t->nano = ts->tv_nsec ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/tain_from_timespec_sysclock.c000066400000000000000000000003611355335115400237730ustar00rootroot00000000000000/* ISC license. */ #include #include int tain_from_timespec_sysclock (tain_t *t, struct timespec const *ts) { if (!tai_from_time_sysclock(&t->sec, ts->tv_sec)) return 0 ; t->nano = ts->tv_nsec ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/tain_from_timeval.c000066400000000000000000000003501355335115400217070ustar00rootroot00000000000000/* ISC license. */ #include #include int tain_from_timeval (tain_t *t, struct timeval const *tv) { if (!tai_from_time(&t->sec, tv->tv_sec)) return 0 ; t->nano = 1000 * tv->tv_usec ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/tain_from_timeval_sysclock.c000066400000000000000000000003721355335115400236250ustar00rootroot00000000000000/* ISC license. */ #include #include int tain_from_timeval_sysclock (tain_t *t, struct timeval const *tv) { if (!tai_from_time_sysclock(&t->sec, tv->tv_sec)) return 0 ; t->nano = 1000 * tv->tv_usec ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/tain_half.c000066400000000000000000000003021355335115400201320ustar00rootroot00000000000000/* ISC license. */ #include void tain_half (tain_t *t, tain_t const *u) { t->nano = u->nano >> 1 ; if (u->sec.x & 1) t->nano += 500000000U ; t->sec.x = u->sec.x >> 1 ; } skalibs-2.9.1.0/src/libstddjb/tain_infinite_relative.c000066400000000000000000000001551355335115400227260ustar00rootroot00000000000000/* ISC license. */ #include tain_t const tain_infinite_relative = TAIN_INFINITE_RELATIVE ; skalibs-2.9.1.0/src/libstddjb/tain_less.c000066400000000000000000000003541355335115400201750ustar00rootroot00000000000000/* ISC license. */ #include int tain_less (tain_t const *t, tain_t const *u) { if (tai_sec(&t->sec) < tai_sec(&u->sec)) return 1 ; if (tai_sec(&t->sec) > tai_sec(&u->sec)) return 0 ; return t->nano < u->nano ; } skalibs-2.9.1.0/src/libstddjb/tain_nano500.c000066400000000000000000000001311355335115400204000ustar00rootroot00000000000000/* ISC license. */ #include tain_t const tain_nano500 = TAIN_NANO500 ; skalibs-2.9.1.0/src/libstddjb/tain_now.c000066400000000000000000000001731355335115400200310ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include tain_clockread_func_t_ref tain_now = &tain_wallclock_read ; skalibs-2.9.1.0/src/libstddjb/tain_now_set_stopwatch.c000066400000000000000000000014011355335115400227730ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include #if defined(SKALIBS_HASCLOCKRT) && (defined(SKALIBS_HASCLOCKMON) || defined(SKALIBS_HASCLOCKBOOT)) #include #ifdef SKALIBS_HASCLOCKMON # define SKALIBS_STOPWATCH CLOCK_MONOTONIC #else # define SKALIBS_STOPWATCH CLOCK_BOOTTIME #endif static tain_t offset ; static int tain_now_stopwatch (tain_t *now) { return tain_stopwatch_read(now, SKALIBS_STOPWATCH, &offset) ; } int tain_now_set_stopwatch (tain_t *now) { if (!tain_stopwatch_init(now, SKALIBS_STOPWATCH, &offset)) return tain_now_set_wallclock(now) ; tain_now = &tain_now_stopwatch ; return 1 ; } #else int tain_now_set_stopwatch (tain_t *now) { return tain_now_set_wallclock(now) ; } #endif skalibs-2.9.1.0/src/libstddjb/tain_now_set_wallclock.c000066400000000000000000000002641355335115400227400ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include int tain_now_set_wallclock (tain_t *now) { tain_now = &tain_wallclock_read ; return tain_wallclock_read(now) ; } skalibs-2.9.1.0/src/libstddjb/tain_pack.c000066400000000000000000000002631355335115400201440ustar00rootroot00000000000000/* ISC license. */ #include #include void tain_pack (char *s, tain_t const *t) { tai_pack(s, &t->sec) ; uint32_pack_big(s+8, t->nano) ; } skalibs-2.9.1.0/src/libstddjb/tain_pack_little.c000066400000000000000000000002751355335115400215240ustar00rootroot00000000000000/* ISC license. */ #include #include void tain_pack_little (char *s, tain_t const *t) { uint32_pack(s, t->nano) ; tai_pack_little(s+4, &t->sec) ; } skalibs-2.9.1.0/src/libstddjb/tain_relative_from_timespec.c000066400000000000000000000003421355335115400237530ustar00rootroot00000000000000/* ISC license. */ #include #include int tain_relative_from_timespec (tain_t *a, struct timespec const *ts) { tai_relative_from_time(&a->sec, ts->tv_sec) ; a->nano = ts->tv_nsec ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/tain_relative_from_timeval.c000066400000000000000000000003531355335115400236050ustar00rootroot00000000000000/* ISC license. */ #include #include int tain_relative_from_timeval (tain_t *a, struct timeval const *tv) { tai_relative_from_time(&a->sec, tv->tv_sec) ; a->nano = 1000 * tv->tv_usec ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/tain_scan.c000066400000000000000000000003601355335115400201500ustar00rootroot00000000000000/* ISC license. */ #include #include size_t tain_scan (char const *s, tain_t *a) { char pack[TAIN_PACK] ; size_t r = ucharn_scan(s, pack, TAIN_PACK) ; if (r) tain_unpack(pack, a) ; return r ; } skalibs-2.9.1.0/src/libstddjb/tain_setnow.c000066400000000000000000000003371355335115400205470ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include int tain_setnow (tain_t const *a) { tain_t aa ; if (!sysclock_from_tai(&aa.sec.x, &a->sec)) return 0 ; aa.nano = a->nano ; return sysclock_set(&aa) ; } skalibs-2.9.1.0/src/libstddjb/tain_stopwatch.c000066400000000000000000000020371355335115400212430ustar00rootroot00000000000000/* ISC license. */ #include #include #if defined(SKALIBS_HASCLOCKRT) && (defined(SKALIBS_HASCLOCKMON) || defined(SKALIBS_HASCLOCKBOOT)) #include int tain_stopwatch_init (tain_t *now, clock_t cl, tain_t *offset) { tain_t a, b ; struct timespec ts ; if (clock_gettime(cl, &ts) < 0) return 0 ; if (!tain_from_timespec(&b, &ts)) return 0 ; if (!tain_wallclock_read(&a)) return 0 ; tain_sub(offset, &a, &b) ; *now = a ; return 1 ; } int tain_stopwatch_read (tain_t *a, clock_t cl, tain_t const *offset) { struct timespec ts ; if (clock_gettime(cl, &ts) < 0) return 0 ; if (!tain_from_timespec(a, &ts)) return 0 ; tain_add(a, a, offset) ; return 1 ; } #else #include int tain_stopwatch_init (tain_t *now, clock_t cl, tain_t *offset) { (void)now ; (void)cl ; (void)offset ; return (errno = ENOSYS, 0) ; } int tain_stopwatch_read (tain_t *now, clock_t cl, tain_t const *offset) { (void)now ; (void)cl ; (void)offset ; return (errno = ENOSYS, 0) ; } #endif skalibs-2.9.1.0/src/libstddjb/tain_sub.c000066400000000000000000000004461355335115400200220ustar00rootroot00000000000000/* ISC license. */ #include int tain_sub (tain_t *t, tain_t const *u, tain_t const *v) { tain_t tt ; tt.sec.x = u->sec.x - v->sec.x ; tt.nano = u->nano - v->nano ; if (tt.nano > u->nano) { tt.sec.x-- ; tt.nano += 1000000000U ; } *t = tt ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/tain_to_millisecs.c000066400000000000000000000004561355335115400217200ustar00rootroot00000000000000/* ISC license. */ #include #include int tain_to_millisecs (tain_t const *a) { if (a->sec.x > (uint64_t)2147483) return -1 ; if ((a->sec.x == (uint64_t)2147483) && (a->nano > 646000000U)) return -1 ; return a->sec.x * 1000 + (a->nano + 999999) / 1000000U ; } skalibs-2.9.1.0/src/libstddjb/tain_ulong.c000066400000000000000000000002421355335115400203470ustar00rootroot00000000000000/* ISC license. */ #include int tain_ulong (tain_t *t, unsigned long s) { if (!tai_u64(&t->sec, s)) return 0 ; t->nano = 0 ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/tain_unpack.c000066400000000000000000000002721355335115400205070ustar00rootroot00000000000000/* ISC license. */ #include #include void tain_unpack (char const *s, tain_t *t) { tai_unpack(s, &t->sec) ; uint32_unpack_big(s+8, &t->nano) ; } skalibs-2.9.1.0/src/libstddjb/tain_unpack_little.c000066400000000000000000000003041355335115400220600ustar00rootroot00000000000000/* ISC license. */ #include #include void tain_unpack_little (char const *s, tain_t *t) { uint32_unpack(s, &t->nano) ; tai_unpack_little(s+4, &t->sec) ; } skalibs-2.9.1.0/src/libstddjb/tain_wallclock_read.c000066400000000000000000000002571355335115400221770ustar00rootroot00000000000000/* ISC license. */ #include int tain_wallclock_read (tain_t *a) { tain_t aa ; if (!sysclock_get(&aa)) return 0 ; return tain_from_sysclock(a, &aa) ; } skalibs-2.9.1.0/src/libstddjb/tain_zero.c000066400000000000000000000001231355335115400202000ustar00rootroot00000000000000/* ISC license. */ #include tain_t const tain_zero = TAIN_ZERO ; skalibs-2.9.1.0/src/libstddjb/time_from_tai.c000066400000000000000000000006331355335115400210320ustar00rootroot00000000000000 /* ISC license. */ #include #include #include #include #include #include int time_from_tai (time_t *u, tai_t const *t) { uint64_t uu = t->x - TAI_MAGIC ; #if SKALIBS_SIZEOFTIME < 8 if ((uu >> 32) && (uu >> 32) != 0xffffffffUL) return (errno = EOVERFLOW, 0) ; #endif *u = (time_t)uu ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/time_from_tai_relative.c000066400000000000000000000005531355335115400227260ustar00rootroot00000000000000 /* ISC license. */ #include #include #include #include #include int time_from_tai_relative (time_t *u, tai_t const *t) { #if SKALIBS_SIZEOFTIME < 8 if ((t->x >> 32) && (t->x >> 32) != 0xffffffffUL) return (errno = EOVERFLOW, 0) ; #endif *u = (time_t)t->x ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/time_sysclock_from_tai.c000066400000000000000000000007211355335115400227420ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include int time_sysclock_from_tai (time_t *u, tai_t const *t) { uint64_t uu ; if (!sysclock_from_tai(&uu, t)) return 0 ; uu -= TAI_MAGIC ; #if SKALIBS_SIZEOFTIME < 8 if ((uu >> 32) && (uu >> 32) != 0xffffffffUL) return (errno = EOVERFLOW, 0) ; #endif *u = (time_t)uu ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/timespec_from_tain.c000066400000000000000000000003401355335115400220560ustar00rootroot00000000000000/* ISC license. */ #include #include int timespec_from_tain (struct timespec *ts, tain_t const *t) { if (!time_from_tai(&ts->tv_sec, &t->sec)) return 0 ; ts->tv_nsec = t->nano ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/timespec_from_tain_relative.c000066400000000000000000000003621355335115400237550ustar00rootroot00000000000000/* ISC license. */ #include #include int timespec_from_tain_relative (struct timespec *ts, tain_t const *t) { if (!time_from_tai_relative(&ts->tv_sec, &t->sec)) return 0 ; ts->tv_nsec = t->nano ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/timespec_sysclock_from_tain.c000066400000000000000000000003621355335115400237740ustar00rootroot00000000000000/* ISC license. */ #include #include int timespec_sysclock_from_tain (struct timespec *ts, tain_t const *t) { if (!time_sysclock_from_tai(&ts->tv_sec, &t->sec)) return 0 ; ts->tv_nsec = t->nano ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/timestamp.c000066400000000000000000000001711355335115400202140ustar00rootroot00000000000000/* ISC license. */ #include int timestamp (char *s) { tain_t now ; return timestamp_r(s, &now) ; } skalibs-2.9.1.0/src/libstddjb/timestamp_fmt.c000066400000000000000000000002171355335115400210630ustar00rootroot00000000000000/* ISC license. */ #include size_t timestamp_fmt (char *s, tain_t const *a) { *s = '@' ; return 1 + tain_fmt(s+1, a) ; } skalibs-2.9.1.0/src/libstddjb/timestamp_r.c000066400000000000000000000002621355335115400205360ustar00rootroot00000000000000/* ISC license. */ #include int timestamp_r (char *s, tain_t *stamp) { if (!tain_wallclock_read(stamp)) return 0 ; timestamp_fmt(s, stamp) ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/timestamp_scan.c000066400000000000000000000002751355335115400212250ustar00rootroot00000000000000/* ISC license. */ #include size_t timestamp_scan (char const *s, tain_t *a) { size_t r ; if (*s != '@') return 0 ; r = tain_scan(s+1, a) ; return r ? r+1 : 0 ; } skalibs-2.9.1.0/src/libstddjb/timeval_from_tain.c000066400000000000000000000003611355335115400217110ustar00rootroot00000000000000/* ISC license. */ #include #include int timeval_from_tain (struct timeval *tv, tain_t const *t) { if (!time_from_tai(&tv->tv_sec, &t->sec)) return 0 ; tv->tv_usec = (t->nano + 500) / 1000 ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/timeval_from_tain_relative.c000066400000000000000000000004031355335115400236010ustar00rootroot00000000000000/* ISC license. */ #include #include int timeval_from_tain_relative (struct timeval *tv, tain_t const *t) { if (!time_from_tai_relative(&tv->tv_sec, &t->sec)) return 0 ; tv->tv_usec = (t->nano + 500) / 1000 ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/timeval_sysclock_from_tain.c000066400000000000000000000004031355335115400236200ustar00rootroot00000000000000/* ISC license. */ #include #include int timeval_sysclock_from_tain (struct timeval *tv, tain_t const *t) { if (!time_sysclock_from_tai(&tv->tv_sec, &t->sec)) return 0 ; tv->tv_usec = (t->nano + 500) / 1000 ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/ucharn_findlen.c000066400000000000000000000002471355335115400211740ustar00rootroot00000000000000/* ISC license. */ #include size_t ucharn_findlen (char const *s) { size_t i = 0 ; while (fmtscan_num(s[i], 16) <= 0xF) i++ ; return i ; } skalibs-2.9.1.0/src/libstddjb/ucharn_fmt.c000066400000000000000000000004431355335115400203410ustar00rootroot00000000000000/* ISC license. */ #include size_t ucharn_fmt (char *s, char const *key, size_t n) { size_t i = 0 ; for (; i < n ; i++) { s[i<<1] = fmtscan_asc((unsigned char)key[i] >> 4) ; s[(i<<1)+1] = fmtscan_asc((unsigned char)key[i] & 0xF) ; } return n << 1 ; } skalibs-2.9.1.0/src/libstddjb/ucharn_fmt_little.c000066400000000000000000000004521355335115400217160ustar00rootroot00000000000000/* ISC license. */ #include size_t ucharn_fmt_little (char *s, char const *key, size_t n) { size_t i = 0 ; for (; i < n ; i++) { s[i<<1] = fmtscan_asc((unsigned char)key[i] & 0xF) ; s[(i<<1)+1] = fmtscan_asc((unsigned char)key[i] >> 4) ; } return n << 1 ; } skalibs-2.9.1.0/src/libstddjb/ucharn_scan.c000066400000000000000000000005431355335115400205000ustar00rootroot00000000000000/* ISC license. */ #include size_t ucharn_scan (char const *s, char *key, size_t n) { size_t i = 0 ; for (; i < n ; i++) { unsigned char c = fmtscan_num(s[2*i], 16) ; if (c > 0xF) return 0 ; key[i] = c << 4 ; c = fmtscan_num(s[2*i+1], 16) ; if (c > 0xF) return 0 ; key[i] += c ; } return n << 1 ; } skalibs-2.9.1.0/src/libstddjb/ucharn_scan_little.c000066400000000000000000000005561355335115400220610ustar00rootroot00000000000000/* ISC license. */ #include size_t ucharn_scan_little (char const *s, char *key, size_t n) { size_t i = 0 ; for (; i < n ; i++) { unsigned char c = fmtscan_num(s[(i<<1)+1], 16) ; if (c > 0xF) return 0 ; key[i] = c << 4 ; c = fmtscan_num(s[i<<1], 16) ; if (c > 0xF) return 0 ; key[i] += c ; } return n << 1 ; } skalibs-2.9.1.0/src/libstddjb/ucspi_get.c000066400000000000000000000006721355335115400202010ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include char const *ucspi_get (char const *s) { char const *x = getenv("PROTO") ; if (x) { size_t len = strlen(s) ; size_t xlen = strlen(x) ; char tmp[len + xlen + 1] ; memcpy(tmp, x, xlen) ; memcpy(tmp + xlen, s, len + 1) ; x = getenv(tmp) ; if (!x) errno = ENOENT ; } else errno = EINVAL ; return x ; } skalibs-2.9.1.0/src/libstddjb/uint160_scan.c000066400000000000000000000001321355335115400204200ustar00rootroot00000000000000/* ISC license. */ #include #include "fmtscan-internal.h" SCANB0(16) skalibs-2.9.1.0/src/libstddjb/uint16_bswap.c000066400000000000000000000002371355335115400205360ustar00rootroot00000000000000/* ISC license. */ #include #include uint16_t uint16_bswap (uint16_t a) { return (a & 0x00ffu) << 8 | (a & 0xff00u) >> 8 ; } skalibs-2.9.1.0/src/libstddjb/uint16_fmtlist.c000066400000000000000000000001301355335115400210740ustar00rootroot00000000000000/* ISC license. */ #include #include "fmtscan-internal.h" FMTL(16) skalibs-2.9.1.0/src/libstddjb/uint16_pack.c000066400000000000000000000003011355335115400203300ustar00rootroot00000000000000/* ISC license. */ #include #include #include void uint16_pack (char *s, uint16_t u) { u = uint16_little(u) ; memcpy(s, &u, sizeof(uint16_t)) ; } skalibs-2.9.1.0/src/libstddjb/uint16_pack_big.c000066400000000000000000000003021355335115400211520ustar00rootroot00000000000000/* ISC license. */ #include #include #include void uint16_pack_big (char *s, uint16_t u) { u = uint16_big(u) ; memcpy(s, &u, sizeof(uint16_t)) ; } skalibs-2.9.1.0/src/libstddjb/uint16_reverse.c000066400000000000000000000003111355335115400210660ustar00rootroot00000000000000/* ISC license. */ #include #include void uint16_reverse (char *s, size_t n) { while (n--) { char c = s[0] ; s[0] = s[1] ; s[1] = c ; s += 2 ; } } skalibs-2.9.1.0/src/libstddjb/uint16_scan.c000066400000000000000000000004601355335115400203440ustar00rootroot00000000000000/* ISC license. */ #include #include #include "fmtscan-internal.h" size_t uint16_scan_base (char const *s, uint16_t *u, uint8_t base) { uint64_t uu ; size_t pos = uint64_scan_base_max(s, &uu, base, UINT16_MAX) ; if (pos) *u = (uint16_t)uu ; return pos ; } skalibs-2.9.1.0/src/libstddjb/uint16_scanlist.c000066400000000000000000000001311355335115400212330ustar00rootroot00000000000000/* ISC license. */ #include "fmtscan-internal.h" #include SCANL(16) skalibs-2.9.1.0/src/libstddjb/uint16_unpack.c000066400000000000000000000003321355335115400206770ustar00rootroot00000000000000/* ISC license. */ #include #include #include void uint16_unpack (char const *s, uint16_t *u) { uint16_t x ; memcpy(&x, s, sizeof(uint16_t)) ; *u = uint16_little(x) ; } skalibs-2.9.1.0/src/libstddjb/uint16_unpack_big.c000066400000000000000000000003331355335115400215210ustar00rootroot00000000000000/* ISC license. */ #include #include #include void uint16_unpack_big (char const *s, uint16_t *u) { uint16_t x ; memcpy(&x, s, sizeof(uint16_t)) ; *u = uint16_big(x) ; } skalibs-2.9.1.0/src/libstddjb/uint320_scan.c000066400000000000000000000001321355335115400204160ustar00rootroot00000000000000/* ISC license. */ #include #include "fmtscan-internal.h" SCANB0(32) skalibs-2.9.1.0/src/libstddjb/uint32_bswap.c000066400000000000000000000003471355335115400205360ustar00rootroot00000000000000/* ISC license. */ #include #include uint32_t uint32_bswap (uint32_t a) { return (a & 0x000000ffu) << 24 | (a & 0x0000ff00u) << 8 | (a & 0x00ff0000u) >> 8 | (a & 0xff000000u) >> 24 ; } skalibs-2.9.1.0/src/libstddjb/uint32_fmtlist.c000066400000000000000000000001301355335115400210720ustar00rootroot00000000000000/* ISC license. */ #include #include "fmtscan-internal.h" FMTL(32) skalibs-2.9.1.0/src/libstddjb/uint32_pack.c000066400000000000000000000003011355335115400203260ustar00rootroot00000000000000/* ISC license. */ #include #include #include void uint32_pack (char *s, uint32_t u) { u = uint32_little(u) ; memcpy(s, &u, sizeof(uint32_t)) ; } skalibs-2.9.1.0/src/libstddjb/uint32_pack_big.c000066400000000000000000000003021355335115400211500ustar00rootroot00000000000000/* ISC license. */ #include #include #include void uint32_pack_big (char *s, uint32_t u) { u = uint32_big(u) ; memcpy(s, &u, sizeof(uint32_t)) ; } skalibs-2.9.1.0/src/libstddjb/uint32_reverse.c000066400000000000000000000004561355335115400210760ustar00rootroot00000000000000/* ISC license. */ #include #include #include void uint32_reverse (char *s, size_t n) { while (n--) { uint32_t x ; memcpy(&x, s, sizeof(uint32_t)) ; x = uint32_bswap(x) ; memcpy(s, &x, sizeof(uint32_t)) ; s += sizeof(uint32_t) ; } } skalibs-2.9.1.0/src/libstddjb/uint32_scan.c000066400000000000000000000004601355335115400203420ustar00rootroot00000000000000/* ISC license. */ #include #include #include "fmtscan-internal.h" size_t uint32_scan_base (char const *s, uint32_t *u, uint8_t base) { uint64_t uu ; size_t pos = uint64_scan_base_max(s, &uu, base, UINT32_MAX) ; if (pos) *u = (uint32_t)uu ; return pos ; } skalibs-2.9.1.0/src/libstddjb/uint32_scanlist.c000066400000000000000000000001311355335115400212310ustar00rootroot00000000000000/* ISC license. */ #include "fmtscan-internal.h" #include SCANL(32) skalibs-2.9.1.0/src/libstddjb/uint32_unpack.c000066400000000000000000000003321355335115400206750ustar00rootroot00000000000000/* ISC license. */ #include #include #include void uint32_unpack (char const *s, uint32_t *u) { uint32_t x ; memcpy(&x, s, sizeof(uint32_t)) ; *u = uint32_little(x) ; } skalibs-2.9.1.0/src/libstddjb/uint32_unpack_big.c000066400000000000000000000003331355335115400215170ustar00rootroot00000000000000/* ISC license. */ #include #include #include void uint32_unpack_big (char const *s, uint32_t *u) { uint32_t x ; memcpy(&x, s, sizeof(uint32_t)) ; *u = uint32_big(x) ; } skalibs-2.9.1.0/src/libstddjb/uint640_fmt_generic.c000066400000000000000000000006051355335115400217660ustar00rootroot00000000000000/* ISC license. */ #include #include #include size_t uint640_fmt_generic (char *s, uint64_t x, size_t n, uint8_t base) { size_t len = uint64_fmt_generic(0, x, base) ; if (s) { if (len < n) { memset(s, '0', n - len) ; s += n - len ; } uint64_fmt_generic(s, x, base) ; } return len > n ? len : n ; } skalibs-2.9.1.0/src/libstddjb/uint640_scan.c000066400000000000000000000001321355335115400204230ustar00rootroot00000000000000/* ISC license. */ #include #include "fmtscan-internal.h" SCANB0(64) skalibs-2.9.1.0/src/libstddjb/uint640_scan_base_max.c000066400000000000000000000006051355335115400222670ustar00rootroot00000000000000/* ISC license. */ #include #include #include size_t uint640_scan_base_max (char const *s, uint64_t *u, uint8_t base, uint64_t max) { size_t pos = uint640_scan_base_max(s, u, base, max) ; if (!pos) return (errno = EINVAL, 0) ; if (!s[pos]) return pos ; errno = fmtscan_num(s[pos], base) < base ? ERANGE : EINVAL ; return 0 ; } skalibs-2.9.1.0/src/libstddjb/uint64_bswap.c000066400000000000000000000006271355335115400205440ustar00rootroot00000000000000/* ISC license. */ #include uint64_t uint64_bswap (uint64_t a) { return (a & 0x00000000000000ffull) << 56 | (a & 0x000000000000ff00ull) << 40 | (a & 0x0000000000ff0000ull) << 24 | (a & 0x00000000ff000000ull) << 8 | (a & 0x000000ff00000000ull) >> 8 | (a & 0x0000ff0000000000ull) >> 24 | (a & 0x00ff000000000000ull) >> 40 | (a & 0xff00000000000000ull) >> 56 ; } skalibs-2.9.1.0/src/libstddjb/uint64_fmt_generic.c000066400000000000000000000005231355335115400217050ustar00rootroot00000000000000/* ISC license. */ #include #include size_t uint64_fmt_generic (char *s, uint64_t x, uint8_t base) { size_t len = 1 ; uint64_t q = x ; while (q >= base) { len++ ; q /= base ; } if (s) { s += len ; do { *--s = fmtscan_asc(x % base) ; x /= base ; } while (x) ; } return len ; } skalibs-2.9.1.0/src/libstddjb/uint64_fmtlist.c000066400000000000000000000001301355335115400210770ustar00rootroot00000000000000/* ISC license. */ #include #include "fmtscan-internal.h" FMTL(64) skalibs-2.9.1.0/src/libstddjb/uint64_fmtlist_generic.c000066400000000000000000000006051355335115400226020ustar00rootroot00000000000000/* ISC license. */ #include size_t uint64_fmtlist_generic (char *s, void const *tab, size_t n, uint8_t base, uint64_t (*get)(void const *, size_t)) { size_t i = 0, len = 0 ; for (; i < n ; i++) { size_t w = uint64_fmt_generic(s, (*get)(tab, i), base) ; len += w ; if (s) s += w ; if (i < n-1) { len++ ; if (s) *s++ = ',' ; } } return len ; } skalibs-2.9.1.0/src/libstddjb/uint64_pack.c000066400000000000000000000002551355335115400203430ustar00rootroot00000000000000/* ISC license. */ #include #include void uint64_pack (char *s, uint64_t u) { u = uint64_little(u) ; memcpy(s, &u, sizeof(uint64_t)) ; } skalibs-2.9.1.0/src/libstddjb/uint64_pack_big.c000066400000000000000000000002561355335115400211650ustar00rootroot00000000000000/* ISC license. */ #include #include void uint64_pack_big (char *s, uint64_t u) { u = uint64_big(u) ; memcpy(s, &u, sizeof(uint64_t)) ; } skalibs-2.9.1.0/src/libstddjb/uint64_reverse.c000066400000000000000000000004321355335115400210750ustar00rootroot00000000000000/* ISC license. */ #include #include void uint64_reverse (char *s, size_t n) { while (n--) { uint64_t x ; memcpy(&x, s, sizeof(uint64_t)) ; x = uint64_bswap(x) ; memcpy(s, &x, sizeof(uint64_t)) ; s += sizeof(uint64_t) ; } } skalibs-2.9.1.0/src/libstddjb/uint64_scan.c000066400000000000000000000003161355335115400203470ustar00rootroot00000000000000/* ISC license. */ #include #include "fmtscan-internal.h" size_t uint64_scan_base (char const *s, uint64_t *u, uint8_t base) { return uint64_scan_base_max(s, u, base, UINT64_MAX) ; } skalibs-2.9.1.0/src/libstddjb/uint64_scan_base_max.c000066400000000000000000000006321355335115400222070ustar00rootroot00000000000000/* ISC license. */ #include #include size_t uint64_scan_base_max (char const *s, uint64_t *u, uint8_t base, uint64_t max) { uint64_t result = 0 ; size_t pos = 0 ; for (;; pos++) { uint8_t c = fmtscan_num(s[pos], base) ; if (c >= base || result > ((max - c) / base)) break ; result = result * base + c ; } if (pos) *u = result ; return pos ; } skalibs-2.9.1.0/src/libstddjb/uint64_scanlist.c000066400000000000000000000001311355335115400212360ustar00rootroot00000000000000/* ISC license. */ #include "fmtscan-internal.h" #include SCANL(64) skalibs-2.9.1.0/src/libstddjb/uint64_unpack.c000066400000000000000000000003061355335115400207030ustar00rootroot00000000000000/* ISC license. */ #include #include void uint64_unpack (char const *s, uint64_t *u) { uint64_t x ; memcpy(&x, s, sizeof(uint64_t)) ; *u = uint64_little(x) ; } skalibs-2.9.1.0/src/libstddjb/uint64_unpack_big.c000066400000000000000000000003071355335115400215250ustar00rootroot00000000000000/* ISC license. */ #include #include void uint64_unpack_big (char const *s, uint64_t *u) { uint64_t x ; memcpy(&x, s, sizeof(uint64_t)) ; *u = uint64_big(x) ; } skalibs-2.9.1.0/src/libstddjb/uncoe.c000066400000000000000000000003221355335115400173200ustar00rootroot00000000000000/* ISC license. */ #include #include int uncoe (int fd) { int flags = fcntl(fd, F_GETFD, 0) ; if (flags < 0) return -1 ; return fcntl(fd, F_SETFD, flags & ~FD_CLOEXEC) ; } skalibs-2.9.1.0/src/libstddjb/unsanitize_read.c000066400000000000000000000003651355335115400214020ustar00rootroot00000000000000/* ISC license. */ #include #include #include ssize_t unsanitize_read (ssize_t r) { return r == -1 ? errno == EPIPE ? (errno = 0, 0) : -1 : !r ? (errno = EWOULDBLOCK, -1) : r ; } skalibs-2.9.1.0/src/libstddjb/utc_from_localtm.c000066400000000000000000000003551355335115400215460ustar00rootroot00000000000000/* ISC license. */ #include #include #include int utc_from_localtm (uint64_t *uu, struct tm const *l) { if (!ltm64_from_localtm(uu, l)) return 0 ; utc_from_ltm64(uu) ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/utc_from_ltm64.c000066400000000000000000000003641355335115400210610ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include "djbtime-internal.h" int utc_from_ltm64 (uint64_t *u) { #ifdef SKALIBS_FLAG_CLOCKISTAI leapsecs_sub(u) ; #endif return 1 ; } skalibs-2.9.1.0/src/libstddjb/utc_from_sysclock.c000066400000000000000000000005341355335115400217440ustar00rootroot00000000000000/* ISC license. */ #include #include #include #ifdef SKALIBS_FLAG_CLOCKISTAI #include int utc_from_sysclock (uint64_t *u) { tai_t t = { .x = *u + 10U } ; return utc_from_tai(u, &t) ; } #else int utc_from_sysclock (uint64_t *u) { (void)u ; return 1 ; } #endif skalibs-2.9.1.0/src/libstddjb/utc_from_tai.c000066400000000000000000000004431355335115400206660ustar00rootroot00000000000000/* ISC license. */ #include #include #include "djbtime-internal.h" int utc_from_tai (uint64_t *u, tai_t const *t) { int r = 1 ; uint64_t tt = t->x - 10 ; if (t->x < 10U) return (errno = EINVAL, 0) ; r += leapsecs_sub(&tt) ; *u = tt ; return r ; } skalibs-2.9.1.0/src/libstddjb/vbaprintf.c000066400000000000000000000010101355335115400201750ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int vbaprintf (bufalloc *ba, char const *format, va_list args) { int r ; { va_list ugly ; va_copy(ugly, args) ; r = vsnprintf(0, 0, format, ugly) ; va_end(ugly) ; } if (r < 0) return r ; if (!stralloc_readyplus(&ba->x, r + 1)) return -1 ; r = vsnprintf(ba->x.s + ba->x.len, r + 1, format, args) ; if (r > 0) ba->x.len += r ; return r ; } skalibs-2.9.1.0/src/libstddjb/vbprintf.c000066400000000000000000000007471355335115400200540ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int vbprintf (buffer *b, char const *format, va_list args) { int r ; { va_list ugly ; va_copy(ugly, args) ; r = vsnprintf(0, 0, format, ugly) ; va_end(ugly) ; } if (r < 0) return r ; { char buf[r+1] ; r = vsnprintf(buf, r + 1, format, args) ; if (r < 0) return r ; if (buffer_put(b, buf, r) < r) return -1 ; } return r ; } skalibs-2.9.1.0/src/libstddjb/wait_nointr.c000066400000000000000000000003431355335115400205470ustar00rootroot00000000000000/* ISC license. */ #include #include #include pid_t wait_nointr (int *wstat) { pid_t r ; do r = wait(wstat) ; while ((r == (pid_t)-1) && (errno == EINTR)) ; return r ; } skalibs-2.9.1.0/src/libstddjb/wait_pid_nohang.c000066400000000000000000000004241355335115400213440ustar00rootroot00000000000000/* ISC license. */ #include #include pid_t wait_pid_nohang (pid_t pid, int *wstat) { int w = 0 ; pid_t r = 0 ; while (r != pid) { r = wait_nohang(&w) ; if (!r || (r == (pid_t)-1)) return r ; } *wstat = w ; return r ; } skalibs-2.9.1.0/src/libstddjb/wait_pids_nohang.c000066400000000000000000000006541355335115400215340ustar00rootroot00000000000000/* ISC license. */ #include #include int wait_pids_nohang (pid_t const *pids, unsigned int len, int *wstat) { for (;;) { int w ; pid_t r = wait_nohang(&w) ; if (!r || (r == (pid_t)-1)) return (int)r ; { unsigned int i = 0 ; for (; i < len ; i++) if (r == pids[i]) break ; if (i < len) { *wstat = w ; return 1+i ; } } } } skalibs-2.9.1.0/src/libstddjb/wait_reap.c000066400000000000000000000002521355335115400201640ustar00rootroot00000000000000/* ISC license. */ #include unsigned int wait_reap () { unsigned int n = 0 ; int wstat ; while (wait_nohang(&wstat) > 0) n++ ; return n ; } skalibs-2.9.1.0/src/libstddjb/waitn.c000066400000000000000000000005311355335115400173330ustar00rootroot00000000000000/* ISC license. */ #include #include int waitn (pid_t *pids, unsigned int n) { while (n) { int wstat ; unsigned int i = 0 ; pid_t pid = wait_nointr(&wstat) ; if (pid < 0) return 0 ; for (; i < n ; i++) if (pid == pids[i]) break ; if (i < n) pids[i] = pids[--n] ; } return 1 ; } skalibs-2.9.1.0/src/libstddjb/waitn_reap.c000066400000000000000000000005121355335115400203410ustar00rootroot00000000000000/* ISC license. */ #include #include int waitn_reap (pid_t *pids, unsigned int len) { unsigned int n = 0 ; while (len) { int w ; int r = wait_pids_nohang(pids, len, &w) ; if (r < 0) return r ; else if (!r) break ; pids[r-1] = pids[--len] ; n++ ; } return n ; } skalibs-2.9.1.0/src/libstddjb/waitpid_nointr.c000066400000000000000000000004071355335115400212450ustar00rootroot00000000000000/* ISC license. */ #include #include #include pid_t waitpid_nointr (pid_t pid, int *wstat, int flags) { pid_t r ; do r = waitpid(pid, wstat, flags) ; while ((r == (pid_t)-1) && (errno == EINTR)) ; return r ; } skalibs-2.9.1.0/src/libstddjb/writenclose_unsafe.c000066400000000000000000000007751355335115400221220ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int writenclose_unsafe_internal (int fd, char const *s, size_t len, dev_t *dev, ino_t *ino, int dosync) { struct stat st ; if (allwrite(fd, s, len) < len) return 0 ; if ((dev || ino) && (fstat(fd, &st) < 0)) return 0 ; if (dosync && (fd_sync(fd) < 0) && (errno != EINVAL)) return 0 ; fd_close(fd) ; if (dev) *dev = st.st_dev ; if (ino) *ino = st.st_ino ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/writevnclose_unsafe.c000066400000000000000000000011201355335115400222710ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include int writevnclose_unsafe_internal (int fd, struct iovec const *v, unsigned int vlen, dev_t *dev, ino_t *ino, int dosync) { struct stat st ; if (allwritev(fd, v, vlen) < siovec_len(v, vlen)) return 0 ; if ((dev || ino) && (fstat(fd, &st) < 0)) return 0 ; if (dosync && (fd_sync(fd) < 0) && (errno != EINVAL)) return 0 ; fd_close(fd) ; if (dev) *dev = st.st_dev ; if (ino) *ino = st.st_ino ; return 1 ; } skalibs-2.9.1.0/src/libstddjb/xexecvep.c000066400000000000000000000005031355335115400200370ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include void xexecvep (char const *file, char const *const *argv, char const *const *envp, char const *path) { execvep(file, argv, envp, path) ; strerr_dieexec(errno == ENOENT ? 127 : 126, file) ; } skalibs-2.9.1.0/src/libstddjb/xpathexec.c000066400000000000000000000003341355335115400202030ustar00rootroot00000000000000/* ISC license. */ #include #include #include void xpathexec (char const *const *argv) { pathexec(argv) ; strerr_dieexec(errno == ENOENT ? 127 : 126, argv[0]) ; } skalibs-2.9.1.0/src/libstddjb/xpathexec0.c000066400000000000000000000003361355335115400202650ustar00rootroot00000000000000/* ISC license. */ #include #include #include void xpathexec0 (char const *const *argv) { pathexec0(argv) ; strerr_dieexec(errno == ENOENT ? 127 : 126, argv[0]) ; } skalibs-2.9.1.0/src/libstddjb/xpathexec0_run.c000066400000000000000000000004051355335115400211460ustar00rootroot00000000000000/* ISC license. */ #include #include #include void xpathexec0_run (char const *const *argv, char const *const *envp) { pathexec0_run(argv, envp) ; strerr_dieexec(errno == ENOENT ? 127 : 126, argv[0]) ; } skalibs-2.9.1.0/src/libstddjb/xpathexec_fromenv.c000066400000000000000000000004421355335115400217370ustar00rootroot00000000000000/* ISC license. */ #include #include #include void xpathexec_fromenv (char const *const *argv, char const *const *envp, size_t envlen) { pathexec_fromenv(argv, envp, envlen) ; strerr_dieexec(errno == ENOENT ? 127 : 126, argv[0]) ; } skalibs-2.9.1.0/src/libstddjb/xpathexec_r.c000066400000000000000000000005151355335115400205250ustar00rootroot00000000000000/* ISC license. */ #include #include #include void xpathexec_r (char const *const *argv, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) { pathexec_r(argv, envp, envlen, modifs, modiflen) ; strerr_dieexec(errno == ENOENT ? 127 : 126, argv[0]) ; } skalibs-2.9.1.0/src/libstddjb/xpathexec_r_name.c000066400000000000000000000005541355335115400215300ustar00rootroot00000000000000/* ISC license. */ #include #include #include void xpathexec_r_name (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) { pathexec_r_name(file, argv, envp, envlen, modifs, modiflen) ; strerr_dieexec(errno == ENOENT ? 127 : 126, file) ; } skalibs-2.9.1.0/src/libstddjb/xpathexec_run.c000066400000000000000000000004301355335115400210640ustar00rootroot00000000000000/* ISC license. */ #include #include #include void xpathexec_run (char const *file, char const *const *argv, char const *const *envp) { pathexec_run(file, argv, envp) ; strerr_dieexec(errno == ENOENT ? 127 : 126, file) ; } skalibs-2.9.1.0/src/libunixonacid/000077500000000000000000000000001355335115400167355ustar00rootroot00000000000000skalibs-2.9.1.0/src/libunixonacid/access_at.c000066400000000000000000000020001355335115400210160ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASLINKAT #ifndef _ATFILE_SOURCE #define _ATFILE_SOURCE #endif #include #include #include #include int access_at (int dirfd, char const *file, int amode, unsigned int flag) { return faccessat(dirfd, file, amode, flag ? AT_EACCESS : 0) ; } #else #include #include #include #include int access_at (int dirfd, char const *file, int amode, unsigned int flag) { int fdhere ; if (getuid() != geteuid() || getgid() != getegid()) return (errno = ENOSYS, -1) ; (void)flag ; fdhere = open_read(".") ; if (fdhere < 0) return -1 ; if (fd_chdir(dirfd) < 0) { fd_close(fdhere) ; return -1 ; } if (access(file, amode) < 0) { int e = errno ; fd_chdir(fdhere) ; fd_close(fdhere) ; return (errno = e, -1) ; } fd_chdir(fdhere) ; fd_close(fdhere) ; return 0 ; } #endif skalibs-2.9.1.0/src/libunixonacid/atomic_rm_rf.c000066400000000000000000000002641355335115400215440ustar00rootroot00000000000000/* ISC license. */ #include #include int atomic_rm_rf (char const *filename) { return atomic_rm_rf_tmp(filename, &satmp) ; } skalibs-2.9.1.0/src/libunixonacid/atomic_rm_rf_tmp.c000066400000000000000000000014411355335115400224220ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include int atomic_rm_rf_tmp (char const *filename, stralloc *tmp) { size_t tmpbase = tmp->len ; size_t start ; if (!stralloc_cats(tmp, ".skalibs-rmrf-") || !stralloc_cats(tmp, filename)) return -1 ; start = tmp->len ; for (;;) { if (!random_sauniquename(tmp, 64)) goto err ; if (!stralloc_0(tmp)) goto err ; if (!rename(filename, tmp->s + tmpbase)) break ; if (errno != EEXIST && errno != ENOTEMPTY) goto err ; tmp->len = start ; } if (rm_rf_in_tmp(tmp, tmpbase) < 0) goto err ; tmp->len = tmpbase ; return 0 ; err: tmp->len = tmpbase ; return -1 ; } skalibs-2.9.1.0/src/libunixonacid/atomic_symlink.c000066400000000000000000000016071355335115400221270ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include int atomic_symlink (char const *target, char const *name, char const *suffix) { { int e = errno ; if (symlink(target, name) == 0) return 1 ; if (errno != EEXIST) return 0 ; errno = e ; } { size_t namelen = strlen(name) ; size_t suffixlen = suffix ? strlen(suffix) + 1 : 0 ; char tmp[namelen + suffixlen + 8] ; memcpy(tmp, name, namelen) ; if (suffix) { tmp[namelen] = ':' ; memcpy(tmp + namelen + 1, suffix, suffixlen - 1) ; } memcpy(tmp + namelen + suffixlen, ":XXXXXX", 7) ; tmp[namelen + suffixlen + 7] = 0 ; if (mkltemp(target, tmp) == -1) return 0 ; if (rename(tmp, name) < 0) { unlink_void(tmp) ; return 0 ; } } return 1 ; } skalibs-2.9.1.0/src/libunixonacid/bufalloc_timed_flush.c000066400000000000000000000006521355335115400232560ustar00rootroot00000000000000/* ISC license. */ #include #include #include static int bufalloc_isnonempty (bufalloc *ba) { return !!bufalloc_len(ba) ; } int bufalloc_timed_flush (bufalloc *ba, tain_t const *deadline, tain_t *stamp) { return timed_flush(ba, (initfunc_t_ref)&bufalloc_getfd, (initfunc_t_ref)&bufalloc_isnonempty, (initfunc_t_ref)&bufalloc_flush, deadline, stamp) ; } skalibs-2.9.1.0/src/libunixonacid/buffer_timed_fill.c000066400000000000000000000006151355335115400225440ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include static ssize_t get (buffer *b) { return sanitize_read(buffer_fill(b)) ; } ssize_t buffer_timed_fill (buffer *b, tain_t const *deadline, tain_t *stamp) { return timed_get(b, (initfunc_t_ref)&buffer_getfd, (getfunc_t_ref)&get, deadline, stamp) ; } skalibs-2.9.1.0/src/libunixonacid/buffer_timed_flush.c000066400000000000000000000006271355335115400227420ustar00rootroot00000000000000/* ISC license. */ #include #include #include static int buffer_isnonempty (buffer *b) { return !buffer_isempty(b) ; } int buffer_timed_flush (buffer *b, tain_t const *deadline, tain_t *stamp) { return timed_flush(b, (initfunc_t_ref)&buffer_getfd, (initfunc_t_ref)&buffer_isnonempty, (initfunc_t_ref)&buffer_flush, deadline, stamp) ; } skalibs-2.9.1.0/src/libunixonacid/buffer_timed_get.c000066400000000000000000000011741355335115400223760ustar00rootroot00000000000000/* ISC license. */ #include #include #include struct blah_s { buffer *b ; char *s ; size_t len ; size_t w ; } ; static int getfd (struct blah_s *blah) { return buffer_fd(blah->b) ; } static ssize_t get (struct blah_s *blah) { return buffer_getall(blah->b, blah->s, blah->len, &blah->w) ; } size_t buffer_timed_get (buffer *b, char *s, size_t len, tain_t const *deadline, tain_t *stamp) { struct blah_s blah = { .b = b, .s = s, .len = len, .w = 0 } ; timed_get(&blah, (initfunc_t_ref)&getfd, (getfunc_t_ref)&get, deadline, stamp) ; return blah.w ; } skalibs-2.9.1.0/src/libunixonacid/dd_cancel.c000066400000000000000000000004551355335115400210010ustar00rootroot00000000000000/* ISC license. */ #include #include #include void dd_cancel (dirdescriptor_t *dd) { dirdescriptor_t zero = DIRDESCRIPTOR_ZERO ; fd_close(dd->fd) ; rm_rf_in_tmp(&dd->new, 0) ; stralloc_free(&dd->new) ; *dd = zero ; } skalibs-2.9.1.0/src/libunixonacid/dd_close.c000066400000000000000000000002271355335115400206560ustar00rootroot00000000000000/* ISC license. */ #include #include void dd_close (dirdescriptor_t *dd) { fd_close(dd->fd) ; } skalibs-2.9.1.0/src/libunixonacid/dd_commit.c000066400000000000000000000037511355335115400210460ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include static char const *mybasename (char const *s, size_t len) { size_t i = len ; while (i--) if (s[i] == '/') return s + i + 1 ; return s ; } int dd_commit (dirdescriptor_t *dd) { dirdescriptor_t zero = DIRDESCRIPTOR_ZERO ; size_t len = strlen(dd->lnkfn) ; size_t oldbase = dd->new.len ; size_t newlnkbase ; char const *lnkbn = mybasename(dd->lnkfn, len) ; if (!sadirname(&dd->new, dd->lnkfn, len)) return 0 ; if (!stralloc_catb(&dd->new, "/", 1)) goto fail ; if (sareadlink(&dd->new, dd->lnkfn) < 0) { size_t lnkbnbase = dd->new.len ; if (errno != EINVAL) goto fail ; if (!stralloc_cats(&dd->new, lnkbn)) goto fail ; if (!random_sauniquename(&dd->new, 8)) goto fail ; if (!stralloc_0(&dd->new)) goto fail ; if (rename(dd->lnkfn, dd->new.s + oldbase) < 0) goto fail ; /* /!\ race condition right here: there's no lnkfn in the fs */ if (symlink(dd->new.s + lnkbnbase, dd->lnkfn) < 0) /* now that's VERY BAD if it fails */ { int e = errno ; rename(dd->new.s + oldbase, dd->lnkfn) ; /* attempt to revert to initial situation */ errno = e ; goto fail ; /* and hope for the best */ } } if (!stralloc_0(&dd->new)) goto fail ; newlnkbase = dd->new.len ; if (!stralloc_catb(&dd->new, dd->lnkfn, len)) goto fail ; if (!random_sauniquename(&dd->new, 8)) goto fail ; if (!stralloc_0(&dd->new)) goto fail ; if (symlink(dd->new.s, dd->new.s + newlnkbase) < 0) goto fail ; if (rename(dd->new.s + newlnkbase, dd->lnkfn) < 0) { int e = errno ; unlink(dd->new.s + newlnkbase) ; errno = e ; goto fail ; } fd_close(dd->fd) ; dd->new.len = newlnkbase ; rm_rf_in_tmp(&dd->new, oldbase) ; stralloc_free(&dd->new) ; *dd = zero ; return 1 ; fail: dd->new.len = oldbase ; return 0 ; } skalibs-2.9.1.0/src/libunixonacid/dd_commit_devino.c000066400000000000000000000004561355335115400224110ustar00rootroot00000000000000/* ISC license. */ #include #include int dd_commit_devino (dirdescriptor_t *dd, dev_t *dev, ino_t *ino) { struct stat st ; if (fstat(dd->fd, &st) < 0) return 0 ; if (!dd_commit(dd)) return 0 ; *dev = st.st_dev ; *ino = st.st_ino ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/dd_open_read.c000066400000000000000000000004441355335115400215060ustar00rootroot00000000000000/* ISC license. */ #include #include int dd_open_read (dirdescriptor_t *dd, char const *path) { dirdescriptor_t d = DIRDESCRIPTOR_ZERO ; d.fd = open_read(path) ; if (d.fd < 0) return 0 ; d.lnkfn = path ; *dd = d ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/dd_open_write.c000066400000000000000000000013371355335115400217270ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include int dd_open_write (dirdescriptor_t *dd, char const *lnkfn, unsigned int mode) { dirdescriptor_t d = DIRDESCRIPTOR_ZERO ; d.lnkfn = lnkfn ; if (!stralloc_cats(&d.new, lnkfn)) return 0 ; if (!random_sauniquename(&d.new, 8)) goto fail ; if (!stralloc_0(&d.new)) goto fail ; if (mkdir(d.new.s, mode) < 0) goto fail ; d.fd = open_read(d.new.s) ; if (d.fd < 0) { int e = errno ; rmdir(d.new.s) ; errno = e ; goto fail ; } *dd = d ; return 1 ; fail: stralloc_free(&d.new) ; return 0 ; } skalibs-2.9.1.0/src/libunixonacid/ipc_timed_recv.c000066400000000000000000000012451355335115400220570ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include struct blah_s { int fd ; char *s ; size_t len ; char *path ; } ; static int getfd (struct blah_s *blah) { return blah->fd ; } static ssize_t get (struct blah_s *blah) { return sanitize_read(ipc_recv(blah->fd, blah->s, blah->len, blah->path)) ; } ssize_t ipc_timed_recv (int fd, char *s, size_t len, char *path, tain_t const *deadline, tain_t *stamp) { struct blah_s blah = { .fd = fd, .s = s, .len = len, .path = path } ; return timed_get(&blah, (initfunc_t_ref)&getfd, (getfunc_t_ref)&get, deadline, stamp) ; } skalibs-2.9.1.0/src/libunixonacid/ipc_timed_send.c000066400000000000000000000014461355335115400220540ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include int ipc_timed_send (int fd, char const *s, size_t len, tain_t const *deadline, tain_t *stamp) { iopause_fd x = { .fd = fd, .events = IOPAUSE_WRITE, .revents = 0 } ; for (;;) { int r = iopause_stamp(&x, 1, deadline, stamp) ; if (r < 0) return 0 ; else if (!r) return (errno = ETIMEDOUT, 0) ; else if (x.revents & IOPAUSE_WRITE) { if (send(fd, s, len, MSG_NOSIGNAL) == (ssize_t)len) break ; if (!error_isagain(errno)) return 0 ; } else if (x.revents & IOPAUSE_EXCEPT) return (send(fd, s, len, MSG_NOSIGNAL) == (ssize_t)len) ; } return 1 ; } skalibs-2.9.1.0/src/libunixonacid/ipc_timed_sendv.c000066400000000000000000000020651355335115400222400ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include int ipc_timed_sendv (int fd, struct iovec const *v, unsigned int n, tain_t const *deadline, tain_t *stamp) { struct msghdr hdr = { .msg_name = 0, .msg_namelen = 0, .msg_iov = (struct iovec *)v, .msg_iovlen = n, .msg_control = 0, .msg_controllen = 0, .msg_flags = 0 } ; size_t len = siovec_len(v, n) ; iopause_fd x = { .fd = fd, .events = IOPAUSE_WRITE, .revents = 0 } ; for (;;) { int r = iopause_stamp(&x, 1, deadline, stamp) ; if (r < 0) return 0 ; else if (!r) return (errno = ETIMEDOUT, 0) ; else if (x.revents & IOPAUSE_WRITE) { if (sendmsg(fd, &hdr, MSG_NOSIGNAL) == (ssize_t)len) break ; if (!error_isagain(errno)) return 0 ; } else if (x.revents & IOPAUSE_EXCEPT) return (sendmsg(fd, &hdr, MSG_NOSIGNAL) == (ssize_t)len) ; } return 1 ; } skalibs-2.9.1.0/src/libunixonacid/kolbak_call.c000066400000000000000000000005111355335115400213340ustar00rootroot00000000000000/* ISC license. */ #include #include #include int kolbak_call (unixmessage_t const *m, kolbak_queue_t *q) { if (q->head == q->tail) return (errno = EILSEQ, 0) ; if (!(*q->x[q->head].f)(m, q->x[q->head].data)) return 0 ; q->head = (q->head + 1) % q->n ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/kolbak_enqueue.c000066400000000000000000000006151355335115400220750ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int kolbak_enqueue (kolbak_queue_t *q, unixmessage_handler_func_t *f, void *data) { size_t newtail = (q->tail + 1) % q->n ; if (newtail == q->head) return (errno = ENOBUFS, 0) ; q->x[q->tail].f = f ; q->x[q->tail].data = data ; q->tail = newtail ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/kolbak_queue_init.c000066400000000000000000000004101355335115400225660ustar00rootroot00000000000000/* ISC license. */ #include #include int kolbak_queue_init (kolbak_queue_t *q, kolbak_closure_t *s, size_t len) { if (len < 2) return (errno = EINVAL, 0) ; q->x = s ; q->n = len ; q->head = 0 ; q->tail = 0 ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/kolbak_unenqueue.c000066400000000000000000000003371355335115400224410ustar00rootroot00000000000000/* ISC license. */ #include #include int kolbak_unenqueue (kolbak_queue_t *q) { if (q->head == q->tail) return (errno = EINVAL, 0) ; q->tail = (q->tail + q->n - 1) % q->n ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/netstring_timed_get.c000066400000000000000000000010711355335115400231360ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int netstring_timed_get (buffer *b, stralloc *sa, tain_t const *deadline, tain_t *stamp) { iopause_fd x = { .fd = buffer_fd(b), .events = IOPAUSE_READ } ; size_t w = 0 ; for (;;) { int r = netstring_get(b, sa, &w) ; if (r > 0) return r ; if (r < 0) return 0 ; r = iopause_stamp(&x, 1, deadline, stamp) ; if (r < 0) return 0 ; else if (!r) return (errno = ETIMEDOUT, 0) ; } } skalibs-2.9.1.0/src/libunixonacid/open2_at.c000066400000000000000000000016321355335115400206120ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASOPENAT #ifndef _ATFILE_SOURCE #define _ATFILE_SOURCE #endif #include #include #include int open2_at (int dirfd, char const *file, int flags) { return openat(dirfd, file, flags) ; } #else #include #include #include #include #include int open2_at (int dirfd, char const *file, int flags) { int fd ; int fdhere = open_read(".") ; if (fdhere < 0) return -1 ; if (fd_chdir(dirfd) < 0) goto errclose ; fd = open2(file, flags) ; if (fd < 0) { int e = errno ; fd_chdir(fdhere) ; errno = e ; goto errclose ; } if (fd_chdir(fdhere) < 0) { fd_close(fd) ; goto errclose ; } fd_close(fdhere) ; return fd ; errclose: fd_close(fdhere) ; return -1 ; } #endif skalibs-2.9.1.0/src/libunixonacid/open3_at.c000066400000000000000000000017141355335115400206140ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASOPENAT #ifndef _ATFILE_SOURCE #define _ATFILE_SOURCE #endif #include #include #include int open3_at (int dirfd, char const *file, int flags, unsigned int mode) { return openat(dirfd, file, flags, mode) ; } #else #include #include #include #include #include int open3_at (int dirfd, char const *file, int flags, unsigned int mode) { int fd ; int fdhere = open_read(".") ; if (fdhere < 0) return -1 ; if (fd_chdir(dirfd) < 0) goto errclose ; fd = open3(file, flags, mode) ; if (fd < 0) { int e = errno ; fd_chdir(fdhere) ; errno = e ; goto errclose ; } if (fd_chdir(fdhere) < 0) { fd_close(fd) ; goto errclose ; } fd_close(fdhere) ; return fd ; errclose: fd_close(fdhere) ; return -1 ; } #endif skalibs-2.9.1.0/src/libunixonacid/open_appendat.c000066400000000000000000000003471355335115400217220ustar00rootroot00000000000000/* ISC license. */ #include #include #include int open_appendat (int fd, char const *name) { return open3_at(fd, name, O_WRONLY | O_NONBLOCK | O_APPEND | O_CREAT, 0666) ; } skalibs-2.9.1.0/src/libunixonacid/open_appendatb.c000066400000000000000000000004051355335115400220570ustar00rootroot00000000000000/* ISC license. */ #include #include int open_appendatb (int dirfd, char const *name) { int fd = open_appendat(dirfd, name) ; if (fd < 0) return -1 ; if (ndelay_off(fd) < 0) return -1 ; return fd ; } skalibs-2.9.1.0/src/libunixonacid/open_readat.c000066400000000000000000000002641355335115400213640ustar00rootroot00000000000000/* ISC license. */ #include #include int open_readat (int fd, char const *name) { return open2_at(fd, name, O_RDONLY | O_NONBLOCK) ; } skalibs-2.9.1.0/src/libunixonacid/open_readatb.c000066400000000000000000000004011355335115400215170ustar00rootroot00000000000000/* ISC license. */ #include #include int open_readatb (int dirfd, char const *name) { int fd = open_readat(dirfd, name) ; if (fd < 0) return -1 ; if (ndelay_off(fd) < 0) return -1 ; return fd ; } skalibs-2.9.1.0/src/libunixonacid/open_truncat.c000066400000000000000000000003171355335115400216030ustar00rootroot00000000000000/* ISC license. */ #include #include int open_truncat (int fd, char const *name) { return open3_at(fd, name, O_WRONLY | O_NONBLOCK | O_TRUNC | O_CREAT, 0666) ; } skalibs-2.9.1.0/src/libunixonacid/open_truncatb.c000066400000000000000000000004031355335115400217410ustar00rootroot00000000000000/* ISC license. */ #include #include int open_truncatb (int dirfd, char const *name) { int fd = open_truncat(dirfd, name) ; if (fd < 0) return -1 ; if (ndelay_off(fd) < 0) return -1 ; return fd ; } skalibs-2.9.1.0/src/libunixonacid/open_writeat.c000066400000000000000000000002651355335115400216040ustar00rootroot00000000000000/* ISC license. */ #include #include int open_writeat (int fd, char const *name) { return open2_at(fd, name, O_WRONLY | O_NONBLOCK) ; } skalibs-2.9.1.0/src/libunixonacid/open_writeatb.c000066400000000000000000000004031355335115400217400ustar00rootroot00000000000000/* ISC license. */ #include #include int open_writeatb (int dirfd, char const *name) { int fd = open_writeat(dirfd, name) ; if (fd < 0) return -1 ; if (ndelay_off(fd) < 0) return -1 ; return fd ; } skalibs-2.9.1.0/src/libunixonacid/opengetlnclose.c000066400000000000000000000007201355335115400221210ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int opengetlnclose (char const *fn, stralloc *sa, int sep) { char buf[BUFFER_INSIZE] ; buffer b ; int r ; int fd = open_readb(fn) ; if (fd < 0) return -1 ; buffer_init(&b, &fd_readv, fd, buf, BUFFER_INSIZE) ; r = skagetln(&b, sa, sep) ; fd_close(fd) ; return r ; } skalibs-2.9.1.0/src/libunixonacid/opengetlnclose_at.c000066400000000000000000000007521355335115400226120ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include int opengetlnclose_at (int dirfd, char const *fn, stralloc *sa, int sep) { char buf[BUFFER_INSIZE] ; buffer b ; int r ; int fd = open_readatb(dirfd, fn) ; if (fd < 0) return -1 ; buffer_init(&b, &buffer_read, fd, buf, BUFFER_INSIZE) ; r = skagetln(&b, sa, sep) ; fd_close(fd) ; return r ; } skalibs-2.9.1.0/src/libunixonacid/openreadnclose_at.c000066400000000000000000000006101355335115400225630ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include size_t openreadnclose_at (int dirfd, char const *file, char *s, size_t n) { size_t r ; int e ; int fd = open_readatb(dirfd, file) ; if (fd < 0) return 0 ; r = allread(fd, s, n) ; e = errno ; fd_close(fd) ; errno = e ; return r ; } skalibs-2.9.1.0/src/libunixonacid/openslurpclose_at.c000066400000000000000000000004721355335115400226450ustar00rootroot00000000000000/* ISC license. */ #include #include int openslurpclose_at (int dirfd, char const *fn, stralloc *sa) { int fd = open_readatb(dirfd, fn) ; if (fd < 0) return 0 ; if (!slurp(sa, fd)) { fd_close(fd) ; return 0 ; } fd_close(fd) ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/openwritenclose_at.c000066400000000000000000000006061355335115400230070ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include size_t openwritenclose_at (int dirfd, char const *file, char const *s, size_t n) { size_t r ; int fd = open_truncatb(dirfd, file) ; if (fd < 0) return 0 ; r = allwrite(fd, s, n) ; if (r >= n) fsync(fd) ; fd_close(fd) ; return r ; } skalibs-2.9.1.0/src/libunixonacid/openwritevnclose_at.c000066400000000000000000000007261355335115400232000ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include size_t openwritevnclose_at (int dirfd, char const *file, struct iovec const *v, unsigned int n) { size_t r ; int fd = open_truncatb(dirfd, file) ; if (fd < 0) return 0 ; r = allwritev(fd, v, n) ; if (r >= siovec_len(v, n)) fsync(fd) ; fd_close(fd) ; return r ; } skalibs-2.9.1.0/src/libunixonacid/skaclient-internal.h000066400000000000000000000006741355335115400227040ustar00rootroot00000000000000/* ISC license. */ #ifndef SKACLIENT_INTERNAL_H #define SKACLIENT_INTERNAL_H #include #include #include #include extern int skaclient_init (skaclient_t *, int, char *, size_t, char *, size_t, char *, size_t, char *, size_t, kolbak_closure_t *, size_t, char const *, size_t) ; extern int skaclient_start_cb (unixmessage_t const *, skaclient_cbdata_t *) ; #endif skalibs-2.9.1.0/src/libunixonacid/skaclient_default_cb.c000066400000000000000000000004771355335115400232360ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int skaclient_default_cb (unixmessage_t const *m, void *p) { unsigned char *err = p ; if (m->len != 1 || m->nfds) return (errno = EPROTO, 0) ; *err = m->s[0] ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_end.c000066400000000000000000000011011355335115400216750ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include void skaclient_end (skaclient_t *a) { fd_close(a->syncout.fd) ; fd_close(a->asyncout.fd) ; unixmessage_sender_free(&a->syncout) ; unixmessage_sender_free(&a->asyncout) ; unixmessage_receiver_free(&a->syncin) ; unixmessage_receiver_free(&a->asyncin) ; if (a->pid && a->options & SKACLIENT_OPTION_WAITPID) { int e = errno ; int wstat ; waitpid_nointr(a->pid, &wstat, 0) ; errno = e ; } *a = skaclient_zero ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_init.c000066400000000000000000000015241355335115400221030ustar00rootroot00000000000000/* ISC license. */ #include #include #include "skaclient-internal.h" int skaclient_init ( skaclient_t *a, int fd, char *bufss, size_t bufsn, char *auxbufss, size_t auxbufsn, char *bufas, size_t bufan, char *auxbufas, size_t auxbufan, kolbak_closure_t *q, size_t qlen, char const *before, size_t beforelen) { unixmessage_t msg = { .s = (char *)before, .len = beforelen, .fds = 0, .nfds = 0 } ; if (!unixmessage_receiver_init(&a->syncin, fd, bufss, bufsn, auxbufss, auxbufsn) || !unixmessage_receiver_init(&a->asyncin, -1, bufas, bufan, auxbufas, auxbufan) || !kolbak_queue_init(&a->kq, q, qlen)) return 0 ; unixmessage_sender_init(&a->syncout, fd) ; unixmessage_sender_init(&a->asyncout, -1) ; if (!unixmessage_put(&a->syncout, &msg)) return 0 ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_put.c000066400000000000000000000004761355335115400217550ustar00rootroot00000000000000/* ISC license. */ #include #include int skaclient_put (skaclient_t *a, char const *s, size_t len, unixmessage_handler_func_t *cb, void *result) { unixmessage_t m = { .s = (char *)s, .len = len, .fds = 0, .nfds = 0 } ; return skaclient_putmsg(a, &m, cb, result) ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_putmsg.c000066400000000000000000000006721355335115400224620ustar00rootroot00000000000000/* ISC license. */ #include #include #include int skaclient_putmsg_and_close (skaclient_t *a, unixmessage_t const *m, unsigned char const *bits, unixmessage_handler_func_t_ref cb, void *result) { if (!kolbak_enqueue(&a->kq, cb, result)) return 0 ; if (!unixmessage_put_and_close(&a->syncout, m, bits)) { kolbak_unenqueue(&a->kq) ; return 0 ; } return 1 ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_putmsgv.c000066400000000000000000000006761355335115400226540ustar00rootroot00000000000000/* ISC license. */ #include #include #include int skaclient_putmsgv_and_close (skaclient_t *a, unixmessage_v_t const *m, unsigned char const *bits, unixmessage_handler_func_t_ref cb, void *result) { if (!kolbak_enqueue(&a->kq, cb, result)) return 0 ; if (!unixmessage_putv_and_close(&a->syncout, m, bits)) { kolbak_unenqueue(&a->kq) ; return 0 ; } return 1 ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_putv.c000066400000000000000000000005601355335115400221350ustar00rootroot00000000000000/* ISC license. */ #include #include #include int skaclient_putv (skaclient_t *a, struct iovec const *v, unsigned int vlen, unixmessage_handler_func_t *cb, void *result) { unixmessage_v_t m = { .v = (struct iovec *)v, .vlen = vlen, .fds = 0, .nfds = 0 } ; return skaclient_putmsgv(a, &m, cb, result) ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_send.c000066400000000000000000000005701355335115400220710ustar00rootroot00000000000000/* ISC license. */ #include #include int skaclient_send (skaclient_t *a, char const *s, size_t len, unixmessage_handler_func_t *cb, void *result, tain_t const *deadline, tain_t *stamp) { unixmessage_t m = { .s = (char *)s, .len = len, .fds = 0, .nfds = 0 } ; return skaclient_sendmsg(a, &m, cb, result, deadline, stamp) ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_sendmsg.c000066400000000000000000000005361355335115400226020ustar00rootroot00000000000000/* ISC license. */ #include int skaclient_sendmsg_and_close (skaclient_t *a, unixmessage_t const *m, unsigned char const *bits, unixmessage_handler_func_t_ref cb, void *result, tain_t const *deadline, tain_t *stamp) { return skaclient_putmsg_and_close(a, m, bits, cb, result) && skaclient_syncify(a, deadline, stamp) ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_sendmsgv.c000066400000000000000000000005431355335115400227660ustar00rootroot00000000000000/* ISC license. */ #include int skaclient_sendmsgv_and_close (skaclient_t *a, unixmessage_v_t const *m, unsigned char const *bits, unixmessage_handler_func_t_ref cb, void *result, tain_t const *deadline, tain_t *stamp) { return skaclient_putmsgv_and_close(a, m, bits, cb, result) && skaclient_syncify(a, deadline, stamp) ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_sendv.c000066400000000000000000000006251355335115400222600ustar00rootroot00000000000000/* ISC license. */ #include #include int skaclient_sendv (skaclient_t *a, struct iovec const *v, unsigned int vlen, unixmessage_handler_func_t *cb, void *result, tain_t const *deadline, tain_t *stamp) { unixmessage_v_t m = { .v = (struct iovec *)v, .vlen = vlen, .fds = 0, .nfds = 0 } ; return skaclient_sendmsgv(a, &m, cb, result, deadline, stamp) ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_server_ack.c000066400000000000000000000016031355335115400232620ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include int skaclient_server_ack (unixmessage_t const *clientmsg, unixmessage_sender_t *out, unixmessage_sender_t *asyncout, char const *before, size_t beforelen, char const *after, size_t afterlen) { int fd[2] ; unixmessage_t m = { .s = (char *)after, .len = afterlen, .fds = fd, .nfds = 1 } ; static unsigned char const bits = 0xff ; if (clientmsg->nfds || clientmsg->len != beforelen || memcmp(clientmsg->s, before, beforelen)) return (errno = EPROTO, 0) ; if (ipc_pair_nbcoe(fd) < 0) return 0 ; unixmessage_sender_init(asyncout, fd[1]) ; if (!unixmessage_put_and_close(out, &m, &bits)) { fd_close(fd[1]) ; fd_close(fd[0]) ; return 0 ; } return 1 ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_server_bidi_ack.c000066400000000000000000000011731355335115400242530ustar00rootroot00000000000000/* ISC license. */ #include #include int skaclient_server_bidi_ack (unixmessage_t const *clientmsg, unixmessage_sender_t *out, unixmessage_sender_t *asyncout, unixmessage_receiver_t *asyncin, char *mainbuf, size_t mainlen, char *auxbuf, size_t auxlen, char const *before, size_t beforelen, char const *after, size_t afterlen) { if (!unixmessage_receiver_init(asyncin, -1, mainbuf, mainlen, auxbuf, auxlen)) return 0 ; if (!skaclient_server_ack(clientmsg, out, asyncout, before, beforelen, after, afterlen)) return 0 ; asyncin->fd = unixmessage_sender_fd(asyncout) ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_server_init.c000066400000000000000000000011231355335115400234640ustar00rootroot00000000000000/* ISC license. */ #include #include #include int skaclient_server_init (unixmessage_receiver_t *in, unixmessage_sender_t *out, unixmessage_sender_t *asyncout, char const *before, size_t beforelen, char const *after, size_t afterlen, tain_t const *deadline, tain_t *stamp) { unixmessage_t m ; return (sanitize_read(unixmessage_timed_receive(in, &m, deadline, stamp)) >= 0) && skaclient_server_ack(&m, out, asyncout, before, beforelen, after, afterlen) && unixmessage_sender_timed_flush(out, deadline, stamp) ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_start.c000066400000000000000000000021201355335115400222660ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include "skaclient-internal.h" int skaclient_start ( skaclient_t *a, char *bufss, size_t bufsn, char *auxbufss, size_t auxbufsn, char *bufas, size_t bufan, char *auxbufas, size_t auxbufan, kolbak_closure_t *q, size_t qlen, char const *path, uint32_t options, char const *before, size_t beforelen, char const *after, size_t afterlen, tain_t const *deadline, tain_t *stamp) { skaclient_cbdata_t blah ; unixmessage_t m ; int r ; if (!skaclient_start_async(a, bufss, bufsn, auxbufss, auxbufsn, bufas, bufan, auxbufas, auxbufan, q, qlen, path, options, before, beforelen, after, afterlen, &blah)) return 0 ; if (!skaclient_timed_flush(a, deadline, stamp)) { int e = errno ; skaclient_end(a) ; errno = e ; return 0 ; } r = unixmessage_timed_receive(&a->syncin, &m, deadline, stamp) ; if (r < 1) { int e = errno ; if (!r) e = EPIPE ; skaclient_end(a) ; errno = e ; return 0 ; } return kolbak_call(&m, &a->kq) ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_start_async.c000066400000000000000000000022131355335115400234660ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include "skaclient-internal.h" int skaclient_start_async ( skaclient_t *a, char *bufss, size_t bufsn, char *auxbufss, size_t auxbufsn, char *bufas, size_t bufan, char *auxbufas, size_t auxbufan, kolbak_closure_t *q, size_t qlen, char const *path, uint32_t options, char const *before, size_t beforelen, char const *after, size_t afterlen, skaclient_cbdata_t *blah) { int fd = ipc_stream_nbcoe() ; if (fd < 0) return 0 ; if ((!ipc_connect(fd, path) && !error_isalready(errno)) || !skaclient_init(a, fd, bufss, bufsn, auxbufss, auxbufsn, bufas, bufan, auxbufas, auxbufan, q, qlen, before, beforelen)) { fd_close(fd) ; return 0 ; } a->pid = 0 ; a->options = options & ~SKACLIENT_OPTION_WAITPID ; if (!kolbak_enqueue(&a->kq, (unixmessage_handler_func_t_ref)&skaclient_start_cb, blah)) { skaclient_end(a) ; return 0 ; } blah->a = a ; blah->after = after ; blah->afterlen = afterlen ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_start_cb.c000066400000000000000000000013561355335115400227440ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include "skaclient-internal.h" int skaclient_start_cb (unixmessage_t const *m, skaclient_cbdata_t *blah) { if (m->len != blah->afterlen || memcmp(m->s, blah->after, m->len) || m->nfds != 1) { unixmessage_drop(m) ; return (errno = EPROTO, 0) ; } blah->a->asyncin.fd = m->fds[0] ; blah->a->asyncout.fd = m->fds[0] ; if (!(blah->a->options & SKACLIENT_OPTION_ASYNC_ACCEPT_FDS)) unixmessage_receiver_refuse_fds(&blah->a->asyncin) ; if (!(blah->a->options & SKACLIENT_OPTION_SYNC_ACCEPT_FDS)) unixmessage_receiver_refuse_fds(&blah->a->syncin) ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_startf.c000066400000000000000000000022241355335115400224410ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include "skaclient-internal.h" int skaclient_startf ( skaclient_t *a, char *bufss, size_t bufsn, char *auxbufss, size_t auxbufsn, char *bufas, size_t bufan, char *auxbufas, size_t auxbufan, kolbak_closure_t *q, size_t qlen, char const *prog, char const *const *argv, char const *const *envp, uint32_t options, char const *before, size_t beforelen, char const *after, size_t afterlen, tain_t const *deadline, tain_t *stamp) { skaclient_cbdata_t blah ; unixmessage_t m ; int r ; if (!skaclient_startf_async(a, bufss, bufsn, auxbufss, auxbufsn, bufas, bufan, auxbufas, auxbufan, q, qlen, prog, argv, envp, options, before, beforelen, after, afterlen, &blah)) return 0 ; if (!skaclient_timed_flush(a, deadline, stamp)) { int e = errno ; skaclient_end(a) ; errno = e ; return 0 ; } r = unixmessage_timed_receive(&a->syncin, &m, deadline, stamp) ; if (r < 1) { int e = errno ; if (!r) e = EPIPE ; skaclient_end(a) ; errno = e ; return 0 ; } return kolbak_call(&m, &a->kq) ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_startf_async.c000066400000000000000000000024611355335115400236410ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include "skaclient-internal.h" int skaclient_startf_async ( skaclient_t *a, char *bufss, size_t bufsn, char *auxbufss, size_t auxbufsn, char *bufas, size_t bufan, char *auxbufas, size_t auxbufan, kolbak_closure_t *q, size_t qlen, char const *prog, char const *const *argv, char const *const *envp, uint32_t options, char const *before, size_t beforelen, char const *after, size_t afterlen, skaclient_cbdata_t *blah) { int fd ; pid_t pid = child_spawn1_socket(prog, argv, envp, &fd) ; if (!pid) return 0 ; if (ndelay_on(fd) < 0 || coe(fd) < 0 || !skaclient_init(a, fd, bufss, bufsn, auxbufss, auxbufsn, bufas, bufan, auxbufas, auxbufan, q, qlen, before, beforelen)) { fd_close(fd) ; if (options & SKACLIENT_OPTION_WAITPID) { int e = errno ; int wstat ; waitpid_nointr(a->pid, &wstat, 0) ; errno = e ; } return 0 ; } a->pid = pid ; a->options = options ; if (!kolbak_enqueue(&a->kq, (unixmessage_handler_func_t_ref)&skaclient_start_cb, blah)) { skaclient_end(a) ; return 0 ; } blah->a = a ; blah->after = after ; blah->afterlen = afterlen ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_syncify.c000066400000000000000000000005071355335115400226240ustar00rootroot00000000000000/* ISC license. */ #include #include int skaclient_syncify (skaclient_t *a, tain_t const *deadline, tain_t *stamp) { int r ; if (!skaclient_timed_flush(a, deadline, stamp)) return 0 ; r = skaclient_timed_supdate(a, deadline, stamp) ; return r < 0 ? 0 : !r ? (errno = EPIPE, 0) : 1 ; } skalibs-2.9.1.0/src/libunixonacid/skaclient_zero.c000066400000000000000000000001501355335115400221110ustar00rootroot00000000000000/* ISC license. */ #include skaclient_t const skaclient_zero = SKACLIENT_ZERO ; skalibs-2.9.1.0/src/libunixonacid/stat_at.c000066400000000000000000000026071355335115400205450ustar00rootroot00000000000000/* ISC license. */ #include #ifdef SKALIBS_HASOPENAT #ifndef _ATFILE_SOURCE #define _ATFILE_SOURCE #endif #include #include #include #include int stat_at (int dirfd, char const *file, struct stat *st) { return fstatat(dirfd, file, st, 0) ; } int lstat_at (int dirfd, char const *file, struct stat *st) { return fstatat(dirfd, file, st, AT_SYMLINK_NOFOLLOW) ; } #else /* OpenBSD plz. lstat() is POSIX. */ #include #include #include #include #include #include static int fstat_at (int dirfd, char const *file, struct stat *st, int (*dostat)(char const *, struct stat *)) { int r ; int fdhere = open_read(".") ; if (fdhere < 0) return -1 ; if (fd_chdir(dirfd) < 0) { fd_close(fdhere) ; return -1 ; } r = (*dostat)(file, st) ; if (r < 0) { int e = errno ; fd_chdir(fdhere) ; fd_close(fdhere) ; errno = e ; return -1 ; } if (fd_chdir(fdhere) < 0) { fd_close(fdhere) ; return -1 ; } fd_close(fdhere) ; return r ; } int stat_at (int dirfd, char const *file, struct stat *st) { return fstat_at(dirfd, file, st, &stat) ; } int lstat_at (int dirfd, char const *file, struct stat *st) { return fstat_at(dirfd, file, st, &lstat) ; } #endif skalibs-2.9.1.0/src/libunixonacid/textclient_command.c000066400000000000000000000007271355335115400227700ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int textclient_command (textclient_t *a, char const *s, size_t len, tain_t const *deadline, tain_t *stamp) { struct iovec ans ; if (!textclient_exchange(a, s, len, &ans, deadline, stamp)) return 0 ; if (ans.iov_len != 1) return (errno = EPROTO, 0) ; if (*(char *)ans.iov_base) return (errno = *(char *)ans.iov_base, 0) ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/textclient_commandv.c000066400000000000000000000007431355335115400231540ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int textclient_commandv (textclient_t *a, struct iovec const *v, unsigned int n, tain_t const *deadline, tain_t *stamp) { struct iovec ans ; if (!textclient_exchangev(a, v, n, &ans, deadline, stamp)) return 0 ; if (ans.iov_len != 1) return (errno = EPROTO, 0) ; if (*(char *)ans.iov_base) return (errno = *(char *)ans.iov_base, 0) ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/textclient_end.c000066400000000000000000000013141355335115400221110ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include void textclient_end (textclient_t *a) { fd_close(textmessage_sender_fd(&a->syncout)) ; if (textmessage_receiver_fd(&a->syncin) != textmessage_sender_fd(&a->syncout)) fd_close(textmessage_receiver_fd(&a->syncin)) ; fd_close(textmessage_receiver_fd(&a->asyncin)) ; textmessage_sender_free(&a->syncout) ; textmessage_receiver_free(&a->syncin) ; textmessage_receiver_free(&a->asyncin) ; if (a->pid && a->options & TEXTCLIENT_OPTION_WAITPID) { int e = errno ; int wstat ; waitpid_nointr(a->pid, &wstat, 0) ; errno = e ; } *a = textclient_zero ; } skalibs-2.9.1.0/src/libunixonacid/textclient_server_init.c000066400000000000000000000011521355335115400236740ustar00rootroot00000000000000/* ISC license. */ #include #include #include int textclient_server_init (textmessage_receiver_t *in, textmessage_sender_t *syncout, textmessage_sender_t *asyncout, char const *before, size_t beforelen, char const *after, size_t afterlen, tain_t const *deadline, tain_t *stamp) { return getenv(SKALIBS_CHILD_SPAWN_FDS_ENVVAR) ? textclient_server_init_frompipe(in, syncout, asyncout, before, beforelen, after, afterlen, deadline, stamp) : textclient_server_init_fromsocket(in, syncout, asyncout, before, beforelen, after, afterlen, deadline, stamp) ; } skalibs-2.9.1.0/src/libunixonacid/textclient_server_init_frompipe.c000066400000000000000000000023541355335115400256020ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include #include #include int textclient_server_init_frompipe (textmessage_receiver_t *in, textmessage_sender_t *syncout, textmessage_sender_t *asyncout, char const *before, size_t beforelen, char const *after, size_t afterlen, tain_t const *deadline, tain_t *stamp) { struct iovec v ; unsigned int asyncfd ; char *x = getenv(SKALIBS_CHILD_SPAWN_FDS_ENVVAR) ; if (!x || !uint0_scan(x, &asyncfd) || asyncfd == textmessage_sender_fd(syncout) || asyncfd == textmessage_receiver_fd(in)) return (errno = EPROTO, 0) ; if (sanitize_read(textmessage_timed_receive(in, &v, deadline, stamp)) <= 0) return 0 ; if (v.iov_len != beforelen || memcmp(v.iov_base, before, beforelen)) return (errno = EPROTO, 0) ; if (fcntl(asyncfd, F_GETFD) < 0) return 0 ; if (!textmessage_timed_send(syncout, after, afterlen, deadline, stamp)) return 0 ; textmessage_sender_init(asyncout, asyncfd) ; if (!textmessage_timed_send(asyncout, after, afterlen, deadline, stamp)) return 0 ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/textclient_server_init_fromsocket.c000066400000000000000000000042541355335115400261360ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include #include #include #include #include union aligner_u { struct cmsghdr cmsghdr ; int i ; } ; static int getfd (void *p) { return ((int *)p)[0] ; } static int one (void *p) { (void)p ; return 1 ; } static int sendit (void *p) { int *fd = p ; union aligner_u ancilbuf[1 + (CMSG_SPACE(sizeof(int)) - 1) / sizeof(union aligner_u)] ; ssize_t r ; char ch = '|' ; struct iovec v = { .iov_base = &ch, .iov_len = 1 } ; struct msghdr hdr = { .msg_name = 0, .msg_namelen = 0, .msg_iov = &v, .msg_iovlen = 1, .msg_control = ancilbuf, .msg_controllen = CMSG_SPACE(sizeof(int)) } ; struct cmsghdr *c = CMSG_FIRSTHDR(&hdr) ; memset(hdr.msg_control, 0, hdr.msg_controllen) ; c->cmsg_level = SOL_SOCKET ; c->cmsg_type = SCM_RIGHTS ; c->cmsg_len = CMSG_LEN(sizeof(int)) ; *(int *)CMSG_DATA(c) = fd[1] ; do r = sendmsg(fd[0], &hdr, MSG_NOSIGNAL) ; while (r < 0 && errno == EINTR) ; if (r <= 0) return 0 ; fd_close(fd[1]) ; return 1 ; } int textclient_server_init_fromsocket (textmessage_receiver_t *in, textmessage_sender_t *syncout, textmessage_sender_t *asyncout, char const *before, size_t beforelen, char const *after, size_t afterlen, tain_t const *deadline, tain_t *stamp) { int fd[3] = { textmessage_sender_fd(syncout) } ; struct iovec v ; if (sanitize_read(textmessage_timed_receive(in, &v, deadline, stamp)) <= 0) return 0 ; if (v.iov_len != beforelen || memcmp(v.iov_base, before, beforelen)) return (errno = EPROTO, 0) ; if (pipenbcoe(fd+1) < 0) return 0 ; if (!timed_flush(fd, &getfd, &one, &sendit, deadline, stamp)) goto err ; if (!textmessage_timed_send(syncout, after, afterlen, deadline, stamp)) goto err ; textmessage_sender_init(asyncout, fd[2]) ; if (!textmessage_timed_send(asyncout, after, afterlen, deadline, stamp)) goto err ; return 1 ; err: fd_close(fd[2]) ; fd_close(fd[1]) ; return 0 ; } skalibs-2.9.1.0/src/libunixonacid/textclient_start.c000066400000000000000000000061751355335115400225120ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include #include #include #include #include #include union aligner_u { struct cmsghdr cmsghdr ; int i ; } ; static int getfd (void *p) { return ((int *)p)[0] ; } static ssize_t get (void *p) { static int const awesomeflags = #ifdef SKALIBS_HASMSGDONTWAIT MSG_DONTWAIT #else 0 #endif | #ifdef SKALIBS_HASCMSGCLOEXEC MSG_CMSG_CLOEXEC #else 0 #endif ; struct cmsghdr *c ; int *fd = p ; ssize_t r ; union aligner_u ancilbuf[1 + (CMSG_SPACE(sizeof(int)) - 1) / sizeof(union aligner_u)] ; char ch ; struct iovec v = { .iov_base = &ch, .iov_len = 1 } ; struct msghdr msghdr = { .msg_name = 0, .msg_namelen = 0, .msg_iov = &v, .msg_iovlen = 1, .msg_flags = 0, .msg_control = ancilbuf, .msg_controllen = CMSG_SPACE(sizeof(int)) } ; do r = recvmsg(fd[0], &msghdr, awesomeflags) ; while (r < 0 && errno == EINTR) ; if (r <= 0) return sanitize_read(r) ; c = CMSG_FIRSTHDR(&msghdr) ; if (ch != '|' || !c || c->cmsg_level != SOL_SOCKET || c->cmsg_type != SCM_RIGHTS || (size_t)(c->cmsg_len - (CMSG_DATA(c) - (unsigned char *)c)) != sizeof(int)) return (errno = EPROTO, -1) ; #ifndef SKALIBS_HASCMSGCLOEXEC if (coe(*(int *)CMSG_DATA(c)) < 0) { fd_close(*(int *)CMSG_DATA(c)) ; return -1 ; } #endif fd[1] = *(int *)CMSG_DATA(c) ; return 1 ; } int textclient_start (textclient_t *a, char const *path, uint32_t options, char const *before, size_t beforelen, char const *after, size_t afterlen, tain_t const *deadline, tain_t *stamp) { struct iovec v ; int fd[2] ; ssize_t r ; fd[0] = ipc_stream_nbcoe() ; if (fd[0] < 0) return 0 ; if (!ipc_timed_connect(fd[0], path, deadline, stamp)) goto err ; textmessage_sender_init(&a->syncout, fd[0]) ; if (!textmessage_timed_send(&a->syncout, before, beforelen, deadline, stamp)) goto ferr ; textmessage_receiver_init(&a->syncin, fd[0], a->syncbuf, TEXTCLIENT_BUFSIZE, TEXTMESSAGE_MAXLEN) ; r = timed_get(fd, &getfd, &get, deadline, stamp) ; if (!r) errno = EPIPE ; if (r <= 0) goto aerr ; if (sanitize_read(textmessage_timed_receive(&a->syncin, &v, deadline, stamp)) <= 0) goto perr ; if (v.iov_len != afterlen || memcmp(v.iov_base, after, afterlen)) { errno = EPROTO ; goto perr ; } textmessage_receiver_init(&a->asyncin, fd[1], a->asyncbuf, TEXTCLIENT_BUFSIZE, TEXTMESSAGE_MAXLEN) ; if (sanitize_read(textmessage_timed_receive(&a->asyncin, &v, deadline, stamp)) <= 0) goto serr ; if (v.iov_len != afterlen || memcmp(v.iov_base, after, afterlen)) goto berr ; a->pid = 0 ; a->options = options & ~TEXTCLIENT_OPTION_WAITPID ; return 1 ; berr: errno = EPROTO ; serr: textmessage_receiver_free(&a->asyncin) ; perr: fd_close(fd[1]) ; aerr: textmessage_receiver_free(&a->syncin) ; ferr: textmessage_sender_free(&a->syncout) ; err: fd_close(fd[0]) ; return 0 ; } skalibs-2.9.1.0/src/libunixonacid/textclient_startf.c000066400000000000000000000024441355335115400226530ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include int textclient_startf (textclient_t *a, char const *const *argv, char const *const *envp, uint32_t options, char const *before, size_t beforelen, char const *after, size_t afterlen, tain_t const *deadline, tain_t *stamp) { struct iovec v ; int fd[3] = { 0, 1 } ; pid_t pid = child_spawn3(argv[0], argv, envp, fd) ; if (!pid) return 0 ; textmessage_receiver_init(&a->syncin, fd[0], a->syncbuf, TEXTCLIENT_BUFSIZE, TEXTMESSAGE_MAXLEN) ; textmessage_receiver_init(&a->asyncin, fd[2], a->asyncbuf, TEXTCLIENT_BUFSIZE, TEXTMESSAGE_MAXLEN) ; textmessage_sender_init(&a->syncout, fd[1]) ; a->pid = pid ; a->options = options ; if (!textclient_exchange(a, before, beforelen, &v, deadline, stamp)) goto err ; if (v.iov_len != afterlen || memcmp(v.iov_base, after, afterlen)) goto errproto ; if (sanitize_read(textmessage_timed_receive(&a->asyncin, &v, deadline, stamp)) <= 0) goto err ; if (v.iov_len != afterlen || memcmp(v.iov_base, after, afterlen)) goto errproto ; return 1 ; errproto: errno = EPROTO ; err: textclient_end(a) ; return 0 ; } skalibs-2.9.1.0/src/libunixonacid/textclient_zero.c000066400000000000000000000001541355335115400223230ustar00rootroot00000000000000/* ISC license. */ #include textclient_t const textclient_zero = TEXTCLIENT_ZERO ; skalibs-2.9.1.0/src/libunixonacid/textmessage_handle.c000066400000000000000000000007451355335115400227530ustar00rootroot00000000000000/* ISC license. */ #include #include 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 ; } skalibs-2.9.1.0/src/libunixonacid/textmessage_put.c000066400000000000000000000010201355335115400223130ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include 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 > TEXTMESSAGE_MAXLEN) return (errno = EINVAL, 0) ; uint32_pack_big(pack, (uint32_t)len) ; return bufalloc_putv(&ts->out, v, 2) ; } skalibs-2.9.1.0/src/libunixonacid/textmessage_putv.c000066400000000000000000000011531355335115400225100ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include 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 > TEXTMESSAGE_MAXLEN) 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) ; } skalibs-2.9.1.0/src/libunixonacid/textmessage_receive.c000066400000000000000000000017571355335115400231460ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include 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 ; } skalibs-2.9.1.0/src/libunixonacid/textmessage_receiver_0.c000066400000000000000000000003741355335115400235410ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include #include static char buf[BUFFER_INSIZE] ; textmessage_receiver_t textmessage_receiver_0_ = TEXTMESSAGE_RECEIVER_INIT(0, buf, BUFFER_INSIZE, TEXTMESSAGE_MAXLEN) ; skalibs-2.9.1.0/src/libunixonacid/textmessage_receiver_free.c000066400000000000000000000003271355335115400243210ustar00rootroot00000000000000/* ISC license. */ #include #include void textmessage_receiver_free (textmessage_receiver_t *ts) { stralloc_free(&ts->indata) ; *ts = textmessage_receiver_zero ; } skalibs-2.9.1.0/src/libunixonacid/textmessage_receiver_hasmsginbuf.c000066400000000000000000000007521355335115400257100ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include 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 ; } skalibs-2.9.1.0/src/libunixonacid/textmessage_receiver_init.c000066400000000000000000000005671355335115400243510ustar00rootroot00000000000000/* ISC license. */ #include #include #include 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 ; } skalibs-2.9.1.0/src/libunixonacid/textmessage_receiver_zero.c000066400000000000000000000002131355335115400243510ustar00rootroot00000000000000/* ISC license. */ #include textmessage_receiver_t const textmessage_receiver_zero = TEXTMESSAGE_RECEIVER_ZERO ; skalibs-2.9.1.0/src/libunixonacid/textmessage_sender_1.c000066400000000000000000000002211355335115400232050ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include textmessage_sender_t textmessage_sender_1_ = TEXTMESSAGE_SENDER_INIT(1) ; skalibs-2.9.1.0/src/libunixonacid/textmessage_sender_flush.c000066400000000000000000000002641355335115400241750ustar00rootroot00000000000000/* ISC license. */ #include #include int textmessage_sender_flush (textmessage_sender_t *ts) { return bufalloc_flush(&ts->out) ; } skalibs-2.9.1.0/src/libunixonacid/textmessage_sender_getfd.c000066400000000000000000000002671355335115400241500ustar00rootroot00000000000000/* ISC license. */ #include #include int textmessage_sender_getfd (textmessage_sender_t const *ts) { return bufalloc_fd(&ts->out) ; } skalibs-2.9.1.0/src/libunixonacid/textmessage_sender_timed_flush.c000066400000000000000000000010041355335115400253500ustar00rootroot00000000000000/* ISC license. */ #include #include #include 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) ; } skalibs-2.9.1.0/src/libunixonacid/textmessage_sender_x.c000066400000000000000000000002161355335115400233200ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include textmessage_sender_t textmessage_sender_x_ = TEXTMESSAGE_SENDER_ZERO ; skalibs-2.9.1.0/src/libunixonacid/textmessage_sender_zero.c000066400000000000000000000002051355335115400240260ustar00rootroot00000000000000/* ISC license. */ #include textmessage_sender_t const textmessage_sender_zero = TEXTMESSAGE_SENDER_ZERO ; skalibs-2.9.1.0/src/libunixonacid/textmessage_timed_handle.c000066400000000000000000000015361355335115400241340ustar00rootroot00000000000000/* ISC license. */ #include #include #include 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) ; } skalibs-2.9.1.0/src/libunixonacid/textmessage_timed_receive.c000066400000000000000000000013311355335115400243140ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include 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) ; } skalibs-2.9.1.0/src/libunixonacid/timed_flush.c000066400000000000000000000012731355335115400214070ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int timed_flush (void *b, initfunc_t_ref getfd, initfunc_t_ref isnonempty, initfunc_t_ref flush, tain_t const *deadline, tain_t *stamp) { iopause_fd x = { .fd = (*getfd)(b), .events = IOPAUSE_WRITE, .revents = 0 } ; while ((*isnonempty)(b)) { int r = iopause_stamp(&x, 1, deadline, stamp) ; if (r < 0) return 0 ; else if (!r) return (errno = ETIMEDOUT, 0) ; else if (x.revents & IOPAUSE_WRITE) { if (!((*flush)(b)) && !error_isagain(errno)) return 0 ; } else if (x.revents & IOPAUSE_EXCEPT) return (*flush)(b) ; } return 1 ; } skalibs-2.9.1.0/src/libunixonacid/timed_get.c000066400000000000000000000011031355335115400210350ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include ssize_t timed_get (void *b, initfunc_t_ref getfd, getfunc_t_ref get, tain_t const *deadline, tain_t *stamp) { iopause_fd x = { .fd = (*getfd)(b), .events = IOPAUSE_READ, .revents = 0 } ; ssize_t r = (*get)(b) ; while (!r) { r = iopause_stamp(&x, 1, deadline, stamp) ; if (!r) return (errno = ETIMEDOUT, -1) ; else if (r > 0 && x.revents & (IOPAUSE_READ | IOPAUSE_EXCEPT)) r = (*get)(b) ; } return unsanitize_read(r) ; } skalibs-2.9.1.0/src/libunixonacid/timed_getln.c000066400000000000000000000013211355335115400213710ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include struct blah_s { buffer *b ; stralloc *sa ; char sep ; } ; static int getfd (struct blah_s *blah) { return buffer_fd(blah->b) ; } static ssize_t get (struct blah_s *blah) { return sanitize_read(skagetln(blah->b, blah->sa, blah->sep)) ; } int timed_getln (buffer *b, stralloc *sa, char sep, tain_t const *deadline, tain_t *stamp) { struct blah_s blah = { .b = b, .sa = sa, .sep = sep } ; return timed_get(&blah, (initfunc_t_ref)&getfd, (getfunc_t_ref)&get, deadline, stamp) ; } skalibs-2.9.1.0/src/libunixonacid/timed_getlnmax.c000066400000000000000000000014541355335115400221060ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include struct blah_s { buffer *b ; char *d ; size_t max ; size_t w ; char sep ; } ; static int getfd (struct blah_s *blah) { return buffer_fd(blah->b) ; } static ssize_t get (struct blah_s *blah) { return sanitize_read(getlnmax(blah->b, blah->d, blah->max, &blah->w, blah->sep)) ; } ssize_t timed_getlnmax (buffer *b, char *d, size_t max, size_t *w, char sep, tain_t const *deadline, tain_t *stamp) { struct blah_s blah = { .b = b, .d = d, .max = max, .w = *w, .sep = sep } ; ssize_t r = timed_get(&blah, (initfunc_t_ref)&getfd, (getfunc_t_ref)&get, deadline, stamp) ; *w = blah.w ; return r ; } skalibs-2.9.1.0/src/libunixonacid/unixconnection_free.c000066400000000000000000000003721355335115400231470ustar00rootroot00000000000000 /* ISC license. */ #include #include void unixconnection_free (unixconnection_t *io) { unixmessage_sender_free(&io->out) ; unixmessage_receiver_free(&io->in) ; *io = unixconnection_zero ; } skalibs-2.9.1.0/src/libunixonacid/unixconnection_init.c000066400000000000000000000003711355335115400231700ustar00rootroot00000000000000 /* ISC license. */ #include #include void unixconnection_init (unixconnection_t *io, int fdin, int fdout) { unixconnection_init_withclosecb(io, fdin, fdout, &unixmessage_sender_closecb, 0) ; } skalibs-2.9.1.0/src/libunixonacid/unixconnection_init_withclosecb.c000066400000000000000000000006241355335115400255570ustar00rootroot00000000000000 /* ISC license. */ #include #include void unixconnection_init_withclosecb (unixconnection_t *io, int fdin, int fdout, unixmessage_sender_closecb_func_t_ref f, void *p) { unixmessage_receiver_init(&io->in, fdin, io->mainbuf, UNIXMESSAGE_BUFSIZE, io->auxbuf, UNIXMESSAGE_AUXBUFSIZE) ; unixmessage_sender_init_withclosecb(&io->out, fdout, f, p) ; } skalibs-2.9.1.0/src/libunixonacid/unixconnection_zero.c000066400000000000000000000001751355335115400232060ustar00rootroot00000000000000 /* ISC license. */ #include unixconnection_t const unixconnection_zero = UNIXCONNECTION_ZERO ; skalibs-2.9.1.0/src/libunixonacid/unixmessage_bits_closeall.c000066400000000000000000000006021355335115400243260ustar00rootroot00000000000000/* ISC license. */ #include #include static unsigned char unixmessage_bits_closeall_[bitarray_div8(UNIXMESSAGE_MAXFDS)] = "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" ; unsigned char const *const unixmessage_bits_closeall = unixmessage_bits_closeall_ ; skalibs-2.9.1.0/src/libunixonacid/unixmessage_bits_closenone.c000066400000000000000000000005031355335115400245150ustar00rootroot00000000000000/* ISC license. */ #include #include static unsigned char unixmessage_bits_closenone_[bitarray_div8(UNIXMESSAGE_MAXFDS)] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" ; unsigned char const *const unixmessage_bits_closenone = unixmessage_bits_closenone_ ; skalibs-2.9.1.0/src/libunixonacid/unixmessage_drop.c000066400000000000000000000003071355335115400224550ustar00rootroot00000000000000/* ISC license. */ #include #include void unixmessage_drop (unixmessage_t const *m) { unsigned int i = m->nfds ; while (i--) fd_close(m->fds[i]) ; } skalibs-2.9.1.0/src/libunixonacid/unixmessage_handle.c000066400000000000000000000007161355335115400227500ustar00rootroot00000000000000/* ISC license. */ #include int unixmessage_handle (unixmessage_receiver_t *b, unixmessage_handler_func_t_ref f, void *p) { unsigned int count = 0 ; while (count < UNIXMESSAGE_MAXREADS || unixmessage_receiver_hasmsginbuf(b)) { unixmessage_t m ; int r = unixmessage_receive(b, &m) ; if (r < 0) return -1 ; if (!r) break ; r = (*f)(&m, p) ; if (r <= 0) return r-2 ; count++ ; } return (int)count ; } skalibs-2.9.1.0/src/libunixonacid/unixmessage_put.c000066400000000000000000000036231355335115400223250ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include #include static inline int copyfds (char *s, int const *fds, unsigned int n, unsigned char const *bits, unixmessage_sender_closecb_func_t_ref closecb, void *closecbdata) { unsigned int i = 0 ; for (; i < n ; i++) { int fd = fds[i] ; if (fd < 0) return (errno = EINVAL, -1) ; if (bitarray_peek(bits, i)) fd = - fd - 1 ; memcpy(s, (char const *)&fd, sizeof(int)) ; s += sizeof(int) ; } return 1 ; } static int reserve_and_copy (unixmessage_sender_t *b, size_t len, int const *fds, unsigned int nfds, unsigned char const *bits) { disize cur = { .left = b->data.len, .right = genalloc_len(int, &b->fds) } ; if (len > UNIXMESSAGE_MAXSIZE || nfds > UNIXMESSAGE_MAXFDS) return (errno = EPROTO, 0) ; if (!genalloc_readyplus(disize, &b->offsets, 1) || !genalloc_readyplus(int, &b->fds, nfds) || !stralloc_readyplus(&b->data, len)) return 0 ; if (!copyfds(b->fds.s + b->fds.len, fds, nfds, bits, b->closecb, b->closecbdata)) return 0 ; genalloc_setlen(int, &b->fds, cur.right + nfds) ; return genalloc_append(disize, &b->offsets, &cur) ; } int unixmessage_put_and_close (unixmessage_sender_t *b, unixmessage_t const *m, unsigned char const *bits) { if (!reserve_and_copy(b, m->len, m->fds, m->nfds, bits)) return 0 ; memmove(b->data.s + b->data.len, m->s, m->len) ; b->data.len += m->len ; return 1 ; } int unixmessage_putv_and_close (unixmessage_sender_t *b, unixmessage_v_t const *m, unsigned char const *bits) { size_t len = siovec_len(m->v, m->vlen) ; if (!reserve_and_copy(b, len, m->fds, m->nfds, bits)) return 0 ; b->data.len += siovec_gather(m->v, m->vlen, b->data.s + b->data.len, len) ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/unixmessage_receive.c000066400000000000000000000077601355335115400231450ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include #include #include #include #include #include union aligner_u { struct cmsghdr cmsghdr ; int i ; } ; static int const awesomeflags = #ifdef SKALIBS_HASMSGDONTWAIT MSG_DONTWAIT #else 0 #endif | #ifdef SKALIBS_HASCMSGCLOEXEC MSG_CMSG_CLOEXEC #else 0 #endif ; static int unixmessage_receiver_fill (unixmessage_receiver_t *b) { union aligner_u ancilbuf[1 + CMSG_SPACE(b->auxb.a - 1) / sizeof(union aligner_u)] ; struct iovec iov[2] ; struct msghdr msghdr = { .msg_name = 0, .msg_namelen = 0, .msg_iov = iov, .msg_iovlen = 2, .msg_flags = 0, .msg_control = b->fds_ok & 1 ? ancilbuf : 0, .msg_controllen = b->fds_ok & 1 ? CMSG_SPACE(b->auxb.a - 1) : 0 } ; ssize_t r = -1 ; if (cbuffer_isfull(&b->mainb) || ((b->fds_ok & 1) && cbuffer_isfull(&b->auxb))) return (errno = ENOBUFS, -1) ; cbuffer_wpeek(&b->mainb, iov) ; while (r < 0) { r = recvmsg(b->fd, &msghdr, awesomeflags) ; if (!r || (r < 0 && errno != EINTR)) return r ; } if (b->fds_ok & 1) { struct cmsghdr *c = CMSG_FIRSTHDR(&msghdr) ; if (c) { size_t auxlen ; if (c->cmsg_level != SOL_SOCKET || c->cmsg_type != SCM_RIGHTS) return (errno = EPROTO, -1) ; auxlen = (size_t)(c->cmsg_len - (CMSG_DATA(c) - (unsigned char *)c)) ; if (auxlen && !(b->fds_ok & 2)) { size_t i = auxlen / sizeof(int) ; while (i--) fd_close(((int *)CMSG_DATA(c))[i]) ; return (errno = EPROTO, -1) ; } #ifndef SKALIBS_HASCMSGCLOEXEC { size_t i = 0 ; for (; i < auxlen / sizeof(int) ; i++) if (coe(((int *)CMSG_DATA(c))[i]) < 0) { i++ ; while (i--) fd_close(((int *)CMSG_DATA(c))[i]) ; return -1 ; } } #endif if ((msghdr.msg_flags & MSG_CTRUNC) || cbuffer_put(&b->auxb, (char *)CMSG_DATA(c), auxlen) < auxlen) { size_t i = auxlen/sizeof(int) ; while (i--) fd_close(((int *)CMSG_DATA(c))[i]) ; return (errno = ENOBUFS, -1) ; } } } cbuffer_WSEEK(&b->mainb, r) ; return 1 ; } int unixmessage_receive (unixmessage_receiver_t *b, unixmessage_t *m) { if (b->maindata.len == b->mainlen && b->auxdata.len == b->auxlen) { char pack[6] ; if (cbuffer_len(&b->mainb) < 6) { ssize_t r = sanitize_read(unixmessage_receiver_fill(b)) ; if (r <= 0) return r ; if (cbuffer_len(&b->mainb) < 6) return (errno = EWOULDBLOCK, 0) ; } cbuffer_get(&b->mainb, pack, 6) ; uint32_unpack_big(pack, &b->mainlen) ; if (b->fds_ok & 1) uint16_unpack_big(pack + 4, &b->auxlen) ; else b->auxlen = 0 ; b->auxlen *= sizeof(int) ; if (b->mainlen > UNIXMESSAGE_MAXSIZE || b->auxlen > ((b->fds_ok & 2) ? UNIXMESSAGE_MAXFDS * sizeof(int) : 0)) return (errno = EPROTO, -1) ; if (!stralloc_ready(&b->maindata, b->mainlen) || !stralloc_ready(&b->auxdata, b->auxlen)) return -1 ; b->maindata.len = 0 ; b->auxdata.len = 0 ; } for (;;) { ssize_t r ; size_t n = cbuffer_len(&b->mainb) ; if (n > b->mainlen - b->maindata.len) n = b->mainlen - b->maindata.len ; b->maindata.len += cbuffer_get(&b->mainb, b->maindata.s + b->maindata.len, n) ; n = cbuffer_len(&b->auxb) ; if (n > b->auxlen - b->auxdata.len) n = b->auxlen - b->auxdata.len ; b->auxdata.len += cbuffer_get(&b->auxb, b->auxdata.s + b->auxdata.len, n) ; if (b->maindata.len == b->mainlen && b->auxdata.len == b->auxlen) break ; r = sanitize_read(unixmessage_receiver_fill(b)) ; if (r <= 0) return r ; } m->s = b->maindata.s ; m->len = b->maindata.len ; m->fds = (int *)b->auxdata.s ; m->nfds = b->auxdata.len / sizeof(int) ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/unixmessage_receiver_0.c000066400000000000000000000004561355335115400235410ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include static char mainbuf[UNIXMESSAGE_BUFSIZE] ; static char auxbuf[UNIXMESSAGE_AUXBUFSIZE] ; unixmessage_receiver_t unixmessage_receiver_0_ = UNIXMESSAGE_RECEIVER_INIT(0, mainbuf, UNIXMESSAGE_BUFSIZE, auxbuf, UNIXMESSAGE_AUXBUFSIZE) ; skalibs-2.9.1.0/src/libunixonacid/unixmessage_receiver_free.c000066400000000000000000000014041355335115400243150ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include void unixmessage_receiver_free (unixmessage_receiver_t *b) { size_t maindatalen = b->maindata.len ; int h ; b->fd = -1 ; stralloc_free(&b->maindata) ; h = maindatalen != b->mainlen || b->auxdata.len != b->auxlen || cbuffer_len(&b->auxb) ; if (h) { size_t n = b->auxdata.len / sizeof(int) ; while (n--) fd_close(((int *)b->auxdata.s)[n]) ; } stralloc_free(&b->auxdata) ; if (h) { size_t n = cbuffer_len(&b->auxb) / sizeof(int) ; if (n) { int fds[n] ; cbuffer_get(&b->auxb, (char *)fds, n * sizeof(int)) ; while (n--) fd_close(fds[n]) ; } } } skalibs-2.9.1.0/src/libunixonacid/unixmessage_receiver_hasmsginbuf.c000066400000000000000000000010021355335115400256740ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include int unixmessage_receiver_hasmsginbuf (unixmessage_receiver_t const *b) { size_t len = cbuffer_len(&b->mainb) ; uint32_t mainlen ; char pack[4] ; struct iovec v[2] ; if (len < 6) return 0 ; cbuffer_rpeek(&b->mainb, v) ; siovec_gather(v, 2, pack, 4) ; uint32_unpack_big(pack, &mainlen) ; return len - 6 >= mainlen ; } skalibs-2.9.1.0/src/libunixonacid/unixmessage_receiver_init.c000066400000000000000000000007521355335115400243440ustar00rootroot00000000000000/* ISC license. */ #include #include #include int unixmessage_receiver_init (unixmessage_receiver_t *b, int fd, char *mainbuf, size_t mainlen, char *auxbuf, size_t auxlen) { if (!cbuffer_init(&b->mainb, mainbuf, mainlen) || !cbuffer_init(&b->auxb, auxbuf, auxlen)) return 0 ; b->fd = fd ; b->mainlen = b->auxlen = 0 ; b->maindata = stralloc_zero ; b->auxdata = stralloc_zero ; b->fds_ok = 3 ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/unixmessage_sender_1.c000066400000000000000000000002211355335115400232040ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include unixmessage_sender_t unixmessage_sender_1_ = UNIXMESSAGE_SENDER_INIT(1) ; skalibs-2.9.1.0/src/libunixonacid/unixmessage_sender_closecb.c000066400000000000000000000002461355335115400244650ustar00rootroot00000000000000/* ISC license. */ #include #include void unixmessage_sender_closecb (int fd, void *p) { fd_close(fd) ; (void)p ; } skalibs-2.9.1.0/src/libunixonacid/unixmessage_sender_flush.c000066400000000000000000000067461355335115400242070ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include union aligner_u { struct cmsghdr cmsghdr ; int i ; } ; /* XXX: sendmsg/recvmsg is badly, badly specified. XXX: We assume ancillary data is attached to the first byte. */ int unixmessage_sender_flush (unixmessage_sender_t *b) { disize last = { .left = b->data.len, .right = genalloc_len(int, &b->fds) } ; disize *offsets = genalloc_s(disize, &b->offsets) ; size_t n = genalloc_len(disize, &b->offsets) ; ssize_t r ; if (b->shorty) /* we had a short write, gotta send the remainder first */ { disize *next = b->head+1 < n ? offsets + b->head+1 : &last ; size_t len = next->left - offsets[b->head].left ; if (b->shorty <= len) r = fd_write(b->fd, b->data.s + offsets[b->head].left + (len - b->shorty), b->shorty) ; else { size_t nfds = next->right - offsets[b->head].right ; char pack[6] ; struct iovec v[2] = { { .iov_base = pack + 6 - (b->shorty - len), .iov_len = b->shorty - len }, { .iov_base = b->data.s + offsets[b->head].left, .iov_len = len } } ; uint32_pack_big(pack, (uint32_t)len) ; uint16_pack_big(pack + 4, (uint16_t)nfds) ; r = fd_writev(b->fd, v, 2) ; } if (r <= 0) return 0 ; b->shorty -= r ; if (b->shorty) return (errno = EWOULDBLOCK, 0) ; } for (; b->head < n ; b->head++) { disize *next = b->head+1 < n ? offsets + b->head+1 : &last ; size_t len = next->left - offsets[b->head].left ; size_t nfds = next->right - offsets[b->head].right ; char pack[6] ; struct iovec v[2] = { { .iov_base = pack, .iov_len = 6 }, { .iov_base = b->data.s + offsets[b->head].left, .iov_len = len } } ; union aligner_u ancilbuf[1 + CMSG_SPACE(nfds * sizeof(int)) / sizeof(union aligner_u)] ; struct msghdr hdr = { .msg_name = 0, .msg_namelen = 0, .msg_iov = v, .msg_iovlen = 2, .msg_control = nfds ? ancilbuf : 0, .msg_controllen = nfds ? CMSG_SPACE(nfds * sizeof(int)) : 0 } ; uint32_pack_big(pack, (uint32_t)len) ; uint16_pack_big(pack + 4, (uint16_t)nfds) ; if (nfds) { struct cmsghdr *cp = CMSG_FIRSTHDR(&hdr) ; size_t i = 0 ; memset(hdr.msg_control, 0, hdr.msg_controllen) ; cp->cmsg_level = SOL_SOCKET ; cp->cmsg_type = SCM_RIGHTS ; cp->cmsg_len = CMSG_LEN(nfds * sizeof(int)) ; for (; i < nfds ; i++) { int fd = genalloc_s(int, &b->fds)[offsets[b->head].right + i] ; ((int *)CMSG_DATA(cp))[i] = fd < 0 ? -(fd+1) : fd ; } } do r = sendmsg(b->fd, &hdr, MSG_NOSIGNAL) ; while (r < 0 && errno == EINTR) ; if (r <= 0) return 0 ; if (nfds) { size_t i = 0 ; for (; i < nfds ; i++) { int fd = genalloc_s(int, &b->fds)[offsets[b->head].right + i] ; if (fd < 0) (*b->closecb)(-(fd+1), b->closecbdata) ; } } if ((size_t)r < 6 + len) { b->shorty = 6 + len - r ; return (errno = EWOULDBLOCK, 0) ; } } b->data.len = 0 ; genalloc_setlen(int, &b->fds, 0) ; genalloc_setlen(disize, &b->offsets, 0) ; b->head = 0 ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/unixmessage_sender_free.c000066400000000000000000000012101355335115400237640ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include void unixmessage_sender_free (unixmessage_sender_t *b) { size_t n = genalloc_len(int, &b->fds) ; if (n) { size_t i = genalloc_s(disize, &b->offsets)[b->head].right ; for (; i < n ; i++) { int fd = genalloc_s(int, &b->fds)[i] ; if (fd < 0) (*b->closecb)(-(fd+1), b->closecbdata) ; } } genalloc_free(disize, &b->offsets) ; genalloc_free(int, &b->fds) ; stralloc_free(&b->data) ; *b = unixmessage_sender_zero ; } skalibs-2.9.1.0/src/libunixonacid/unixmessage_sender_getfd.c000066400000000000000000000002101355335115400241330ustar00rootroot00000000000000/* ISC license. */ #include int unixmessage_sender_getfd (unixmessage_sender_t const *b) { return b->fd ; } skalibs-2.9.1.0/src/libunixonacid/unixmessage_sender_init.c000066400000000000000000000003101355335115400240060ustar00rootroot00000000000000/* ISC license. */ #include void unixmessage_sender_init (unixmessage_sender_t *b, int fd) { unixmessage_sender_init_withclosecb(b, fd, &unixmessage_sender_closecb, 0) ; } skalibs-2.9.1.0/src/libunixonacid/unixmessage_sender_init_withclosecb.c000066400000000000000000000006441355335115400264060ustar00rootroot00000000000000/* ISC license. */ #include #include #include void unixmessage_sender_init_withclosecb (unixmessage_sender_t *b, int fd, unixmessage_sender_closecb_func_t_ref f, void *p) { b->fd = fd ; b->data = stralloc_zero ; b->fds = genalloc_zero ; b->offsets = genalloc_zero ; b->head = 0 ; b->shorty = 0 ; b->closecb = f ; b->closecbdata = p ; } skalibs-2.9.1.0/src/libunixonacid/unixmessage_sender_timed_flush.c000066400000000000000000000010001355335115400253430ustar00rootroot00000000000000/* ISC license. */ #include #include #include static int unixmessage_sender_isnonempty (unixmessage_sender_t *b) { return !unixmessage_sender_isempty(b) ; } int unixmessage_sender_timed_flush (unixmessage_sender_t *b, tain_t const *deadline, tain_t *stamp) { return timed_flush(b, (initfunc_t_ref)&unixmessage_sender_getfd, (initfunc_t_ref)&unixmessage_sender_isnonempty, (initfunc_t_ref)&unixmessage_sender_flush, deadline, stamp) ; } skalibs-2.9.1.0/src/libunixonacid/unixmessage_sender_x.c000066400000000000000000000002161355335115400233170ustar00rootroot00000000000000/* ISC license. */ /* MT-unsafe */ #include unixmessage_sender_t unixmessage_sender_x_ = UNIXMESSAGE_SENDER_ZERO ; skalibs-2.9.1.0/src/libunixonacid/unixmessage_sender_zero.c000066400000000000000000000002051355335115400240250ustar00rootroot00000000000000/* ISC license. */ #include unixmessage_sender_t const unixmessage_sender_zero = UNIXMESSAGE_SENDER_ZERO ; skalibs-2.9.1.0/src/libunixonacid/unixmessage_timed_handle.c000066400000000000000000000015301355335115400241250ustar00rootroot00000000000000/* ISC license. */ #include #include #include typedef struct unixmessage_handler_blah_s unixmessage_handler_blah_t, *unixmessage_handler_blah_t_ref ; struct unixmessage_handler_blah_s { unixmessage_receiver_t *b ; unixmessage_handler_func_t_ref f ; void *p ; } ; static int getfd (unixmessage_handler_blah_t *blah) { return unixmessage_receiver_fd(blah->b) ; } static ssize_t get (unixmessage_handler_blah_t *blah) { return unixmessage_handle(blah->b, blah->f, blah->p) ; } int unixmessage_timed_handle (unixmessage_receiver_t *b, unixmessage_handler_func_t_ref f, void *p, tain_t const *deadline, tain_t *stamp) { unixmessage_handler_blah_t blah = { .b = b, .f = f, .p = p } ; return timed_get(&blah, (initfunc_t_ref)&getfd, (getfunc_t_ref)&get, deadline, stamp) ; } skalibs-2.9.1.0/src/libunixonacid/unixmessage_timed_receive.c000066400000000000000000000013271355335115400243200ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include typedef struct unixmessage_get_s unixmessage_get_t, *unixmessage_get_t_ref ; struct unixmessage_get_s { unixmessage_receiver_t *b ; unixmessage_t *m ; } ; static int getfd (unixmessage_get_t *g) { return unixmessage_receiver_fd(g->b) ; } static ssize_t get (unixmessage_get_t *g) { return unixmessage_receive(g->b, g->m) ; } int unixmessage_timed_receive (unixmessage_receiver_t *b, unixmessage_t *m, tain_t const *deadline, tain_t *stamp) { unixmessage_get_t g = { .b = b, .m = m } ; return timed_get(&g, (initfunc_t_ref)&getfd, (getfunc_t_ref)&get, deadline, stamp) ; } skalibs-2.9.1.0/src/libunixonacid/unixmessage_unput.c000066400000000000000000000013431355335115400226650ustar00rootroot00000000000000 /* ISC license. */ #include #include #include #include int unixmessage_unput_and_maybe_drop (unixmessage_sender_t *b, int drop) { disize *start ; size_t n = genalloc_len(disize, &b->offsets) ; size_t i ; int *fds ; if (!n) return 0 ; start = genalloc_s(disize, &b->offsets) + n - 1 ; fds = genalloc_s(int, &b->fds) + start->right ; i = genalloc_len(int, &b->fds) - start->right ; while (i--) if (fds[i] < 0) (*b->closecb)(-(fds[i]+1), b->closecbdata) ; else if (drop) fd_close(fds[i]) ; b->data.len = start->left ; genalloc_setlen(int, &b->fds, start->right) ; genalloc_setlen(disize, &b->offsets, n-1) ; return 1 ; } skalibs-2.9.1.0/src/libunixonacid/unixmessage_v_zero.c000066400000000000000000000001661355335115400230200ustar00rootroot00000000000000/* ISC license. */ #include unixmessage_v_t const unixmessage_v_zero = UNIXMESSAGE_V_ZERO ; skalibs-2.9.1.0/src/libunixonacid/unixmessage_zero.c000066400000000000000000000001601355335115400224650ustar00rootroot00000000000000/* ISC license. */ #include unixmessage_t const unixmessage_zero = UNIXMESSAGE_ZERO ; skalibs-2.9.1.0/src/sysdeps/000077500000000000000000000000001355335115400155775ustar00rootroot00000000000000skalibs-2.9.1.0/src/sysdeps/tryaccept4.c000066400000000000000000000010611355335115400200230ustar00rootroot00000000000000/* ISC license. */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE #ifndef _XPG4_2 #define _XPG4_2 #endif #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #ifndef _DEFAULT_SOURCE #define _DEFAULT_SOURCE #endif #include #include #include #include int main (void) { struct sockaddr blah ; socklen_t blahlen = sizeof(blah) ; int fd = open("/dev/null", O_RDONLY | O_NONBLOCK) ; if (fd < 0) return 111 ; if ((accept4(fd, &blah, &blahlen, SOCK_NONBLOCK) < 0) && (errno != ENOTSOCK)) return 1 ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/tryarc4random.c000066400000000000000000000006311355335115400205340ustar00rootroot00000000000000/* 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 int main (void) { return arc4random_uniform(1) ; } skalibs-2.9.1.0/src/sysdeps/tryarc4random_addrandom.c000066400000000000000000000007251355335115400225510ustar00rootroot00000000000000/* 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 int main (void) { unsigned char *blah = (unsigned char *)"" ; arc4random_addrandom(blah, 1) ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/tryclockboot.c000066400000000000000000000002321355335115400204560ustar00rootroot00000000000000/* ISC license. */ #include int main (void) { struct timespec ts ; if (clock_gettime(CLOCK_BOOTTIME, &ts) < 0) return 111 ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/tryclockmon.c000066400000000000000000000002331355335115400203050ustar00rootroot00000000000000/* ISC license. */ #include int main (void) { struct timespec ts ; if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) return 111 ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/tryclockrt.c000066400000000000000000000002321355335115400201400ustar00rootroot00000000000000/* ISC license. */ #include int main (void) { struct timespec ts ; if (clock_gettime(CLOCK_REALTIME, &ts) < 0) return 111 ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/trycmsgcloexec.c000066400000000000000000000004331355335115400207760ustar00rootroot00000000000000/* ISC license. */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE #ifndef _XPG4_2 # define _XPG4_2 #endif #ifndef _XPG_6 # define _XPG6 #endif #ifndef _GNU_SOURCE # define _GNU_SOURCE #endif #include int main (void) { int flag = MSG_CMSG_CLOEXEC ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/trydevurandom.c000066400000000000000000000006441355335115400206520ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include int main (void) { char a[64] ; char b[64] ; int fd ; fd = open("/dev/urandom", O_RDONLY) ; if ((fd == -1) || (read(fd, a, 64) < 64) ) return 111 ; close(fd) ; fd = open("/dev/urandom", O_RDONLY) ; if ((fd == -1) || (read(fd, b, 64) < 64) ) return 111 ; close(fd) ; return (!memcmp(a, b, 64)) ; } skalibs-2.9.1.0/src/sysdeps/trydirfd.c000066400000000000000000000004661355335115400176000ustar00rootroot00000000000000/* ISC license. */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #ifndef _NETBSD_SOURCE #define _NETBSD_SOURCE #endif #ifndef __EXTENSIONS__ #define __EXTENSIONS__ #endif #include int main (void) { DIR *dir = opendir(".") ; return dirfd(dir) ; } skalibs-2.9.1.0/src/sysdeps/tryeventfd.c000066400000000000000000000002161355335115400201340ustar00rootroot00000000000000/* ISC license. */ #include int main (void) { int fd = eventfd(0, EFD_NONBLOCK) ; if (fd < 0) return 1 ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/tryexplicit_bzero.c000066400000000000000000000007071355335115400215300ustar00rootroot00000000000000/* 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 #include int main (void) { char blah[4] ; explicit_bzero(blah, 4) ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/tryflock.c000066400000000000000000000002601355335115400175760ustar00rootroot00000000000000/* ISC license. */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE #include #include int main (void) { return flock(0, LOCK_EX | LOCK_UN | LOCK_NB) ; } skalibs-2.9.1.0/src/sysdeps/tryfutimens.c000066400000000000000000000005201355335115400203310ustar00rootroot00000000000000/* ISC license. */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE #ifndef __EXTENSIONS__ #define __EXTENSIONS__ #endif #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include int main (void) { struct timespec foo[2] = { { .tv_sec = 0, .tv_nsec = 0 }, { .tv_sec = 0, .tv_nsec = 0 } } ; futimens(0, foo) ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/tryfutimes.c000066400000000000000000000004311355335115400201540ustar00rootroot00000000000000/* ISC license. */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE #ifndef _BSD_SOURCE #define _BSD_SOURCE #endif #include int main (void) { struct timeval foo[2] = { { .tv_sec = 0, .tv_usec = 0 }, { .tv_sec = 0, .tv_usec = 0 } } ; futimes(0, foo) ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/trygetpeereid.c000066400000000000000000000007401355335115400206200ustar00rootroot00000000000000/* 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 #include int main (void) { uid_t uid ; gid_t gid ; int fd = 0 ; return getpeereid(fd, &uid, &gid) ; } skalibs-2.9.1.0/src/sysdeps/trygetpeerucred.c000066400000000000000000000004651355335115400211650ustar00rootroot00000000000000/* ISC license. */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE #include #include int main (void) { ucred_t *cred ; uid_t uid ; gid_t gid ; int s = 0 ; getpeerucred(s, &cred) ; uid = ucred_geteuid(cred) ; gid = ucred_getegid(cred) ; ucred_free(cred) ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/trygetrandom.c000066400000000000000000000002251355335115400204610ustar00rootroot00000000000000/* ISC license. */ #include int main (void) { char buf[4] ; if (getrandom(buf, 4, GRND_NONBLOCK) < 0) return 1 ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/tryipv6.c000066400000000000000000000011421355335115400173640ustar00rootroot00000000000000/* ISC license. */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE #define _XPG4_2 #define _XPG6 #include #include #include #include int main (void) { int s, r ; struct in6_addr foo ; struct sockaddr_in6 bar ; memset(&foo, 0, sizeof(struct sockaddr_in6)) ; bar.sin6_addr = foo ; bar.sin6_port = 1026 ; s = socket(AF_INET6, SOCK_STREAM, 0) ; if (s < 0) return 111 ; do r = connect(s, (struct sockaddr *)&bar, sizeof bar) ; while ((r == -1) && (errno == EINTR)) ; if ((r == -1) && (errno == EALREADY)) errno = EINPROGRESS ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/tryitimer.c000066400000000000000000000002341355335115400177720ustar00rootroot00000000000000/* ISC license. */ #include int main (void) { struct itimerval blah ; if (getitimer(ITIMER_REAL, &blah) < 0) return 111 ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/trylinkat.c000066400000000000000000000006731355335115400177720ustar00rootroot00000000000000/* ISC license. */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #ifndef _ATFILE_SOURCE #define _ATFILE_SOURCE #endif #ifndef _INCOMPLETE_XOPEN_C063 #define _INCOMPLETE_XOPEN_C063 #endif #ifndef __EXTENSIONS__ #define __EXTENSIONS__ #endif #include #include int main (void) { int r = linkat(AT_FDCWD, "/foo", AT_FDCWD, "foo", AT_SYMLINK_FOLLOW) ; return (r < 0) ; } skalibs-2.9.1.0/src/sysdeps/trylsock.c000066400000000000000000000003461355335115400176200ustar00rootroot00000000000000/* ISC license. */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE #ifndef _XPG4_2 #define _XPG4_2 #endif #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include int main (void) { shutdown(0, 0) ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/trymalloc0.c000066400000000000000000000001221355335115400200240ustar00rootroot00000000000000/* ISC license */ #include int main (void) { return !malloc(0) ; } skalibs-2.9.1.0/src/sysdeps/trymemmem.c000066400000000000000000000006441355335115400177630ustar00rootroot00000000000000/* 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 int main (void) { memmem("blah", 4, "la", 2) ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/trymsgdontwait.c000066400000000000000000000003161355335115400210420ustar00rootroot00000000000000/* ISC license. */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE #ifndef _XPG4_2 # define _XPG4_2 #endif #ifndef _BSD_SOURCE #define _BSD_SOURCE #endif #include int value = MSG_DONTWAIT ; skalibs-2.9.1.0/src/sysdeps/trynamespaces.c000066400000000000000000000006151355335115400206230ustar00rootroot00000000000000/* 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 int main (void) { return unshare(0) ; } skalibs-2.9.1.0/src/sysdeps/trynsgetparent.c000066400000000000000000000002501355335115400210310ustar00rootroot00000000000000/* ISC license. */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE #include #include int main (void) { return ioctl(0, NS_GET_PARENT) ; } skalibs-2.9.1.0/src/sysdeps/tryodirectory.c000066400000000000000000000001021355335115400206560ustar00rootroot00000000000000/* ISC license. */ #include int dummy = O_DIRECTORY ; skalibs-2.9.1.0/src/sysdeps/tryopenat.c000066400000000000000000000006331355335115400177720ustar00rootroot00000000000000/* ISC license. */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #ifndef _ATFILE_SOURCE #define _ATFILE_SOURCE #endif #ifndef _INCOMPLETE_XOPEN_C063 #define _INCOMPLETE_XOPEN_C063 #endif #ifndef __EXTENSIONS__ #define __EXTENSIONS__ #endif #include #include int main (void) { int fd = openat(0, "/", O_RDONLY) ; return (fd < 0) ; } skalibs-2.9.1.0/src/sysdeps/trypipe2.c000066400000000000000000000007551355335115400175300ustar00rootroot00000000000000/* 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 _DEFAULT_SOURCE #define _DEFAULT_SOURCE #endif #ifndef _NETBSD_SOURCE #define _NETBSD_SOURCE #endif #ifndef _INCOMPLETE_XOPEN_C063 #define _INCOMPLETE_XOPEN_C063 #endif #include int main (void) { int p[2] ; if (pipe2(p, 0) < 0) return 111 ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/tryposixspawn.c000066400000000000000000000005441355335115400207200ustar00rootroot00000000000000/* ISC license. */ #include int main (void) { pid_t pid ; posix_spawn_file_actions_t actions ; posix_spawnattr_t attr ; char *const argv[2] = { "/bin/true", 0 } ; char *const envp[1] = { 0 } ; posix_spawnattr_setflags(&attr, 0) ; posix_spawn_file_actions_init(&actions) ; return posix_spawn(&pid, argv[0], 0, 0, argv, envp) ; } skalibs-2.9.1.0/src/sysdeps/tryppoll.c000066400000000000000000000011141355335115400176250ustar00rootroot00000000000000/* 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 #include #include #include int main (void) { struct pollfd x = { .events = POLLIN } ; struct timespec ts = { .tv_sec = 0, .tv_nsec = 10 } ; x.fd = open("src/sysdeps/tryppoll.c", O_RDONLY); if (x.fd < 0) return 111 ; if (ppoll(&x, 1, &ts, 0) < 0) return 1 ; if (x.revents != POLLIN) return 1 ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/tryrevoke.c000066400000000000000000000002011355335115400177660ustar00rootroot00000000000000/* ISC license. */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE #include int main (void) { return revoke("/") ; } skalibs-2.9.1.0/src/sysdeps/trysendfile.c000066400000000000000000000001541355335115400202730ustar00rootroot00000000000000/* ISC license. */ #include int main (void) { sendfile(1, 0, 0, 4096) ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/trysetgroups.c000066400000000000000000000007101355335115400205330ustar00rootroot00000000000000/* 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 #ifndef _NETBSD_SOURCE #define _NETBSD_SOURCE #endif #ifndef __EXTENSIONS__ #define __EXTENSIONS__ #endif #include #include #include int main (void) { gid_t g = 0 ; setgroups(1, &g) ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/trysettimeofday.c000066400000000000000000000005351355335115400212020ustar00rootroot00000000000000/* ISC license. */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE #ifndef _BSD_SOURCE #define _BSD_SOURCE #endif #ifndef _NETBSD_SOURCE #define _NETBSD_SOURCE #endif #ifndef __EXTENSIONS__ #define __EXTENSIONS__ #endif #include int main (void) { struct timeval tv ; gettimeofday(&tv, 0) ; settimeofday(&tv, 0) ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/trysignalfd.c000066400000000000000000000003021355335115400202640ustar00rootroot00000000000000/* ISC license. */ #include #include int main (void) { sigset_t foo ; sigemptyset(&foo) ; if (signalfd(-1, &foo, SFD_NONBLOCK) < 0) return 1 ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/trysopeercred.c000066400000000000000000000005441355335115400206400ustar00rootroot00000000000000/* ISC license. */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE #ifndef _XPG4_2 #define _XPG4_2 #endif #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #include int main (void) { int s ; struct ucred dummy ; socklen_t len = sizeof(struct ucred) ; return getsockopt(s, SOL_SOCKET, SO_PEERCRED, &dummy, &len) ; } skalibs-2.9.1.0/src/sysdeps/trysplice.c000066400000000000000000000007071355335115400177650ustar00rootroot00000000000000/* ISC license. */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #include int main (void) { 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 ; } skalibs-2.9.1.0/src/sysdeps/trystrcasestr.c000066400000000000000000000006401355335115400206770ustar00rootroot00000000000000/* 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 int main (void) { return !strcasestr("foobar", "bar") ; } skalibs-2.9.1.0/src/sysdeps/trystrnlen.c000066400000000000000000000001301355335115400201610ustar00rootroot00000000000000/* ISC license. */ #include int main (void) { return strnlen("/", 1) ; } skalibs-2.9.1.0/src/sysdeps/trytimer.c000066400000000000000000000010271355335115400176220ustar00rootroot00000000000000/* ISC license. */ #include #include int main (void) { timer_t blah ; struct itimerspec it = { .it_interval = { .tv_sec = 0, .tv_nsec = 0 }, .it_value = { .tv_sec = 1, .tv_nsec = 0 } } ; struct sigevent se = { .sigev_notify = SIGEV_SIGNAL, .sigev_signo = SIGALRM, .sigev_value = { .sival_int = 0 }, .sigev_notify_function = 0, .sigev_notify_attributes = 0 } ; if (timer_create(CLOCK_REALTIME, &se, &blah) < 0) return 111 ; if (timer_settime(blah, TIMER_ABSTIME, &it, 0) < 0) return 111 ; return 0 ; } skalibs-2.9.1.0/src/sysdeps/tryuint64t.c000066400000000000000000000000761355335115400200220ustar00rootroot00000000000000/* ISC license. */ #include uint64_t dummy = 0 ; skalibs-2.9.1.0/tools/000077500000000000000000000000001355335115400144565ustar00rootroot00000000000000skalibs-2.9.1.0/tools/convert-leapsecs.c000066400000000000000000000026131355335115400201010ustar00rootroot00000000000000/* ISC license. */ #include #include #include #include #include #include #include #include static genalloc table = GENALLOC_ZERO ; /* uint64_t */ static void add_leapsecs (uint64_t *t) { uint64_t *tab = genalloc_s(uint64_t, &table) ; size_t n = genalloc_len(uint64_t, &table) ; size_t i = 0 ; for (; i < n ; i++) if (*t >= tab[i]) (*t)++ ; } int main (int argc, char const *const *argv) { stralloc sa = STRALLOC_ZERO ; for (;;) { struct tm tm ; uint64_t tt ; time_t t ; char *p ; int r ; char fmt[UINT64_FMT] ; sa.len = 0 ; r = skagetln(buffer_0, &sa, '\n') ; if (r < 0) strerr_diefu1sys(111, "read from stdin") ; if (!r) break ; sa.s[sa.len-1] = 0 ; if (!strptime(sa.s, "+%Y-%m-%d", &tm)) continue ; tm.tm_sec = 59 ; tm.tm_min = 59 ; tm.tm_hour = 23 ; t = mktime(&tm) ; if (t < 0) strerr_diefu1sys(111, "mktime") ; tt = t + 1 ; add_leapsecs(&tt) ; if (!genalloc_append(uint64_t, &table, &tt)) strerr_diefu1sys(111, "genalloc_append") ; fmt[uint64_fmt(fmt, tt)] = 0 ; buffer_puts(buffer_1, " TAI_MAGIC + ") ; buffer_puts(buffer_1, fmt) ; buffer_puts(buffer_1, ",\n") ; } buffer_unput(buffer_1, 2) ; buffer_putsflush(buffer_1, "\n") ; return 0 ; } skalibs-2.9.1.0/tools/gen-bits.sh000077500000000000000000000017431355335115400165320ustar00rootroot00000000000000#!/bin/sh -e sysdeps="$1" bits="$2" dfmt="$3" 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 cat src/headers/uint64-defs if grep -qF 'uint64t: no' "$sysdeps" ; then if grep -qF 'sizeofulong: 8' "$sysdeps" ; then cat src/headers/uint64-ulong64 else cat src/headers/uint64-noulong64 fi cat src/headers/uint64-macros fi else cat src/headers/uint64-include fi if grep -qF 'endianness: little' < "$sysdeps" ; then endian=l elif grep -qF 'endianness: big' < "$sysdeps" ; then endian=b else echo 'Error ! Unsupported endianness' 1>&2 ./crash fi tools/gen-types-internal.sh "" "" "$bits" < src/headers/bits-${endian}endian gen_bits "$bits" "$dfmt" "$ofmt" "$xfmt" "$bfmt" exec tools/gen-types-internal.sh "" "" "$bits" < src/headers/bits-footer skalibs-2.9.1.0/tools/gen-deps.sh000077500000000000000000000024771355335115400165310ustar00rootroot00000000000000#!/bin/sh -e . package/info echo '#' echo '# This file has been generated by tools/gen-deps.sh' echo '#' echo for dir in src/include/${package} src/lib* ; do for file in $(ls -1 $dir | grep -- \\.h$) ; do { grep -F "#include <${package}/" < ${dir}/$file | cut -d/ -f2- | cut -d'>' -f1 ; grep -- '#include ".*-internal\.h"' < ${dir}/$file | cut -d'"' -f2 } | sort -u | { deps= while read dep ; do if echo $dep | grep -q -- -internal\\.h$ ; then deps="$deps ${dir}/$dep" else deps="$deps src/include/${package}/$dep" fi done if test -n "$deps" ; then echo "${dir}/${file}:${deps}" fi } done done for dir in src/lib* ; do for file in $(ls -1 $dir | grep -- \\.c$) ; do { grep -F "#include <${package}/" < ${dir}/$file | cut -d/ -f2- | cut -d'>' -f1 ; grep -- '#include ".*-internal\.h"' < ${dir}/$file | cut -d'"' -f2 } | sort -u | { deps=" ${dir}/$file" while read dep ; do if echo $dep | grep -q -- -internal\\.h$ ; then deps="$deps ${dir}/$dep" else deps="$deps src/include/${package}/$dep" fi done o=$(echo $file | sed s/\\.c$/.o/) lo=$(echo $file | sed s/\\.c$/.lo/) echo "${dir}/${o} ${dir}/${lo}:${deps}" } done done skalibs-2.9.1.0/tools/gen-sysdepsh.sh000077500000000000000000000013771355335115400174360ustar00rootroot00000000000000#!/bin/sh cat <&2 exit 1 } mkdirp=false symlink=false mode=0755 while getopts Dlm: name ; do case "$name" in D) mkdirp=true ;; l) symlink=true ;; m) mode=$OPTARG ;; ?) usage ;; esac done shift $(($OPTIND - 1)) test "$#" -eq 2 || usage src=$1 dst=$2 tmp="$dst.tmp.$$" case "$dst" in */) echo "$0: $dst ends in /" 1>&2 ; exit 1 ;; esac set -C set -e if $mkdirp ; then umask 022 case "$2" in */*) mkdir -p "${dst%/*}" ;; esac fi trap 'rm -f "$tmp"' EXIT INT QUIT TERM HUP umask 077 if $symlink ; then ln -s "$src" "$tmp" else cat < "$1" > "$tmp" chmod "$mode" "$tmp" fi mv -f "$tmp" "$dst" if test -d "$dst" ; then rm -f "$dst/$(basename $tmp)" if $symlink ; then mkdir "$tmp" ln -s "$src" "$tmp/$(basename $dst)" mv -f "$tmp/$(basename $dst)" "${dst%/*}" rmdir "$tmp" else echo "$0: $dst is a directory" 1>&2 exit 1 fi fi skalibs-2.9.1.0/tools/leapsecs.txt000066400000000000000000000006001355335115400170120ustar00rootroot00000000000000# # 1972-01-01 00:00:00 UTC was 1972-01-01 00:00:10 TAI. # +1972-06-30 +1972-12-31 +1973-12-31 +1974-12-31 +1975-12-31 +1976-12-31 +1977-12-31 +1978-12-31 +1979-12-31 +1981-06-30 +1982-06-30 +1983-06-30 +1985-06-30 +1987-12-31 +1989-12-31 +1990-12-31 +1992-06-30 +1993-06-30 +1994-06-30 +1995-12-31 +1997-06-30 +1998-12-31 +2005-12-31 +2008-12-31 +2012-06-30 +2015-06-30 +2016-12-31 skalibs-2.9.1.0/tools/make-leapsecs_table000077500000000000000000000012751355335115400202720ustar00rootroot00000000000000#!/command/execlineb -P # Compile convert-leapsecs.c, then use this to create # src/libstddjb/leapsecs_table.c define PREFIX ./tools backtick -n N { pipeline { redirfd -r 0 ${PREFIX}/leapsecs.txt ${PREFIX}/convert-leapsecs } wc -l } import -u N if { s6-echo "/* ISC license. */ /* This file has been generated by ./tools/make-leapsecs_table */ #include #include #include \"djbtime-internal.h\" unsigned int const leapsecs_table_len = ${N} ; static uint64_t const leapsecs_table_[${N}] =\n{" } if { redirfd -r 0 ${PREFIX}/leapsecs.txt ${PREFIX}/convert-leapsecs } s6-echo "} ;\nuint64_t const *const leapsecs_table = leapsecs_table_ ;"