pax_global_header00006660000000000000000000000064143333227570014523gustar00rootroot0000000000000052 comment=66bda012a7afb232877e315c91e21d6ddaffbdab libfixposix-0.5.1/000077500000000000000000000000001433332275700140665ustar00rootroot00000000000000libfixposix-0.5.1/.gitignore000066400000000000000000000001741433332275700160600ustar00rootroot00000000000000aclocal.m4 autom4te.cache/ config/aux/ config/m4/libtool.m4 config/m4/lt*.m4 build/ configure config.h.in* Makefile.in TAGS libfixposix-0.5.1/.travis.yml000066400000000000000000000023541433332275700162030ustar00rootroot00000000000000os: - freebsd - linux - osx dist: jammy osx_image: xcode14 language: c compiler: - gcc - clang jobs: fast_finish: true notifications: email: on_success: change on_failure: always irc: channels: - "chat.freenode.net#iolib" on_success: change on_failure: always use_notice: true skip_join: true before_install: - if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get update -qq; fi - if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get install -qq check; fi env: global: # Coverity Scan token - secure: "jJirBkZOyJ8KuYXMbjUpKem2FGaCsLBq7roP9oHs5mz8wIKENGB3i7pBe5USVLCwVAuqJ+TPjbfSo4nSnCIf5mLdJoNnyrq8FAYhSRzA/zl4COW6eN0Of9dgCOzcOriPY9rXUVbIapWoMogntnAS6MpmbiSxQCsq99VsIHq3TYk=" before_script: - source config/travis.cflags.sh script: - | autoreconf -f -i tests=disable; if [ "$TRAVIS_OS_NAME" = "linux" ]; then tests=enable; fi env CFLAGS="${WERR_CFLAGS}" ./configure --${tests}-tests make -j2 make check addons: coverity_scan: project: name: sionescu/libfixposix build_command_prepend: autoreconf -f -i && ./configure --enable-tests build_command: make -j4 branch_pattern: coverity_scan notification_email: sionescu@cddr.org libfixposix-0.5.1/LICENCE000066400000000000000000000024001433332275700150470ustar00rootroot00000000000000Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. libfixposix-0.5.1/Makefile.am000066400000000000000000000121221433332275700161200ustar00rootroot00000000000000# -*- makefile-automake -*- ######################################################################## # # # Global Automake variables # # # ######################################################################## ACLOCAL_AMFLAGS = -I config/m4 AM_CFLAGS = $(LFP_CFLAGS) -fvisibility=hidden AM_CPPFLAGS = -include $(top_builddir)/config.h \ -include $(top_srcdir)/src/lib/aux/macros.h \ -I$(top_srcdir)/src/include \ -I$(top_builddir)/src/include EXTRA_DIST = \ LICENCE \ README.md \ VERSION \ libfixposix.spec \ debian \ src/tests/lib \ $(wildcard $(top_srcdir)/src/tests/*.in) ######################################################################## # # # PKG-CONFIG # # # ######################################################################## pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = src/libfixposix.pc ######################################################################## # # # libfixposix.so # # # ######################################################################## lib_LTLIBRARIES = src/lib/libfixposix.la # Private headers, used only for internal definitions # The only purpose of this definition it to ensure that # «make dist» knows about them noinst_HEADERS = \ src/lib/aux/inlines.h \ src/lib/aux/macros.h \ src/lib/bitset.h \ src/lib/spawn.h include_HEADERS = src/include/lfp.h include_lfpdir = $(includedir)/lfp include_lfp_HEADERS = \ src/include/lfp/aux.h \ src/include/lfp/stdlib.h \ src/include/lfp/string.h \ src/include/lfp/strerror.h \ src/include/lfp/errno.h \ src/include/lfp/fcntl.h \ src/include/lfp/stat.h \ src/include/lfp/unistd.h \ src/include/lfp/ioctl.h \ src/include/lfp/mman.h \ src/include/lfp/select.h \ src/include/lfp/socket.h \ src/include/lfp/wait.h \ src/include/lfp/signal.h \ src/include/lfp/spawn.h \ src/include/lfp/dirent.h \ $(top_builddir)/src/include/lfp/time.h \ src/include/lfp/resource.h \ src/include/lfp/sendfile.h \ src/include/lfp/syslog.h \ src/include/lfp/buildinfo.h # src/include/lfp/signalfd.h src_lib_libfixposix_la_SOURCES = \ src/libfixposix.libtool \ src/lib/stdlib.c \ src/lib/string.c \ src/lib/strerror.c \ src/lib/errno.c \ src/lib/fcntl.c \ src/lib/stat.c \ src/lib/unistd.c \ src/lib/ioctl.c \ src/lib/mman.c \ src/lib/select.c \ src/lib/socket.c \ src/lib/wait.c \ src/lib/signal.c \ src/lib/spawnattr.c \ src/lib/bitset.c \ src/lib/spawn_file_actions.c \ src/lib/spawn.c \ src/lib/dirent.c \ src/lib/time.c \ src/lib/resource.c \ src/lib/sendfile.c \ src/lib/syslog.c \ src/lib/buildinfo.c # src/lib/install_signalfd.c src_lib_libfixposix_la_DEPENDENCIES = \ src/libfixposix.libtool src_lib_libfixposix_la_LIBADD = $(LFP_LIBS) src_lib_libfixposix_la_LDFLAGS = $(LFP_LDFLAGS) -no-undefined \ -version-info `@AWK@ '/^Version:/ { print $$2 }' $(top_srcdir)/src/libfixposix.libtool` ######################################################################## # # # TESTS # # # ######################################################################## if TESTS LOG_DRIVER = env AM_TAP_AWK='$(AWK)' \ TOP_SRCDIR=$(top_srcdir) \ TOP_BUILDDIR=$(top_builddir) \ $(SHELL) $(top_srcdir)/config/aux/tap-driver.sh compile_tests = \ src/tests/buildinfo run_tests = \ src/tests/spawn \ src/tests/select \ src/tests/mkstemp check_PROGRAMS = $(compile_tests) $(run_tests) check_SCRIPTS = \ src/tests/buildinfo.bats # Bats tests must be created by /.configure to get the correct path of # the Bats interpreter, but the configure script fails to preserve the # execute bit, so we restore it here. %.bats: %.bats.in $(top_builddir)/Makefile sed 's:\@BATSPATH\@:$(BATSPATH):' < $< > $@ chmod +x $@ TESTS = ${run_tests} ${check_SCRIPTS} XFAIL_TESTS = src_tests_buildinfo_SOURCES = src/tests/buildinfo.c src_tests_buildinfo_CFLAGS = @CHECK_CFLAGS@ src_tests_buildinfo_LDADD = @CHECK_LIBS@ $(top_builddir)/src/lib/libfixposix.la src_tests_spawn_SOURCES = src/tests/spawn.c src_tests_spawn_CFLAGS = @CHECK_CFLAGS@ src_tests_spawn_LDADD = @CHECK_LIBS@ $(top_builddir)/src/lib/libfixposix.la src_tests_select_SOURCES = src/tests/select.c src_tests_select_CFLAGS = @CHECK_CFLAGS@ src_tests_select_LDADD = @CHECK_LIBS@ $(top_builddir)/src/lib/libfixposix.la src_tests_mkstemp_SOURCES = src/tests/mkstemp.c src_tests_mkstemp_CFLAGS = @CHECK_CFLAGS@ src_tests_mkstemp_LDADD = @CHECK_LIBS@ $(top_builddir)/src/lib/libfixposix.la endif libfixposix-0.5.1/README.md000066400000000000000000000027711433332275700153540ustar00rootroot00000000000000[![Build Status](https://app.travis-ci.com/sionescu/libfixposix.svg?branch=master)](https://app.travis-ci.com/sionescu/libfixposix) [![Coverity Scan Build Status](https://scan.coverity.com/projects/113/badge.svg)](https://scan.coverity.com/projects/sionescu-libfixposix) The purpose of libfixposix is to offer replacements for parts of POSIX whose behaviour is inconsistent across *NIX flavours. * Compilation If you've downloaded this library through git, you'll first need to generate the ./configure script; in order to do that you need to have at least autoconf-2.67, automake-1.10, libtool-2.2.6b, pkg-config and check (for the test suite: see http://check.sf.net) then run this inside the top directory: > autoreconf -i -f For best results use a dedicated build directory instead of running the configure script directly in the source tree: > mkdir build ; cd build > ../libfixposix/configure > make > make install On Linux, you might need to run «ldconfig» as superuser after installing, otherwise the *nix linker won't be able to find the library * Installation through distro repositories For a certain number of Linux distributions, there are officially supported repositories. You can find the instructions to configure the binary repository at https://software.opensuse.org/download.html?project=home:sionescu&package=libfixposix. Just click on your distribution, if present. http://article.gmane.org/gmane.lisp.iolib.devel/422 also has a set of older instructions about installing on Debian-based distros. libfixposix-0.5.1/VERSION000066400000000000000000000000061433332275700151320ustar00rootroot000000000000000.5.1 libfixposix-0.5.1/config/000077500000000000000000000000001433332275700153335ustar00rootroot00000000000000libfixposix-0.5.1/config/m4/000077500000000000000000000000001433332275700156535ustar00rootroot00000000000000libfixposix-0.5.1/config/m4/ax_pthread.m4000066400000000000000000000260621433332275700202420ustar00rootroot00000000000000# =========================================================================== # http://www.gnu.org/software/autoconf-archive/ax_pthread.html # =========================================================================== # # SYNOPSIS # # AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) # # DESCRIPTION # # This macro figures out how to build C programs using POSIX threads. It # sets the PTHREAD_LIBS output variable to the threads library and linker # flags, and the PTHREAD_CFLAGS output variable to any special C compiler # flags that are needed. (The user can also force certain compiler # flags/libs to be tested by setting these environment variables.) # # Also sets PTHREAD_CC to any special C compiler that is needed for # multi-threaded programs (defaults to the value of CC otherwise). (This # is necessary on AIX to use the special cc_r compiler alias.) # # NOTE: You are assumed to not only compile your program with these flags, # but also link it with them as well. e.g. you should link with # $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS # # If you are only building threads programs, you may wish to use these # variables in your default LIBS, CFLAGS, and CC: # # LIBS="$PTHREAD_LIBS $LIBS" # CFLAGS="$CFLAGS $PTHREAD_CFLAGS" # CC="$PTHREAD_CC" # # In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant # has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name # (e.g. PTHREAD_CREATE_UNDETACHED on AIX). # # ACTION-IF-FOUND is a list of shell commands to run if a threads library # is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it # is not found. If ACTION-IF-FOUND is not specified, the default action # will define HAVE_PTHREAD. # # Please let the authors know if this macro fails on any platform, or if # you have any other suggestions or comments. This macro was based on work # by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help # from M. Frigo), as well as ac_pthread and hb_pthread macros posted by # Alejandro Forero Cuervo to the autoconf macro repository. We are also # grateful for the helpful feedback of numerous users. # # LICENSE # # Copyright (c) 2008 Steven G. Johnson # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation, either version 3 of the License, or (at your # option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program. If not, see . # # As a special exception, the respective Autoconf Macro's copyright owner # gives unlimited permission to copy, distribute and modify the configure # scripts that are the output of Autoconf when processing the Macro. You # need not follow the terms of the GNU General Public License when using # or distributing such scripts, even though portions of the text of the # Macro appear in them. The GNU General Public License (GPL) does govern # all other use of the material that constitutes the Autoconf Macro. # # This special exception to the GPL applies to versions of the Autoconf # Macro released by the Autoconf Archive. When you make and distribute a # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. #serial 11 AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) AC_DEFUN([AX_PTHREAD], [ AC_REQUIRE([AC_CANONICAL_HOST]) AC_LANG_SAVE AC_LANG_C ax_pthread_ok=no # We used to check for pthread.h first, but this fails if pthread.h # requires special compiler flags (e.g. on True64 or Sequent). # It gets checked for in the link test anyway. # First of all, check if the user has set any of the PTHREAD_LIBS, # etcetera environment variables, and if threads linking works using # them: if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" save_LIBS="$LIBS" LIBS="$PTHREAD_LIBS $LIBS" AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) AC_TRY_LINK_FUNC(pthread_join, ax_pthread_ok=yes) AC_MSG_RESULT($ax_pthread_ok) if test x"$ax_pthread_ok" = xno; then PTHREAD_LIBS="" PTHREAD_CFLAGS="" fi LIBS="$save_LIBS" CFLAGS="$save_CFLAGS" fi # We must check for the threads library under a number of different # names; the ordering is very important because some systems # (e.g. DEC) have both -lpthread and -lpthreads, where one of the # libraries is broken (non-POSIX). # Create a list of thread flags to try. Items starting with a "-" are # C compiler flags, and other items are library names, except for "none" # which indicates that we try without any flags at all, and "pthread-config" # which is a program returning the flags for the Pth emulation library. ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" # The ordering *is* (sometimes) important. Some notes on the # individual items follow: # pthreads: AIX (must check this before -lpthread) # none: in case threads are in libc; should be tried before -Kthread and # other compiler flags to prevent continual compiler warnings # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) # -pthreads: Solaris/gcc # -mthreads: Mingw32/gcc, Lynx/gcc # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it # doesn't hurt to check since this sometimes defines pthreads too; # also defines -D_REENTRANT) # ... -mt is also the pthreads flag for HP/aCC # pthread: Linux, etcetera # --thread-safe: KAI C++ # pthread-config: use pthread-config program (for GNU Pth library) case "${host_cpu}-${host_os}" in *solaris*) # On Solaris (at least, for some versions), libc contains stubbed # (non-functional) versions of the pthreads routines, so link-based # tests will erroneously succeed. (We need to link with -pthreads/-mt/ # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather # a function called by this macro, so we could check for that, but # who knows whether they'll stub that too in a future libc.) So, # we'll just look for -pthreads and -lpthread first: ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags" ;; *-darwin*) ax_pthread_flags="-pthread $ax_pthread_flags" ;; esac if test x"$ax_pthread_ok" = xno; then for flag in $ax_pthread_flags; do case $flag in none) AC_MSG_CHECKING([whether pthreads work without any flags]) ;; -*) AC_MSG_CHECKING([whether pthreads work with $flag]) PTHREAD_CFLAGS="$flag" ;; pthread-config) AC_CHECK_PROG(ax_pthread_config, pthread-config, yes, no) if test x"$ax_pthread_config" = xno; then continue; fi PTHREAD_CFLAGS="`pthread-config --cflags`" PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" ;; *) AC_MSG_CHECKING([for the pthreads library -l$flag]) PTHREAD_LIBS="-l$flag" ;; esac save_LIBS="$LIBS" save_CFLAGS="$CFLAGS" LIBS="$PTHREAD_LIBS $LIBS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" # Check for various functions. We must include pthread.h, # since some functions may be macros. (On the Sequent, we # need a special flag -Kthread to make this header compile.) # We check for pthread_join because it is in -lpthread on IRIX # while pthread_create is in libc. We check for pthread_attr_init # due to DEC craziness with -lpthreads. We check for # pthread_cleanup_push because it is one of the few pthread # functions on Solaris that doesn't have a non-functional libc stub. # We try pthread_create on general principles. AC_TRY_LINK([#include static void routine(void* a) {a=0;} static void* start_routine(void* a) {return a;}], [pthread_t th; pthread_attr_t attr; pthread_create(&th,0,start_routine,0); pthread_join(th, 0); pthread_attr_init(&attr); pthread_cleanup_push(routine, 0); pthread_cleanup_pop(0); ], [ax_pthread_ok=yes]) LIBS="$save_LIBS" CFLAGS="$save_CFLAGS" AC_MSG_RESULT($ax_pthread_ok) if test "x$ax_pthread_ok" = xyes; then break; fi PTHREAD_LIBS="" PTHREAD_CFLAGS="" done fi # Various other checks: if test "x$ax_pthread_ok" = xyes; then save_LIBS="$LIBS" LIBS="$PTHREAD_LIBS $LIBS" save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. AC_MSG_CHECKING([for joinable pthread attribute]) attr_name=unknown for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do AC_TRY_LINK([#include ], [int attr=$attr; return attr;], [attr_name=$attr; break]) done AC_MSG_RESULT($attr_name) if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name, [Define to necessary symbol if this constant uses a non-standard name on your system.]) fi AC_MSG_CHECKING([if more special flags are required for pthreads]) flag=no case "${host_cpu}-${host_os}" in *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";; *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; esac AC_MSG_RESULT(${flag}) if test "x$flag" != xno; then PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" fi LIBS="$save_LIBS" CFLAGS="$save_CFLAGS" # More AIX lossage: must compile with xlc_r or cc_r if test x"$GCC" != xyes; then AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC}) else PTHREAD_CC=$CC fi else PTHREAD_CC="$CC" fi AC_SUBST(PTHREAD_LIBS) AC_SUBST(PTHREAD_CFLAGS) AC_SUBST(PTHREAD_CC) # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: if test x"$ax_pthread_ok" = xyes; then ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) : else ax_pthread_ok=no $2 fi AC_LANG_RESTORE ])dnl AX_PTHREAD libfixposix-0.5.1/config/m4/custom_checks.m4000066400000000000000000000106771433332275700207620ustar00rootroot00000000000000# -*- Autoconf -*- AC_DEFUN([LFP_TESTS_CHECK], [ AC_ARG_ENABLE([tests], [AS_HELP_STRING([--enable-tests], [enable test suite using CHECK @<:@default=no@:>@])], [], [enable_tests=no]) AS_CASE($enable_tests, [yes], [PKG_CHECK_MODULES([CHECK], [check >= 0.9.4]) AC_SUBST([CHECK_CFLAGS]) AC_SUBST([CHECK_LIBS])], [no], [], AC_MSG_ERROR( [--enable-tests was given an illegal value: "$enable_tests"]) ) AM_CONDITIONAL(TESTS, test x$enable_tests = xyes) ]) AC_DEFUN([LFP_INIT], [ # Build flags LFP_CFLAGS="" AC_SUBST(LFP_CFLAGS) LFP_LDFLAGS="" AC_SUBST(LFP_LDFLAGS) LFP_LIBS="" AC_SUBST(LFP_LIBS) # Version Info major=`echo $1 | cut -d . -f 1` AC_SUBST(LFP_MAJOR_VERSION, $major) minor=`echo $1 | cut -d . -f 2` AC_SUBST(LFP_MINOR_VERSION, $minor) micro=`echo $1 | cut -d . -f 3` AC_SUBST(LFP_MICRO_VERSION, $micro) AC_CHECK_PROG([GIT], [git], [yes]) if test "x$ac_cv_prog_GIT" = xyes then vcsid=`git rev-parse --short HEAD` fi AC_SUBST(LFP_VCSID, $vcsid) ]) AC_DEFUN([LFP_SYS_PLATFORM_SPECIFIC_DEFINITIONS], [ case "$host_os" in linux*) LFP_CFLAGS="$LFP_CFLAGS -D_XOPEN_SOURCE=700 -D_GNU_SOURCE=1" ;; freebsd*) LFP_CFLAGS="$LFP_CFLAGS -D_XOPEN_SOURCE=700 -D__BSD_VISIBLE=1" ;; netbsd*) LFP_CFLAGS="$LFP_CFLAGS -D_XOPEN_SOURCE=700 -D_NETBSD_SOURCE=1" ;; openbsd*) LFP_CFLAGS="$LFP_CFLAGS -D__BSD_VISIBLE=1" ;; darwin*) LFP_CFLAGS="$LFP_CFLAGS -D_DARWIN_C_SOURCE=1" ;; sunos* | solaris*) LFP_CFLAGS="$LFP_CFLAGS -D_XOPEN_SOURCE=700 -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS" ;; esac ]) AC_DEFUN([LFP_SYS_LARGEFILE], [ LFP_GETCONF_UNDEF([LFS_CFLAGS], [LFS_CFLAGS]) LFP_GETCONF_UNDEF([LFS_LDFLAGS], [LFS_LDFLAGS]) LFP_GETCONF_UNDEF([LFS_LIBS], [LFS_LIBS]) ]) AC_DEFUN([LFP_CHECK_POSIX_REALTIME_CLOCK_TYPES], [ LFP_REQUIRE_TYPE([clockid_t], [sys/time.h time.h]) AC_SUBST([HAVE_CLOCKID_T], [1]) LFP_REQUIRE_DECL([CLOCK_REALTIME], [sys/time.h time.h]) LFP_REQUIRE_DECL([CLOCK_MONOTONIC], [sys/time.h time.h]) ]) AC_DEFUN([LFP_CHECK_POSIX_REALTIME_CLOCK_ALTERNATIVES], [ case "$host_os" in darwin*) LFP_REQUIRE_HEADERS([mach/mach.h mach/clock.h]) LFP_REQUIRE_FUNCS([host_get_clock_service clock_get_attributes]) dnl LFP_REQUIRE_DECL([CLOCK_GET_TIME_RES], [mach/mach.h mach/clock.h]) dnl LFP_REQUIRE_DECL([CALENDAR_CLOCK], [mach/mach.h mach/clock.h]) dnl LFP_REQUIRE_DECL([REALTIME_CLOCK], [mach/mach.h mach/clock.h]) ;; *) AC_MSG_ERROR([clock_gettime not found and no workaround available]) ;; esac ]) AC_DEFUN([LFP_REQUIRE_MONOTONIC_CLOCK], [ LFP_SEARCH_LIBS([clock_gettime], [], [ AC_SUBST([HAVE_CLOCK_GETTIME], [1]) LFP_CHECK_POSIX_REALTIME_CLOCK_TYPES AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [We have the function clock_gettime()])], [AC_SUBST([HAVE_CLOCK_GETTIME], [0]) AC_SUBST([HAVE_CLOCKID_T], [0]) LFP_CHECK_POSIX_REALTIME_CLOCK_ALTERNATIVES], [rt]) ]) AC_DEFUN([LFP_REQUIRE_GETPEEREID], [ AC_CHECK_FUNCS([getpeereid], [AC_DEFINE([HAVE_GETPEEREID], [1], [We have the function getpeereid()])], AC_CHECK_FUNCS([getpeerucred], [LFP_REQUIRE_HEADERS([ucred.h]) AC_DEFINE([HAVE_GETPEERUCRED], [1], [We have the function getpeerucred()])], [LFP_REQUIRE_DECL([SO_PEERCRED], [sys/types.h sys/socket.h])])) ]) AC_DEFUN([LFP_ARG_ENABLE_EMULATED_SIGNALFD], [ AC_ARG_ENABLE([emulated-signalfd], [AS_HELP_STRING([--enable-emulated-signalfd={yes|no|check}], [Use emulated signalfd @<:@default=check@:>@])], [], [enable_emulated_signalfd=check]) AS_CASE($enable_emulated_signalfd, [yes], [AC_DEFINE(HAVE_EMULATED_SIGNALFD, 1, [Whether to use signalfd emulation]) AC_SUBST(HAVE_EMULATED_SIGNALFD, 1) ], [check], [if test x"$ac_cv_header_sys_signalfd_h" = xyes ; then AC_DEFINE(HAVE_EMULATED_SIGNALFD, 0, [Whether to use signalfd emulation]) AC_SUBST(HAVE_EMULATED_SIGNALFD, 0) else AC_DEFINE(HAVE_EMULATED_SIGNALFD, 1, [Whether to use signalfd emulation]) AC_SUBST(HAVE_EMULATED_SIGNALFD, 1) fi], [no], [if test x"$ac_cv_header_sys_signalfd_h" = xyes ; then AC_DEFINE(HAVE_EMULATED_SIGNALFD, 0, [Whether to use signalfd emulation]) AC_SUBST(HAVE_EMULATED_SIGNALFD, 0) else AC_MSG_FAILURE([signalfd emulation was disabled although is absent]) fi], [AC_MSG_FAILURE( [--enable-emulated-signalfd was given an illegal value: "$enable_emulated_signalfd"])]) ]) libfixposix-0.5.1/config/m4/utils.m4000066400000000000000000000047641433332275700172700ustar00rootroot00000000000000# -*- Autoconf -*- AC_DEFUN([LFP_SAVE_FLAGS], [ _lfp_saved_cppflags_$1=$CPPFLAGS _lfp_saved_cflags_$1=$CFLAGS _lfp_saved_ldflags_$1=$LDFLAGS _lfp_saved_libs_$1=$LIBS CPPFLAGS="$LFP_CPPFLAGS" CFLAGS="$LFP_CFLAGS" LDFLAGS="$LFP_LDFLAGS" LIBS="$LFP_LIBS" ]) AC_DEFUN([LFP_RESTORE_FLAGS], [ CPPFLAGS="$_lfp_saved_cppflags_$1" CFLAGS="$_lfp_saved_cflags_$1" LDFLAGS="$_lfp_saved_ldflags_$1" LIBS="$_lfp_saved_libs_$1" ]) # Check for some headers and print an error if not found AC_DEFUN([LFP_REQUIRE_HEADERS], [ LFP_SAVE_FLAGS(AS_TR_CPP($1)) AC_CHECK_HEADERS($1,,AC_MSG_FAILURE([Cannot find header $ac_header])) LFP_RESTORE_FLAGS(AS_TR_CPP($1)) ]) # Check for a function and print an error if not found AC_DEFUN([LFP_REQUIRE_FUNCS], [ LFP_SAVE_FLAGS(AS_TR_CPP($1)) AC_CHECK_FUNCS($1,,AC_MSG_FAILURE([Cannot find function $ac_func])) LFP_RESTORE_FLAGS(AS_TR_CPP($1)) ]) # Check for a type and print an error if not found AC_DEFUN([LFP_REQUIRE_TYPE], [ LFP_SAVE_FLAGS(AS_TR_CPP($1)) AC_CHECK_TYPES($1,,AC_MSG_FAILURE([Cannot find type $1 in $2]), [m4_foreach_w([header], [$2], [[#]include [<]header[>] ])]) LFP_RESTORE_FLAGS(AS_TR_CPP($1)) ]) # Check for a declaration and print an error if not found AC_DEFUN([LFP_REQUIRE_DECL], [ LFP_SAVE_FLAGS(AS_TR_CPP($1)) AC_CHECK_DECL($1,,AC_MSG_FAILURE([Cannot find $1 in <$2>]), [m4_foreach_w([header], [$2], [[#]include [<]header[>] ])]) LFP_RESTORE_FLAGS(AS_TR_CPP($1)) ]) # Check for a library and print an error if not found AC_DEFUN([LFP_SEARCH_LIBS], [ LFP_SAVE_FLAGS(AS_TR_CPP($1)) AC_SEARCH_LIBS($1,$2,$3 [if test -n "$LIBS"; then LFP_LIBS="$LFP_LIBS $LIBS"; fi], m4_default_nblank_quoted([$4],AC_MSG_FAILURE([Cannot find $1 in <$2>]))) LFP_RESTORE_FLAGS(AS_TR_CPP($1)) ]) AC_DEFUN([LFP_REQUIRE_PROG], [ AC_CHECK_PROG($1, $2, [yes]) if test "x$ac_cv_prog_$1" != xyes then AC_MSG_FAILURE([Program $2 not found]) fi ]) # Check for a declaration and print an error if not found # Syntax: LFP_GETCONF(VARIABLE, SYSTEM_VAR, # ACTION-IF-FOUND, ACTION-IF-NOT-FOUND) AC_DEFUN([LFP_GETCONF], [ $1=`(getconf $2) 2>/dev/null` AC_SUBST($1) if test $? -eq 0 ; then : ; $3 else : ; $4 fi ]) # Check for a declaration and print an error if not found or is undefined # Syntax: LFP_GETCONF(VARIABLE, SYSTEM_VAR, # ACTION-IF-FOUND, ACTION-IF-NOT-FOUND) AC_DEFUN([LFP_GETCONF_UNDEF], [ $1=`(getconf $2) 2>/dev/null` AC_SUBST($1) if test $? -eq 0 && test x"$$1" != xundefined ; then : ; $3 else : ; $4 fi ]) libfixposix-0.5.1/config/travis.cflags.sh000066400000000000000000000004011433332275700204300ustar00rootroot00000000000000#!/bin/bash WERR_CFLAGS="\ -Werror=implicit-function-declaration \ -Werror=varargs \ " WERR_CFLAGS_OSX="\ -Werror=unguarded-availability-new \ " if [ "${TRAVIS_OS_NAME}" = "osx" ]; then WERR_CFLAGS+=" ${WERR_CFLAGS_OSX}"; fi export WERR_CFLAGS libfixposix-0.5.1/configure.ac000066400000000000000000000070201433332275700163530ustar00rootroot00000000000000dnl Process this file with autoconf to produce a configure script. dnl dnl This file is free software; as a special exception the author gives dnl unlimited permission to copy and/or distribute it, with or without dnl modifications, as long as this notice is preserved. dnl dnl This program is distributed in the hope that it will be useful, but dnl WITHOUT ANY WARRANTY, to the extent permitted by law; without even the dnl implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. dnl Minimum Autoconf version required. AC_PREREQ([2.67]) dnl Ensures that ./configure will be automatically re-run when VERSION changes. m4_include([VERSION]) AC_INIT([LibFixPOSIX], m4_esyscmd_s([cat VERSION]), [iolib-devel@common-lisp.net], [libfixposix], [https://github.com/sionescu/libfixposix]) AC_COPYRIGHT([Copyright © 2010-2020 Stelian Ionescu ]) AC_MSG_NOTICE([srcdir: $srcdir]) AC_MSG_NOTICE([builddir: $builddir]) AC_MSG_NOTICE([CPPFLAGS: $CPPFLAGS]) AC_MSG_NOTICE([CFLAGS: $CFLAGS]) AC_MSG_NOTICE([LDFLAGS: $LDFLAGS]) AS_IF([test "`/bin/pwd`" = "`cd $srcdir; /bin/pwd`"], [ AC_MSG_WARN([you should configure in a separate build directory]) ]) AC_CONFIG_HEADERS([config.h]) dnl Where to generate output; srcdir location. AC_CONFIG_SRCDIR([src/lib/spawn.c]) dnl Auxiliary M4 macros AC_CONFIG_MACRO_DIR([config/m4]) dnl Must come before AM_INIT_AUTOMAKE. AC_CONFIG_AUX_DIR([config/aux]) AM_INIT_AUTOMAKE([1.10 foreign silent-rules subdir-objects color-tests parallel-tests]) dnl Have Kbuild-like build output AM_SILENT_RULES([yes]) dnl Contains replacement functions dnl AC_CONFIG_LIBOBJ_DIR([lib]) AC_LANG([C]) dnl Checks for programs. dnl We need a C compiler. AC_PROG_CC_C99 AC_PROG_AWK dnl And we need libtool for building the shared library LT_INIT([pic-only disable-static disable-fast-install]) LT_PREREQ([2.2.6]) AC_SUBST([PACKAGE_VERSION]) LFP_INIT($PACKAGE_VERSION) dnl Checks for programs LFP_REQUIRE_PROG([GETCONF], [getconf]) LFP_REQUIRE_PROG([PKGCONFIG], [pkg-config]) dnl Set compiler & linker flags LFP_SYS_PLATFORM_SPECIFIC_DEFINITIONS AX_PTHREAD LFP_SYS_LARGEFILE dnl Checks for C99 & POSIX headers AC_HEADER_ASSERT AC_HEADER_STDBOOL LFP_REQUIRE_HEADERS([stdlib.h stdio.h string.h errno.h time.h]) LFP_REQUIRE_HEADERS([sys/types.h unistd.h fcntl.h sys/signal.h signal.h]) LFP_CFLAGS="$LFP_CFLAGS $LFS_CFLAGS $PTHREAD_CFLAGS" LFP_LDFLAGS="$LFP_LDFLAGS $LFS_LDFLAGS" LFP_LIBS="$LFP_LIBS $PTHREAD_LIBS $LFS_LIBS" dnl Checks for declarations LFP_REQUIRE_DECL([TIOCSCTTY], [sys/ioctl.h sys/termios.h]) LFP_REQUIRE_DECL([NSIG], [sys/types.h sys/signal.h signal.h]) LFP_REQUIRE_DECL([IP_HDRINCL], [sys/types.h sys/socket.h netinet/in.h]) dnl Checks for non-standard headers AC_CHECK_HEADER([sys/signalfd.h]) dnl Checks for functions AC_CHECK_FUNCS([__xpg_strerror_r strnlen strndup clearenv mkostemp]) LFP_REQUIRE_FUNCS([strtok_r]) LFP_SEARCH_LIBS([socket], [socket nsl]) AC_CHECK_FUNCS([accept4 pipe2 sendfile pselect ptsname_r]) LFP_REQUIRE_FUNCS([vsyslog ptsname posix_openpt]) # OSX 10.12 added clock_gettime to libc # TODO(2025): Remove compat functions LFP_REQUIRE_MONOTONIC_CLOCK LFP_REQUIRE_GETPEEREID dnl Checks for types dnl Configuration switches dnl LFP_ARG_ENABLE_EMULATED_SIGNALFD dnl Test suite. LFP_TESTS_CHECK AC_SUBST([BATSPATH], [$srcdir/src/tests/lib]) AC_CONFIG_FILES([Makefile libfixposix.spec src/libfixposix.pc src/lib/buildinfo.c src/include/lfp/time.h]) AC_REQUIRE_AUX_FILE([tap-driver.sh]) AC_OUTPUT libfixposix-0.5.1/debian/000077500000000000000000000000001433332275700153105ustar00rootroot00000000000000libfixposix-0.5.1/debian/changelog000066400000000000000000000042341433332275700171650ustar00rootroot00000000000000libfixposix (0.5.1) unstable; urgency=low * Release 0.5.1 -- Stelian Ionescu Thu, 10 Nov 2022 20:00:00 -0400 libfixposix (0.5.0) unstable; urgency=low * Release 0.5.0 -- Stelian Ionescu Wed, 9 Nov 2022 14:00:00 -0400 libfixposix (0.4.3) unstable; urgency=low * Release 0.4.3 -- Stelian Ionescu Mon, 19 Feb 2018 21:00:00 +0100 libfixposix (0.4.2) unstable; urgency=low * Release 0.4.2 -- Stelian Ionescu Sat, 17 Feb 2018 15:00:00 +0100 libfixposix (0.4.1) unstable; urgency=low * Release 0.4.1 -- Stelian Ionescu Thu, 23 Jun 2016 21:00:00 +0200 libfixposix (0.4.0) unstable; urgency=low * Release 0.4.0 -- Stelian Ionescu Tue, 3 May 2016 20:00:00 +0200 libfixposix (0.3.0-1) unstable; urgency=low * Release 0.3.0 -- Stelian Ionescu Tue, 5 Mar 2013 12:00:00 +0200 libfixposix (0.2.4-3) unstable; urgency=low * Add symbols file -- Stelian Ionescu Tue, 26 Jun 2012 20:48:00 +0200 libfixposix (0.2.4-2) unstable; urgency=low * Update copyright file -- Stelian Ionescu Tue, 26 Jun 2012 20:23:00 +0200 libfixposix (0.2.4-1) unstable; urgency=low * Increase epoch to 1 -- Stelian Ionescu Tue, 26 Jun 2012 19:17:00 +0200 libfixposix (0.2.4-1) unstable; urgency=low * Release 0.2.4 -- Stelian Ionescu Wed, 12 Jun 2012 16:45:00 +0200 libfixposix (0.2.3-1) unstable; urgency=low * Release 0.2.3 -- Stelian Ionescu Wed, 12 Jun 2012 15:57:00 +0200 libfixposix (0.2.2-1) unstable; urgency=low * Release 0.2.2 -- Stelian Ionescu Wed, 30 May 2012 18:13:00 +0200 libfixposix (0.2.1-1) unstable; urgency=low * Release 0.2.1 -- Stelian Ionescu Fri, 25 Nov 2011 23:08:12 +0200 libfixposix (0.2-1) unstable; urgency=low * Release 0.2 -- Stelian Ionescu Mon, 14 Nov 2011 15:52:33 +0200 libfixposix (0.1-1) unstable; urgency=low * Initial package -- Stelian Ionescu Tue, 6 Sep 2011 01:55:44 +0200 libfixposix-0.5.1/debian/compat000066400000000000000000000000031433332275700165070ustar00rootroot0000000000000011 libfixposix-0.5.1/debian/control000066400000000000000000000016111433332275700167120ustar00rootroot00000000000000Source: libfixposix Priority: optional Section: libdevel Maintainer: Stelian Ionescu Standards-Version: 4.5.0 Build-Depends: debhelper (>= 11), pkg-config, check (>= 0.10.0) Homepage: https://common-lisp.net/project/iolib Vcs-Browser: https://github.com/sionescu/libfixposix Vcs-Git: https://github.com/sionescu/libfixposix.git Package: libfixposix-dev Architecture: any Depends: libfixposix4 (= ${binary:Version}), libc6-dev, ${misc:Depends} Description: Development files for LibFixPOSIX . This package contains header files and static archives. Package: libfixposix4 Section: libs Architecture: any Multi-Arch: same Depends: ${shlibs:Depends}, ${misc:Depends} Description: Thin wrapper over POSIX syscalls The purpose of libfixposix is to offer replacements for parts of POSIX whose behaviour is inconsistent across *NIX flavours . This package contains the shared library. libfixposix-0.5.1/debian/copyright000066400000000000000000000032711433332275700172460ustar00rootroot00000000000000Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: LibFixPOSIX Upstream-Contact: Stelian Ionescu Source: https://github.com/sionescu/libfixposix/releases/ Files: * Copyright: 2010-2022 Stelian Ionescu 2010 Francois-Rene Rideau 2011 David Lichteblau License: BSL License: BSL Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: . The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. . 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. libfixposix-0.5.1/debian/docs000066400000000000000000000000121433332275700161540ustar00rootroot00000000000000README.md libfixposix-0.5.1/debian/libfixposix-dev.install000066400000000000000000000001061433332275700220110ustar00rootroot00000000000000usr/include/* usr/lib/*/lib*.a usr/lib/*/lib*.so usr/lib/*/pkgconfig/ libfixposix-0.5.1/debian/libfixposix4.install000066400000000000000000000000241433332275700213200ustar00rootroot00000000000000usr/lib/*/lib*.so.* libfixposix-0.5.1/debian/libfixposix4.symbols000066400000000000000000000063541433332275700213560ustar00rootroot00000000000000libfixposix.so.4 libfixposix4 #MINVER# lfp_accept@Base 0.3.0 lfp_buildinfo@Base 0.4.3 lfp_clearenv@Base 0.3.0 lfp_clock_getres@Base 0.3.0 lfp_clock_gettime@Base 0.3.0 lfp_clock_settime@Base 0.3.0 lfp_closedir@Base 0.4.0 lfp_closelog@Base 0.3.0 lfp_cmsg_data@Base 0.3.0 lfp_cmsg_firsthdr@Base 0.3.0 lfp_cmsg_len@Base 0.3.0 lfp_cmsg_nxthdr@Base 0.3.0 lfp_cmsg_space@Base 0.3.0 lfp_creat@Base 0.3.0 lfp_errno@Base 0.3.0 lfp_execve@Base 0.3.0 lfp_execvpe@Base 0.3.0 lfp_fd_clr@Base 0.3.0 lfp_fd_isset@Base 0.3.0 lfp_fd_set@Base 0.3.0 lfp_fd_zero@Base 0.3.0 lfp_fstat@Base 0.3.0 lfp_ftruncate@Base 0.3.0 lfp_get_environ@Base 0.3.0 lfp_getpath@Base 0.3.0 lfp_getpeereid@Base 0.3.0 lfp_getrlimit@Base 0.3.0 lfp_is_fd_cloexec@Base 0.3.0 lfp_is_fd_nonblock@Base 0.3.0 lfp_is_fd_open@Base 0.3.0 lfp_isblk@Base 0.3.0 lfp_ischr@Base 0.3.0 lfp_isdir@Base 0.3.0 lfp_isfifo@Base 0.3.0 lfp_islnk@Base 0.3.0 lfp_isreg@Base 0.3.0 lfp_issock@Base 0.3.0 lfp_log_mask@Base 0.3.0 lfp_log_upto@Base 0.3.0 lfp_lseek@Base 0.3.0 lfp_lstat@Base 0.3.0 lfp_mkostemp@Base 0.3.0 lfp_mkstemp@Base 0.3.0 lfp_mmap@Base 0.3.0 lfp_munmap@Base 0.3.0 lfp_nice_k@Base 0.5.0 lfp_open@Base 0.3.0 lfp_open_k@Base 0.5.0 lfp_opendir@Base 0.4.0 lfp_openlog@Base 0.3.0 lfp_openpt@Base 0.3.0 lfp_parse_memsize@Base 0.3.0 lfp_pipe@Base 0.3.0 lfp_pread@Base 0.3.0 lfp_ptsname@Base 0.3.0 lfp_pwrite@Base 0.3.0 lfp_readdir@Base 0.3.0 lfp_rewinddir@Base 0.4.0 lfp_seekdir@Base 0.4.0 lfp_select@Base 0.3.0 lfp_sendfile@Base 0.3.0 lfp_set_environ@Base 0.3.0 lfp_set_errno@Base 0.3.0 lfp_set_fd_cloexec@Base 0.3.0 lfp_set_fd_nonblock@Base 0.3.0 lfp_setlogmask@Base 0.3.0 lfp_setrlimit@Base 0.3.0 lfp_sig_dfl@Base 0.3.0 lfp_sig_err@Base 0.3.0 lfp_sig_hold@Base 0.3.0 lfp_sig_ign@Base 0.3.0 lfp_sigrtmax@Base 0.3.0 lfp_sigrtmin@Base 0.3.0 lfp_socket@Base 0.3.0 lfp_spawn@Base 0.3.0 lfp_spawn_file_actions_addclose@Base 0.3.0 lfp_spawn_file_actions_adddup2@Base 0.3.0 lfp_spawn_file_actions_addkeep@Base 0.4.0 lfp_spawn_file_actions_addopen@Base 0.3.0 lfp_spawn_file_actions_destroy@Base 0.3.0 lfp_spawn_file_actions_init@Base 0.3.0 lfp_spawnattr_destroy@Base 0.3.0 lfp_spawnattr_getctty@Base 0.3.0 lfp_spawnattr_getcwd@Base 0.3.0 lfp_spawnattr_getflags@Base 0.3.0 lfp_spawnattr_getpgroup@Base 0.3.0 lfp_spawnattr_getrlimit@Base 0.5.0 lfp_spawnattr_getsigdefault@Base 0.3.0 lfp_spawnattr_getsigmask@Base 0.3.0 lfp_spawnattr_getumask@Base 0.5.0 lfp_spawnattr_init@Base 0.3.0 lfp_spawnattr_setctty@Base 0.3.0 lfp_spawnattr_setcwd@Base 0.3.0 lfp_spawnattr_setflags@Base 0.3.0 lfp_spawnattr_setpgroup@Base 0.3.0 lfp_spawnattr_setrlimit@Base 0.5.0 lfp_spawnattr_setsid@Base 0.3.0 lfp_spawnattr_setsigdefault@Base 0.3.0 lfp_spawnattr_setsigmask@Base 0.3.0 lfp_spawnattr_setumask@Base 0.5.0 lfp_spawnp@Base 0.3.0 lfp_stat@Base 0.3.0 lfp_strerror@Base 0.3.0 lfp_strndup@Base 0.3.0 lfp_strnlen@Base 0.3.0 lfp_syslog@Base 0.3.0 lfp_telldir@Base 0.4.0 lfp_truncate@Base 0.3.0 lfp_tty_attach@Base 0.3.0 lfp_tty_fattach@Base 0.3.0 lfp_vsyslog@Base 0.3.0 lfp_wcoredump@Base 0.3.0 lfp_wexitstatus@Base 0.3.0 lfp_wifcontinued@Base 0.3.0 lfp_wifexited@Base 0.3.0 lfp_wifsignaled@Base 0.3.0 lfp_wifstopped@Base 0.3.0 lfp_wstopsig@Base 0.3.0 lfp_wtermsig@Base 0.3.0 libfixposix-0.5.1/debian/rules000077500000000000000000000001601433332275700163650ustar00rootroot00000000000000#!/usr/bin/make -f %: dh $@ override_dh_auto_configure: dh_auto_configure -- --enable-static --enable-tests libfixposix-0.5.1/debian/source/000077500000000000000000000000001433332275700166105ustar00rootroot00000000000000libfixposix-0.5.1/debian/source/format000066400000000000000000000000151433332275700200170ustar00rootroot000000000000003.0 (native) libfixposix-0.5.1/libfixposix.spec.in000066400000000000000000000030761433332275700177150ustar00rootroot00000000000000Name: libfixposix Summary: POSIX syscall wrappers Version: @PACKAGE_VERSION@ Release: 0 License: BSL-1.0 Group: Development/Libraries/C and C++ URL: https://github.com/sionescu/%{name} Source: https://github.com/sionescu/%{name}/releases/download/v%{version}/%{name}_%{version}.tar.xz %define srcdir %{name} BuildRequires: check-devel pkgconfig BuildRoot: %{_tmppath}/%{name}-%{version}-build %description Thin wrapper over POSIX syscalls and some replacement functionality, most notably lfp_spawn(). %package -n libfixposix4 Summary: Shared library for libfixposix Group: Development/Libraries/C and C++ %description -n libfixposix4 Thin wrapper over POSIX syscalls. %package -n libfixposix-devel Summary: Development files Group: Development/Libraries/C and C++ Requires: glibc-devel Requires: libfixposix4 = %{version}-%{release} Provides: %{name}-static = %{version}-%{release} %description devel Header files, static libraries and API documentation for using libfixposix. %prep %setup -q -n %{srcdir} %build %configure --enable-static --enable-tests make %{?_smp_mflags} %check make %{?_smp_mflags} check %install make %{?_smp_mflags} DESTDIR=%{buildroot} install find %{buildroot} -type f -name "*.la" -delete -print %post -n libfixposix4 -p /sbin/ldconfig %postun -n libfixposix4 -p /sbin/ldconfig %files -n libfixposix4 %defattr(-,root,root) %{_libdir}/lib*so.* %files -n libfixposix-devel %defattr(-,root,root) %{_includedir}/* %{_libdir}/lib*.so %{_libdir}/lib*.a %{_libdir}/pkgconfig/libfixposix.pc libfixposix-0.5.1/src/000077500000000000000000000000001433332275700146555ustar00rootroot00000000000000libfixposix-0.5.1/src/include/000077500000000000000000000000001433332275700163005ustar00rootroot00000000000000libfixposix-0.5.1/src/include/lfp.h000066400000000000000000000045321433332275700172360ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_H_) # define _LFP_H_ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #endif /* _LFP_H_ */ libfixposix-0.5.1/src/include/lfp/000077500000000000000000000000001433332275700170615ustar00rootroot00000000000000libfixposix-0.5.1/src/include/lfp/aux.h000066400000000000000000000044641433332275700200370ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_AUX_H_) # define _LFP_AUX_H_ #if defined(__cplusplus) # define LFP_BEGIN_DECLS extern "C" { #else # define LFP_BEGIN_DECLS #endif #if defined(__cplusplus) # define LFP_END_DECLS } #else # define LFP_END_DECLS #endif #ifdef GCC # define ATTRIBUTE_NONNULL __attribute__((nonnull (1))) #else # define ATTRIBUTE_NONNULL #endif #if (__STDC_VERSION__ - 0) < 199901L // only C99 has restricted pointers # define restrict #endif #endif /* _LFP_AUX_H_ */ libfixposix-0.5.1/src/include/lfp/buildinfo.h000066400000000000000000000041741433332275700212130ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_BUILDINFO_H_) # define _LFP_BUILDINFO_H_ #include #include LFP_BEGIN_DECLS struct lfp_buildinfo { uint64_t release; char vcsid[32+1]; }; int lfp_buildinfo(struct lfp_buildinfo *v); LFP_END_DECLS #endif /* _LFP_BUILDINFO_H_ */ libfixposix-0.5.1/src/include/lfp/dirent.h000066400000000000000000000043631433332275700205250ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_DIRENT_H_) # define _LFP_DIRENT_H_ #include LFP_BEGIN_DECLS #include DIR* lfp_opendir(const char *name); int lfp_readdir(DIR *dirp, struct dirent *entry, struct dirent **result); long lfp_telldir(DIR *dirp); void lfp_seekdir(DIR *dirp, long offset); void lfp_rewinddir(DIR *dirp); int lfp_closedir(DIR *dirp); LFP_END_DECLS #endif /* _LFP_DIRENT_H_ */ libfixposix-0.5.1/src/include/lfp/errno.h000066400000000000000000000041011433332275700203530ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LPF_ERRNO_H_) # define _LPF_ERRNO_H_ #include LFP_BEGIN_DECLS #include #define EBUG 10000 int lfp_errno(void); int lfp_set_errno(int value); LFP_END_DECLS #endif /* _LPF_ERRNO_H_ */ libfixposix-0.5.1/src/include/lfp/fcntl.h000066400000000000000000000052611433332275700203440ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_FCNTL_H_) # define _LFP_FCNTL_H_ #include LFP_BEGIN_DECLS #include #include #include #if !defined(O_CLOEXEC) // Syscalls use "int" for passing flags, and since // *nix systems use the LP64 data model, "int" is 32 bits // which means that we can allocate unsupported flags in the // upper part of an uint64_t value # define O_CLOEXEC ( 1ULL << 32 ) #endif int lfp_open(const char *pathname, uint64_t flags, ...); int lfp_open_k(int *newfd, const char *pathname, uint64_t flags, mode_t mode); int lfp_openpt(uint64_t flags); int lfp_creat(const char *pathname, mode_t mode); int lfp_is_fd_cloexec(int fd); int lfp_set_fd_cloexec(int fd, bool enabled); int lfp_is_fd_nonblock(int fd); int lfp_set_fd_nonblock(int fd, bool enabled); LFP_END_DECLS #endif /* _LFP_FCNTL_H_ */ libfixposix-0.5.1/src/include/lfp/ioctl.h000066400000000000000000000041571433332275700203530ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_IOCTL_H_) # define _LFP_IOCTL_H_ #include LFP_BEGIN_DECLS #include #include #include int lfp_tty_attach(const char *path); int lfp_tty_fattach(int fd); LFP_END_DECLS #endif /* _LFP_IOCTL_H_ */ libfixposix-0.5.1/src/include/lfp/mman.h000066400000000000000000000042121433332275700201610ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_MMAN_H_) # define _LFP_MMAN_H_ #include LFP_BEGIN_DECLS #include void* lfp_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset); int lfp_munmap(void *addr, size_t length); LFP_END_DECLS #endif /* _LFP_MMAN_H_ */ libfixposix-0.5.1/src/include/lfp/resource.h000066400000000000000000000041741433332275700210670ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LPF_RESOURCE_H_) # define _LPF_RESOURCE_H_ #include LFP_BEGIN_DECLS #include int lfp_getrlimit(int resource, struct rlimit *rlim); int lfp_setrlimit(int resource, const struct rlimit *rlim); LFP_END_DECLS #endif /* _LPF_RESOURCE_H_ */ libfixposix-0.5.1/src/include/lfp/select.h000066400000000000000000000045011433332275700205110ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_SELECT_H_) # define _LFP_SELECT_H_ #include LFP_BEGIN_DECLS #include #include #include int lfp_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout); void lfp_fd_clr(int fd, fd_set *set); bool lfp_fd_isset(int fd, fd_set *set); void lfp_fd_set(int fd, fd_set *set); void lfp_fd_zero(fd_set *set); LFP_END_DECLS #endif /* _LFP_SELECT_H_ */ libfixposix-0.5.1/src/include/lfp/sendfile.h000066400000000000000000000041201433332275700210200ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_SENDFILE_H_) # define _LFP_SENDFILE_H_ #include LFP_BEGIN_DECLS #include ssize_t lfp_sendfile(int out_fd, int in_fd, off_t offset, size_t nbytes); LFP_END_DECLS #endif /* _LFP_SENDFILE_H_ */ libfixposix-0.5.1/src/include/lfp/signal.h000066400000000000000000000044331433332275700205130ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_SIGNAL_H_) # define _LFP_SIGNAL_H_ #include LFP_BEGIN_DECLS #include #include #include typedef void (*lfp_sighandler_t) (int); lfp_sighandler_t lfp_sig_dfl(void); lfp_sighandler_t lfp_sig_err(void); lfp_sighandler_t lfp_sig_hold(void); lfp_sighandler_t lfp_sig_ign(void); int lfp_sigrtmin(void); int lfp_sigrtmax(void); LFP_END_DECLS #endif /* _LFP_SIGNAL_H_ */ libfixposix-0.5.1/src/include/lfp/signalfd.h000066400000000000000000000045131433332275700210240ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_SIGNALFD_H_) # define _LFP_SIGNALFD_H_ #include LFP_BEGIN_DECLS #include #include #if defined(__linux__) # if @HAVE_EMULATED_SIGNALFD@ // HAVE_EMULATED_SIGNALFD struct signalfd_siginfo { unsigned int ssi_signo; }; # else # include # endif #endif int lfp_install_signalfd(int signum, int sa_flags, bool* blockp); int lfp_uninstall_signalfd(int signum, bool block); LFP_END_DECLS #endif /* _LFP_SIGNALFD_H_ */ libfixposix-0.5.1/src/include/lfp/socket.h000066400000000000000000000051121433332275700205210ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_SOCKET_H_) # define _LFP_SOCKET_H_ #include LFP_BEGIN_DECLS #include #include #include int lfp_socket(int domain, int type, int protocol, uint64_t flags); int lfp_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen, uint64_t flags); struct cmsghdr* lfp_cmsg_firsthdr(struct msghdr* msgh); struct cmsghdr* lfp_cmsg_nxthdr(struct msghdr* msgh, struct cmsghdr* cmsg); size_t lfp_cmsg_space(size_t length); size_t lfp_cmsg_len(size_t length); void* lfp_cmsg_data(struct cmsghdr* cmsg); int lfp_getpeereid(int socket, uid_t *euid, gid_t *egid); LFP_END_DECLS #endif /* _LFP_SOCKET_H_ */ libfixposix-0.5.1/src/include/lfp/spawn.h000066400000000000000000000142231433332275700203640ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_SPAWN_H_) # define _LFP_SPAWN_H_ #include LFP_BEGIN_DECLS #include #include #include #include #include #include typedef struct { uint initialized; uint allocated; struct lfp_spawn_action *actions; bool keep_descriptors; int *kfd; int kfd_size; } lfp_spawn_file_actions_t; int lfp_spawn_file_actions_init(lfp_spawn_file_actions_t *file_actions); int lfp_spawn_file_actions_destroy(lfp_spawn_file_actions_t *file_actions); int lfp_spawn_file_actions_addopen(lfp_spawn_file_actions_t *file_actions, int fd, const char *path, uint64_t oflags, mode_t mode); int lfp_spawn_file_actions_addclose(lfp_spawn_file_actions_t *file_actions, int fd); int lfp_spawn_file_actions_adddup2(lfp_spawn_file_actions_t *file_actions, int fd, int newfd); int lfp_spawn_file_actions_addkeep(lfp_spawn_file_actions_t *file_actions, int fd); typedef struct { int resource; struct rlimit rlim; } lfp_rlimit_t; typedef struct { uint32_t flags; sigset_t sigdefault; sigset_t sigmask; pid_t pgroup; uid_t uid; gid_t gid; char *chdir_path; char *pts_path; mode_t umask; lfp_rlimit_t *rlim; unsigned rlim_size; } lfp_spawnattr_t; typedef enum { LFP_SPAWN_SETSIGMASK = 1 << 0, #define LFP_SPAWN_SETSIGMASK ( 1 << 0 ) LFP_SPAWN_SETSIGDEFAULT = 1 << 1, #define LFP_SPAWN_SETSIGDEFAULT ( 1 << 1 ) LFP_SPAWN_SETPGROUP = 1 << 2, #define LFP_SPAWN_SETPGROUP ( 1 << 2 ) LFP_SPAWN_RESETIDS = 1 << 3, #define LFP_SPAWN_RESETIDS ( 1 << 3 ) LFP_SPAWN_SETCWD = 1 << 6, #define LFP_SPAWN_SETCWD ( 1 << 6 ) LFP_SPAWN_SETSID = 1 << 7, #define LFP_SPAWN_SETSID ( 1 << 7 ) LFP_SPAWN_SETCTTY = 1 << 8, #define LFP_SPAWN_SETCTTY ( 1 << 8 ) LFP_SPAWN_USEVFORK = 1 << 9, #define LFP_SPAWN_USEVFORK ( 1 << 9 ) LFP_SPAWN_SETUMASK = 1 << 10, #define LFP_SPAWN_SETUMASK ( 1 << 10 ) LFP_SPAWN_SETRLIMIT = 1 << 11, #define LFP_SPAWN_SETRLIMIT ( 1 << 11 ) } lfp_spawnattr_flags; int lfp_spawnattr_init(lfp_spawnattr_t *attr); int lfp_spawnattr_destroy(lfp_spawnattr_t *attr); int lfp_spawnattr_getflags(lfp_spawnattr_t *attr, uint32_t *flags); int lfp_spawnattr_setflags(lfp_spawnattr_t *attr, const uint32_t flags); int lfp_spawnattr_getsigmask(lfp_spawnattr_t *attr, sigset_t *sigmask); int lfp_spawnattr_setsigmask(lfp_spawnattr_t *attr, const sigset_t *sigmask); int lfp_spawnattr_getsigdefault(lfp_spawnattr_t *attr, sigset_t *sigdefault); int lfp_spawnattr_setsigdefault(lfp_spawnattr_t *attr, const sigset_t *sigdefault); int lfp_spawnattr_getpgroup(lfp_spawnattr_t *attr, pid_t *pgroup); int lfp_spawnattr_setpgroup(lfp_spawnattr_t *attr, const pid_t pgroup); int lfp_spawnattr_setsid(lfp_spawnattr_t *attr); int lfp_spawnattr_getctty(lfp_spawnattr_t *attr, char **path); int lfp_spawnattr_setctty(lfp_spawnattr_t *attr, const char *path); int lfp_spawnattr_getcwd(lfp_spawnattr_t *attr, char **path); int lfp_spawnattr_setcwd(lfp_spawnattr_t *attr, const char *path); int lfp_spawnattr_getumask(lfp_spawnattr_t *attr, mode_t *umask); int lfp_spawnattr_setumask(lfp_spawnattr_t *attr, const mode_t umask); int lfp_spawnattr_getrlimit(lfp_spawnattr_t *attr, lfp_rlimit_t **rlim, size_t *rlim_size); int lfp_spawnattr_setrlimit(lfp_spawnattr_t *attr, const lfp_rlimit_t *rlim, size_t rlim_size); int lfp_spawn(pid_t *restrict pid, const char *restrict path, char *const argv[restrict], char *const envp[restrict], const lfp_spawn_file_actions_t *restrict file_actions, const lfp_spawnattr_t *restrict attr); int lfp_spawnp(pid_t *restrict pid, const char *restrict file, char *const argv[restrict], char *const envp[restrict], const lfp_spawn_file_actions_t *restrict file_actions, const lfp_spawnattr_t *restrict attr); LFP_END_DECLS #endif /* _LFP_SPAWN_H_ */ libfixposix-0.5.1/src/include/lfp/stat.h000066400000000000000000000046201433332275700202070ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_STAT_H_) # define _LFP_STAT_H_ #include LFP_BEGIN_DECLS #include #include int lfp_stat(const char *path, struct stat *buf); int lfp_fstat(int fd, struct stat *buf); int lfp_lstat(const char *path, struct stat *buf); int lfp_is_fd_open(int fd); bool lfp_isreg(mode_t mode); bool lfp_isdir(mode_t mode); bool lfp_ischr(mode_t mode); bool lfp_isblk(mode_t mode); bool lfp_isfifo(mode_t mode); bool lfp_islnk(mode_t mode); bool lfp_issock(mode_t mode); LFP_END_DECLS #endif /* _LFP_STAT_H_ */ libfixposix-0.5.1/src/include/lfp/stdlib.h000066400000000000000000000043101433332275700205110ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_STDLIB_H_) # define _LFP_STDLIB_H_ #include LFP_BEGIN_DECLS #include #include int lfp_mkstemp(char *tmplate); int lfp_mkostemp(char *tmplate, uint64_t flags); char* lfp_getpath(char *const envp[]); int lfp_ptsname(int masterfd, char *buf, size_t buflen); LFP_END_DECLS #endif /* _LFP_STDLIB_H_ */ libfixposix-0.5.1/src/include/lfp/strerror.h000066400000000000000000000040701433332275700211150ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_STRING_H_) # define _LFP_STRING_H_ #include LFP_BEGIN_DECLS #include int lfp_strerror(int errnum, char *buf, size_t buflen); LFP_END_DECLS #endif /* _LFP_STRING_H_ */ libfixposix-0.5.1/src/include/lfp/string.h000066400000000000000000000047151433332275700205470ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_STRING_H_) # define _LFP_STRING_H_ #include LFP_BEGIN_DECLS #include #include #include #include size_t lfp_strnlen(const char *s, size_t maxlen); char* lfp_strndup(const char *s, size_t maxlen); enum lfp_memsize_measure_unit { LFP_OCTETS = 0, LFP_KB, LFP_KIB, LFP_MB, LFP_MIB, LFP_GB, LFP_GIB, LFP_TB, LFP_TIB, LFP_PB, LFP_PIB, LFP_EB, LFP_EIB }; int64_t lfp_parse_memsize(const char *s, enum lfp_memsize_measure_unit default_unit); LFP_END_DECLS #endif /* _LFP_STRING_H_ */ libfixposix-0.5.1/src/include/lfp/syslog.h000066400000000000000000000045061433332275700205570ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_SYSLOG_H_) # define _LFP_SYSLOG_H_ #include LFP_BEGIN_DECLS #include #include void lfp_openlog(const char *ident, int options, int facility); void lfp_syslog(int priority, const char *msg, ...); void lfp_vsyslog(int priority, const char *msg, va_list args); void lfp_closelog(void); int lfp_setlogmask(int maskpri); int lfp_log_mask(int priority); int lfp_log_upto(int priority); LFP_END_DECLS #endif /* _LFP_SYSLOG_H_ */ libfixposix-0.5.1/src/include/lfp/time.h.in000066400000000000000000000046251433332275700206040ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_TIME_H_) # define _LFP_TIME_H_ #include LFP_BEGIN_DECLS #include #include #include #if ! @HAVE_CLOCKID_T@ typedef int clockid_t; #endif // HAVE_CLOCKID_T #if ! @HAVE_CLOCK_GETTIME@ # define CLOCK_REALTIME 0 # define CLOCK_MONOTONIC 1 #endif // HAVE_CLOCK_GETTIME int lfp_clock_getres(clockid_t clk_id, struct timespec *res); int lfp_clock_gettime(clockid_t clk_id, struct timespec *tp); int lfp_clock_settime(clockid_t clk_id, struct timespec *tp); LFP_END_DECLS #endif /* _LFP_TIME_H_ */ libfixposix-0.5.1/src/include/lfp/unistd.h000066400000000000000000000052721433332275700205460ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_UNISTD_H_) # define _LFP_UNISTD_H_ #include LFP_BEGIN_DECLS #include #include #include char **lfp_get_environ(void); int lfp_set_environ(char **newenv); int lfp_clearenv(void); off_t lfp_lseek(int fd, off_t offset, int whence); int lfp_pipe(int pipefd[2], uint64_t flags); ssize_t lfp_pread(int fd, void *buf, size_t count, off_t offset); ssize_t lfp_pwrite(int fd, const void *buf, size_t count, off_t offset); int lfp_truncate(const char *path, off_t length); int lfp_ftruncate(int fd, off_t length); int lfp_execve(const char *path, char *const argv[], char *const envp[]) ATTRIBUTE_NONNULL; int lfp_execvpe(const char *file, char *const argv[], char *const envp[]) ATTRIBUTE_NONNULL; int lfp_nice_k(int incr, int *new_nice); LFP_END_DECLS #endif /* _LFP_UNISTD_H_ */ libfixposix-0.5.1/src/include/lfp/wait.h000066400000000000000000000044311433332275700202000ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_WAIT_H_) # define _LFP_WAIT_H_ #include LFP_BEGIN_DECLS #include #include bool lfp_wifexited(int status); int lfp_wexitstatus(int status); bool lfp_wifsignaled(int status); int lfp_wtermsig(int status); bool lfp_wcoredump(int status); bool lfp_wifstopped(int status); int lfp_wstopsig(int status); bool lfp_wifcontinued(int status); LFP_END_DECLS #endif /* _LFP_WAIT_H_ */ libfixposix-0.5.1/src/lib/000077500000000000000000000000001433332275700154235ustar00rootroot00000000000000libfixposix-0.5.1/src/lib/aux/000077500000000000000000000000001433332275700162205ustar00rootroot00000000000000libfixposix-0.5.1/src/lib/aux/inlines.h000066400000000000000000000061331433332275700200350ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_INTERNAL_AUX_INLINES_H_) # define _LFP_INTERNAL_AUX_INLINES_H_ #include #include #include #include #if defined(__APPLE__) # include #endif static inline void _lfp_timespec_to_timeval(const struct timespec *ts, struct timeval *tv) { tv->tv_sec = ts->tv_sec; // Syscalls often have special code paths for null timeouts // so set this to 1 microsecond if(ts->tv_sec == 0 && ts->tv_nsec > 0 && ts->tv_nsec <= 1000) tv->tv_usec = 1; else tv->tv_usec = ts->tv_nsec / 1000; } #if defined(__APPLE__) static inline void _lfp_mach_timespec_t_to_timespec(const mach_timespec_t *mts, struct timespec *ts) { ts->tv_sec = mts->tv_sec; ts->tv_nsec = mts->tv_nsec; } #endif /* xorshift rng from Marsaglia */ static inline uint32_t _xorshift(uint32_t y) { if (y == 0) return 1; /* 0 is a degenerate case we won't reach this unless stores to uint32_t are non-atomic for thread-safety we need this. */ y ^= y << 13; y ^= y >> 17; return (y ^ (y << 5)); } #endif /* _LFP_INTERNAL_AUX_INLINES_H_ */ libfixposix-0.5.1/src/lib/aux/macros.h000066400000000000000000000046631433332275700176660ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_INTERNAL_AUX_MACROS_H_) # define _LFP_INTERNAL_AUX_MACROS_H_ #include #define SYSERR(errnum) \ do { errno = errnum; return (-1); } while(0) #define SYSCHECK(errnum,expr) \ do { if(expr) SYSERR(errnum); } while(0) #define SYSCHECK_K(expr,errnum) \ do { if(expr) return (-(errnum)); } while(0) #define SYSGUARD(expr) \ do { if((expr) < 0) return (-1); } while(0) #define GET_ERRNO(expr) \ (expr) == -1 ? lfp_errno() : 0 #define DSO_PUBLIC __attribute__ ((visibility ("default"))) #endif /* _LFP_INTERNAL_AUX_MACROS_H_ */ libfixposix-0.5.1/src/lib/bitset.c000066400000000000000000000050141433332275700170610ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN 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 #include "bitset.h" #define NBITS (sizeof(int) * 8) int bitset_alloc(int **bitset, size_t size) { size_t alloc_size = (size / 8) + ((size % 8) ? 1 : 0); if (posix_memalign((void**)bitset, sizeof(uint64_t), alloc_size) < 0 ) return -1; memset(*bitset, 0, alloc_size); return 0; } int bitset_insert(int *bitset, int i) { bitset[i / NBITS] |= (1 << (i % NBITS)); return 0; } int bitset_delete(int *bitset, int i) { bitset[i / NBITS] &= ~(1 << (i % NBITS)); return 0; } bool bitset_contains(int *bitset, int i) { return bitset[i / NBITS] & (1 << (i % NBITS)) ? true : false; } libfixposix-0.5.1/src/lib/bitset.h000066400000000000000000000041551433332275700170730ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_BITSET_H_) # define _LFP_BITSET_H_ #include int bitset_alloc(int **bitset, size_t size); int bitset_insert(int *bitset, int i); int bitset_delete(int *bitset, int i); bool bitset_contains(int *bitset, int i); #endif // _LFP_BITSET_H_ libfixposix-0.5.1/src/lib/buildinfo.c.in000066400000000000000000000046371433332275700201610ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN 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 #define MAJOR__ (@LFP_MAJOR_VERSION@ << 16) #define MINOR__ (@LFP_MINOR_VERSION@ << 8) #define MICRO__ @LFP_MICRO_VERSION@ #define VCSID__ "@LFP_VCSID@" DSO_PUBLIC int lfp_buildinfo(struct lfp_buildinfo *v) { SYSCHECK(EFAULT, v == NULL); v->release = (uint64_t) MAJOR__ | MINOR__ | MICRO__; memset(v->vcsid, 0, sizeof(v->vcsid)); // TODO: Switch sources to C11 and use _Static_assert. SYSCHECK(EINVAL, sizeof(VCSID__) > sizeof(v->vcsid)); strncpy(v->vcsid, VCSID__, sizeof(v->vcsid)); return 0; } libfixposix-0.5.1/src/lib/dirent.c000066400000000000000000000051111433332275700170520ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN 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 DSO_PUBLIC DIR* lfp_opendir(const char *name) { return opendir(name); } DSO_PUBLIC int lfp_readdir(DIR *dirp, struct dirent *entry, struct dirent **result) { int ret = readdir_r(dirp, entry, result); if ( ret > 0 ) { lfp_set_errno(ret); return -1; } else if (*result == NULL) { return 0; } else { return 1; } } DSO_PUBLIC long lfp_telldir(DIR *dirp) { return telldir(dirp); } DSO_PUBLIC void lfp_seekdir(DIR *dirp, long offset) { return seekdir(dirp, offset); } DSO_PUBLIC void lfp_rewinddir(DIR *dirp) { return rewinddir(dirp); } DSO_PUBLIC int lfp_closedir(DIR *dirp) { return closedir(dirp); } libfixposix-0.5.1/src/lib/errno.c000066400000000000000000000037721433332275700167250ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include DSO_PUBLIC int lfp_errno (void) { return errno; } DSO_PUBLIC int lfp_set_errno (int value) { errno = value; return errno; } libfixposix-0.5.1/src/lib/fcntl.c000066400000000000000000000106221433332275700166760ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN 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 #include #include DSO_PUBLIC int lfp_open (const char *pathname, uint64_t flags, ...) { int mode = 0; if (flags & O_CREAT) { va_list args; va_start(args, flags); mode = va_arg(args, int); va_end(args); } int newfd = 0; errno = -lfp_open_k(&newfd, pathname, flags, mode); if (errno != 0) { return -1; } return newfd; } DSO_PUBLIC int lfp_open_k (int *newfd, const char *pathname, uint64_t flags, mode_t mode) { SYSCHECK_K(newfd == NULL || pathname == NULL, EFAULT); int fd = 0; if (flags & O_CREAT) { fd = open(pathname, (int)flags & 0xFFFFFFFF, mode); } else { fd = open(pathname, (int)flags & 0xFFFFFFFF); } if (fd < 0) { return -errno; } *newfd = fd; return 0; } DSO_PUBLIC int lfp_openpt (uint64_t flags) { bool cloexec = flags & O_CLOEXEC; flags &= ~O_CLOEXEC; int fd; SYSGUARD(fd = posix_openpt((int)flags & 0xFFFFFFFF)); if (cloexec && lfp_set_fd_cloexec(fd, true) < 0) { close(fd); return -1; } else { return fd; } } DSO_PUBLIC int lfp_creat (const char *pathname, mode_t mode) { return creat(pathname, mode); } DSO_PUBLIC int lfp_is_fd_cloexec (int fd) { int current_flags = fcntl(fd, F_GETFD); if (current_flags < 0) { return -1; } else { return (current_flags & FD_CLOEXEC) ? true : false; } } DSO_PUBLIC int lfp_set_fd_cloexec (int fd, bool enabled) { int current_flags = fcntl(fd, F_GETFD); if (current_flags < 0) { return -1; } else { int new_flags = enabled ? current_flags | FD_CLOEXEC \ : current_flags & ~FD_CLOEXEC; if ( new_flags != current_flags ) { return fcntl(fd, F_SETFD, new_flags); } else { return 0; } } } DSO_PUBLIC int lfp_is_fd_nonblock (int fd) { int current_flags = fcntl(fd, F_GETFL); if (current_flags < 0) { return -1; } else { return (current_flags & O_NONBLOCK) ? true : false; } } DSO_PUBLIC int lfp_set_fd_nonblock (int fd, bool enabled) { int current_flags = fcntl(fd, F_GETFL); if (current_flags < 0) { return -1; } else { int new_flags = enabled ? current_flags | O_NONBLOCK \ : current_flags & ~O_NONBLOCK; if ( new_flags != current_flags ) { return fcntl(fd, F_SETFL, new_flags); } else { return 0; } } } libfixposix-0.5.1/src/lib/install_signalfd.c000066400000000000000000000141641433332275700211120ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include static struct signalfd_params { int read_fd; int write_fd; } *(signalfd_params[NSIG]); static inline int lfp_signalfd (int fd, const sigset_t *mask, int flags) { if (HAVE_EMULATED_SIGNALFD) SYSERR(ENOSYS); else return signalfd(fd, mask, flags); } static void signalfd_emulator (int signum) { struct signalfd_siginfo ssi; struct signalfd_params *params = signalfd_params[signum]; int ret; assert (params != NULL); assert (params->write_fd != -1); memset(&ssi, 0, sizeof(ssi)); ssi.ssi_signo = signum; notify_listener: ret = write(params->write_fd, &ssi, sizeof(ssi)); if (ret == sizeof(ssi)) { return; } if (ret == -1) { switch (lfp_errno()) { case EAGAIN: /* The pipe buffer is full, therefore there's already a notification in the pipe pending reception. We can drop the redundant signal notification. Redundant signals are NEVER guaranteed not to be dropped anyway, and signals may have been dropped on our way already if the system was busy. */ return; case EINTR: /* Some other signal trumped us; try again! */ goto notify_listener; } } /* Something went deeply wrong. Abort. */ abort(); } static void warning_signal_handler (int signum) { char msg[128]; int i = snprintf(msg, sizeof(msg), "\nCaught signalfd-monitored signal %d, which should have been blocked.\n", signum); write(STDERR_FILENO, msg, i); } int lfp_install_signalfd(int signum, int sa_flags, bool* blockp) { int pipefd[2]; bool block; sigset_t sigmask; int emulate_signalfd; struct signalfd_params *params; struct sigaction sa; SYSCHECK(EINVAL, signum < 0 || signum >= NSIG); /* Setup sigaction */ memset(&sa, 0, sizeof(sa)); sa.sa_flags = (sa_flags & (SA_NOCLDSTOP | SA_NOCLDWAIT)) | SA_ONSTACK; /* Create mask with one signal */ sigemptyset(&sigmask); sigaddset(&sigmask, signum); /* Allocate parameters */ SYSCHECK(EALREADY, signalfd_params[signum]); params = malloc(sizeof(signalfd_params)); SYSCHECK(ENOMEM, params == NULL); /* Before we touch the handler, block the signal */ if (sigprocmask(SIG_BLOCK, &sigmask, NULL) < 0) return -1; /* First, try signalfd */ int sigfd = lfp_signalfd(-1, &sigmask, SFD_CLOEXEC | SFD_NONBLOCK); if (sigfd != -1) { /* success with signalfd, block signal and install warning handler */ emulate_signalfd = 0; sa.sa_handler = &warning_signal_handler; /* SIG_DFL would work but we want to catch bugs */ params->read_fd = sigfd; params->write_fd = -1; block = true; goto signalfd_sigaction; } /* no success with signalfd (probably ENOSYS), emulate! */ emulate_signalfd = 1; sa.sa_handler = &signalfd_emulator; if (lfp_pipe(pipefd, O_NONBLOCK | O_CLOEXEC) < 0) return -1; params->read_fd = pipefd[0]; params->write_fd = pipefd[1]; block = false; signalfd_sigaction: signalfd_params[signum] = params; if (sigaction(signum,&sa,NULL) < 0) return -1; if (emulate_signalfd && sigprocmask(SIG_UNBLOCK, &sigmask, NULL) < 0) return -1; if (blockp) { *blockp = block; } return params->read_fd; } int lfp_uninstall_signalfd(int signum, bool block) { sigset_t sigmask; struct signalfd_params *params; struct sigaction sa; SYSCHECK(EINVAL, signum < 0 || signum >= NSIG); /* Setup sigaction */ memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_DFL; /* Create mask with one signal */ sigemptyset(&sigmask); sigaddset(&sigmask, signum); /* Before we touch the handler, block the signal */ if (sigprocmask(SIG_BLOCK, &sigmask, NULL) != 0) return -1; /* Release parameters */ params = signalfd_params[signum]; if ( params == NULL) return 0; close(params->read_fd); if (params->write_fd != -1) close(params->write_fd); free(params); signalfd_params[signum] = NULL; if (sigaction(signum, &sa, NULL) < 0) return -1; if (!block && sigprocmask(SIG_UNBLOCK, &sigmask, NULL) != 0) return -1; return 0; } libfixposix-0.5.1/src/lib/ioctl.c000066400000000000000000000047741433332275700167150ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN 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 #include #include #include #include #include DSO_PUBLIC int lfp_tty_attach(const char *path) { SYSCHECK(EFAULT, path == NULL); SYSCHECK(ENOENT, path[0] == '\0'); int ttyfd; SYSGUARD(ttyfd = lfp_open(path, O_RDONLY | O_NOCTTY)); if (lfp_tty_fattach(ttyfd) < 0) { int saved_errno = lfp_errno(); close(ttyfd); SYSERR(saved_errno); } else { close(ttyfd); } return 0; } DSO_PUBLIC int lfp_tty_fattach(int fd) { SYSGUARD(ioctl(fd, TIOCSCTTY, 0)); return 0; } libfixposix-0.5.1/src/lib/mman.c000066400000000000000000000041661433332275700165260ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include DSO_PUBLIC void* lfp_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) { return mmap(addr, length, prot, flags, fd, offset); } DSO_PUBLIC int lfp_munmap(void *addr, size_t length) { return munmap(addr, length); } libfixposix-0.5.1/src/lib/resource.c000066400000000000000000000041251433332275700174200ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include DSO_PUBLIC int lfp_getrlimit(int resource, struct rlimit *rlim) { return getrlimit(resource, rlim); } DSO_PUBLIC int lfp_setrlimit(int resource, const struct rlimit *rlim) { return setrlimit(resource, rlim); } libfixposix-0.5.1/src/lib/select.c000066400000000000000000000051141433332275700170470ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN 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 "aux/inlines.h" DSO_PUBLIC int lfp_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout) { #if defined(HAVE_PSELECT) return pselect(nfds, readfds, writefds, exceptfds, timeout, NULL); #else struct timeval tv; _lfp_timespec_to_timeval(timeout, &tv); return select(nfds, readfds, writefds, exceptfds, &tv); #endif } DSO_PUBLIC void lfp_fd_clr(int fd, fd_set *set) { FD_CLR(fd, set); } DSO_PUBLIC bool lfp_fd_isset(int fd, fd_set *set) { return (bool) FD_ISSET(fd, set); } DSO_PUBLIC void lfp_fd_set(int fd, fd_set *set) { FD_SET(fd, set); } DSO_PUBLIC void lfp_fd_zero(fd_set *set) { FD_ZERO(set); } libfixposix-0.5.1/src/lib/sendfile.c000066400000000000000000000062131433332275700173620ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #if defined(HAVE_SENDFILE) # if defined(__linux__) # include # elif defined(__FreeBSD__) || defined(__DragonFly__) # include # include # include # elif defined(__APPLE__) // OSX doesn't expose sendfile if XOPEN_SOURCE is defined int sendfile(int, int, off_t, off_t *, void *, int); # endif #endif #include #include DSO_PUBLIC ssize_t lfp_sendfile(int out_fd, int in_fd, off_t offset, size_t nbytes) { #if defined(HAVE_SENDFILE) # if defined(__linux__) off_t off = offset; return (ssize_t) sendfile(out_fd, in_fd, &off, nbytes); # elif defined(__FreeBSD__) || defined(__DragonFly__) off_t sbytes = 0; int res = sendfile(in_fd, out_fd, offset, nbytes, NULL, &sbytes, 0); if (res == 0 || (res < 0 && errno == EAGAIN && sbytes > 0)) { return sbytes; } return -1; # elif defined(__APPLE__) off_t len = nbytes; int res = sendfile(in_fd, out_fd, offset, &len, NULL, 0); if (res == 0 || (res < 0 && errno == EAGAIN && len > 0)) { return len; } return -1; # else # error "It appears that this OS has sendfile(), but LFP doesn't use it at the moment" # error "Please send an email to iolib-devel@common-lisp.net" # endif #else SYSERR(ENOSYS); #endif } libfixposix-0.5.1/src/lib/signal.c000066400000000000000000000050171433332275700170470ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) # include #endif DSO_PUBLIC lfp_sighandler_t lfp_sig_dfl (void) { return SIG_DFL; } DSO_PUBLIC lfp_sighandler_t lfp_sig_err (void) { return SIG_ERR; } DSO_PUBLIC lfp_sighandler_t lfp_sig_hold (void) { return SIG_HOLD; } DSO_PUBLIC lfp_sighandler_t lfp_sig_ign (void) { return SIG_IGN; } DSO_PUBLIC int lfp_sigrtmin (void) { #if defined(SIGRTMIN) return SIGRTMIN; #else SYSERR(ENOSYS); #endif // SIGRTMIN } DSO_PUBLIC int lfp_sigrtmax (void) { #if defined(SIGRTMAX) return SIGRTMAX; #else SYSERR(ENOSYS); #endif // SIGRTMAX } libfixposix-0.5.1/src/lib/socket.c000066400000000000000000000112271433332275700170620ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN 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 #if defined(HAVE_GETPEERUCRED) #include #endif DSO_PUBLIC int lfp_socket(int domain, int type, int protocol, uint64_t flags) { #if defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK) return socket(domain, type | ((flags & O_CLOEXEC) ? SOCK_CLOEXEC : 0) \ | ((flags & O_NONBLOCK) ? SOCK_NONBLOCK : 0), protocol); #else int fd = socket(domain, type, protocol); if (fd < 0) { goto error_return; } if (((flags & O_CLOEXEC) && (lfp_set_fd_cloexec(fd, true) < 0)) || \ ((flags & O_NONBLOCK) && (lfp_set_fd_nonblock(fd, true) < 0))) { goto error_close; } return fd; error_close: close(fd); error_return: return -1; #endif } DSO_PUBLIC int lfp_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen, uint64_t flags) { // FIXME: This branch requires that SOCK_CLOEXEC and SOCK_NONBLOCK be // defined when accept4(2) is present. Should we add an Autoconf check ? #if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK) return accept4(sockfd, addr, addrlen, ((flags & O_CLOEXEC) ? SOCK_CLOEXEC : 0) | \ ((flags & O_NONBLOCK) ? SOCK_NONBLOCK : 0)); #else int fd = accept(sockfd, addr, addrlen); if (fd < 0) { goto error_return; } if (((flags & O_CLOEXEC) && (lfp_set_fd_cloexec(fd, true) < 0)) || \ ((flags & O_NONBLOCK) && (lfp_set_fd_nonblock(fd, true) < 0))) { goto error_close; } return fd; error_close: close(fd); error_return: return -1; #endif } DSO_PUBLIC struct cmsghdr* lfp_cmsg_firsthdr (struct msghdr* msgh) { return CMSG_FIRSTHDR(msgh); } DSO_PUBLIC struct cmsghdr* lfp_cmsg_nxthdr (struct msghdr* msgh, struct cmsghdr* cmsg) { return CMSG_NXTHDR(msgh, cmsg); } DSO_PUBLIC size_t lfp_cmsg_space (size_t length) { return CMSG_SPACE(length); } DSO_PUBLIC size_t lfp_cmsg_len (size_t length) { return CMSG_LEN(length); } DSO_PUBLIC void* lfp_cmsg_data (struct cmsghdr* cmsg) { return CMSG_DATA(cmsg); } DSO_PUBLIC int lfp_getpeereid(int sockfd, uid_t *euid, gid_t *egid) { SYSCHECK(EFAULT, euid == NULL || egid == NULL); #if defined(HAVE_GETPEEREID) return getpeereid(sockfd, euid, egid); #elif defined(HAVE_GETPEERUCRED) ucred_t **ucred = NULL; SYSGUARD(getpeerucred(sockfd, ucred)); *euid = ucred_geteuid(*ucred); *egid = ucred_getegid(*ucred); ucred_free(*ucred); return (*euid < 0 || *egid < 0) ? -1 : 0; #elif defined(SO_PEERCRED) struct ucred ucred; socklen_t len = sizeof(ucred); SYSGUARD(getsockopt(sockfd, SOL_SOCKET, SO_PEERCRED, &ucred, &len)); *euid = ucred.uid; *egid = ucred.gid; return 0; #endif } libfixposix-0.5.1/src/lib/spawn.c000066400000000000000000000126601433332275700167240ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN 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 #include #include #include "spawn.h" typedef int (*execfun)(const char*, char *const[], char *const[]); static void child_exit(int pipefd, int child_errno) { int noctets = write(pipefd, &child_errno, sizeof(int)); if (noctets == sizeof(int)) _exit(255); else _exit(254); } static int _lfp_spawn_apply_default_attributes(const lfp_spawnattr_t *attr) { if (attr == NULL || ! (attr->flags & LFP_SPAWN_SETSIGMASK)) { sigset_t set; sigemptyset(&set); SYSGUARD(sigprocmask(SIG_SETMASK, &set, NULL)); } return 0; } static void handle_child(execfun execfn, const char *path, char *const argv[], char *const envp[], const lfp_spawn_file_actions_t *file_actions, const lfp_spawnattr_t *attr, int pipes[2], bool use_vfork) { if (_lfp_spawn_apply_default_attributes(attr) || lfp_spawn_apply_attributes(attr) || lfp_spawn_apply_file_actions(file_actions)) { goto error; } execfn(path, argv, envp); error: if (use_vfork) _exit(255); else child_exit(pipes[1], errno); } static int handle_parent(pid_t child_pid, int pipes[2]) { close(pipes[1]); int status, child_errno; int noctets = read(pipes[0], &child_errno, sizeof(int)); int read_errno = lfp_errno(); close(pipes[0]); switch (noctets) { case -1: SYSERR(read_errno); case 0: return 0; case 4: waitpid(child_pid, &status, WNOHANG); SYSERR(child_errno); default: // This is not suppose to happen because all 4 octets // of the child's errno should get here with one write SYSERR(EBUG); } } static int _lfp_spawn(execfun execfn, pid_t *restrict pid, const char *restrict path, char *const argv[restrict], char *const envp[restrict], const lfp_spawn_file_actions_t *restrict file_actions, const lfp_spawnattr_t *restrict attr) { int pipes[2]; bool use_vfork = (attr && (attr->flags & LFP_SPAWN_USEVFORK)); // Used for passing the error code from child to parent in case // some of the syscalls executed in the child fail if (!use_vfork && lfp_pipe(pipes, O_CLOEXEC) < 0) return -1; if(use_vfork) { *pid = vfork(); } else { *pid = fork(); } switch (*pid) { case -1: return -1; case 0: handle_child(execfn, path, argv, envp, file_actions, attr, pipes, use_vfork); // Flow reaches this point only if child_exit() mysteriously fails SYSERR(EBUG); default: return use_vfork ? 0 : handle_parent(*pid, pipes); } } DSO_PUBLIC int lfp_spawn(pid_t *restrict pid, const char *restrict path, char *const argv[restrict], char *const envp[restrict], const lfp_spawn_file_actions_t *restrict file_actions, const lfp_spawnattr_t *restrict attr) { SYSCHECK(EFAULT, pid == NULL); return _lfp_spawn(&lfp_execve, pid, path, argv, envp, file_actions, attr); } DSO_PUBLIC int lfp_spawnp(pid_t *restrict pid, const char *restrict file, char *const argv[restrict], char *const envp[restrict], const lfp_spawn_file_actions_t *restrict file_actions, const lfp_spawnattr_t *restrict attr) { SYSCHECK(EFAULT, pid == NULL); return _lfp_spawn(&lfp_execvpe, pid, file, argv, envp, file_actions, attr); } libfixposix-0.5.1/src/lib/spawn.h000066400000000000000000000041601433332275700167250ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_INTERNAL_SPAWN_H_) # define _LFP_INTERNAL_SPAWN_H_ #include int lfp_spawn_apply_attributes(const lfp_spawnattr_t *attr); int lfp_spawn_apply_file_actions(const lfp_spawn_file_actions_t *file_actions); #endif /* _LFP_INTERNAL_SPAWN_H_ */ libfixposix-0.5.1/src/lib/spawn_file_actions.c000066400000000000000000000176771433332275700214600ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN 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 #include #include #include #include #include "spawn.h" #include "bitset.h" /* not checking for OPEN_MAX, which might not be valid, on Linux */ #define INVALID_FD(fd) ( fd < 0 ) typedef enum { LFP_SPAWN_FILE_ACTION_OPEN, LFP_SPAWN_FILE_ACTION_CLOSE, LFP_SPAWN_FILE_ACTION_DUP2 } lfp_spawn_action_type; typedef struct lfp_spawn_action { lfp_spawn_action_type type; int fd; int newfd; const char *path; uint64_t flags; mode_t mode; } lfp_spawn_action; static inline int _lfp_spawn_file_actions_init(lfp_spawn_file_actions_t *file_actions, size_t kfd_size) { *file_actions = (lfp_spawn_file_actions_t) {0}; file_actions->kfd_size = kfd_size; return bitset_alloc(&file_actions->kfd, kfd_size); } DSO_PUBLIC int lfp_spawn_file_actions_init(lfp_spawn_file_actions_t *file_actions) { struct rlimit limit; SYSCHECK(EFAULT, file_actions == NULL); SYSGUARD(lfp_getrlimit(RLIMIT_NOFILE, &limit)); return _lfp_spawn_file_actions_init(file_actions, limit.rlim_cur); } static void lfp_spawn_file_actions_free_paths(lfp_spawn_action *actions, int initialized) { for (int i = 0; i < initialized; i++) if (actions[i].type == LFP_SPAWN_FILE_ACTION_OPEN) free((void*)actions[i].path); } DSO_PUBLIC int lfp_spawn_file_actions_destroy(lfp_spawn_file_actions_t *file_actions) { SYSCHECK(EFAULT, file_actions == NULL); lfp_spawn_file_actions_free_paths(file_actions->actions, file_actions->initialized); if (file_actions->actions) free(file_actions->actions); if (file_actions->kfd) free(file_actions->kfd); *file_actions = (lfp_spawn_file_actions_t) {0}; return 0; } static lfp_spawn_action* lfp_spawn_file_actions_allocate(lfp_spawn_file_actions_t *file_actions) { int init_index = file_actions->initialized++; int allocated = file_actions->allocated; lfp_spawn_action *actions = file_actions->actions; int new_allocated; lfp_spawn_action *new_actions; if (init_index >= allocated) { /* Note: this code assumes we run out of memory before we overflow. */ new_allocated = 4 + allocated * 3 / 2; new_actions = calloc(new_allocated, sizeof(lfp_spawn_action)); if (!new_actions) { return NULL; } if (actions) { memcpy(new_actions, actions, allocated * sizeof(lfp_spawn_action)); free(actions); } actions = new_actions; file_actions->actions = actions; file_actions->allocated = new_allocated; memset(actions + init_index, 0, (new_allocated - init_index) * sizeof(lfp_spawn_action)); } return actions + init_index; } DSO_PUBLIC int lfp_spawn_file_actions_addopen(lfp_spawn_file_actions_t *file_actions, int fd, const char *path, uint64_t oflags, mode_t mode) { SYSCHECK(EFAULT, file_actions == NULL); SYSCHECK(EBADF, INVALID_FD(fd)); lfp_spawn_action *action = lfp_spawn_file_actions_allocate(file_actions); SYSCHECK(ENOMEM, !action); action->type = LFP_SPAWN_FILE_ACTION_OPEN; action->fd = fd; action->path = strdup(path); action->flags = oflags; action->mode = mode; return 0; } DSO_PUBLIC int lfp_spawn_file_actions_addclose(lfp_spawn_file_actions_t *file_actions, int fd) { SYSCHECK(EFAULT, file_actions == NULL); SYSCHECK(EBADF, INVALID_FD(fd)); lfp_spawn_action *action = lfp_spawn_file_actions_allocate(file_actions); SYSCHECK(ENOMEM, !action); action->type = LFP_SPAWN_FILE_ACTION_CLOSE; action->fd = fd; return 0; } DSO_PUBLIC int lfp_spawn_file_actions_adddup2(lfp_spawn_file_actions_t *file_actions, int fd, int newfd) { SYSCHECK(EFAULT, file_actions == NULL); SYSCHECK(EBADF, INVALID_FD(fd) || INVALID_FD(newfd)); lfp_spawn_action *action = lfp_spawn_file_actions_allocate(file_actions); SYSCHECK(ENOMEM, !action); action->type = LFP_SPAWN_FILE_ACTION_DUP2; action->fd = fd; action->newfd = newfd; return 0; } DSO_PUBLIC int lfp_spawn_file_actions_addkeep(lfp_spawn_file_actions_t *file_actions, int fd) { file_actions->keep_descriptors = true; return bitset_insert(file_actions->kfd, fd); } static int lfp_spawn_apply_one_file_action(const lfp_spawn_action *action) { int err, fd; switch (action->type) { case LFP_SPAWN_FILE_ACTION_OPEN: fd = lfp_open(action->path, action->flags, action->mode); if (fd == -1) { return lfp_errno(); } if (fd != action->fd) { int dup2_errno = GET_ERRNO(dup2(fd, action->fd)); int close_errno = GET_ERRNO(close(fd)); if (dup2_errno) { return dup2_errno; } else if (close_errno) { return close_errno; } } return 0; case LFP_SPAWN_FILE_ACTION_CLOSE: err = close(action->fd); if (err == -1) { return errno; } return 0; case LFP_SPAWN_FILE_ACTION_DUP2: err = dup2(action->fd, action->newfd); if (err == -1) { return errno; } return 0; default: return EINVAL; } } static int _lfp_spawn_close_descriptors(const lfp_spawn_file_actions_t *file_actions) { for (int i = 0; i < file_actions->kfd_size; i++) if (!bitset_contains(file_actions->kfd, i)) { // Ignore EBADF int ret = lfp_set_fd_cloexec(i, true); if(ret < 0 && lfp_errno() != EBADF) return -1; } return 0; } int lfp_spawn_apply_file_actions(const lfp_spawn_file_actions_t *file_actions) { if (file_actions == NULL) return 0; if(file_actions->keep_descriptors) _lfp_spawn_close_descriptors(file_actions); lfp_spawn_action *action = file_actions->actions; int err; for ( int count = file_actions->initialized; count > 0; count-- ) { err = lfp_spawn_apply_one_file_action (action++); if (err) { return err; } } return 0; } libfixposix-0.5.1/src/lib/spawnattr.c000066400000000000000000000233251433332275700176170ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN 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 #include #include #include #include #include #include #include #include #include "spawn.h" #define LFP_SPAWN_ALLATTRS ( LFP_SPAWN_SETSIGMASK | \ LFP_SPAWN_SETSIGDEFAULT | \ LFP_SPAWN_SETPGROUP | \ LFP_SPAWN_RESETIDS | \ LFP_SPAWN_SETCWD | \ LFP_SPAWN_SETSID | \ LFP_SPAWN_SETCTTY | \ LFP_SPAWN_USEVFORK | \ LFP_SPAWN_SETUMASK | \ LFP_SPAWN_SETRLIMIT ) DSO_PUBLIC int lfp_spawnattr_init(lfp_spawnattr_t *attr) { SYSCHECK(EFAULT, attr == NULL); *attr = (lfp_spawnattr_t) {0}; return 0; } DSO_PUBLIC int lfp_spawnattr_destroy(lfp_spawnattr_t *attr) { SYSCHECK(EFAULT, attr == NULL); if (attr->chdir_path) free(attr->chdir_path); if (attr->pts_path) free(attr->pts_path); if (attr->rlim) free(attr->rlim); *attr = (lfp_spawnattr_t) {0}; return 0; } DSO_PUBLIC int lfp_spawnattr_getflags(lfp_spawnattr_t *attr, uint32_t *flags) { SYSCHECK(EFAULT, attr == NULL || flags == NULL); *flags = attr->flags; return 0; } DSO_PUBLIC int lfp_spawnattr_setflags(lfp_spawnattr_t *attr, const uint32_t flags) { SYSCHECK(EFAULT, attr == NULL); SYSCHECK(EINVAL, (flags & ~LFP_SPAWN_ALLATTRS) != 0); attr->flags = flags; return 0; } DSO_PUBLIC int lfp_spawnattr_getsigmask(lfp_spawnattr_t *attr, sigset_t *sigmask) { SYSCHECK(EFAULT, attr == NULL || sigmask == NULL); memcpy(sigmask, &attr->sigmask, sizeof(sigset_t)); return 0; } DSO_PUBLIC int lfp_spawnattr_setsigmask(lfp_spawnattr_t *attr, const sigset_t *sigmask) { SYSCHECK(EFAULT, attr == NULL); attr->flags |= LFP_SPAWN_SETSIGMASK; memcpy(&attr->sigmask, sigmask, sizeof(sigset_t)); return 0; } DSO_PUBLIC int lfp_spawnattr_getsigdefault(lfp_spawnattr_t *attr, sigset_t *sigdefault) { SYSCHECK(EFAULT, attr == NULL || sigdefault == NULL); memcpy(sigdefault, &attr->sigdefault, sizeof(sigset_t)); return 0; } DSO_PUBLIC int lfp_spawnattr_setsigdefault(lfp_spawnattr_t *attr, const sigset_t *sigdefault) { SYSCHECK(EFAULT, attr == NULL || sigdefault == NULL); attr->flags |= LFP_SPAWN_SETSIGDEFAULT; memcpy(&attr->sigdefault, sigdefault, sizeof(sigset_t)); return 0; } DSO_PUBLIC int lfp_spawnattr_getpgroup(lfp_spawnattr_t *attr, pid_t *pgroup) { SYSCHECK(EFAULT, attr == NULL || pgroup == NULL); *pgroup = attr->pgroup; return 0; } DSO_PUBLIC int lfp_spawnattr_setpgroup(lfp_spawnattr_t *attr, const pid_t pgroup) { SYSCHECK(EFAULT, attr == NULL); attr->flags |= LFP_SPAWN_SETPGROUP; attr->pgroup = pgroup; return 0; } DSO_PUBLIC int lfp_spawnattr_setsid(lfp_spawnattr_t *attr) { SYSCHECK(EFAULT, attr == NULL); attr->flags |= LFP_SPAWN_SETSID; return 0; } DSO_PUBLIC int lfp_spawnattr_getctty(lfp_spawnattr_t *attr, char **path) { SYSCHECK(EFAULT, attr == NULL || path == NULL || *path != NULL); *path = strdup(attr->pts_path); return 0; } DSO_PUBLIC int lfp_spawnattr_setctty(lfp_spawnattr_t *attr, const char *path) { SYSCHECK(EFAULT, attr == NULL || path == NULL); attr->flags |= LFP_SPAWN_SETCTTY | LFP_SPAWN_SETSID; if (attr->pts_path) { free(attr->pts_path); } attr->pts_path = strdup(path); return 0; } DSO_PUBLIC int lfp_spawnattr_getcwd(lfp_spawnattr_t *attr, char **path) { SYSCHECK(EFAULT, attr == NULL || path == NULL || *path != NULL); *path = strdup(attr->chdir_path); return 0; } DSO_PUBLIC int lfp_spawnattr_setcwd(lfp_spawnattr_t *attr, const char *path) { SYSCHECK(EFAULT, attr == NULL || path == NULL); attr->flags |= LFP_SPAWN_SETCWD; if (attr->chdir_path) { free(attr->chdir_path); } attr->chdir_path = strdup(path); return 0; } DSO_PUBLIC int lfp_spawnattr_getumask(lfp_spawnattr_t *attr, mode_t *umask) { SYSCHECK(EFAULT, attr == NULL || umask == NULL); *umask = attr->umask; return 0; } DSO_PUBLIC int lfp_spawnattr_setumask(lfp_spawnattr_t *attr, const mode_t umask) { SYSCHECK(EFAULT, attr == NULL); attr->flags |= LFP_SPAWN_SETUMASK; attr->umask = umask; return 0; } DSO_PUBLIC int lfp_spawnattr_getrlimit(lfp_spawnattr_t *attr, lfp_rlimit_t **rlim, size_t *rlim_size) { SYSCHECK(EFAULT, attr == NULL || rlim == NULL || rlim_size == NULL); SYSCHECK(EFAULT, *rlim != NULL); size_t size = attr->rlim_size * sizeof(lfp_rlimit_t); lfp_rlimit_t *copy = malloc(size); if (copy == NULL) return -1; memcpy(copy, attr->rlim, size); *rlim = copy; *rlim_size = attr->rlim_size; return 0; } DSO_PUBLIC int lfp_spawnattr_setrlimit(lfp_spawnattr_t *attr, const lfp_rlimit_t *rlim, size_t rlim_size) { SYSCHECK(EFAULT, attr == NULL || rlim == NULL); SYSCHECK(EINVAL, rlim_size == 0); attr->flags |= LFP_SPAWN_SETRLIMIT; size_t size = rlim_size * sizeof(lfp_rlimit_t); lfp_rlimit_t *copy = malloc(size); if (copy == NULL) return -1; memcpy(copy, rlim, size); if (attr->rlim) free(attr->rlim); attr->rlim = copy; attr->rlim_size = rlim_size; return 0; } int lfp_spawn_apply_attributes(const lfp_spawnattr_t *attr) { if (attr == NULL) return 0; if (attr->flags & LFP_SPAWN_SETSIGMASK) if (sigprocmask(SIG_SETMASK, &attr->sigmask, NULL) < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:SETSIGMASK:sigprocmask"); #endif goto error_return; } if (attr->flags & LFP_SPAWN_SETSIGDEFAULT) { struct sigaction sa = { .sa_flags = 0, .sa_handler = SIG_DFL }; for (int i = 1; i <= NSIG; i++) if (sigismember(&attr->sigdefault, i)) if (sigaction(i, &sa, NULL) < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:SETSIGDEFAULT:sigaction"); #endif goto error_return; } } if (attr->flags & LFP_SPAWN_SETPGROUP) if (setpgid(0, attr->pgroup) < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:SETPGROUP:setpgid"); #endif goto error_return; } if (attr->flags & LFP_SPAWN_SETSID) if (setsid() < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:SETSID:setsid"); #endif goto error_return; } if (attr->flags & LFP_SPAWN_SETCTTY) { if (lfp_tty_attach(attr->pts_path) < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:SETCTTY:lfp_tty_attach"); #endif goto error_return; } } if (attr->flags & LFP_SPAWN_SETCWD) if (chdir(attr->chdir_path) < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:SETCWD:chdir"); #endif goto error_return; } if (attr->flags & LFP_SPAWN_RESETIDS) { if (setegid(getgid()) < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:RESETIDS:setegid"); #endif goto error_return; } if (seteuid(getuid()) < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:RESETIDS:seteuid"); #endif goto error_return; } } if (attr->flags & LFP_SPAWN_SETUMASK) umask(attr->umask); // always success if (attr->flags & LFP_SPAWN_SETRLIMIT) for (int i = 0; i < attr->rlim_size; i++) { lfp_rlimit_t *lim = &attr->rlim[i]; if (setrlimit(lim->resource, &lim->rlim) < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:SETRLIMIT:setrlimit"); #endif goto error_return; } } return 0; error_return: return lfp_errno(); } libfixposix-0.5.1/src/lib/stat.c000066400000000000000000000057101433332275700165450ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN 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 DSO_PUBLIC int lfp_stat(const char *path, struct stat *buf) { return stat(path, buf); } DSO_PUBLIC int lfp_fstat(int fd, struct stat *buf) { return fstat(fd, buf); } DSO_PUBLIC int lfp_lstat(const char *path, struct stat *buf) { return lstat(path, buf); } DSO_PUBLIC int lfp_is_fd_open(int fd) { struct stat buf; int ret = fstat(fd, &buf); if ( ret < 0 ) { if ( lfp_errno() == EBADF ) { return false; } else { return -1; } } else { return true; } } DSO_PUBLIC bool lfp_isreg(mode_t mode) { return (bool) S_ISREG(mode); } DSO_PUBLIC bool lfp_isdir(mode_t mode) { return (bool) S_ISDIR(mode); } DSO_PUBLIC bool lfp_ischr(mode_t mode) { return (bool) S_ISCHR(mode); } DSO_PUBLIC bool lfp_isblk(mode_t mode) { return (bool) S_ISBLK(mode); } DSO_PUBLIC bool lfp_isfifo(mode_t mode) { return (bool) S_ISFIFO(mode); } DSO_PUBLIC bool lfp_islnk(mode_t mode) { return (bool) S_ISLNK(mode); } DSO_PUBLIC bool lfp_issock(mode_t mode) { return (bool) S_ISSOCK(mode); } libfixposix-0.5.1/src/lib/stdlib.c000066400000000000000000000132411433332275700170510ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN 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 #include #include #include #include #include "aux/inlines.h" #include #include #include #if !defined(HAVE_MKOSTEMP) static char* _valid_template_p(char *s, size_t len) { size_t start_offset = len - 6; for (size_t off = start_offset; off < len; off++) { if (s[off] != 'X') return NULL; } return s + start_offset; } static int _randomize_template(uint32_t *seed, char *s) { uint32_t internalSeed = *seed; int retval = 0; char random_value[6]; memcpy(random_value, &internalSeed, 4); internalSeed = _xorshift(internalSeed); memcpy(random_value + 4, &internalSeed, 2); char bag[] = "0123456789QWERTYUIOPASDFGHJKLZXCVBNM"; for (unsigned i = 0; i < 6; i++) { s[i] = bag[random_value[i]%(sizeof(bag)-1)]; //random_value /= (sizeof(bag)-1); } *seed = internalSeed; return retval; } static inline uint32_t _pid_seed(void) { /* Try to pick a seed different from everyone else */ struct timespec ts; SYSGUARD(lfp_clock_gettime(CLOCK_REALTIME, &ts)); return (ts.tv_nsec << 2) + getpid() + ts.tv_sec; } #endif // HAVE_MKOSTEMP DSO_PUBLIC int lfp_mkostemp(char *template, uint64_t flags) { SYSCHECK(EFAULT, template == NULL); #if defined(HAVE_MKOSTEMP) return mkostemp(template, flags); #else static uint32_t seed = 0; size_t len = strlen(template); SYSCHECK(EINVAL, len < 6 || template[0] != '/'); char *x_start = _valid_template_p(template, len); SYSCHECK(EINVAL, x_start == NULL); for (int i = 0; i < 1024; i++) { SYSGUARD(_randomize_template(&seed, x_start)); int fd = lfp_open(template, O_EXCL | O_CREAT | O_RDWR | flags, S_IRUSR | S_IWUSR); if (fd >= 0) { return fd; } else { switch (lfp_errno()) { case EEXIST: /* If we hit here, we may be colliding with * a forked process, so increment the seed */ if(i == 0) { seed = _pid_seed(); } //seed+=1; continue; default: return -1; } } } SYSERR(EEXIST); #endif } DSO_PUBLIC int lfp_mkstemp(char *template) { return lfp_mkostemp(template, O_CLOEXEC); } static bool valid_path_p(const char *path, size_t len) { return path[len] == '/' && path[len+1] != '\0' ? true : false; } static char* _lfp_getenv(const char *name, size_t len, char *const envp[]) { if (envp == NULL || *envp == NULL) return NULL; do { if (strncmp(name, *envp, len) == 0 && valid_path_p(*envp, len)) return *envp+len; } while(*(++envp) != NULL); return NULL; } // FIXME: add autoconf check that confstr(_CS_PATH) returns sane values static char* _lfp_default_path(void) { size_t default_path_size = confstr(_CS_PATH, NULL, 0); char *default_path = malloc(default_path_size); confstr(_CS_PATH, default_path, default_path_size); return default_path; } DSO_PUBLIC char* lfp_getpath(char *const envp[]) { char *envpath = _lfp_getenv("PATH=", sizeof("PATH=") - 1, envp ? envp : lfp_get_environ()); if (envpath != NULL) { return strdup(envpath); } else { return _lfp_default_path(); } } DSO_PUBLIC int lfp_ptsname(int masterfd, char *buf, size_t buflen) { SYSCHECK(EFAULT, buf == NULL); #if defined(HAVE_PTSNAME_R) return ptsname_r(masterfd, buf, buflen); #elif defined(HAVE_PTSNAME) char *pts = ptsname(masterfd); size_t ptslen = lfp_strnlen(pts, buflen); if (ptslen >= buflen) { SYSERR(EINVAL); } else { memcpy(buf, pts, ptslen); return 0; } #endif } libfixposix-0.5.1/src/lib/strerror.c000066400000000000000000000044101433332275700174500ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN 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 #if defined(HAVE___XPG_STRERROR_R) int __xpg_strerror_r (int errnum, char *buf, size_t buflen); #endif DSO_PUBLIC int lfp_strerror (int errnum, char *buf, size_t buflen) { SYSCHECK(EFAULT, buf == NULL); #if defined(HAVE___XPG_STRERROR_R) return __xpg_strerror_r(errnum, buf, buflen); #else return strerror_r(errnum, buf, buflen); #endif // HAVE___XPG_STRERROR_R } libfixposix-0.5.1/src/lib/string.c000066400000000000000000000134111433332275700170750ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN 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 #include #include #include static int64_t compute_multiplier(enum lfp_memsize_measure_unit unit); DSO_PUBLIC size_t lfp_strnlen(const char *s, size_t maxlen) { #if defined(HAVE_STRNLEN) return strnlen(s, maxlen); #else for (size_t i = 0; i < maxlen; i++) { if (s[i] == '\0') { return i; } } return maxlen; #endif } DSO_PUBLIC char* lfp_strndup(const char *s, size_t maxlen) { #if defined(HAVE_STRNDUP) return strndup(s, maxlen); #else if (s == NULL) { return NULL; } else { size_t len = lfp_strnlen(s, maxlen); char *newstr = malloc(len + 1); if (newstr != NULL) { memcpy(newstr, s, len); newstr[len] = '\0'; } return newstr; } #endif } static inline int64_t compute_multiplier(enum lfp_memsize_measure_unit unit) { switch(unit) { case LFP_OCTETS: return 1; case LFP_KB: return 1000LL; case LFP_KIB: return 1024LL; case LFP_MB: return 1000LL*1000LL; case LFP_MIB: return 1024LL*1024LL; case LFP_GB: return 1000LL*1000LL*1000LL; case LFP_GIB: return 1024LL*1024LL*1024LL; case LFP_TB: return 1000LL*1000LL*1000LL*1000LL; case LFP_TIB: return 1024LL*1024LL*1024LL*1024LL; case LFP_PB: return 1000LL*1000LL*1000LL*1000LL*1000LL; case LFP_PIB: return 1024LL*1024LL*1024LL*1024LL*1024LL; case LFP_EB: return 1000LL*1000LL*1000LL*1000LL*1000LL*1000LL; case LFP_EIB: return 1024LL*1024LL*1024LL*1024LL*1024LL*1024LL; default: SYSERR(EINVAL); } } DSO_PUBLIC int64_t lfp_parse_memsize(const char *s, enum lfp_memsize_measure_unit default_unit) { int64_t default_multiplier, multiplier, amount; SYSCHECK(EFAULT, s == NULL); SYSCHECK(EINVAL, *s == '\0'); SYSGUARD(default_multiplier = compute_multiplier(default_unit)); char *endptr = NULL; lfp_set_errno(0); SYSGUARD(amount = strtoll(s, &endptr, 10)); SYSCHECK(ERANGE, amount < 0); if (amount == 0) { return 0; } else if (*endptr) { if (strcasecmp(endptr, "KB") == 0) { multiplier = 1000LL; } else if (strcasecmp(endptr, "K") == 0 || strcasecmp(endptr, "KiB") == 0) { multiplier = 1024LL; } else if (strcasecmp(endptr, "MB") == 0) { multiplier = 1000LL*1000LL; } else if (strcasecmp(endptr, "M") == 0 || strcasecmp(endptr, "MiB") == 0) { multiplier = 1024LL*1024LL; } else if (strcasecmp(endptr, "GB") == 0) { multiplier = 1000LL*1000LL*1000LL; } else if (strcasecmp(endptr, "G") == 0 || strcasecmp(endptr, "GiB") == 0) { multiplier = 1024LL*1024LL*1024LL; } else if (strcasecmp(endptr, "TB") == 0) { multiplier = 1000LL*1000LL*1000LL*1000LL; } else if (strcasecmp(endptr, "T") == 0 || strcasecmp(endptr, "TiB") == 0) { multiplier = 1024LL*1024LL*1024LL*1024LL; } else if (strcasecmp(endptr, "PB") == 0) { multiplier = 1000LL*1000LL*1000LL*1000LL*1000LL; } else if (strcasecmp(endptr, "P") == 0 || strcasecmp(endptr, "PiB") == 0) { multiplier = 1024LL*1024LL*1024LL*1024LL*1024LL; } else if (strcasecmp(endptr, "EB") == 0) { multiplier = 1000LL*1000LL*1000LL*1000LL*1000LL*1000LL; } else if (strcasecmp(endptr, "E") == 0 || strcasecmp(endptr, "EiB") == 0) { multiplier = 1024LL*1024LL*1024LL*1024LL*1024LL*1024LL; } else { SYSERR(EINVAL); } } else { multiplier = default_multiplier; } // Check for overflow if (amount > (INT64_MAX / multiplier)) { SYSERR(ERANGE); } else { return amount * multiplier; } } libfixposix-0.5.1/src/lib/syslog.c000066400000000000000000000065071433332275700171170ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN 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 #include static pthread_mutex_t syslog_mutex = PTHREAD_MUTEX_INITIALIZER; static char *syslog_ident = NULL; #define SYSLOG_IDENT_SIZE 1024 static void _lfp_closelog(void) { closelog(); if (syslog_ident) { free(syslog_ident); syslog_ident = NULL; } } static void copy_syslog_ident(const char *ident) { if (ident) { syslog_ident = malloc(SYSLOG_IDENT_SIZE); strncpy(syslog_ident, ident, SYSLOG_IDENT_SIZE - 1); syslog_ident[SYSLOG_IDENT_SIZE - 1] = 0; } } DSO_PUBLIC void lfp_openlog(const char *ident, int options, int facility) { pthread_mutex_lock(&syslog_mutex); _lfp_closelog(); copy_syslog_ident(ident); openlog(syslog_ident, options, facility); pthread_mutex_unlock(&syslog_mutex); } DSO_PUBLIC void lfp_syslog(int priority, const char *msg, ...) { va_list args; va_start(args, msg); vsyslog(priority, msg, args); va_end(args); } DSO_PUBLIC void lfp_vsyslog(int priority, const char *msg, va_list args) { vsyslog(priority, msg, args); } DSO_PUBLIC void lfp_closelog(void) { pthread_mutex_lock(&syslog_mutex); _lfp_closelog(); pthread_mutex_unlock(&syslog_mutex); } DSO_PUBLIC int lfp_setlogmask(int maskpri) { return setlogmask(maskpri); } DSO_PUBLIC int lfp_log_mask(int priority) { return LOG_MASK(priority); } DSO_PUBLIC int lfp_log_upto(int priority) { return LOG_UPTO(priority); } libfixposix-0.5.1/src/lib/time.c000066400000000000000000000127101433332275700165260ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN 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 #if defined(__APPLE__) # include # include #endif #include "aux/inlines.h" #define MACH_SYSERR(errcode) \ do { errno = errcode; ret = -1; goto cleanup; } while(0) #define MACH_SYSCHECK(errcode, expr) \ do { if(expr) MACH_SYSERR(errcode); } while(0) /*******************/ /* clock_getres() */ /*******************/ #if defined(__APPLE__) && !HAVE_CLOCK_GETTIME static int _lfp_clock_getres(clock_id_t clk_id, struct timespec *tp) { int ret = 0; kern_return_t kr; clock_serv_t clk_serv; host_t host_self = mach_host_self(); kr = host_get_clock_service(host_self, clk_id, &clk_serv); MACH_SYSCHECK(EINVAL, kr != KERN_SUCCESS); natural_t attributes[4]; mach_msg_type_number_t count = sizeof(attributes) / sizeof(natural_t); kr = clock_get_attributes(clk_serv, CLOCK_GET_TIME_RES, (clock_attr_t)attributes, &count); MACH_SYSCHECK(EINVAL, kr != KERN_SUCCESS); tp->tv_sec = attributes[0] / 1000000000; tp->tv_nsec = attributes[0] % 1000000000; cleanup: mach_port_deallocate(mach_task_self(), host_self); mach_port_deallocate(mach_task_self(), clk_serv); return ret; } #endif DSO_PUBLIC int lfp_clock_getres(clockid_t clk_id, struct timespec *res) { SYSCHECK(EFAULT, res == NULL); #if HAVE_CLOCK_GETTIME return clock_getres(clk_id, res); #elif defined(__APPLE__) switch (clk_id) { case CLOCK_REALTIME: return _lfp_clock_getres(CALENDAR_CLOCK, res); case CLOCK_MONOTONIC: return _lfp_clock_getres(REALTIME_CLOCK, res); default: SYSERR(EINVAL); } #else # error "BUG! This point should not be reached" #endif } /*******************/ /* clock_gettime() */ /*******************/ #if defined(__APPLE__) && !HAVE_CLOCK_GETTIME static inline int _lfp_clock_gettime(clock_id_t clk_id, struct timespec *tp) { int ret = 0; kern_return_t kr; clock_serv_t clk_serv; mach_timespec_t mtp; host_t host_self = mach_host_self(); kr = host_get_clock_service(host_self, clk_id, &clk_serv); MACH_SYSCHECK(EINVAL, kr != KERN_SUCCESS); kr = clock_get_time(clk_serv, &mtp); MACH_SYSCHECK(EINVAL, kr != KERN_SUCCESS); _lfp_mach_timespec_t_to_timespec(&mtp, tp); cleanup: mach_port_deallocate(mach_task_self(), host_self); mach_port_deallocate(mach_task_self(), clk_serv); return ret; } #endif DSO_PUBLIC int lfp_clock_gettime(clockid_t clk_id, struct timespec *tp) { SYSCHECK(EFAULT, tp == NULL); #if HAVE_CLOCK_GETTIME return clock_gettime(clk_id, tp); #elif defined(__APPLE__) switch (clk_id) { case CLOCK_REALTIME: return _lfp_clock_gettime(CALENDAR_CLOCK, tp); case CLOCK_MONOTONIC: return _lfp_clock_gettime(REALTIME_CLOCK, tp); default: SYSERR(EINVAL); } #else # error "BUG! This point should not be reached" #endif } /*******************/ /* clock_settime() */ /*******************/ #if defined(__APPLE__) && !HAVE_CLOCK_GETTIME static inline int _lfp_clock_settime_realtime(struct timespec *tp) { struct timeval tv; _lfp_timespec_to_timeval(tp, &tv); SYSGUARD(settimeofday(&tv, NULL)); return 0; } #endif DSO_PUBLIC int lfp_clock_settime(clockid_t clk_id, struct timespec *tp) { SYSCHECK(EFAULT, tp == NULL); #if HAVE_CLOCK_GETTIME return clock_settime(clk_id, tp); #elif defined(__APPLE__) switch (clk_id) { case CLOCK_REALTIME: return _lfp_clock_settime_realtime(tp); case CLOCK_MONOTONIC: SYSERR(EPERM); default: SYSERR(EINVAL); } #else # error "BUG! This point should not be reached" #endif } libfixposix-0.5.1/src/lib/unistd.c000066400000000000000000000147261433332275700171070ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN 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 #include #include #if !defined(HAVE_GETPEEREID) # if defined(HAVE_UCRED_H) # include # else # include # endif #endif #if defined(__APPLE__) # include #else extern char** environ; #endif #include #include DSO_PUBLIC char** lfp_get_environ(void) { #if defined(__APPLE__) return *_NSGetEnviron(); #else return environ; #endif } DSO_PUBLIC int lfp_set_environ(char **newenv) { if (lfp_clearenv() < 0) { return -1; } else if (newenv != NULL) { for(char **var = newenv; *var != NULL; var++) { putenv(*var); } } return 0; } #if !defined(HAVE_CLEARENV) static void _lfp_reset_environ(void) { # if defined(__APPLE__) char ***envptr = _NSGetEnviron(); *envptr = NULL; # else environ = NULL; # endif } static char** _lfp_copy_environ(void) { char **env = lfp_get_environ(); if (env == NULL) return NULL; size_t len = 1; for(char **var = env; *var != NULL; var++) { ++len; } char **copy_env = calloc(len, sizeof(char*)); memcpy(copy_env, env, len * sizeof(char *)); return copy_env; } #endif DSO_PUBLIC int lfp_clearenv(void) { #if defined(HAVE_CLEARENV) return clearenv(); #else char **env = _lfp_copy_environ(); if (env == NULL) return 0; for(char **var = env; *var != NULL; var++) { char *tmp = strdup(*var); if (tmp == NULL) return -1; char *eql = strchr(tmp, '='); if (eql == NULL) { free(tmp); return -1; } else { *eql = '\0'; unsetenv(tmp); free(tmp); } } _lfp_reset_environ(); return 0; #endif } DSO_PUBLIC off_t lfp_lseek(int fd, off_t offset, int whence) { return lseek(fd, offset, whence); } DSO_PUBLIC int lfp_pipe (int pipefd[2], uint64_t flags) { #if defined(HAVE_PIPE2) // We assume that if pipe2() is defined then O_CLOEXEC too // exists, which means that it's in the lower part of "flags" return pipe2(pipefd, (int)flags & 0xFFFFFFFF); #else if (pipe(pipefd) < 0) { goto error_return; } if ((flags & O_CLOEXEC) && (lfp_set_fd_cloexec(pipefd[0], true) < 0 || lfp_set_fd_cloexec(pipefd[1], true) < 0)) { goto error_close; } if ((flags & O_NONBLOCK) && (lfp_set_fd_nonblock(pipefd[0], true) < 0 || lfp_set_fd_nonblock(pipefd[1], true) < 0)) { goto error_close; } return 0; error_close: close(pipefd[0]); close(pipefd[1]); error_return: return -1; #endif // HAVE_PIPE2 } DSO_PUBLIC ssize_t lfp_pread(int fd, void *buf, size_t count, off_t offset) { return pread(fd, buf, count, offset); } DSO_PUBLIC ssize_t lfp_pwrite(int fd, const void *buf, size_t count, off_t offset) { return pwrite(fd, buf, count, offset); } DSO_PUBLIC int lfp_truncate(const char *path, off_t length) { return truncate(path, length); } DSO_PUBLIC int lfp_ftruncate(int fd, off_t length) { return ftruncate(fd, length); } DSO_PUBLIC int lfp_execve(const char *path, char *const argv[], char *const envp[]) { SYSCHECK(EFAULT, path == NULL); SYSCHECK(ENOENT, path[0] == '\0'); return execve(path, argv, envp); } DSO_PUBLIC int lfp_execvpe(const char *file, char *const argv[], char *const envp[]) { SYSCHECK(EFAULT, file == NULL); SYSCHECK(ENOENT, file[0] == '\0'); if (strchr(file, '/')) return execve(file, argv, envp); size_t filelen = strlen(file); char path[PATH_MAX]; char *searchpath, *tmpath, *bindir, *saveptr = NULL; tmpath = searchpath = lfp_getpath(envp); while ((bindir = strtok_r(tmpath, ":", &saveptr)) != NULL) { tmpath = NULL; if ( bindir[0] != '\0' ) { size_t dirlen = lfp_strnlen(bindir, PATH_MAX); // directory + '/' + file size_t pathlen = dirlen + 1 + filelen; // if pathlen == PATH_MAX there's no room for the final \0 if (pathlen >= PATH_MAX) { errno = ENAMETOOLONG; break; } snprintf(path, PATH_MAX, "%s/%s", bindir, file); path[pathlen] = '\0'; execve(path, argv, envp); if ( errno == E2BIG || errno == ENOMEM ) break; } } free(searchpath); return -1; } DSO_PUBLIC int lfp_nice_k (int incr, int *new_nice) { SYSCHECK_K(new_nice == NULL, EFAULT); errno = 0; int ret = nice(incr); if (ret == -1 && errno != 0) { return -errno; } *new_nice = ret; return 0; } libfixposix-0.5.1/src/lib/wait.c000066400000000000000000000050751433332275700165420ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include DSO_PUBLIC bool lfp_wifexited (int status) { return WIFEXITED(status); } DSO_PUBLIC int lfp_wexitstatus (int status) { return WEXITSTATUS(status); } DSO_PUBLIC bool lfp_wifsignaled (int status) { return WIFSIGNALED(status); } DSO_PUBLIC int lfp_wtermsig (int status) { return WTERMSIG(status); } DSO_PUBLIC bool lfp_wcoredump (int status) { #ifdef WCOREDUMP return WCOREDUMP(status); #else return false; #endif } DSO_PUBLIC bool lfp_wifstopped (int status) { return WIFSTOPPED(status); } DSO_PUBLIC int lfp_wstopsig (int status) { return WSTOPSIG(status); } DSO_PUBLIC bool lfp_wifcontinued (int status) { #ifdef WIFCONTINUED return WIFCONTINUED(status); #else return false; #endif } libfixposix-0.5.1/src/libfixposix.libtool000066400000000000000000000002101433332275700205740ustar00rootroot00000000000000# -*- conf -*- # # Makes sure that the library is properly re-linked # when the version changes # # CURRENT:REVISION:AGE Version: 4:1:0 libfixposix-0.5.1/src/libfixposix.pc.in000066400000000000000000000005731433332275700201530ustar00rootroot00000000000000prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: @PACKAGE_NAME@ Description: Thin wrapper over POSIX functions Version: @PACKAGE_VERSION@ URL: @PACKAGE_URL@ Cflags: -I${includedir} @LFP_CFLAGS@ @LFS_CFLAGS@ Libs: -L${libdir} -lfixposix @PTHREAD_LIBS@ @LFS_LDFLAGS@ @LFS_LIBS@ Libs.private: -L${libdir} @LFP_LIBS@ @LFS_LDFLAGS@ @LFS_LIBS@ libfixposix-0.5.1/src/tests/000077500000000000000000000000001433332275700160175ustar00rootroot00000000000000libfixposix-0.5.1/src/tests/buildinfo.bats.in000066400000000000000000000010731433332275700212530ustar00rootroot00000000000000#!@BATSPATH@/bats # -*- shell-script -*- srcdir="${BATS_PREFIX}/../.." testbin="./src/tests/buildinfo" verfile=${srcdir}/VERSION @test "should return correct status code" { run "${testbin}" [ "${status}" -eq 0 ] } @test "should print build info" { run "${testbin}" got_release=$(echo "${output}" | cut -d \; -f 1) got_vcsid=$(echo "${output}" | cut -d \; -f 2) env 1>&2 release=$(< "${verfile}") [ ${release} == "${got_release}" ] vcsid=$(git rev-parse --short HEAD 2>/dev/null || true) [ x"${vcsid}" == x"${got_vcsid}" ] } libfixposix-0.5.1/src/tests/buildinfo.c000066400000000000000000000006641433332275700201440ustar00rootroot00000000000000#include #include int main() { struct lfp_buildinfo info; int ret = lfp_buildinfo(&info); if (ret != 0) { perror("lfp_buildinfo()"); return 1; } unsigned major = (info.release >> 16) & 0xff; unsigned minor = (info.release >> 8) & 0xff; unsigned micro = info.release & 0xff; printf("%u.%u.%u;%s\n", major, minor, micro, info.vcsid); return 0; } libfixposix-0.5.1/src/tests/lib/000077500000000000000000000000001433332275700165655ustar00rootroot00000000000000libfixposix-0.5.1/src/tests/lib/LICENSE000066400000000000000000000020421433332275700175700ustar00rootroot00000000000000Copyright (c) 2014 Sam Stephenson 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. libfixposix-0.5.1/src/tests/lib/bats000077500000000000000000000054201433332275700174450ustar00rootroot00000000000000#!/usr/bin/env bash set -e version() { echo "Bats 0.4.0" } usage() { version echo "Usage: bats [-c] [-p | -t] [ ...]" } help() { usage echo echo " is the path to a Bats test file, or the path to a directory" echo " containing Bats test files." echo echo " -c, --count Count the number of test cases without running any tests" echo " -h, --help Display this help message" echo " -p, --pretty Show results in pretty format (default for terminals)" echo " -t, --tap Show results in TAP format" echo " -v, --version Display the version number" echo echo " For more information, see https://github.com/sstephenson/bats" echo } resolve_link() { $(type -p greadlink readlink | head -1) "$1" } abs_dirname() { local cwd="$(pwd)" local path="$1" while [ -n "$path" ]; do cd "${path%/*}" local name="${path##*/}" path="$(resolve_link "$name" || true)" done pwd cd "$cwd" } expand_path() { { cd "$(dirname "$1")" 2>/dev/null local dirname="$PWD" cd "$OLDPWD" echo "$dirname/$(basename "$1")" } || echo "$1" } BATS_LIBEXEC="$(abs_dirname "$0")" export BATS_PREFIX="$(abs_dirname "$BATS_LIBEXEC")" export BATS_CWD="$(abs_dirname .)" export PATH="$BATS_LIBEXEC:$PATH" options=() arguments=() for arg in "$@"; do if [ "${arg:0:1}" = "-" ]; then if [ "${arg:1:1}" = "-" ]; then options[${#options[*]}]="${arg:2}" else index=1 while option="${arg:$index:1}"; do [ -n "$option" ] || break options[${#options[*]}]="$option" let index+=1 done fi else arguments[${#arguments[*]}]="$arg" fi done unset count_flag pretty [ -t 0 ] && [ -t 1 ] && pretty="1" [ -n "$CI" ] && pretty="" for option in "${options[@]}"; do case "$option" in "h" | "help" ) help exit 0 ;; "v" | "version" ) version exit 0 ;; "c" | "count" ) count_flag="-c" ;; "t" | "tap" ) pretty="" ;; "p" | "pretty" ) pretty="1" ;; * ) usage >&2 exit 1 ;; esac done if [ "${#arguments[@]}" -eq 0 ]; then usage >&2 exit 1 fi filenames=() for filename in "${arguments[@]}"; do if [ -d "$filename" ]; then shopt -s nullglob for suite_filename in "$(expand_path "$filename")"/*.bats; do filenames["${#filenames[@]}"]="$suite_filename" done shopt -u nullglob else filenames["${#filenames[@]}"]="$(expand_path "$filename")" fi done if [ "${#filenames[@]}" -eq 1 ]; then command="bats-exec-test" else command="bats-exec-suite" fi if [ -n "$pretty" ]; then extended_syntax_flag="-x" formatter="bats-format-tap-stream" else extended_syntax_flag="" formatter="cat" fi set -o pipefail execfail exec "$command" $count_flag $extended_syntax_flag "${filenames[@]}" | "$formatter" libfixposix-0.5.1/src/tests/lib/bats-exec-suite000077500000000000000000000017511433332275700215210ustar00rootroot00000000000000#!/usr/bin/env bash set -e count_only_flag="" if [ "$1" = "-c" ]; then count_only_flag=1 shift fi extended_syntax_flag="" if [ "$1" = "-x" ]; then extended_syntax_flag="-x" shift fi trap "kill 0; exit 1" int count=0 for filename in "$@"; do let count+="$(bats-exec-test -c "$filename")" done if [ -n "$count_only_flag" ]; then echo "$count" exit fi echo "1..$count" status=0 offset=0 for filename in "$@"; do index=0 { IFS= read -r # 1..n while IFS= read -r line; do case "$line" in "begin "* ) let index+=1 echo "${line/ $index / $(($offset + $index)) }" ;; "ok "* | "not ok "* ) [ -n "$extended_syntax_flag" ] || let index+=1 echo "${line/ $index / $(($offset + $index)) }" [ "${line:0:6}" != "not ok" ] || status=1 ;; * ) echo "$line" ;; esac done } < <( bats-exec-test $extended_syntax_flag "$filename" ) offset=$(($offset + $index)) done exit "$status" libfixposix-0.5.1/src/tests/lib/bats-exec-test000077500000000000000000000161341433332275700213500ustar00rootroot00000000000000#!/usr/bin/env bash set -e set -E set -T BATS_COUNT_ONLY="" if [ "$1" = "-c" ]; then BATS_COUNT_ONLY=1 shift fi BATS_EXTENDED_SYNTAX="" if [ "$1" = "-x" ]; then BATS_EXTENDED_SYNTAX="$1" shift fi BATS_TEST_FILENAME="$1" if [ -z "$BATS_TEST_FILENAME" ]; then echo "usage: bats-exec " >&2 exit 1 elif [ ! -f "$BATS_TEST_FILENAME" ]; then echo "bats: $BATS_TEST_FILENAME does not exist" >&2 exit 1 else shift fi BATS_TEST_DIRNAME="$(dirname "$BATS_TEST_FILENAME")" BATS_TEST_NAMES=() load() { local name="$1" local filename if [ "${name:0:1}" = "/" ]; then filename="${name}" else filename="$BATS_TEST_DIRNAME/${name}.bash" fi [ -f "$filename" ] || { echo "bats: $filename does not exist" >&2 exit 1 } source "${filename}" } run() { local e E T oldIFS [[ ! "$-" =~ e ]] || e=1 [[ ! "$-" =~ E ]] || E=1 [[ ! "$-" =~ T ]] || T=1 set +e set +E set +T output="$("$@" 2>&1)" status="$?" oldIFS=$IFS IFS=$'\n' lines=($output) [ -z "$e" ] || set -e [ -z "$E" ] || set -E [ -z "$T" ] || set -T IFS=$oldIFS } setup() { true } teardown() { true } skip() { BATS_TEST_SKIPPED=${1:-1} BATS_TEST_COMPLETED=1 exit 0 } bats_test_begin() { BATS_TEST_DESCRIPTION="$1" if [ -n "$BATS_EXTENDED_SYNTAX" ]; then echo "begin $BATS_TEST_NUMBER $BATS_TEST_DESCRIPTION" >&3 fi setup } bats_test_function() { local test_name="$1" BATS_TEST_NAMES["${#BATS_TEST_NAMES[@]}"]="$test_name" } bats_capture_stack_trace() { BATS_PREVIOUS_STACK_TRACE=( "${BATS_CURRENT_STACK_TRACE[@]}" ) BATS_CURRENT_STACK_TRACE=() local test_pattern=" $BATS_TEST_NAME $BATS_TEST_SOURCE" local setup_pattern=" setup $BATS_TEST_SOURCE" local teardown_pattern=" teardown $BATS_TEST_SOURCE" local frame local index=1 while frame="$(caller "$index")"; do BATS_CURRENT_STACK_TRACE["${#BATS_CURRENT_STACK_TRACE[@]}"]="$frame" if [[ "$frame" = *"$test_pattern" || \ "$frame" = *"$setup_pattern" || \ "$frame" = *"$teardown_pattern" ]]; then break else let index+=1 fi done BATS_SOURCE="$(bats_frame_filename "${BATS_CURRENT_STACK_TRACE[0]}")" BATS_LINENO="$(bats_frame_lineno "${BATS_CURRENT_STACK_TRACE[0]}")" } bats_print_stack_trace() { local frame local index=1 local count="${#@}" for frame in "$@"; do local filename="$(bats_trim_filename "$(bats_frame_filename "$frame")")" local lineno="$(bats_frame_lineno "$frame")" if [ $index -eq 1 ]; then echo -n "# (" else echo -n "# " fi local fn="$(bats_frame_function "$frame")" if [ "$fn" != "$BATS_TEST_NAME" ]; then echo -n "from function \`$fn' " fi if [ $index -eq $count ]; then echo "in test file $filename, line $lineno)" else echo "in file $filename, line $lineno," fi let index+=1 done } bats_print_failed_command() { local frame="$1" local status="$2" local filename="$(bats_frame_filename "$frame")" local lineno="$(bats_frame_lineno "$frame")" local failed_line="$(bats_extract_line "$filename" "$lineno")" local failed_command="$(bats_strip_string "$failed_line")" echo -n "# \`${failed_command}' " if [ $status -eq 1 ]; then echo "failed" else echo "failed with status $status" fi } bats_frame_lineno() { local frame="$1" local lineno="${frame%% *}" echo "$lineno" } bats_frame_function() { local frame="$1" local rest="${frame#* }" local fn="${rest%% *}" echo "$fn" } bats_frame_filename() { local frame="$1" local rest="${frame#* }" local filename="${rest#* }" if [ "$filename" = "$BATS_TEST_SOURCE" ]; then echo "$BATS_TEST_FILENAME" else echo "$filename" fi } bats_extract_line() { local filename="$1" local lineno="$2" sed -n "${lineno}p" "$filename" } bats_strip_string() { local string="$1" printf "%s" "$string" | sed -e "s/^[ "$'\t'"]*//" -e "s/[ "$'\t'"]*$//" } bats_trim_filename() { local filename="$1" local length="${#BATS_CWD}" if [ "${filename:0:length+1}" = "${BATS_CWD}/" ]; then echo "${filename:length+1}" else echo "$filename" fi } bats_debug_trap() { if [ "$BASH_SOURCE" != "$1" ]; then bats_capture_stack_trace fi } bats_error_trap() { BATS_ERROR_STATUS="$?" BATS_ERROR_STACK_TRACE=( "${BATS_PREVIOUS_STACK_TRACE[@]}" ) trap - debug } bats_teardown_trap() { trap "bats_exit_trap" exit local status=0 teardown >>"$BATS_OUT" 2>&1 || status="$?" if [ $status -eq 0 ]; then BATS_TEARDOWN_COMPLETED=1 elif [ -n "$BATS_TEST_COMPLETED" ]; then BATS_ERROR_STATUS="$status" BATS_ERROR_STACK_TRACE=( "${BATS_CURRENT_STACK_TRACE[@]}" ) fi bats_exit_trap } bats_exit_trap() { local status local skipped trap - err exit skipped="" if [ -n "$BATS_TEST_SKIPPED" ]; then skipped=" # skip" if [ "1" != "$BATS_TEST_SKIPPED" ]; then skipped+=" ($BATS_TEST_SKIPPED)" fi fi if [ -z "$BATS_TEST_COMPLETED" ] || [ -z "$BATS_TEARDOWN_COMPLETED" ]; then echo "not ok $BATS_TEST_NUMBER $BATS_TEST_DESCRIPTION" >&3 bats_print_stack_trace "${BATS_ERROR_STACK_TRACE[@]}" >&3 bats_print_failed_command "${BATS_ERROR_STACK_TRACE[${#BATS_ERROR_STACK_TRACE[@]}-1]}" "$BATS_ERROR_STATUS" >&3 sed -e "s/^/# /" < "$BATS_OUT" >&3 status=1 else echo "ok ${BATS_TEST_NUMBER}${skipped} ${BATS_TEST_DESCRIPTION}" >&3 status=0 fi rm -f "$BATS_OUT" exit "$status" } bats_perform_tests() { echo "1..$#" test_number=1 status=0 for test_name in "$@"; do "$0" $BATS_EXTENDED_SYNTAX "$BATS_TEST_FILENAME" "$test_name" "$test_number" || status=1 let test_number+=1 done exit "$status" } bats_perform_test() { BATS_TEST_NAME="$1" if [ "$(type -t "$BATS_TEST_NAME" || true)" = "function" ]; then BATS_TEST_NUMBER="$2" if [ -z "$BATS_TEST_NUMBER" ]; then echo "1..1" BATS_TEST_NUMBER="1" fi BATS_TEST_COMPLETED="" BATS_TEARDOWN_COMPLETED="" trap "bats_debug_trap \"\$BASH_SOURCE\"" debug trap "bats_error_trap" err trap "bats_teardown_trap" exit "$BATS_TEST_NAME" >>"$BATS_OUT" 2>&1 BATS_TEST_COMPLETED=1 else echo "bats: unknown test name \`$BATS_TEST_NAME'" >&2 exit 1 fi } if [ -z "$TMPDIR" ]; then BATS_TMPDIR="/tmp" else BATS_TMPDIR="${TMPDIR%/}" fi BATS_TMPNAME="$BATS_TMPDIR/bats.$$" BATS_PARENT_TMPNAME="$BATS_TMPDIR/bats.$PPID" BATS_OUT="${BATS_TMPNAME}.out" bats_preprocess_source() { BATS_TEST_SOURCE="${BATS_TMPNAME}.src" { tr -d '\r' < "$BATS_TEST_FILENAME"; echo; } | bats-preprocess > "$BATS_TEST_SOURCE" trap "bats_cleanup_preprocessed_source" err exit trap "bats_cleanup_preprocessed_source; exit 1" int } bats_cleanup_preprocessed_source() { rm -f "$BATS_TEST_SOURCE" } bats_evaluate_preprocessed_source() { if [ -z "$BATS_TEST_SOURCE" ]; then BATS_TEST_SOURCE="${BATS_PARENT_TMPNAME}.src" fi source "$BATS_TEST_SOURCE" } exec 3<&1 if [ "$#" -eq 0 ]; then bats_preprocess_source bats_evaluate_preprocessed_source if [ -n "$BATS_COUNT_ONLY" ]; then echo "${#BATS_TEST_NAMES[@]}" else bats_perform_tests "${BATS_TEST_NAMES[@]}" fi else bats_evaluate_preprocessed_source bats_perform_test "$@" fi libfixposix-0.5.1/src/tests/lib/bats-format-tap-stream000077500000000000000000000052421433332275700230100ustar00rootroot00000000000000#!/usr/bin/env bash set -e # Just stream the TAP output (sans extended syntax) if tput is missing command -v tput >/dev/null || exec grep -v "^begin " header_pattern='[0-9]+\.\.[0-9]+' IFS= read -r header if [[ "$header" =~ $header_pattern ]]; then count="${header:3}" index=0 failures=0 skipped=0 name="" count_column_width=$(( ${#count} * 2 + 2 )) else # If the first line isn't a TAP plan, print it and pass the rest through printf "%s\n" "$header" exec cat fi update_screen_width() { screen_width="$(tput cols)" count_column_left=$(( $screen_width - $count_column_width )) } trap update_screen_width WINCH update_screen_width begin() { go_to_column 0 printf_with_truncation $(( $count_column_left - 1 )) " %s" "$name" clear_to_end_of_line go_to_column $count_column_left printf "%${#count}s/${count}" "$index" go_to_column 1 } pass() { go_to_column 0 printf " ✓ %s" "$name" advance } skip() { local reason="$1" [ -z "$reason" ] || reason=": $reason" go_to_column 0 printf " - %s (skipped%s)" "$name" "$reason" advance } fail() { go_to_column 0 set_color 1 bold printf " ✗ %s" "$name" advance } log() { set_color 1 printf " %s\n" "$1" clear_color } summary() { printf "\n%d test%s" "$count" "$(plural "$count")" printf ", %d failure%s" "$failures" "$(plural "$failures")" if [ "$skipped" -gt 0 ]; then printf ", %d skipped" "$skipped" fi printf "\n" } printf_with_truncation() { local width="$1" shift local string="$(printf "$@")" if [ "${#string}" -gt "$width" ]; then printf "%s..." "${string:0:$(( $width - 4 ))}" else printf "%s" "$string" fi } go_to_column() { local column="$1" printf "\x1B[%dG" $(( $column + 1 )) } clear_to_end_of_line() { printf "\x1B[K" } advance() { clear_to_end_of_line echo clear_color } set_color() { local color="$1" local weight="$2" printf "\x1B[%d;%dm" $(( 30 + $color )) "$( [ "$weight" = "bold" ] && echo 1 || echo 22 )" } clear_color() { printf "\x1B[0m" } plural() { [ "$1" -eq 1 ] || echo "s" } _buffer="" buffer() { _buffer="${_buffer}$("$@")" } flush() { printf "%s" "$_buffer" _buffer="" } finish() { flush printf "\n" } trap finish EXIT while IFS= read -r line; do case "$line" in "begin "* ) let index+=1 name="${line#* $index }" buffer begin flush ;; "ok "* ) skip_expr="ok $index # skip (\(([^)]*)\))?" if [[ "$line" =~ $skip_expr ]]; then let skipped+=1 buffer skip "${BASH_REMATCH[2]}" else buffer pass fi ;; "not ok "* ) let failures+=1 buffer fail ;; "# "* ) buffer log "${line:2}" ;; esac done buffer summary libfixposix-0.5.1/src/tests/lib/bats-preprocess000077500000000000000000000021211433332275700216230ustar00rootroot00000000000000#!/usr/bin/env bash set -e encode_name() { local name="$1" local result="test_" if [[ ! "$name" =~ [^[:alnum:]\ _-] ]]; then name="${name//_/-5f}" name="${name//-/-2d}" name="${name// /_}" result+="$name" else local length="${#name}" local char i for ((i=0; i #include #include #include #include #define CHILDREN 128 #define NTEMPFILES (TMP_MAX/CHILDREN) char **allocStrings(int, int); void *stuff(void *arg); char **allocStrings(int nstrings, int length) { char **out=malloc(sizeof(char *) *nstrings); char *buf=malloc(length*nstrings); char *p=buf; for(int i=0;i #include int main(void) { fd_set rset, wset, eset; printf("1..1\n"); lfp_fd_zero(&rset); lfp_fd_zero(&wset); lfp_fd_zero(&eset); for(unsigned i = 0; i < FD_SETSIZE; i++) { if(lfp_fd_isset(i, &rset)) { printf("%d ", i); } } printf("ok 1\n"); return 0; } libfixposix-0.5.1/src/tests/signalfd.c000066400000000000000000000023521433332275700177540ustar00rootroot00000000000000#include #include #include #include #include #include #include static void error_abort (const char* msg, int perrorp) { if (perrorp) { perror(msg); } else { fprintf(stderr,"%s\n",msg); } abort(); } static ssize_t do_read(int fd, void *buf, size_t count) { ssize_t s; fd_set readfds; lfp_fd_zero(&readfds); do_try_read: lfp_fd_set(fd,&readfds); lfp_select(fd+1, &readfds, NULL, NULL, NULL, NULL); s = read(fd, buf, count); if (s != -1) { return s; } switch (errno) { case EAGAIN: case ERESTART: case EINTR: goto do_try_read; } return -1; } int main () { struct signalfd_siginfo fdsi; int sfd = lfp_install_signalfd(SIGINT, 0, NULL); size_t s = do_read(sfd, &fdsi, sizeof(struct signalfd_siginfo)); if (s != sizeof(struct signalfd_siginfo)) { error_abort("read", 1); } if (fdsi.ssi_signo == SIGINT) { printf("\nGot SIGINT\n"); } else { error_abort("unexpected signal", 0); } lfp_uninstall_signalfd(SIGINT, 0); lfp_install_signalfd(SIGINT, 0, NULL); lfp_uninstall_signalfd(SIGINT, 0); return 0; } libfixposix-0.5.1/src/tests/spawn.c000066400000000000000000000063531433332275700173220ustar00rootroot00000000000000#include #include static void error_abort (const char* msg, int perrorp) { if (perrorp) { perror(msg); } else { fprintf(stderr,"%s\n",msg); } abort(); } int main (void) { printf("1..1\n"); // Not implemented yet pid_t pid; char *path = "/bin/sh"; char *myargv[] = {"/bin/sh","-c","echo foo ; echo bar >&2 ; cat",NULL}; lfp_spawn_file_actions_t file_actions; lfp_spawnattr_t attr; int err, status; char tempnam1[] = {"/tmp/lfp_spawn_test_1_XXXXXX"}; char tempnam2[] = {"/tmp/lfp_spawn_test_2_XXXXXX"}; int tempfd1, tempfd2; char buf[256]; char expected[] = {"foo\nbar\nquux\n"}; if ( (tempfd1 = mkstemp(tempnam1)) == -1 ) { error_abort("failed to create temp file 1", true); } if ( (tempfd2 = mkstemp(tempnam2)) == -1 ) { error_abort("failed to create temp file 2", true); } if (write(tempfd1,"quux\n",5)!=5) { error_abort("failed to initialize temp file 1", true); } if (close(tempfd1) == -1) { error_abort("failed to close temp file 1", true); } if (close(tempfd2) == -1) { error_abort("failed to close temp file 2", true); } err = lfp_spawn_file_actions_init(&file_actions); if (err) { error_abort("failed to init file actions", true); } err = lfp_spawnattr_init(&attr); if (err) { error_abort("failed to init attr", true); } err = lfp_spawn_file_actions_addopen(&file_actions,10,tempnam1,O_EXCL|O_RDONLY,0); err = lfp_spawn_file_actions_adddup2(&file_actions,10,0); err = lfp_spawn_file_actions_addclose(&file_actions,10); err = lfp_spawn_file_actions_addopen(&file_actions,1,tempnam2,O_WRONLY|O_APPEND,0); err = lfp_spawn_file_actions_adddup2(&file_actions,1,2); err = lfp_spawn(&pid, path, myargv, lfp_get_environ(), &file_actions, &attr); if (err) { error_abort("failed to spawn", true); } fprintf(stderr,"spawned child %d\n",pid); err = lfp_spawn_file_actions_destroy(&file_actions); if (err) { error_abort("failed to init file actions", true); } err = lfp_spawnattr_destroy(&attr); if (err) { error_abort("failed to init attr", true); } err = waitpid(pid,&status,0); if (err == -1) { error_abort("failed to wait for child", true); } if (!WIFEXITED(status)) { error_abort("child didn't exit properly", false); } if (WEXITSTATUS(status)) { error_abort("child didn't exited with status 0", false); } tempfd2 = open(tempnam2, O_RDONLY); if (tempfd2==-1) { error_abort("failed to open the output file", true); } err = read(tempfd2,buf,sizeof(buf)); if (err == -1) { error_abort("failed to read the output file", true); } if (err != (sizeof(expected)-1)) { fprintf(stderr,"expected %zu bytes, got %d\n", sizeof(expected)-1, err); error_abort("found the wrong number of bytes", false); } err = strncmp(expected,buf,err); if (err) { error_abort("output doesn't match expectation", false); } err = unlink(tempnam1); if (err == -1) { error_abort("failed to remove the input file", true); } unlink(tempnam2); if (err == -1) { error_abort("failed to remove the output file", true); } fprintf(stderr,"spawn test successful\n"); printf("ok 1\n"); return 0; }