├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── COPYING ├── Makefile ├── README ├── TODO ├── Versions ├── cmake └── dist.cmake ├── dist.info ├── get-version ├── include ├── bsd │ ├── bsd.h │ ├── cdefs.h │ ├── err.h │ ├── getopt.h │ ├── inet.h │ ├── ip_icmp.h │ ├── libutil.h │ ├── md5.h │ ├── netinet │ │ └── ip_icmp.h │ ├── nlist.h │ ├── queue.h │ ├── random.h │ ├── readpassphrase.h │ ├── stdio.h │ ├── stdlib.h │ ├── string.h │ ├── sys │ │ ├── bitstring.h │ │ ├── cdefs.h │ │ ├── endian.h │ │ ├── poll.h │ │ ├── queue.h │ │ └── tree.h │ ├── unistd.h │ └── vis.h ├── libutil.h ├── nlist.h └── vis.h ├── libbsd-overlay.pc.in ├── libbsd.pc.in └── src ├── .gitignore ├── arc4random.3 ├── arc4random.c ├── arc4random_addrandom.3 ├── arc4random_buf.3 ├── arc4random_stir.3 ├── arc4random_uniform.3 ├── bsd_getopt.c ├── dehumanize_number.3 ├── dehumanize_number.c ├── err.c ├── fgetln.3 ├── fgetln.c ├── flopen.3 ├── flopen.c ├── fmtcheck.3 ├── fmtcheck.c ├── fpurge.c ├── getmode.3 ├── getpeereid.3 ├── getpeereid.c ├── hash ├── .gitignore ├── helper.c └── md5.c ├── heapsort.3 ├── heapsort.c ├── humanize_number.3 ├── humanize_number.c ├── inet_net_pton.c ├── local-elf.h ├── mdX.3 ├── merge.c ├── mergesort.3 ├── nlist.3 ├── nlist.c ├── pidfile.3 ├── pidfile.c ├── progname.c ├── radixsort.3 ├── radixsort.c ├── readpassphrase.3 ├── readpassphrase.c ├── reallocf.3 ├── reallocf.c ├── setmode.3 ├── setmode.c ├── setproctitle.c ├── sradixsort.3 ├── strlcat.3 ├── strlcat.c ├── strlcpy.3 ├── strlcpy.c ├── strmode.3 ├── strmode.c ├── strtonum.3 ├── strtonum.c ├── unvis.3 ├── unvis.c ├── vis.3 └── vis.c /.gitignore: -------------------------------------------------------------------------------- 1 | ChangeLog 2 | *.pc 3 | *.lo 4 | *.o 5 | *.so* 6 | *.a 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # 2 | # LuaDist Travis-CI Hook 3 | # 4 | 5 | # We assume C build environments 6 | language: C 7 | 8 | # Try using multiple Lua Implementations 9 | env: 10 | - TOOL="gcc" # Use native compiler (GCC usually) 11 | - TOOL="clang" # Use clang 12 | - TOOL="i686-w64-mingw32" # 32bit MinGW 13 | - TOOL="x86_64-w64-mingw32" # 64bit MinGW 14 | - TOOL="arm-linux-gnueabihf" # ARM hard-float (hf), linux 15 | 16 | # Crosscompile builds may fail 17 | matrix: 18 | allow_failures: 19 | - env: TOOL="i686-w64-mingw32" 20 | - env: TOOL="x86_64-w64-mingw32" 21 | - env: TOOL="arm-linux-gnueabihf" 22 | 23 | # Install dependencies 24 | install: 25 | - git clone git://github.com/LuaDist/Tools.git ~/_tools 26 | - ~/_tools/travis/travis install 27 | 28 | # Bootstap 29 | before_script: 30 | - ~/_tools/travis/travis bootstrap 31 | 32 | # Build the module 33 | script: 34 | - ~/_tools/travis/travis build 35 | 36 | # Execute additional tests or commands 37 | after_script: 38 | - ~/_tools/travis/travis test 39 | 40 | # Only watch the master branch 41 | branches: 42 | only: 43 | - master 44 | 45 | # Notify the LuaDist Dev group if needed 46 | notifications: 47 | recipients: 48 | - luadist-dev@googlegroups.com 49 | email: 50 | on_success: change 51 | on_failure: always 52 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2012 LuaDist 2 | # Submitted by David Manura. 3 | # Redistribution and use of this file is allowed according to the terms of the MIT license. 4 | # For details see the COPYRIGHT file distributed with LuaDist. 5 | # Please note that the package source code is licensed under its own license. 6 | 7 | project ( libbsd C ) 8 | cmake_minimum_required ( VERSION 2.8 ) 9 | include ( cmake/dist.cmake ) 10 | 11 | add_definitions ( 12 | -DLIBBSD_OVERLAY 13 | -DLIBBSD_DISABLE_DEPRECATED 14 | -D_GNU_SOURCE 15 | -D__REENTRANT 16 | ) 17 | include_directories ( include/bsd include ) 18 | 19 | # custom builders. 20 | file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/make_md5.cmake " 21 | file ( READ ${CMAKE_CURRENT_SOURCE_DIR}/src/hash/helper.c _text ) 22 | string ( REPLACE hashinc bsd/md5.h _text \"\${_text}\" ) 23 | string ( REPLACE HASH MD5 _text \"\${_text}\" ) 24 | file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/md5hl.c \"\${_text}\" ) 25 | " ) 26 | file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/make_man.cmake " 27 | file ( READ ${CMAKE_CURRENT_SOURCE_DIR}/src/mdX.3 _text ) 28 | string ( REPLACE mdX md5 _text \"\${_text}\" ) 29 | string ( REPLACE mdY md4 _text \"\${_text}\" ) 30 | string ( REPLACE MDX MD5 _text \"\${_text}\" ) 31 | file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/md5.3bsd \"\${_text}\" ) 32 | " ) 33 | add_custom_command ( 34 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/md5hl.c 35 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/make_md5.cmake 36 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/hash/helper.c 37 | ) 38 | add_custom_command ( 39 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/md5.3bsd 40 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/make_man.cmake 41 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/mdX.3 42 | ) 43 | add_custom_target ( md5.3bsd_target ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/md5.3bsd ) 44 | 45 | set ( SRC 46 | src/fmtcheck.c 47 | src/setproctitle.c 48 | src/strlcat.c 49 | src/strlcpy.c 50 | ) 51 | if ( WIN32 AND NOT CYGWIN ) 52 | message ( WARNING 53 | "WARNING: disabling many functions that are not currently compiling on windows [TODO]" ) 54 | else () 55 | set ( SRC ${SRC} 56 | src/arc4random.c 57 | src/bsd_getopt.c 58 | src/dehumanize_number.c 59 | src/err.c 60 | src/fgetln.c 61 | src/flopen.c 62 | src/fpurge.c 63 | src/getpeereid.c 64 | src/heapsort.c 65 | src/humanize_number.c 66 | src/inet_net_pton.c 67 | src/merge.c 68 | src/nlist.c 69 | src/pidfile.c 70 | src/progname.c 71 | src/radixsort.c 72 | src/readpassphrase.c 73 | src/reallocf.c 74 | src/setmode.c 75 | src/strmode.c 76 | src/strtonum.c 77 | src/unvis.c 78 | src/vis.c 79 | src/hash/md5.c 80 | ${CMAKE_CURRENT_BINARY_DIR}/md5hl.c 81 | ) 82 | endif () 83 | 84 | 85 | set ( INCLUDE_BSD_SYS 86 | include/bsd/sys/bitstring.h 87 | include/bsd/sys/cdefs.h 88 | include/bsd/sys/endian.h 89 | include/bsd/sys/poll.h 90 | include/bsd/sys/queue.h 91 | include/bsd/sys/tree.h ) 92 | set ( INCLUDE_BSD_NETINET 93 | include/bsd/netinet/ip_icmp.h ) 94 | set ( INCLUDE_BSD 95 | include/bsd/bsd.h 96 | include/bsd/cdefs.h 97 | include/bsd/err.h 98 | include/bsd/getopt.h 99 | include/bsd/inet.h 100 | include/bsd/ip_icmp.h 101 | include/bsd/libutil.h 102 | include/bsd/md5.h 103 | include/bsd/nlist.h 104 | include/bsd/queue.h 105 | include/bsd/random.h 106 | include/bsd/readpassphrase.h 107 | include/bsd/stdio.h 108 | include/bsd/stdlib.h 109 | include/bsd/string.h 110 | include/bsd/unistd.h 111 | include/bsd/vis.h ) 112 | set ( INCLUDE 113 | include/libutil.h 114 | include/nlist.h 115 | include/vis.h 116 | ) 117 | 118 | set ( MAN 119 | src/arc4random.3 120 | src/arc4random_addrandom.3 121 | src/arc4random_buf.3 122 | src/dehumanize_number.3 123 | src/arc4random_stir.3 124 | src/arc4random_uniform.3 125 | src/fgetln.3 126 | src/flopen.3 127 | src/fmtcheck.3 128 | src/getmode.3 129 | src/getpeereid.3 130 | src/heapsort.3 131 | src/humanize_number.3 132 | src/mergesort.3 133 | src/nlist.3 134 | src/pidfile.3 135 | src/readpassphrase.3 136 | src/reallocf.3 137 | src/strlcpy.3 138 | src/strlcat.3 139 | src/strtonum.3 140 | src/radixsort.3 141 | src/setmode.3 142 | src/sradixsort.3 143 | src/strmode.3 144 | src/unvis.3 145 | src/vis.3 146 | ${CMAKE_CURRENT_BINARY_DIR}/md5.3bsd 147 | ) 148 | 149 | add_library ( bsd ${SRC} ) 150 | install_library ( bsd ) 151 | install_header ( ${INCLUDE} ) 152 | install_header ( ${INCLUDE_BSD} INTO bsd ) 153 | install_header ( ${INCLUDE_BSD_NETINET} INTO bsd/netinet ) 154 | install_header ( ${INCLUDE_BSD_SYS} INTO bsd/sys ) 155 | install_doc ( ${MAN} INTO man ) 156 | install_data ( COPYING README TODO Versions ) 157 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | VERSION := $(shell ./get-version) 2 | 3 | LIB_NAME := libbsd 4 | LIB_VERSION_MAJOR := 0 5 | LIB_VERSION_MINOR := 3 6 | LIB_VERSION_MICRO := 0 7 | LIB_VERSION := $(LIB_VERSION_MAJOR).$(LIB_VERSION_MINOR).$(LIB_VERSION_MICRO) 8 | 9 | LIB_PKGCONFIG := $(LIB_NAME).pc 10 | LIB_PKGCONFIG_OVERLAY := $(LIB_NAME)-overlay.pc 11 | LIB_STATIC := $(LIB_NAME).a 12 | LIB_SHARED_SO := $(LIB_NAME).so 13 | LIB_SONAME := $(LIB_SHARED_SO).$(LIB_VERSION_MAJOR) 14 | LIB_SHARED := $(LIB_SONAME).$(LIB_VERSION_MINOR).$(LIB_VERSION_MICRO) 15 | 16 | TAR_NAME := $(LIB_NAME)-$(VERSION) 17 | TAR_FILE := $(TAR_NAME).tar.gz 18 | 19 | LIB_DIST := \ 20 | ChangeLog 21 | 22 | LIB_SRCS_GEN := \ 23 | hash/md5hl.c 24 | LIB_SRCS := \ 25 | arc4random.c \ 26 | bsd_getopt.c \ 27 | err.c \ 28 | fgetln.c \ 29 | flopen.c \ 30 | fpurge.c \ 31 | getpeereid.c \ 32 | heapsort.c \ 33 | merge.c \ 34 | humanize_number.c \ 35 | dehumanize_number.c \ 36 | inet_net_pton.c \ 37 | hash/md5.c \ 38 | pidfile.c \ 39 | readpassphrase.c \ 40 | reallocf.c \ 41 | setmode.c \ 42 | setproctitle.c \ 43 | strmode.c \ 44 | strtonum.c \ 45 | strlcat.c strlcpy.c \ 46 | fmtcheck.c \ 47 | nlist.c \ 48 | progname.c \ 49 | radixsort.c \ 50 | vis.c unvis.c \ 51 | $(LIB_SRCS_GEN) 52 | LIB_SRCS_GEN := $(patsubst %,src/%,$(LIB_SRCS_GEN)) 53 | LIB_SRCS := $(patsubst %,src/%,$(LIB_SRCS)) 54 | 55 | LIB_INCLUDES := \ 56 | bsd/cdefs.h \ 57 | bsd/queue.h \ 58 | bsd/ip_icmp.h \ 59 | bsd/sys/cdefs.h \ 60 | bsd/sys/bitstring.h \ 61 | bsd/sys/endian.h \ 62 | bsd/sys/poll.h \ 63 | bsd/sys/queue.h \ 64 | bsd/sys/tree.h \ 65 | bsd/netinet/ip_icmp.h \ 66 | bsd/err.h \ 67 | bsd/getopt.h \ 68 | bsd/inet.h \ 69 | bsd/random.h \ 70 | bsd/md5.h \ 71 | bsd/string.h \ 72 | bsd/bsd.h \ 73 | bsd/stdio.h \ 74 | bsd/stdlib.h \ 75 | bsd/readpassphrase.h \ 76 | bsd/unistd.h \ 77 | bsd/nlist.h \ 78 | bsd/vis.h \ 79 | bsd/libutil.h \ 80 | nlist.h \ 81 | vis.h \ 82 | libutil.h 83 | 84 | LIB_MANS_GEN := \ 85 | md5.3bsd 86 | LIB_MANS := \ 87 | arc4random.3 \ 88 | arc4random_addrandom.3 \ 89 | arc4random_buf.3 \ 90 | arc4random_stir.3 \ 91 | arc4random_uniform.3 \ 92 | dehumanize_number.3 \ 93 | strtonum.3 \ 94 | strlcpy.3 \ 95 | strlcat.3 \ 96 | fgetln.3 \ 97 | flopen.3 \ 98 | getpeereid.3 \ 99 | readpassphrase.3 \ 100 | reallocf.3 \ 101 | heapsort.3 \ 102 | humanize_number.3 \ 103 | fmtcheck.3 \ 104 | mergesort.3 \ 105 | radixsort.3 \ 106 | sradixsort.3 \ 107 | nlist.3 \ 108 | pidfile.3 \ 109 | setmode.3 \ 110 | getmode.3 \ 111 | strmode.3 \ 112 | unvis.3 \ 113 | vis.3 \ 114 | $(LIB_MANS_GEN) 115 | LIB_MANS_GEN := $(patsubst %,src/%,$(LIB_MANS_GEN)) 116 | LIB_MANS := $(patsubst %,src/%,$(LIB_MANS)) 117 | 118 | LIB_STATIC_OBJS := $(LIB_SRCS:%.c=%.o) 119 | LIB_SHARED_OBJS := $(LIB_SRCS:%.c=%.lo) 120 | 121 | AR = ar 122 | CC = gcc 123 | CCLD = $(CC) 124 | 125 | # Set default values for user variables 126 | CPPFLAGS ?= 127 | CFLAGS ?= -g -Wall -Wextra -Wno-unused-variable 128 | LDFLAGS ?= 129 | 130 | # Internal makefile variables 131 | MK_CPPFLAGS := -Iinclude/bsd/ -Iinclude/ \ 132 | -DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \ 133 | -D_GNU_SOURCE -D__REENTRANT 134 | MK_CFLAGS := 135 | MK_LDFLAGS := 136 | 137 | COMPILE = $(CC) $(MK_CPPFLAGS) $(CPPFLAGS) $(MK_CFLAGS) $(CFLAGS) 138 | LINK = $(CCLD) $(MK_CFLAGS) $(CFLAGS) $(MK_LDFLAGS) $(LDFLAGS) 139 | 140 | prefix = /usr 141 | exec_prefix = 142 | libdir = ${exec_prefix}/lib 143 | usrlibdir = ${prefix}/lib 144 | includedir = ${prefix}/include 145 | pkgconfigdir = ${usrlibdir}/pkgconfig 146 | mandir = ${prefix}/share/man 147 | 148 | .PHONY: libs 149 | libs: $(LIB_STATIC) $(LIB_SHARED_SO) $(LIB_PKGCONFIG) $(LIB_PKGCONFIG_OVERLAY) 150 | 151 | .PHONY: man 152 | man: $(LIB_MANS) 153 | 154 | %.lo: %.c 155 | $(COMPILE) -o $@ -DPIC -fPIC -c $< 156 | 157 | %.o: %.c 158 | $(COMPILE) -o $@ -c $< 159 | 160 | src/md5.3bsd: src/mdX.3 161 | sed -e 's/mdX/md5/g' -e 's/mdY/md4/g' -e 's/MDX/MD5/g' $< > $@ 162 | 163 | src/hash/md5hl.c: src/hash/helper.c 164 | sed -e 's:hashinc:bsd/md5.h:g' -e 's:HASH:MD5:g' $< > $@ 165 | 166 | %.pc: %.pc.in 167 | sed -e 's:@VERSION@:$(VERSION):' \ 168 | -e 's:@prefix@:$(value prefix):' \ 169 | -e 's:@exec_prefix@:$(value exec_prefix):' \ 170 | -e 's:@libdir@:$(value usrlibdir):' \ 171 | -e 's:@includedir@:$(value includedir):' \ 172 | $< > $@ 173 | 174 | $(LIB_STATIC): $(LIB_STATIC_OBJS) 175 | $(AR) rcs $@ $^ 176 | 177 | $(LIB_SHARED_SO): $(LIB_SONAME) 178 | ln -fs $^ $@ 179 | 180 | $(LIB_SONAME): $(LIB_SHARED) 181 | ln -fs $^ $@ 182 | 183 | $(LIB_SHARED): $(LIB_SHARED_OBJS) 184 | $(LINK) \ 185 | -shared \ 186 | -Wl,-soname -Wl,$(LIB_SONAME) \ 187 | -Wl,--version-script=Versions \ 188 | -o $@ $^ 189 | 190 | .PHONY: ChangeLog 191 | ChangeLog: 192 | -git log --stat -C >$@ 193 | 194 | .PHONY: dist 195 | dist: $(LIB_DIST) 196 | mkdir $(TAR_NAME) 197 | echo $(VERSION) >$(TAR_NAME)/.dist-version 198 | cp -a --parents $(LIB_DIST) `git ls-files` $(TAR_NAME) 199 | tar czf $(TAR_FILE) --exclude=.gitignore $(TAR_NAME) 200 | rm -rf $(TAR_NAME) 201 | gpg -a -b $(TAR_FILE) 202 | 203 | .PHONY: install 204 | install: libs man 205 | mkdir -p $(DESTDIR)$(libdir) 206 | mkdir -p $(DESTDIR)$(usrlibdir) 207 | mkdir -p $(DESTDIR)$(includedir)/bsd/ 208 | mkdir -p $(DESTDIR)$(includedir)/bsd/sys/ 209 | mkdir -p $(DESTDIR)$(includedir)/bsd/netinet/ 210 | mkdir -p $(DESTDIR)$(mandir)/man3 211 | mkdir -p $(DESTDIR)$(pkgconfigdir) 212 | install -m644 $(LIB_STATIC) $(DESTDIR)$(usrlibdir) 213 | install -m755 $(LIB_SHARED) $(DESTDIR)$(libdir) 214 | for i in $(LIB_INCLUDES); do \ 215 | install -m644 include/$$i $(DESTDIR)$(includedir)/$$i; \ 216 | done 217 | install -m644 $(LIB_MANS) $(DESTDIR)$(mandir)/man3 218 | install -m644 $(LIB_PKGCONFIG) $(DESTDIR)$(pkgconfigdir) 219 | install -m644 $(LIB_PKGCONFIG_OVERLAY) $(DESTDIR)$(pkgconfigdir) 220 | ifeq ($(libdir),$(usrlibdir)) 221 | # If both dirs are the same, do a relative symlink. 222 | ln -sf $(LIB_SHARED) $(DESTDIR)$(usrlibdir)/$(LIB_SHARED_SO) 223 | else 224 | # Otherwise, do an absolute one. 225 | ln -sf $(libdir)/$(LIB_SHARED) $(DESTDIR)$(usrlibdir)/$(LIB_SHARED_SO) 226 | endif 227 | ln -sf $(LIB_SHARED) $(DESTDIR)$(libdir)/$(LIB_SONAME) 228 | 229 | .PHONY: clean 230 | clean: 231 | rm -f $(LIB_PKGCONFIG) 232 | rm -f $(LIB_PKGCONFIG_OVERLAY) 233 | rm -f $(LIB_SRCS_GEN) $(LIB_MANS_GEN) 234 | rm -f $(LIB_STATIC_OBJS) 235 | rm -f $(LIB_STATIC) 236 | rm -f $(LIB_SHARED_OBJS) 237 | rm -f $(LIB_SHARED) $(LIB_SONAME) $(LIB_SHARED_SO) 238 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | libbsd - Utility functions from BSD systems 2 | 3 | This library provides useful functions commonly found on BSD systems, 4 | and lacking on others like GNU systems, thus making it easier to port 5 | projects with strong BSD origins, without needing to embed the same 6 | code over and over again on each project. 7 | 8 | 9 | Releases 10 | -------- 11 | 12 | 13 | 14 | 15 | Mailing List 16 | ------------ 17 | 18 | The subscription interface and web archives can be found at: 19 | 20 | 21 | 22 | The mail address is: 23 | 24 | libbsd@lists.freedesktop.org 25 | 26 | 27 | Source Repository 28 | ----------------- 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | * Add more functions used by ported packages (check openssh). 2 | * Add missing man pages. 3 | * Add a README.import file. 4 | -------------------------------------------------------------------------------- /Versions: -------------------------------------------------------------------------------- 1 | LIBBSD_0.0 { 2 | global: 3 | arc4random; 4 | arc4random_stir; 5 | arc4random_addrandom; 6 | 7 | bsd_getopt; 8 | optreset; 9 | 10 | errc; 11 | warnc; 12 | verrc; 13 | vwarnc; 14 | 15 | fgetln; 16 | fmtcheck; 17 | heapsort; 18 | humanize_number; 19 | 20 | inet_net_pton; /* XXX: Already provided by glibc, remove. */ 21 | 22 | getprogname; 23 | setprogname; 24 | 25 | strlcpy; 26 | strlcat; 27 | 28 | setmode; 29 | getmode; 30 | 31 | vis; 32 | strvis; 33 | strvisx; 34 | unvis; 35 | strunvis; 36 | strunvisx; 37 | 38 | MD5Init; 39 | MD5Update; 40 | MD5Pad; 41 | MD5Final; 42 | MD5Transform; 43 | MD5End; 44 | MD5File; 45 | MD5FileChunk; 46 | MD5Data; 47 | 48 | local: 49 | *; 50 | }; 51 | 52 | LIBBSD_0.1 { 53 | strmode; 54 | 55 | __fdnlist; /* Private symbol, but libkvm uses it. */ 56 | nlist; 57 | } LIBBSD_0.0; 58 | 59 | LIBBSD_0.2 { 60 | strtonum; 61 | 62 | strnvis; 63 | strnunvis; 64 | 65 | dehumanize_number; 66 | 67 | readpassphrase; 68 | 69 | flopen; 70 | 71 | pidfile_open; 72 | pidfile_write; 73 | pidfile_close; 74 | pidfile_remove; 75 | 76 | setproctitle; 77 | 78 | arc4random_buf; 79 | arc4random_uniform; 80 | } LIBBSD_0.1; 81 | 82 | LIBBSD_0.3 { 83 | reallocf; 84 | getpeereid; 85 | 86 | mergesort; 87 | radixsort; 88 | sradixsort; 89 | 90 | fpurge; 91 | } LIBBSD_0.2; 92 | -------------------------------------------------------------------------------- /dist.info: -------------------------------------------------------------------------------- 1 | --- This file is part of LuaDist project 2 | 3 | name = "libbsd" 4 | version = "0.3.0" 5 | 6 | desc = "BSD functions common only on BSD systems, for portability to non-BSD systems." 7 | author = "many (see COPYING)" 8 | license = "mostly New BSD and MIT style" 9 | url = "http://libbsd.freedesktop.org/wiki/" 10 | maintainer = "David Manura" 11 | 12 | depends = { 13 | "lua ~> 5.1" 14 | } 15 | -------------------------------------------------------------------------------- /get-version: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # get-version 4 | # 5 | # Copyright © 2009 Guillem Jover 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 1. Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # 2. Redistributions in binary form must reproduce the above copyright 13 | # notice, this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | # 3. The name of the author may not be used to endorse or promote products 16 | # derived from this software without specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 19 | # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 20 | # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | # THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 24 | # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26 | # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 27 | # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | if [ -f .dist-version ]; then 30 | # Get the version from the file distributed in the tarball. 31 | version=$(cat .dist-version) 32 | elif [ -d .git ]; then 33 | # Ger the version from the git repository. 34 | version=$(git describe --abbrev=4 HEAD 2>/dev/null) 35 | 36 | # Check if we are on a dirty checkout. 37 | git update-index --refresh -q >/dev/null 38 | dirty=$(git diff-index --name-only HEAD 2>/dev/null) 39 | if [ -n "$dirty" ]; then 40 | version="$version-dirty" 41 | fi 42 | else 43 | echo "error: cannot get project version." 1>&2 44 | exit 1 45 | fi 46 | 47 | echo "$version" 48 | -------------------------------------------------------------------------------- /include/bsd/bsd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2004, 2005, 2006 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_H 28 | #define LIBBSD_H 29 | 30 | /* 31 | * Include all bsd compat headers. 32 | */ 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | /* FIXME: Will be removed in the future. */ 45 | #ifndef LIBBSD_DISABLE_DEPRECATED 46 | #include 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /include/bsd/cdefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2009 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_BSD_CDEFS_H 28 | #define LIBBSD_BSD_CDEFS_H 29 | 30 | #ifdef LIBBSD_DISABLE_DEPRECATED 31 | #error "Deprecated header, use or libbsd-overlay.pc instead." 32 | #else 33 | #warning "Deprecated header, use or libbsd-overlay.pc instead." 34 | #endif 35 | 36 | #ifdef LIBBSD_OVERLAY 37 | #include 38 | #else 39 | #include 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/bsd/err.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2006 Robert Millan 3 | * Copyright © 2009, 2011 Guillem Jover 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 18 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 19 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef LIBBSD_ERR_H 29 | #define LIBBSD_ERR_H 30 | 31 | #include 32 | 33 | #include 34 | 35 | #ifdef LIBBSD_OVERLAY 36 | #include_next 37 | #else 38 | #include 39 | #endif 40 | 41 | __BEGIN_DECLS 42 | extern void warnc (int code, const char *format, ...); 43 | extern void vwarnc (int code, const char *format, va_list ap); 44 | extern void errc (int status, int code, const char *format, ...); 45 | extern void verrc (int status, int code, const char *format, va_list ap); 46 | __END_DECLS 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /include/bsd/getopt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2011 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_GETOPT_H 28 | #define LIBBSD_GETOPT_H 29 | 30 | #ifdef LIBBSD_OVERLAY 31 | #include_next 32 | #include 33 | #else 34 | #warning "Deprecated header, use or with libbsd-overlay.pc instead." 35 | #include 36 | #include 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/bsd/inet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2008, 2009 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_INET_H 28 | #define LIBBSD_INET_H 29 | 30 | #ifdef LIBBSD_DISABLE_DEPRECATED 31 | #error "Deprecated header, use instead." 32 | #else 33 | #warning "Deprecated header, use instead." 34 | #endif 35 | 36 | #include 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /include/bsd/ip_icmp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2009 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_BSD_IP_ICMP_H 28 | #define LIBBSD_BSD_IP_ICMP_H 29 | 30 | #ifdef LIBBSD_DISABLE_DEPRECATED 31 | #error "Deprecated header, use or libbsd-overlay.pc instead." 32 | #else 33 | #warning "Deprecated header, use or libbsd-overlay.pc instead." 34 | #endif 35 | 36 | #ifdef LIBBSD_OVERLAY 37 | #include 38 | #else 39 | #include 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/bsd/libutil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996 Peter Wemm . 3 | * All rights reserved. 4 | * Copyright (c) 2002 Networks Associates Technology, Inc. 5 | * All rights reserved. 6 | * 7 | * Portions of this software were developed for the FreeBSD Project by 8 | * ThinkSec AS and NAI Labs, the Security Research Division of Network 9 | * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 10 | * ("CBOSS"), as part of the DARPA CHATS research program. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, is permitted provided that the following conditions 14 | * are met: 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * 3. The name of the author may not be used to endorse or promote 21 | * products derived from this software without specific prior written 22 | * permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 | * SUCH DAMAGE. 35 | * 36 | * $FreeBSD: src/lib/libutil/libutil.h,v 1.47 2008/04/23 00:49:12 scf Exp $ 37 | */ 38 | 39 | #ifndef _LIBUTIL_H_ 40 | #define _LIBUTIL_H_ 41 | 42 | #include 43 | #include 44 | 45 | /* for pidfile.c */ 46 | struct pidfh { 47 | int pf_fd; 48 | char *pf_path; 49 | dev_t pf_dev; 50 | ino_t pf_ino; 51 | }; 52 | 53 | __BEGIN_DECLS 54 | int humanize_number(char *buf, size_t len, int64_t bytes, 55 | const char *suffix, int scale, int flags); 56 | 57 | int flopen(const char *_path, int _flags, ...); 58 | 59 | struct pidfh *pidfile_open(const char *path, mode_t mode, pid_t *pidptr); 60 | int pidfile_write(struct pidfh *pfh); 61 | int pidfile_close(struct pidfh *pfh); 62 | int pidfile_remove(struct pidfh *pfh); 63 | __END_DECLS 64 | 65 | /* humanize_number(3) */ 66 | #define HN_DECIMAL 0x01 67 | #define HN_NOSPACE 0x02 68 | #define HN_B 0x04 69 | #define HN_DIVISOR_1000 0x08 70 | 71 | #define HN_GETSCALE 0x10 72 | #define HN_AUTOSCALE 0x20 73 | 74 | #endif /* !_LIBUTIL_H_ */ 75 | -------------------------------------------------------------------------------- /include/bsd/md5.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: md5.h,v 1.16 2004/06/22 01:57:30 jfb Exp $ */ 2 | 3 | /* 4 | * This code implements the MD5 message-digest algorithm. 5 | * The algorithm is due to Ron Rivest. This code was 6 | * written by Colin Plumb in 1993, no copyright is claimed. 7 | * This code is in the public domain; do with it what you wish. 8 | * 9 | * Equivalent code is available from RSA Data Security, Inc. 10 | * This code has been tested against that, and is equivalent, 11 | * except that you don't need to include two pages of legalese 12 | * with every copy. 13 | */ 14 | 15 | #ifndef _MD5_H_ 16 | #define _MD5_H_ 17 | 18 | #define MD5_BLOCK_LENGTH 64 19 | #define MD5_DIGEST_LENGTH 16 20 | #define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1) 21 | 22 | typedef struct MD5Context { 23 | u_int32_t state[4]; /* state */ 24 | u_int64_t count; /* number of bits, mod 2^64 */ 25 | u_int8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */ 26 | } MD5_CTX; 27 | 28 | #include 29 | 30 | __BEGIN_DECLS 31 | void MD5Init(MD5_CTX *); 32 | void MD5Update(MD5_CTX *, const u_int8_t *, size_t) 33 | __attribute__((__bounded__(__string__,2,3))); 34 | void MD5Pad(MD5_CTX *); 35 | void MD5Final(u_int8_t [MD5_DIGEST_LENGTH], MD5_CTX *) 36 | __attribute__((__bounded__(__minbytes__,1,MD5_DIGEST_LENGTH))); 37 | void MD5Transform(u_int32_t [4], const u_int8_t [MD5_BLOCK_LENGTH]) 38 | __attribute__((__bounded__(__minbytes__,1,4))) 39 | __attribute__((__bounded__(__minbytes__,2,MD5_BLOCK_LENGTH))); 40 | char *MD5End(MD5_CTX *, char *) 41 | __attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH))); 42 | char *MD5File(const char *, char *) 43 | __attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH))); 44 | char *MD5FileChunk(const char *, char *, off_t, off_t) 45 | __attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH))); 46 | char *MD5Data(const u_int8_t *, size_t, char *) 47 | __attribute__((__bounded__(__string__,1,2))) 48 | __attribute__((__bounded__(__minbytes__,3,MD5_DIGEST_STRING_LENGTH))); 49 | __END_DECLS 50 | 51 | #endif /* _MD5_H_ */ 52 | -------------------------------------------------------------------------------- /include/bsd/nlist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2009 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_NLIST_H 28 | #define LIBBSD_NLIST_H 29 | 30 | #include 31 | #include 32 | 33 | __BEGIN_DECLS 34 | extern int nlist(const char *filename, struct nlist *list); 35 | __END_DECLS 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/bsd/queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2009 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_BSD_QUEUE_H 28 | #define LIBBSD_BSD_QUEUE_H 29 | 30 | #ifdef LIBBSD_DISABLE_DEPRECATED 31 | #error "Deprecated header, use or libbsd-overlay.pc instead." 32 | #else 33 | #warning "Deprecated header, use or libbsd-overlay.pc instead." 34 | #endif 35 | 36 | #ifdef LIBBSD_OVERLAY 37 | #include 38 | #else 39 | #include 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/bsd/random.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2004, 2005, 2009 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_RANDOM_H 28 | #define LIBBSD_RANDOM_H 29 | 30 | #ifdef LIBBSD_DISABLE_DEPRECATED 31 | #error "Deprecated header, use instead." 32 | #else 33 | #warning "Deprecated header, use instead." 34 | #endif 35 | 36 | #ifdef LIBBSD_OVERLAY 37 | #include 38 | #else 39 | #include 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/bsd/readpassphrase.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: readpassphrase.h,v 1.4 2003/06/03 01:52:39 millert Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2000, 2002 Todd C. Miller 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | * 18 | * Sponsored in part by the Defense Advanced Research Projects 19 | * Agency (DARPA) and Air Force Research Laboratory, Air Force 20 | * Materiel Command, USAF, under agreement number F39502-99-1-0512. 21 | */ 22 | 23 | #ifndef _READPASSPHRASE_H_ 24 | #define _READPASSPHRASE_H_ 25 | 26 | #define RPP_ECHO_OFF 0x00 /* Turn off echo (default). */ 27 | #define RPP_ECHO_ON 0x01 /* Leave echo on. */ 28 | #define RPP_REQUIRE_TTY 0x02 /* Fail if there is no tty. */ 29 | #define RPP_FORCELOWER 0x04 /* Force input to lower case. */ 30 | #define RPP_FORCEUPPER 0x08 /* Force input to upper case. */ 31 | #define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */ 32 | #define RPP_STDIN 0x20 /* Read from stdin, not /dev/tty */ 33 | 34 | #include 35 | #include 36 | 37 | __BEGIN_DECLS 38 | char * readpassphrase(const char *, char *, size_t, int); 39 | __END_DECLS 40 | 41 | #endif /* !_READPASSPHRASE_H_ */ 42 | -------------------------------------------------------------------------------- /include/bsd/stdio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2004, 2005, 2009, 2011 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_STDIO_H 28 | #define LIBBSD_STDIO_H 29 | 30 | #include 31 | #include 32 | 33 | #ifdef LIBBSD_OVERLAY 34 | #include_next 35 | #else 36 | #include 37 | #endif 38 | 39 | __BEGIN_DECLS 40 | const char *fmtcheck(const char *, const char *); 41 | 42 | char *fgetln(FILE *fp, size_t *lenp); 43 | 44 | int fpurge(FILE *fp); 45 | __END_DECLS 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /include/bsd/stdlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2005 Aurelien Jarno 3 | * Copyright © 2006 Robert Millan 4 | * Copyright © 2008-2011 Guillem Jover 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 19 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 20 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef LIBBSD_STDLIB_H 30 | #define LIBBSD_STDLIB_H 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #ifdef LIBBSD_OVERLAY 37 | #include_next 38 | #else 39 | #include 40 | #endif 41 | 42 | /* For compatibility with NetBSD, which defines humanize_number here. */ 43 | #ifdef LIBBSD_OVERLAY 44 | #include 45 | #else 46 | #include 47 | #endif 48 | 49 | /* FIXME: Temporary inclusions to avoid API breakage, will be removed soon. */ 50 | #ifndef LIBBSD_DISABLE_DEPRECATED 51 | #ifdef LIBBSD_OVERLAY 52 | #include 53 | #include 54 | #else 55 | #include 56 | #include 57 | #endif 58 | #endif 59 | 60 | __BEGIN_DECLS 61 | u_int32_t arc4random(); 62 | void arc4random_stir(); 63 | void arc4random_addrandom(u_char *dat, int datlen); 64 | void arc4random_buf(void *_buf, size_t n); 65 | u_int32_t arc4random_uniform(u_int32_t upper_bound); 66 | 67 | int dehumanize_number(const char *str, int64_t *size); 68 | 69 | const char *getprogname(void); 70 | void setprogname(const char *); 71 | 72 | int heapsort (void *, size_t, size_t, int (*)(const void *, const void *)); 73 | int mergesort(void *base, size_t nmemb, size_t size, 74 | int (*cmp)(const void *, const void *)); 75 | int radixsort(const unsigned char **base, int nmemb, 76 | const unsigned char *table, unsigned endbyte); 77 | int sradixsort(const unsigned char **base, int nmemb, 78 | const unsigned char *table, unsigned endbyte); 79 | 80 | void *reallocf(void *ptr, size_t size); 81 | 82 | long long strtonum(const char *nptr, long long minval, long long maxval, 83 | const char **errstr); 84 | __END_DECLS 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /include/bsd/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2004, 2005, 2009, 2011 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_STRING_H 28 | #define LIBBSD_STRING_H 29 | 30 | #include 31 | #include 32 | 33 | #ifdef LIBBSD_OVERLAY 34 | #include_next 35 | #else 36 | #include 37 | #endif 38 | 39 | #ifndef LIBBSD_DISABLE_DEPRECATED 40 | /* FIXME: Temporary inclusion to avoid API breakage, will be removed soon. */ 41 | #ifdef LIBBSD_OVERLAY 42 | #include 43 | #else 44 | #include 45 | #endif 46 | #endif 47 | 48 | __BEGIN_DECLS 49 | size_t strlcpy(char *dst, const char *src, size_t siz); 50 | size_t strlcat(char *dst, const char *src, size_t siz); 51 | void strmode(mode_t mode, char *str); 52 | __END_DECLS 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /include/bsd/sys/bitstring.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1989, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * This code is derived from software contributed to Berkeley by 6 | * Paul Vixie. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 4. Neither the name of the University nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | * 32 | * $FreeBSD$ 33 | */ 34 | 35 | #ifndef _SYS_BITSTRING_H_ 36 | #define _SYS_BITSTRING_H_ 37 | 38 | typedef unsigned char bitstr_t; 39 | 40 | /* internal macros */ 41 | /* byte of the bitstring bit is in */ 42 | #define _bit_byte(bit) \ 43 | ((bit) >> 3) 44 | 45 | /* mask for the bit within its byte */ 46 | #define _bit_mask(bit) \ 47 | (1 << ((bit)&0x7)) 48 | 49 | /* external macros */ 50 | /* bytes in a bitstring of nbits bits */ 51 | #define bitstr_size(nbits) \ 52 | (((nbits) + 7) >> 3) 53 | 54 | /* allocate a bitstring */ 55 | #define bit_alloc(nbits) \ 56 | (bitstr_t *)calloc((size_t)bitstr_size(nbits), sizeof(bitstr_t)) 57 | 58 | /* allocate a bitstring on the stack */ 59 | #define bit_decl(name, nbits) \ 60 | ((name)[bitstr_size(nbits)]) 61 | 62 | /* is bit N of bitstring name set? */ 63 | #define bit_test(name, bit) \ 64 | ((name)[_bit_byte(bit)] & _bit_mask(bit)) 65 | 66 | /* set bit N of bitstring name */ 67 | #define bit_set(name, bit) \ 68 | ((name)[_bit_byte(bit)] |= _bit_mask(bit)) 69 | 70 | /* clear bit N of bitstring name */ 71 | #define bit_clear(name, bit) \ 72 | ((name)[_bit_byte(bit)] &= ~_bit_mask(bit)) 73 | 74 | /* clear bits start ... stop in bitstring */ 75 | #define bit_nclear(name, start, stop) do { \ 76 | register bitstr_t *_name = (name); \ 77 | register int _start = (start), _stop = (stop); \ 78 | register int _startbyte = _bit_byte(_start); \ 79 | register int _stopbyte = _bit_byte(_stop); \ 80 | if (_startbyte == _stopbyte) { \ 81 | _name[_startbyte] &= ((0xff >> (8 - (_start&0x7))) | \ 82 | (0xff << ((_stop&0x7) + 1))); \ 83 | } else { \ 84 | _name[_startbyte] &= 0xff >> (8 - (_start&0x7)); \ 85 | while (++_startbyte < _stopbyte) \ 86 | _name[_startbyte] = 0; \ 87 | _name[_stopbyte] &= 0xff << ((_stop&0x7) + 1); \ 88 | } \ 89 | } while (0) 90 | 91 | /* set bits start ... stop in bitstring */ 92 | #define bit_nset(name, start, stop) do { \ 93 | register bitstr_t *_name = (name); \ 94 | register int _start = (start), _stop = (stop); \ 95 | register int _startbyte = _bit_byte(_start); \ 96 | register int _stopbyte = _bit_byte(_stop); \ 97 | if (_startbyte == _stopbyte) { \ 98 | _name[_startbyte] |= ((0xff << (_start&0x7)) & \ 99 | (0xff >> (7 - (_stop&0x7)))); \ 100 | } else { \ 101 | _name[_startbyte] |= 0xff << ((_start)&0x7); \ 102 | while (++_startbyte < _stopbyte) \ 103 | _name[_startbyte] = 0xff; \ 104 | _name[_stopbyte] |= 0xff >> (7 - (_stop&0x7)); \ 105 | } \ 106 | } while (0) 107 | 108 | /* find first bit clear in name */ 109 | #define bit_ffc(name, nbits, value) do { \ 110 | register bitstr_t *_name = (name); \ 111 | register int _byte, _nbits = (nbits); \ 112 | register int _stopbyte = _bit_byte(_nbits - 1), _value = -1; \ 113 | if (_nbits > 0) \ 114 | for (_byte = 0; _byte <= _stopbyte; ++_byte) \ 115 | if (_name[_byte] != 0xff) { \ 116 | bitstr_t _lb; \ 117 | _value = _byte << 3; \ 118 | for (_lb = _name[_byte]; (_lb&0x1); \ 119 | ++_value, _lb >>= 1); \ 120 | break; \ 121 | } \ 122 | if (_value >= nbits) \ 123 | _value = -1; \ 124 | *(value) = _value; \ 125 | } while (0) 126 | 127 | /* find first bit set in name */ 128 | #define bit_ffs(name, nbits, value) do { \ 129 | register bitstr_t *_name = (name); \ 130 | register int _byte, _nbits = (nbits); \ 131 | register int _stopbyte = _bit_byte(_nbits - 1), _value = -1; \ 132 | if (_nbits > 0) \ 133 | for (_byte = 0; _byte <= _stopbyte; ++_byte) \ 134 | if (_name[_byte]) { \ 135 | bitstr_t _lb; \ 136 | _value = _byte << 3; \ 137 | for (_lb = _name[_byte]; !(_lb&0x1); \ 138 | ++_value, _lb >>= 1); \ 139 | break; \ 140 | } \ 141 | if (_value >= nbits) \ 142 | _value = -1; \ 143 | *(value) = _value; \ 144 | } while (0) 145 | 146 | #endif /* !_SYS_BITSTRING_H_ */ 147 | -------------------------------------------------------------------------------- /include/bsd/sys/cdefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2004-2006, 2009-2011 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_SYS_CDEFS_H 28 | #define LIBBSD_SYS_CDEFS_H 29 | 30 | #ifdef LIBBSD_OVERLAY 31 | #include_next 32 | #else 33 | #include 34 | #endif 35 | 36 | /* 37 | * Some kFreeBSD headers expect those macros to be set for sanity checks. 38 | */ 39 | #ifndef _SYS_CDEFS_H_ 40 | #define _SYS_CDEFS_H_ 41 | #endif 42 | #ifndef _SYS_CDEFS_H 43 | #define _SYS_CDEFS_H 44 | #endif 45 | 46 | #ifdef __GNUC__ 47 | #define LIBBSD_GCC_VERSION (__GNUC__ << 8 | __GNUC_MINOR__) 48 | #else 49 | #define LIBBSD_GCC_VERSION 0 50 | #endif 51 | 52 | #ifndef __dead2 53 | # if LIBBSD_GCC_VERSION >= 0x0207 54 | # define __dead2 __attribute__((__noreturn__)) 55 | # else 56 | # define __dead2 57 | # endif 58 | #endif 59 | 60 | #ifndef __pure2 61 | # if LIBBSD_GCC_VERSION >= 0x0207 62 | # define __pure2 __attribute__((__const__)) 63 | # else 64 | # define __pure2 65 | # endif 66 | #endif 67 | 68 | #ifndef __packed 69 | # if LIBBSD_GCC_VERSION >= 0x0207 70 | # define __packed __attribute__((__packed__)) 71 | # else 72 | # define __packed 73 | # endif 74 | #endif 75 | 76 | #ifndef __aligned 77 | # if LIBBSD_GCC_VERSION >= 0x0207 78 | # define __aligned(x) __attribute__((__aligned__(x))) 79 | # else 80 | # define __aligned(x) 81 | # endif 82 | #endif 83 | 84 | /* Linux headers define a struct with a member names __unused. 85 | * Debian bugs: #522773 (linux), #522774 (libc). 86 | * Disable for now. */ 87 | #if 0 88 | #ifndef __unused 89 | # if LIBBSD_GCC_VERSION >= 0x0300 90 | # define __unused __attribute__((unused)) 91 | # else 92 | # define __unused 93 | # endif 94 | #endif 95 | #endif 96 | 97 | #ifndef __printflike 98 | # if LIBBSD_GCC_VERSION >= 0x0300 99 | # define __printflike(x, y) __attribute((format(printf, (x), (y)))) 100 | # else 101 | # define __printflike(x, y) 102 | # endif 103 | #endif 104 | 105 | #ifndef __nonnull 106 | # if LIBBSD_GCC_VERSION >= 0x0302 107 | # define __nonnull(x) __attribute__((__nonnull__(x))) 108 | # else 109 | # define __nonnull(x) 110 | # endif 111 | #endif 112 | 113 | #ifndef __bounded__ 114 | # define __bounded__(x, y, z) 115 | #endif 116 | 117 | #ifndef __RCSID 118 | # define __RCSID(x) 119 | #endif 120 | 121 | #ifndef __FBSDID 122 | # define __FBSDID(x) 123 | #endif 124 | 125 | #ifndef __RCSID 126 | # define __RCSID(x) 127 | #endif 128 | 129 | #ifndef __RCSID_SOURCE 130 | # define __RCSID_SOURCE(x) 131 | #endif 132 | 133 | #ifndef __SCCSID 134 | # define __SCCSID(x) 135 | #endif 136 | 137 | #ifndef __COPYRIGHT 138 | # define __COPYRIGHT(x) 139 | #endif 140 | 141 | #endif 142 | -------------------------------------------------------------------------------- /include/bsd/sys/endian.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2011 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_SYS_ENDIAN_H 28 | #define LIBBSD_SYS_ENDIAN_H 29 | 30 | #ifdef LIBBSD_OVERLAY 31 | #include_next 32 | #else 33 | #include 34 | #endif 35 | 36 | #ifndef _BYTE_ORDER 37 | #define _BYTE_ORDER __BYTE_ORDER 38 | #endif 39 | 40 | #ifndef _LITTLE_ENDIAN 41 | #define _LITTLE_ENDIAN __LITTLE_ENDIAN 42 | #endif 43 | 44 | #ifndef _BIG_ENDIAN 45 | #define _BIG_ENDIAN __BIG_ENDIAN 46 | #endif 47 | 48 | #ifndef _PDP_ENDIAN 49 | #define _PDP_ENDIAN __PDP_ENDIAN 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /include/bsd/sys/poll.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2011 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_SYS_POLL_H 28 | #define LIBBSD_SYS_POLL_H 29 | 30 | #ifdef LIBBSD_OVERLAY 31 | #include_next 32 | #else 33 | #include 34 | #endif 35 | 36 | #ifndef INFTIM 37 | #define INFTIM (-1) 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /include/bsd/unistd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2006 Robert Millan 3 | * Copyright © 2008-2011 Guillem Jover 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 18 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 19 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef LIBBSD_UNISTD_H 29 | #define LIBBSD_UNISTD_H 30 | 31 | #include 32 | #include 33 | 34 | #ifdef LIBBSD_OVERLAY 35 | #include_next 36 | #else 37 | #include 38 | #endif 39 | 40 | #ifndef S_ISTXT 41 | #define S_ISTXT S_ISVTX 42 | #endif 43 | 44 | __BEGIN_DECLS 45 | extern int optreset; 46 | 47 | #ifdef LIBBSD_OVERLAY 48 | #undef getopt 49 | #define getopt(argc, argv, optstr) bsd_getopt(argc, argv, optstr) 50 | #endif 51 | 52 | int bsd_getopt(int, char **, char *); 53 | 54 | mode_t getmode(const void *set, mode_t mode); 55 | void *setmode(const char *mode_str); 56 | 57 | void setproctitle(const char *fmt, ...); 58 | 59 | int getpeereid(int s, uid_t *euid, gid_t *egid); 60 | __END_DECLS 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /include/bsd/vis.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1990, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)vis.h 8.1 (Berkeley) 6/2/93 30 | * $FreeBSD: src/include/vis.h,v 1.11 2003/10/30 10:40:49 phk Exp $ 31 | */ 32 | 33 | #ifndef _VIS_H_ 34 | #define _VIS_H_ 35 | 36 | #include 37 | 38 | /* 39 | * to select alternate encoding format 40 | */ 41 | #define VIS_OCTAL 0x01 /* use octal \ddd format */ 42 | #define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropriate */ 43 | 44 | /* 45 | * to alter set of characters encoded (default is to encode all 46 | * non-graphic except space, tab, and newline). 47 | */ 48 | #define VIS_SP 0x04 /* also encode space */ 49 | #define VIS_TAB 0x08 /* also encode tab */ 50 | #define VIS_NL 0x10 /* also encode newline */ 51 | #define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL) 52 | #define VIS_SAFE 0x20 /* only encode "unsafe" characters */ 53 | 54 | /* 55 | * other 56 | */ 57 | #define VIS_NOSLASH 0x40 /* inhibit printing '\' */ 58 | #define VIS_HTTPSTYLE 0x80 /* http-style escape % HEX HEX */ 59 | #define VIS_GLOB 0x100 /* encode glob(3) magics */ 60 | 61 | /* 62 | * unvis return codes 63 | */ 64 | #define UNVIS_VALID 1 /* character valid */ 65 | #define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */ 66 | #define UNVIS_NOCHAR 3 /* valid sequence, no character produced */ 67 | #define UNVIS_SYNBAD -1 /* unrecognized escape sequence */ 68 | #define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */ 69 | 70 | /* 71 | * unvis flags 72 | */ 73 | #define UNVIS_END 1 /* no more characters */ 74 | 75 | #include 76 | 77 | __BEGIN_DECLS 78 | char *vis(char *, int, int, int); 79 | int strvis(char *, const char *, int); 80 | int strvisx(char *, const char *, size_t, int); 81 | int strnvis(char *, const char *, size_t, int); 82 | int strunvis(char *, const char *); 83 | int strunvisx(char *, const char *, int); 84 | ssize_t strnunvis(char *, const char *, size_t); 85 | int unvis(char *, int, int *, int); 86 | __END_DECLS 87 | 88 | #endif /* !_VIS_H_ */ 89 | -------------------------------------------------------------------------------- /include/libutil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2011 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_LIBUTIL_H 28 | #define LIBBSD_LIBUTIL_H 29 | 30 | #ifdef LIBBSD_DISABLE_DEPRECATED 31 | #error "Deprecated header, use or libbsd-overlay.pc instead." 32 | #else 33 | #warning "Deprecated header, use or libbsd-overlay.pc instead." 34 | #endif 35 | 36 | #include 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /include/nlist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2011 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_DEPRECATED_NLIST_H 28 | #define LIBBSD_DEPRECATED_NLIST_H 29 | 30 | #ifdef LIBBSD_DISABLE_DEPRECATED 31 | #error "Deprecated header, use or libbsd-overlay.pc instead." 32 | #else 33 | #warning "Deprecated header, use or libbsd-overlay.pc instead." 34 | #endif 35 | 36 | #include 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /include/vis.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2011 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_VIS_H 28 | #define LIBBSD_VIS_H 29 | 30 | #ifdef LIBBSD_DISABLE_DEPRECATED 31 | #error "Deprecated header, use or libbsd-overlay.pc instead." 32 | #else 33 | #warning "Deprecated header, use or libbsd-overlay.pc instead." 34 | #endif 35 | 36 | #include 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /libbsd-overlay.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libbsd 7 | Description: Utility functions from BSD systems (overlay) 8 | Version: @VERSION@ 9 | URL: http://libbsd.freedesktop.org/ 10 | Libs: -L${libdir} -lbsd 11 | Cflags: -isystem ${includedir}/bsd -DLIBBSD_OVERLAY 12 | -------------------------------------------------------------------------------- /libbsd.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libbsd 7 | Description: Utility functions from BSD systems 8 | Version: @VERSION@ 9 | URL: http://libbsd.freedesktop.org/ 10 | Libs: -L${libdir} -lbsd 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | md5.3 2 | md5.3bsd 3 | -------------------------------------------------------------------------------- /src/arc4random.3: -------------------------------------------------------------------------------- 1 | .\" $OpenBSD: arc4random.3,v 1.2 1997/04/27 22:40:25 angelos Exp $ 2 | .\" Copyright 1997 Niels Provos 3 | .\" All rights reserved. 4 | .\" 5 | .\" Redistribution and use in source and binary forms, with or without 6 | .\" modification, are permitted provided that the following conditions 7 | .\" are met: 8 | .\" 1. Redistributions of source code must retain the above copyright 9 | .\" notice, this list of conditions and the following disclaimer. 10 | .\" 2. Redistributions in binary form must reproduce the above copyright 11 | .\" notice, this list of conditions and the following disclaimer in the 12 | .\" documentation and/or other materials provided with the distribution. 13 | .\" 3. All advertising materials mentioning features or use of this software 14 | .\" must display the following acknowledgement: 15 | .\" This product includes software developed by Niels Provos. 16 | .\" 4. The name of the author may not be used to endorse or promote products 17 | .\" derived from this software without specific prior written permission. 18 | .\" 19 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | .\" 30 | .\" Manual page, using -mandoc macros 31 | .\" $FreeBSD$ 32 | .\" 33 | .Dd April 15, 1997 34 | .Dt ARC4RANDOM 3 35 | .Os 36 | .Sh NAME 37 | .Nm arc4random , 38 | .Nm arc4random_buf , 39 | .Nm arc4random_uniform , 40 | .Nm arc4random_stir , 41 | .Nm arc4random_addrandom 42 | .Nd arc4 random number generator 43 | .Sh LIBRARY 44 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) 45 | .Lb libbsd 46 | .Sh SYNOPSIS 47 | .In bsd/stdlib.h 48 | .Ft u_int32_t 49 | .Fn arc4random "void" 50 | .Ft void 51 | .Fn arc4random_buf "void *buf" "size_t nbytes" 52 | .Ft u_int32_t 53 | .Fn arc4random_uniform "u_int32_t upper_bound" 54 | .Ft void 55 | .Fn arc4random_stir "void" 56 | .Ft void 57 | .Fn arc4random_addrandom "unsigned char *dat" "int datlen" 58 | .Sh DESCRIPTION 59 | The 60 | .Fn arc4random 61 | function uses the key stream generator employed by the 62 | arc4 cipher, which uses 8*8 8 bit S-Boxes. 63 | The S-Boxes 64 | can be in about 65 | .if t 2\u\s71700\s10\d 66 | .if n (2**1700) 67 | states. 68 | The 69 | .Fn arc4random 70 | function returns pseudo-random numbers in the range of 0 to 71 | .if t 2\u\s731\s10\d\(mi1, 72 | .if n (2**32)\(mi1, 73 | and therefore has twice the range of 74 | .Xr rand 3 75 | and 76 | .Xr random 3 . 77 | .Pp 78 | .Fn arc4random_buf 79 | function fills the region 80 | .Fa buf 81 | of length 82 | .Fa nbytes 83 | with ARC4-derived random data. 84 | .Pp 85 | .Fn arc4random_uniform 86 | will return a uniformly distributed random number less than 87 | .Fa upper_bound . 88 | .Fn arc4random_uniform 89 | is recommended over constructions like 90 | .Dq Li arc4random() % upper_bound 91 | as it avoids "modulo bias" when the upper bound is not a power of two. 92 | .Pp 93 | The 94 | .Fn arc4random_stir 95 | function reads data from 96 | .Pa /dev/urandom 97 | and uses it to permute the S-Boxes via 98 | .Fn arc4random_addrandom . 99 | .Pp 100 | There is no need to call 101 | .Fn arc4random_stir 102 | before using 103 | .Fn arc4random 104 | functions family, since 105 | they automatically initialize themselves. 106 | .Sh EXAMPLES 107 | The following produces a drop-in replacement for the traditional 108 | .Fn rand 109 | and 110 | .Fn random 111 | functions using 112 | .Fn arc4random : 113 | .Pp 114 | .Dl "#define foo4random() (arc4random() % ((unsigned)RAND_MAX + 1))" 115 | .Sh SEE ALSO 116 | .Xr rand 3 , 117 | .Xr random 3 , 118 | .Xr srandomdev 3 119 | .Sh HISTORY 120 | .Pa RC4 121 | has been designed by RSA Data Security, Inc. 122 | It was posted anonymously 123 | to the USENET and was confirmed to be equivalent by several sources who 124 | had access to the original cipher. 125 | Since 126 | .Pa RC4 127 | used to be a trade secret, the cipher is now referred to as 128 | .Pa ARC4 . 129 | -------------------------------------------------------------------------------- /src/arc4random_addrandom.3: -------------------------------------------------------------------------------- 1 | .so man3/arc4random.3 2 | -------------------------------------------------------------------------------- /src/arc4random_buf.3: -------------------------------------------------------------------------------- 1 | .so man3/arc4random.3 2 | -------------------------------------------------------------------------------- /src/arc4random_stir.3: -------------------------------------------------------------------------------- 1 | .so man3/arc4random.3 2 | -------------------------------------------------------------------------------- /src/arc4random_uniform.3: -------------------------------------------------------------------------------- 1 | .so man3/arc4random.3 2 | -------------------------------------------------------------------------------- /src/bsd_getopt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2006 Robert Millan 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #include 28 | 29 | int optreset = 0; 30 | 31 | int 32 | bsd_getopt(int argc, char **argv, char *shortopts) 33 | { 34 | if (optreset == 1) { 35 | optreset = 0; 36 | optind = 0; 37 | } 38 | 39 | /* 40 | * Make sure we are using the system getopt() and not a possible 41 | * overlay macro. 42 | */ 43 | return (getopt)(argc, argv, shortopts); 44 | } 45 | -------------------------------------------------------------------------------- /src/dehumanize_number.3: -------------------------------------------------------------------------------- 1 | .so man3/humanize_number.3 2 | -------------------------------------------------------------------------------- /src/dehumanize_number.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: dehumanize_number.c,v 1.2 2007/12/14 17:32:47 xtraeme Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc. 5 | * All rights reserved. 6 | * 7 | * This code is derived from software contributed to The NetBSD Foundation 8 | * by Julio M. Merino Vidal, developed as part of Google's Summer of Code 9 | * 2005 program. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | #include 33 | #if defined(LIBC_SCCS) && !defined(lint) 34 | __RCSID("$NetBSD: dehumanize_number.c,v 1.2 2007/12/14 17:32:47 xtraeme Exp $"); 35 | #endif /* LIBC_SCCS and not lint */ 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | /* 45 | * Converts the number given in 'str', which may be given in a humanized 46 | * form (as described in humanize_number(3), but with some limitations), 47 | * to an int64_t without units. 48 | * In case of success, 0 is returned and *size holds the value. 49 | * Otherwise, -1 is returned and *size is untouched. 50 | * 51 | * TODO: Internationalization, SI units. 52 | */ 53 | int 54 | dehumanize_number(const char *str, int64_t *size) 55 | { 56 | char *ep, unit; 57 | const char *delimit; 58 | long multiplier; 59 | long long tmp, tmp2; 60 | size_t len; 61 | 62 | len = strlen(str); 63 | if (len == 0) { 64 | errno = EINVAL; 65 | return -1; 66 | } 67 | 68 | multiplier = 1; 69 | 70 | unit = str[len - 1]; 71 | if (isalpha((unsigned char)unit)) { 72 | switch (tolower((unsigned char)unit)) { 73 | case 'b': 74 | multiplier = 1; 75 | break; 76 | 77 | case 'k': 78 | multiplier = 1024; 79 | break; 80 | 81 | case 'm': 82 | multiplier = 1024 * 1024; 83 | break; 84 | 85 | case 'g': 86 | multiplier = 1024 * 1024 * 1024; 87 | break; 88 | 89 | default: 90 | errno = EINVAL; 91 | return -1; /* Invalid suffix. */ 92 | } 93 | 94 | delimit = &str[len - 1]; 95 | } else 96 | delimit = NULL; 97 | 98 | errno = 0; 99 | tmp = strtoll(str, &ep, 10); 100 | if (str[0] == '\0' || (ep != delimit && *ep != '\0')) 101 | return -1; /* Not a number. */ 102 | else if (errno == ERANGE && (tmp == LLONG_MAX || tmp == LLONG_MIN)) 103 | return -1; /* Out of range. */ 104 | 105 | tmp2 = tmp * multiplier; 106 | tmp2 = tmp2 / multiplier; 107 | if (tmp != tmp2) { 108 | errno = ERANGE; 109 | return -1; /* Out of range. */ 110 | } 111 | *size = tmp * multiplier; 112 | 113 | return 0; 114 | } 115 | -------------------------------------------------------------------------------- /src/err.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2006 Robert Millan 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | void 32 | warnc(int code, const char *format, ...) 33 | { 34 | int tmp = errno; 35 | va_list ap; 36 | 37 | va_start(ap, format); 38 | 39 | errno = code; 40 | warn(format, ap); 41 | errno = tmp; 42 | 43 | va_end(ap); 44 | } 45 | 46 | void 47 | vwarnc(int code, const char *format, va_list ap) 48 | { 49 | int tmp = errno; 50 | 51 | errno = code; 52 | vwarn(format, ap); 53 | errno = tmp; 54 | } 55 | 56 | void 57 | errc(int status, int code, const char *format, ...) 58 | { 59 | va_list ap; 60 | 61 | va_start(ap, format); 62 | 63 | errno = code; 64 | err(status, format, ap); 65 | 66 | va_end(ap); 67 | } 68 | 69 | void 70 | verrc(int status, int code, const char *format, va_list ap) 71 | { 72 | errno = code; 73 | verr(status, format, ap); 74 | } 75 | -------------------------------------------------------------------------------- /src/fgetln.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1990, 1991, 1993 2 | .\" The Regents of the University of California. All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 3. Neither the name of the University nor the names of its contributors 13 | .\" may be used to endorse or promote products derived from this software 14 | .\" without specific prior written permission. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | .\" SUCH DAMAGE. 27 | .\" 28 | .\" @(#)fgetln.3 8.3 (Berkeley) 4/19/94 29 | .\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/stdio/fgetln.3,v 1.8 2004/07/16 06:07:12 tjr Exp $ 30 | .\" 31 | .Dd April 19, 1994 32 | .Dt FGETLN 3 33 | .Os 34 | .Sh NAME 35 | .Nm fgetln 36 | .Nd get a line from a stream 37 | .Sh LIBRARY 38 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) 39 | .Lb libbsd 40 | .Sh SYNOPSIS 41 | .In bsd/stdio.h 42 | .Ft char * 43 | .Fn fgetln "FILE *stream" "size_t *len" 44 | .Sh DESCRIPTION 45 | The 46 | .Fn fgetln 47 | function 48 | returns a pointer to the next line from the stream referenced by 49 | .Fa stream . 50 | This line is 51 | .Em not 52 | a C string as it does not end with a terminating 53 | .Dv NUL 54 | character. 55 | The length of the line, including the final newline, 56 | is stored in the memory location to which 57 | .Fa len 58 | points and is guaranteed to be greater than 0 upon successful completion. 59 | (Note, however, that if the line is the last 60 | in a file that does not end in a newline, 61 | the returned text will not contain a newline.) 62 | .Sh RETURN VALUES 63 | Upon successful completion a pointer is returned; 64 | this pointer becomes invalid after the next 65 | .Tn I/O 66 | operation on 67 | .Fa stream 68 | (whether successful or not) 69 | or as soon as the stream is closed. 70 | Otherwise, 71 | .Dv NULL 72 | is returned. 73 | The 74 | .Fn fgetln 75 | function 76 | does not distinguish between end-of-file and error; the routines 77 | .Xr feof 3 78 | and 79 | .Xr ferror 3 80 | must be used 81 | to determine which occurred. 82 | If an error occurs, the global variable 83 | .Va errno 84 | is set to indicate the error. 85 | The end-of-file condition is remembered, even on a terminal, and all 86 | subsequent attempts to read will return 87 | .Dv NULL 88 | until the condition is 89 | cleared with 90 | .Xr clearerr 3 . 91 | .Pp 92 | The text to which the returned pointer points may be modified, 93 | provided that no changes are made beyond the returned size. 94 | These changes are lost as soon as the pointer becomes invalid. 95 | .Sh ERRORS 96 | .Bl -tag -width Er 97 | .It Bq Er EBADF 98 | The argument 99 | .Fa stream 100 | is not a stream open for reading. 101 | .El 102 | .Pp 103 | The 104 | .Fn fgetln 105 | function 106 | may also fail and set 107 | .Va errno 108 | for any of the errors specified for the routines 109 | .Xr fflush 3 , 110 | .Xr malloc 3 , 111 | .Xr read 2 , 112 | .Xr stat 2 , 113 | or 114 | .Xr realloc 3 . 115 | .Sh SEE ALSO 116 | .Xr ferror 3 , 117 | .Xr fgets 3 , 118 | .Xr fgetwln 3 , 119 | .Xr fopen 3 , 120 | .Xr putc 3 121 | .Sh HISTORY 122 | The 123 | .Fn fgetln 124 | function first appeared in 125 | .Bx 4.4 . 126 | -------------------------------------------------------------------------------- /src/fgetln.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2005 Hector Garcia Alvarez 3 | * Copyright © 2005, 2008, 2009, 2011 Guillem Jover 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 18 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 19 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #ifdef __GLIBC__ 34 | char * 35 | fgetln(FILE *stream, size_t *len) 36 | { 37 | static char *line = NULL; 38 | static size_t line_len = 0; 39 | ssize_t nread; 40 | 41 | nread = getline(&line, &line_len, stream); 42 | /* Note: the getdelim/getline API ensures nread != 0. */ 43 | if (nread == -1) { 44 | *len = 0; 45 | return NULL; 46 | } else { 47 | *len = (size_t)nread; 48 | return line; 49 | } 50 | } 51 | #else 52 | #error "Function fgetln() needs to be ported." 53 | #endif 54 | -------------------------------------------------------------------------------- /src/flopen.3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LuaDist/libbsd/a70385d07e690015a3c8eea06b1621a4cb127d00/src/flopen.3 -------------------------------------------------------------------------------- /src/flopen.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2007 Dag-Erling Coïdan Smørgrav 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer 10 | * in this position and unchanged. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 | * SUCH DAMAGE. 26 | */ 27 | 28 | #include 29 | __FBSDID("$FreeBSD$"); 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | int 40 | flopen(const char *path, int flags, ...) 41 | { 42 | int fd, operation, serrno, trunc; 43 | struct stat sb, fsb; 44 | mode_t mode; 45 | 46 | #ifdef O_EXLOCK 47 | flags &= ~O_EXLOCK; 48 | #endif 49 | 50 | mode = 0; 51 | if (flags & O_CREAT) { 52 | va_list ap; 53 | 54 | va_start(ap, flags); 55 | mode = (mode_t)va_arg(ap, int); /* mode_t promoted to int */ 56 | va_end(ap); 57 | } 58 | 59 | operation = LOCK_EX; 60 | if (flags & O_NONBLOCK) 61 | operation |= LOCK_NB; 62 | 63 | trunc = (flags & O_TRUNC); 64 | flags &= ~O_TRUNC; 65 | 66 | for (;;) { 67 | if ((fd = open(path, flags, mode)) == -1) 68 | /* non-existent or no access */ 69 | return (-1); 70 | if (flock(fd, operation) == -1) { 71 | /* unsupported or interrupted */ 72 | serrno = errno; 73 | (void)close(fd); 74 | errno = serrno; 75 | return (-1); 76 | } 77 | if (stat(path, &sb) == -1) { 78 | /* disappeared from under our feet */ 79 | (void)close(fd); 80 | continue; 81 | } 82 | if (fstat(fd, &fsb) == -1) { 83 | /* can't happen [tm] */ 84 | serrno = errno; 85 | (void)close(fd); 86 | errno = serrno; 87 | return (-1); 88 | } 89 | if (sb.st_dev != fsb.st_dev || 90 | sb.st_ino != fsb.st_ino) { 91 | /* changed under our feet */ 92 | (void)close(fd); 93 | continue; 94 | } 95 | if (trunc && ftruncate(fd, 0) != 0) { 96 | /* can't happen [tm] */ 97 | serrno = errno; 98 | (void)close(fd); 99 | errno = serrno; 100 | return (-1); 101 | } 102 | return (fd); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/fmtcheck.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2000 The NetBSD Foundation, Inc. 2 | .\" All rights reserved. 3 | .\" 4 | .\" This file was contributed to The NetBSD Foundation by Allen Briggs. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions 8 | .\" are met: 9 | .\" 1. Redistributions of source code must retain the above copyright 10 | .\" notice, this list of conditions and the following disclaimer. 11 | .\" 2. Redistributions in binary form must reproduce the above copyright 12 | .\" notice, this list of conditions and the following disclaimer in the 13 | .\" documentation and/or other materials provided with the distribution. 14 | .\" 15 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | .\" POSSIBILITY OF SUCH DAMAGE. 26 | .\" 27 | .\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/fmtcheck.3,v 1.9 2004/07/02 23:52:10 ru Exp $ 28 | .Dd October 16, 2002 29 | .Os 30 | .Dt FMTCHECK 3 31 | .Sh NAME 32 | .Nm fmtcheck 33 | .Nd sanitizes user-supplied 34 | .Xr printf 3 Ns -style 35 | format string 36 | .Sh LIBRARY 37 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) 38 | .Lb libbsd 39 | .Sh SYNOPSIS 40 | .In bsd/stdio.h 41 | .Ft const char * 42 | .Fn fmtcheck "const char *fmt_suspect" "const char *fmt_default" 43 | .Sh DESCRIPTION 44 | The 45 | .Fn fmtcheck 46 | scans 47 | .Fa fmt_suspect 48 | and 49 | .Fa fmt_default 50 | to determine if 51 | .Fa fmt_suspect 52 | will consume the same argument types as 53 | .Fa fmt_default 54 | and to ensure that 55 | .Fa fmt_suspect 56 | is a valid format string. 57 | .Pp 58 | The 59 | .Xr printf 3 60 | family of functions cannot verify the types of arguments that they are 61 | passed at run-time. 62 | In some cases, like 63 | .Xr catgets 3 , 64 | it is useful or necessary to use a user-supplied format string with no 65 | guarantee that the format string matches the specified arguments. 66 | .Pp 67 | The 68 | .Fn fmtcheck 69 | was designed to be used in these cases, as in: 70 | .Bd -literal -offset indent 71 | printf(fmtcheck(user_format, standard_format), arg1, arg2); 72 | .Ed 73 | .Pp 74 | In the check, field widths, fillers, precisions, etc.\& are ignored (unless 75 | the field width or precision is an asterisk 76 | .Ql * 77 | instead of a digit string). 78 | Also, any text other than the format specifiers 79 | is completely ignored. 80 | .Sh RETURN VALUES 81 | If 82 | .Fa fmt_suspect 83 | is a valid format and consumes the same argument types as 84 | .Fa fmt_default , 85 | then the 86 | .Fn fmtcheck 87 | will return 88 | .Fa fmt_suspect . 89 | Otherwise, it will return 90 | .Fa fmt_default . 91 | .Sh SECURITY CONSIDERATIONS 92 | Note that the formats may be quite different as long as they accept the 93 | same arguments. 94 | For example, 95 | .Qq Li "%p %o %30s %#llx %-10.*e %n" 96 | is compatible with 97 | .Qq Li "This number %lu %d%% and string %s has %qd numbers and %.*g floats (%n)" . 98 | However, 99 | .Qq Li %o 100 | is not equivalent to 101 | .Qq Li %lx 102 | because 103 | the first requires an integer and the second requires a long. 104 | .Sh SEE ALSO 105 | .Xr printf 3 106 | .Sh BUGS 107 | The 108 | .Fn fmtcheck 109 | function does not understand all of the conversions that 110 | .Xr printf 3 111 | does. 112 | -------------------------------------------------------------------------------- /src/fpurge.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2011 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #define _GNU_SOURCE 1 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #ifdef __GLIBC__ 34 | int 35 | fpurge(FILE *fp) 36 | { 37 | if (fp == NULL || fileno(fp) < 0) { 38 | errno = EBADF; 39 | return EOF; 40 | } 41 | 42 | __fpurge(fp); 43 | 44 | return 0; 45 | } 46 | #else 47 | #error "Function fpurge() needs to be ported." 48 | #endif 49 | 50 | #ifdef TEST 51 | int 52 | main() 53 | { 54 | static FILE fp_bad; 55 | FILE *fp; 56 | 57 | if (fpurge(&fp_bad) == 0) 58 | return 1; 59 | 60 | fp = fopen("/dev/zero", "r"); 61 | if (fpurge(fp) < 0) 62 | return 1; 63 | 64 | fclose(fp); 65 | 66 | return 0; 67 | } 68 | #endif 69 | -------------------------------------------------------------------------------- /src/getmode.3: -------------------------------------------------------------------------------- 1 | .so man3/setmode.3 2 | -------------------------------------------------------------------------------- /src/getpeereid.3: -------------------------------------------------------------------------------- 1 | .\" 2 | .\" Copyright (c) 2001 Dima Dorfman. 3 | .\" All rights reserved. 4 | .\" 5 | .\" Redistribution and use in source and binary forms, with or without 6 | .\" modification, are permitted provided that the following conditions 7 | .\" are met: 8 | .\" 1. Redistributions of source code must retain the above copyright 9 | .\" notice, this list of conditions and the following disclaimer. 10 | .\" 2. Redistributions in binary form must reproduce the above copyright 11 | .\" notice, this list of conditions and the following disclaimer in the 12 | .\" documentation and/or other materials provided with the distribution. 13 | .\" 14 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | .\" SUCH DAMAGE. 25 | .\" 26 | .\" $FreeBSD$ 27 | .\" 28 | .Dd July 15, 2001 29 | .Dt GETPEEREID 3 30 | .Os 31 | .Sh NAME 32 | .Nm getpeereid 33 | .Nd get the effective credentials of a UNIX-domain peer 34 | .Sh LIBRARY 35 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) 36 | .Lb libbsd 37 | .Sh SYNOPSIS 38 | .In sys/types.h 39 | .In bsd/unistd.h 40 | .Ft int 41 | .Fn getpeereid "int s" "uid_t *euid" "gid_t *egid" 42 | .Sh DESCRIPTION 43 | The 44 | .Fn getpeereid 45 | function returns the effective user and group IDs of the 46 | peer connected to a 47 | .Ux Ns -domain 48 | socket. 49 | The argument 50 | .Fa s 51 | must be a 52 | .Ux Ns -domain 53 | socket 54 | .Pq Xr unix 4 55 | of type 56 | .Dv SOCK_STREAM 57 | on which either 58 | .Xr connect 2 59 | or 60 | .Xr listen 2 61 | have been called. 62 | The effective used ID is placed in 63 | .Fa euid , 64 | and the effective group ID in 65 | .Fa egid . 66 | .Pp 67 | The credentials returned to the 68 | .Xr listen 2 69 | caller are those of its peer at the time it called 70 | .Xr connect 2 ; 71 | the credentials returned to the 72 | .Xr connect 2 73 | caller are those of its peer at the time it called 74 | .Xr listen 2 . 75 | This mechanism is reliable; there is no way for either side to influence 76 | the credentials returned to its peer except by calling the appropriate 77 | system call (i.e., either 78 | .Xr connect 2 79 | or 80 | .Xr listen 2 ) 81 | under different effective credentials. 82 | .Pp 83 | One common use of this routine is for a 84 | .Ux Ns -domain 85 | server 86 | to verify the credentials of its client. 87 | Likewise, the client can verify the credentials of the server. 88 | .Sh IMPLEMENTATION NOTES 89 | On 90 | .Fx , 91 | .Fn getpeereid 92 | is implemented in terms of the 93 | .Dv LOCAL_PEERCRED 94 | .Xr unix 4 95 | socket option. 96 | .Sh RETURN VALUES 97 | .Rv -std getpeereid 98 | .Sh ERRORS 99 | The 100 | .Fn getpeereid 101 | function 102 | fails if: 103 | .Bl -tag -width Er 104 | .It Bq Er EBADF 105 | The argument 106 | .Fa s 107 | is not a valid descriptor. 108 | .It Bq Er ENOTSOCK 109 | The argument 110 | .Fa s 111 | is a file, not a socket. 112 | .It Bq Er ENOTCONN 113 | The argument 114 | .Fa s 115 | does not refer to a socket on which 116 | .Xr connect 2 117 | or 118 | .Xr listen 2 119 | have been called. 120 | .It Bq Er EINVAL 121 | The argument 122 | .Fa s 123 | does not refer to a socket of type 124 | .Dv SOCK_STREAM , 125 | or the kernel returned invalid data. 126 | .El 127 | .Sh SEE ALSO 128 | .Xr connect 2 , 129 | .Xr getpeername 2 , 130 | .Xr getsockname 2 , 131 | .Xr getsockopt 2 , 132 | .Xr listen 2 , 133 | .Xr unix 4 134 | .Sh HISTORY 135 | The 136 | .Fn getpeereid 137 | function appeared in 138 | .Fx 4.6 . 139 | -------------------------------------------------------------------------------- /src/getpeereid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | #if defined(SO_PEERCRED) 38 | /* Linux and OpenBSD */ 39 | int 40 | getpeereid(int s, uid_t *euid, gid_t *egid) 41 | { 42 | /* XXX: This should be autodetected at build time instead. */ 43 | #if defined(__linux__) 44 | struct ucred cred; 45 | #elif defined(__OpenBSD__) 46 | struct sockpeercred cred; 47 | #endif 48 | socklen_t credlen = sizeof(cred); 49 | int ret; 50 | 51 | ret = getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cred, &credlen); 52 | if (ret != 0) 53 | return ret; 54 | 55 | *euid = cred.uid; 56 | *egid = cred.gid; 57 | 58 | return 0; 59 | } 60 | #elif defined(LOCAL_PEERCRED) 61 | /* FreeBSD */ 62 | #include 63 | 64 | int 65 | getpeereid(int s, uid_t *euid, gid_t *egid) 66 | { 67 | struct xucred cred; 68 | socklen_t credlen = sizeof(cred); 69 | int ret; 70 | 71 | ret = getsockopt(s, 0, LOCAL_PEERCRED, &cred, &credlen); 72 | if (ret != 0) 73 | return ret; 74 | if (cred.cr_version != XUCRED_VERSION) 75 | return EINVAL; 76 | 77 | *euid = cred.cr_uid; 78 | *egid = cred.cr_gid; 79 | 80 | return 0; 81 | } 82 | #elif defined(LOCAL_PEEREID) 83 | /* NetBSD */ 84 | int 85 | getpeereid(int s, uid_t *euid, gid_t *egid) 86 | { 87 | struct unpcbid cred; 88 | socklen_t credlen = sizeof(cred); 89 | int ret; 90 | 91 | ret = getsockopt(s, 0, LOCAL_PEEREID, &cred, &credlen); 92 | if (ret != 0) 93 | return ret; 94 | 95 | *euid = cred.unp_euid; 96 | *egid = cred.unp_egid; 97 | 98 | return 0; 99 | } 100 | #elif defined(__sun) 101 | /* Solaris */ 102 | int 103 | getpeereid(int s, uid_t *euid, gid_t *egid) 104 | { 105 | ucred_t cred_inst; 106 | ucred_t *cred = &cred_inst; 107 | int ret; 108 | 109 | ret = getpeerucred(s, &cred); 110 | if (ret != 0) 111 | return ret; 112 | 113 | *euid = ucred_geteuid(cred); 114 | if (*euid < 0) 115 | return -1; 116 | *egid = ucred_getegid(cred); 117 | if (*egid < 0) 118 | return -1; 119 | 120 | return 0; 121 | } 122 | #else 123 | #warning "This platform needs an implementation of getpeereid()" 124 | int 125 | getpeereid(int s, uid_t *euid, gid_t *egid) 126 | { 127 | *euid = geteuid(); 128 | *egid = getegid(); 129 | 130 | return 0; 131 | } 132 | #endif 133 | -------------------------------------------------------------------------------- /src/hash/.gitignore: -------------------------------------------------------------------------------- 1 | md5hl.c 2 | -------------------------------------------------------------------------------- /src/hash/helper.c: -------------------------------------------------------------------------------- 1 | /** $MirOS: src/lib/libc/hash/helper.c,v 1.5 2007/05/07 15:21:18 tg Exp $ */ 2 | /* $OpenBSD: helper.c,v 1.8 2005/08/08 08:05:35 espie Exp $ */ 3 | 4 | /* 5 | * ---------------------------------------------------------------------------- 6 | * "THE BEER-WARE LICENSE" (Revision 42): 7 | * wrote this file. As long as you retain this notice you 8 | * can do whatever you want with this stuff. If we meet some day, and you think 9 | * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp 10 | * ---------------------------------------------------------------------------- 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | /* ARGSUSED */ 26 | char * 27 | HASHEnd(HASH_CTX *ctx, char *buf) 28 | { 29 | int i; 30 | u_int8_t digest[HASH_DIGEST_LENGTH]; 31 | #ifdef HASH_DIGEST_UPPERCASE 32 | static const char hex[] = "0123456789ABCDEF"; 33 | #else 34 | static const char hex[] = "0123456789abcdef"; 35 | #endif 36 | 37 | if (buf == NULL && (buf = malloc(HASH_DIGEST_STRING_LENGTH)) == NULL) 38 | return (NULL); 39 | 40 | HASHFinal(digest, ctx); 41 | for (i = 0; i < HASH_DIGEST_LENGTH; i++) { 42 | buf[i + i] = hex[digest[i] >> 4]; 43 | buf[i + i + 1] = hex[digest[i] & 0x0f]; 44 | } 45 | buf[i + i] = '\0'; 46 | memset(digest, 0, sizeof(digest)); 47 | return (buf); 48 | } 49 | 50 | char * 51 | HASHFileChunk(const char *filename, char *buf, off_t off, off_t len) 52 | { 53 | struct stat sb; 54 | u_char buffer[BUFSIZ]; 55 | HASH_CTX ctx; 56 | int fd, save_errno; 57 | ssize_t nr; 58 | 59 | HASHInit(&ctx); 60 | 61 | if ((fd = open(filename, O_RDONLY)) < 0) 62 | return (NULL); 63 | if (len == 0) { 64 | if (fstat(fd, &sb) == -1) { 65 | close(fd); 66 | return (NULL); 67 | } 68 | len = sb.st_size; 69 | } 70 | if ((len < 0) || (off > 0 && lseek(fd, off, SEEK_SET) < 0)) 71 | return (NULL); 72 | 73 | while ((nr = read(fd, buffer, 74 | (size_t)(len ? MIN(BUFSIZ, len) : BUFSIZ))) > 0) { 75 | HASHUpdate(&ctx, buffer, (size_t)nr); 76 | if (len > 0 && (len -= nr) == 0) 77 | break; 78 | } 79 | 80 | save_errno = errno; 81 | close(fd); 82 | errno = save_errno; 83 | return (nr < 0 ? NULL : HASHEnd(&ctx, buf)); 84 | } 85 | 86 | char * 87 | HASHFile(const char *filename, char *buf) 88 | { 89 | return (HASHFileChunk(filename, buf, (off_t)0, (off_t)0)); 90 | } 91 | 92 | char * 93 | HASHData(const u_char *data, size_t len, char *buf) 94 | { 95 | HASH_CTX ctx; 96 | 97 | HASHInit(&ctx); 98 | HASHUpdate(&ctx, data, len); 99 | return (HASHEnd(&ctx, buf)); 100 | } 101 | -------------------------------------------------------------------------------- /src/heapsort.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1990, 1991, 1993 2 | .\" The Regents of the University of California. All rights reserved. 3 | .\" 4 | .\" This code is derived from software contributed to Berkeley by 5 | .\" the American National Standards Committee X3, on Information 6 | .\" Processing Systems. 7 | .\" 8 | .\" Redistribution and use in source and binary forms, with or without 9 | .\" modification, are permitted provided that the following conditions 10 | .\" are met: 11 | .\" 1. Redistributions of source code must retain the above copyright 12 | .\" notice, this list of conditions and the following disclaimer. 13 | .\" 2. Redistributions in binary form must reproduce the above copyright 14 | .\" notice, this list of conditions and the following disclaimer in the 15 | .\" documentation and/or other materials provided with the distribution. 16 | .\" 4. Neither the name of the University nor the names of its contributors 17 | .\" may be used to endorse or promote products derived from this software 18 | .\" without specific prior written permission. 19 | .\" 20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | .\" SUCH DAMAGE. 31 | .\" 32 | .\" @(#)qsort.3 8.1 (Berkeley) 6/4/93 33 | .\" $FreeBSD$ 34 | .\" 35 | .Dd September 30, 2003 36 | .Dt QSORT 3 37 | .Os 38 | .Sh NAME 39 | .Nm heapsort , mergesort 40 | .Nd sort functions 41 | .Sh LIBRARY 42 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) 43 | .Lb libbsd 44 | .Sh SYNOPSIS 45 | .In bsd/stdlib.h 46 | .Ft int 47 | .Fo heapsort 48 | .Fa "void *base" 49 | .Fa "size_t nmemb" 50 | .Fa "size_t size" 51 | .Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]" 52 | .Fc 53 | .Ft int 54 | .Fo mergesort 55 | .Fa "void *base" 56 | .Fa "size_t nmemb" 57 | .Fa "size_t size" 58 | .Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]" 59 | .Fc 60 | .Sh DESCRIPTION 61 | The 62 | .Fn heapsort 63 | function is a modified selection sort. 64 | The 65 | .Fn mergesort 66 | function is a modified merge sort with exponential search 67 | intended for sorting data with pre-existing order. 68 | .Pp 69 | The 70 | .Fn heapsort 71 | function sorts an array of 72 | .Fa nmemb 73 | objects, the initial member of which is pointed to by 74 | .Fa base . 75 | The size of each object is specified by 76 | .Fa size . 77 | The 78 | .Fn mergesort 79 | function 80 | behaves similarly, but 81 | .Em requires 82 | that 83 | .Fa size 84 | be greater than 85 | .Dq "sizeof(void *) / 2" . 86 | .Pp 87 | The contents of the array 88 | .Fa base 89 | are sorted in ascending order according to 90 | a comparison function pointed to by 91 | .Fa compar , 92 | which requires two arguments pointing to the objects being 93 | compared. 94 | .Pp 95 | The comparison function must return an integer less than, equal to, or 96 | greater than zero if the first argument is considered to be respectively 97 | less than, equal to, or greater than the second. 98 | .Pp 99 | The algorithm implemented by 100 | .Fn heapsort 101 | is 102 | .Em not 103 | stable, that is, if two members compare as equal, their order in 104 | the sorted array is undefined. 105 | The 106 | .Fn mergesort 107 | algorithm is stable. 108 | .Pp 109 | The 110 | .Fn heapsort 111 | function is an implementation of 112 | .An "J.W.J. William" Ns 's 113 | .Dq heapsort 114 | algorithm, 115 | a variant of selection sorting; in particular, see 116 | .An "D.E. Knuth" Ns 's 117 | .%T "Algorithm H" . 118 | .Sy Heapsort 119 | takes O N lg N worst-case time. 120 | Its 121 | .Em only 122 | advantage over 123 | .Fn qsort 124 | is that it uses almost no additional memory; while 125 | .Fn qsort 126 | does not allocate memory, it is implemented using recursion. 127 | .Pp 128 | The function 129 | .Fn mergesort 130 | requires additional memory of size 131 | .Fa nmemb * 132 | .Fa size 133 | bytes; it should be used only when space is not at a premium. 134 | The 135 | .Fn mergesort 136 | function 137 | is optimized for data with pre-existing order; its worst case 138 | time is O N lg N; its best case is O N. 139 | .Pp 140 | Normally, 141 | .Fn qsort 142 | is faster than 143 | .Fn mergesort 144 | is faster than 145 | .Fn heapsort . 146 | Memory availability and pre-existing order in the data can make this 147 | untrue. 148 | .Sh RETURN VALUES 149 | .Rv -std heapsort mergesort 150 | .Sh ERRORS 151 | The 152 | .Fn heapsort 153 | and 154 | .Fn mergesort 155 | functions succeed unless: 156 | .Bl -tag -width Er 157 | .It Bq Er EINVAL 158 | The 159 | .Fa size 160 | argument is zero, or, 161 | the 162 | .Fa size 163 | argument to 164 | .Fn mergesort 165 | is less than 166 | .Dq "sizeof(void *) / 2" . 167 | .It Bq Er ENOMEM 168 | The 169 | .Fn heapsort 170 | or 171 | .Fn mergesort 172 | functions 173 | were unable to allocate memory. 174 | .El 175 | .Sh SEE ALSO 176 | .Xr sort 1 , 177 | .Xr radixsort 3 178 | .Rs 179 | .%A Williams, J.W.J 180 | .%D 1964 181 | .%T "Heapsort" 182 | .%J "Communications of the ACM" 183 | .%V 7:1 184 | .%P pp. 347-348 185 | .Re 186 | .Rs 187 | .%A Knuth, D.E. 188 | .%D 1968 189 | .%B "The Art of Computer Programming" 190 | .%V Vol. 3 191 | .%T "Sorting and Searching" 192 | .%P pp. 114-123, 145-149 193 | .Re 194 | .Rs 195 | .%A McIlroy, P.M. 196 | .%T "Optimistic Sorting and Information Theoretic Complexity" 197 | .%J "Fourth Annual ACM-SIAM Symposium on Discrete Algorithms" 198 | .%V January 1992 199 | .Re 200 | .Rs 201 | .%A Bentley, J.L. 202 | .%A McIlroy, M.D. 203 | .%T "Engineering a Sort Function" 204 | .%J "Software--Practice and Experience" 205 | .%V Vol. 23(11) 206 | .%P pp. 1249-1265 207 | .%D November\ 1993 208 | .Re 209 | -------------------------------------------------------------------------------- /src/heapsort.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1991, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * This code is derived from software contributed to Berkeley by 6 | * Ronnie Kon at Mindcraft Inc., Kevin Lew and Elmer Yglesias. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. Neither the name of the University nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | /* 38 | * Swap two areas of size number of bytes. Although qsort(3) permits random 39 | * blocks of memory to be sorted, sorting pointers is almost certainly the 40 | * common case (and, were it not, could easily be made so). Regardless, it 41 | * isn't worth optimizing; the SWAP's get sped up by the cache, and pointer 42 | * arithmetic gets lost in the time required for comparison function calls. 43 | */ 44 | #define SWAP(a, b, count, size, tmp) { \ 45 | count = size; \ 46 | do { \ 47 | tmp = *a; \ 48 | *a++ = *b; \ 49 | *b++ = tmp; \ 50 | } while (--count); \ 51 | } 52 | 53 | /* Copy one block of size size to another. */ 54 | #define COPY(a, b, count, size, tmp1, tmp2) { \ 55 | count = size; \ 56 | tmp1 = a; \ 57 | tmp2 = b; \ 58 | do { \ 59 | *tmp1++ = *tmp2++; \ 60 | } while (--count); \ 61 | } 62 | 63 | /* 64 | * Build the list into a heap, where a heap is defined such that for 65 | * the records K1 ... KN, Kj/2 >= Kj for 1 <= j/2 <= j <= N. 66 | * 67 | * There two cases. If j == nmemb, select largest of Ki and Kj. If 68 | * j < nmemb, select largest of Ki, Kj and Kj+1. 69 | */ 70 | #define CREATE(initval, nmemb, par_i, child_i, par, child, size, count, tmp) { \ 71 | for (par_i = initval; (child_i = par_i * 2) <= nmemb; \ 72 | par_i = child_i) { \ 73 | child = base + child_i * size; \ 74 | if (child_i < nmemb && compar(child, child + size) < 0) { \ 75 | child += size; \ 76 | ++child_i; \ 77 | } \ 78 | par = base + par_i * size; \ 79 | if (compar(child, par) <= 0) \ 80 | break; \ 81 | SWAP(par, child, count, size, tmp); \ 82 | } \ 83 | } 84 | 85 | /* 86 | * Select the top of the heap and 'heapify'. Since by far the most expensive 87 | * action is the call to the compar function, a considerable optimization 88 | * in the average case can be achieved due to the fact that k, the displaced 89 | * elememt, is ususally quite small, so it would be preferable to first 90 | * heapify, always maintaining the invariant that the larger child is copied 91 | * over its parent's record. 92 | * 93 | * Then, starting from the *bottom* of the heap, finding k's correct place, 94 | * again maintianing the invariant. As a result of the invariant no element 95 | * is 'lost' when k is assigned its correct place in the heap. 96 | * 97 | * The time savings from this optimization are on the order of 15-20% for the 98 | * average case. See Knuth, Vol. 3, page 158, problem 18. 99 | * 100 | * XXX Don't break the #define SELECT line, below. Reiser cpp gets upset. 101 | */ 102 | #define SELECT(par_i, child_i, nmemb, par, child, size, k, count, tmp1, tmp2) { \ 103 | for (par_i = 1; (child_i = par_i * 2) <= nmemb; par_i = child_i) { \ 104 | child = base + child_i * size; \ 105 | if (child_i < nmemb && compar(child, child + size) < 0) { \ 106 | child += size; \ 107 | ++child_i; \ 108 | } \ 109 | par = base + par_i * size; \ 110 | COPY(par, child, count, size, tmp1, tmp2); \ 111 | } \ 112 | for (;;) { \ 113 | child_i = par_i; \ 114 | par_i = child_i / 2; \ 115 | child = base + child_i * size; \ 116 | par = base + par_i * size; \ 117 | if (child_i == 1 || compar(k, par) < 0) { \ 118 | COPY(child, k, count, size, tmp1, tmp2); \ 119 | break; \ 120 | } \ 121 | COPY(child, par, count, size, tmp1, tmp2); \ 122 | } \ 123 | } 124 | 125 | /* 126 | * Heapsort -- Knuth, Vol. 3, page 145. Runs in O (N lg N), both average 127 | * and worst. While heapsort is faster than the worst case of quicksort, 128 | * the BSD quicksort does median selection so that the chance of finding 129 | * a data set that will trigger the worst case is nonexistent. Heapsort's 130 | * only advantage over quicksort is that it requires little additional memory. 131 | */ 132 | int 133 | heapsort(vbase, nmemb, size, compar) 134 | void *vbase; 135 | size_t nmemb, size; 136 | int (*compar)(const void *, const void *); 137 | { 138 | int cnt, i, j, l; 139 | char tmp, *tmp1, *tmp2; 140 | char *base, *k, *p, *t; 141 | 142 | if (nmemb <= 1) 143 | return (0); 144 | 145 | if (!size) { 146 | errno = EINVAL; 147 | return (-1); 148 | } 149 | 150 | if ((k = malloc(size)) == NULL) 151 | return (-1); 152 | 153 | /* 154 | * Items are numbered from 1 to nmemb, so offset from size bytes 155 | * below the starting address. 156 | */ 157 | base = (char *)vbase - size; 158 | 159 | for (l = nmemb / 2 + 1; --l;) 160 | CREATE(l, nmemb, i, j, t, p, size, cnt, tmp); 161 | 162 | /* 163 | * For each element of the heap, save the largest element into its 164 | * final slot, save the displaced element (k), then recreate the 165 | * heap. 166 | */ 167 | while (nmemb > 1) { 168 | COPY(k, base + nmemb * size, cnt, size, tmp1, tmp2); 169 | COPY(base + nmemb * size, base + size, cnt, size, tmp1, tmp2); 170 | --nmemb; 171 | SELECT(i, j, nmemb, t, p, size, k, cnt, tmp1, tmp2); 172 | } 173 | free(k); 174 | return (0); 175 | } 176 | -------------------------------------------------------------------------------- /src/humanize_number.3: -------------------------------------------------------------------------------- 1 | .\" $NetBSD: humanize_number.3,v 1.8 2008/04/30 13:10:50 martin Exp $ 2 | .\" 3 | .\" Copyright (c) 1999, 2002, 2008 The NetBSD Foundation, Inc. 4 | .\" All rights reserved. 5 | .\" 6 | .\" This code is derived from software contributed to The NetBSD Foundation 7 | .\" by Luke Mewburn and by Tomas Svensson. 8 | .\" 9 | .\" Redistribution and use in source and binary forms, with or without 10 | .\" modification, are permitted provided that the following conditions 11 | .\" are met: 12 | .\" 1. Redistributions of source code must retain the above copyright 13 | .\" notice, this list of conditions and the following disclaimer. 14 | .\" 2. Redistributions in binary form must reproduce the above copyright 15 | .\" notice, this list of conditions and the following disclaimer in the 16 | .\" documentation and/or other materials provided with the distribution. 17 | .\" 18 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | .\" POSSIBILITY OF SUCH DAMAGE. 29 | .\" 30 | .Dd February 9, 2008 31 | .Dt HUMANIZE_NUMBER 3 32 | .Os 33 | .Sh NAME 34 | .Nm dehumanize_number , 35 | .Nm humanize_number 36 | .Nd format a number into a human readable form and viceversa 37 | .Sh LIBRARY 38 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) 39 | .Lb libbsd 40 | .Sh SYNOPSIS 41 | .In bsd/stdlib.h 42 | .Ft int 43 | .Fn dehumanize_number "const char *str" "int64_t *result" 44 | .Ft int 45 | .Fn humanize_number "char *buf" "size_t len" "int64_t number" "const char *suffix" "int scale" "int flags" 46 | .Sh DESCRIPTION 47 | The 48 | .Fn humanize_number 49 | function formats the signed 64 bit quantity given in 50 | .Fa number 51 | into 52 | .Fa buffer . 53 | A space and then 54 | .Fa suffix 55 | is appended to the end. 56 | .Fa buffer 57 | must be at least 58 | .Fa len 59 | bytes long. 60 | .Pp 61 | If the formatted number (including 62 | .Fa suffix ) 63 | would be too long to fit into 64 | .Fa buffer , 65 | then divide 66 | .Fa number 67 | by 1024 until it will. 68 | In this case, prefix 69 | .Fa suffix 70 | with the appropriate SI designator. 71 | .Pp 72 | The prefixes are: 73 | .Bl -column "Prefix" "Description" "Multiplier" -offset indent 74 | .It Sy "Prefix" Ta Sy "Description" Ta Sy "Multiplier" 75 | .It k kilo 1024 76 | .It M mega 1048576 77 | .It G giga 1073741824 78 | .It T tera 1099511627776 79 | .It P peta 1125899906842624 80 | .It E exa 1152921504606846976 81 | .El 82 | .Pp 83 | .Fa len 84 | must be at least 4 plus the length of 85 | .Fa suffix , 86 | in order to ensure a useful result is generated into 87 | .Fa buffer . 88 | To use a specific prefix, specify this as 89 | .Fa scale 90 | (Multiplier = 1024 ^ scale). 91 | This can not be combined with any of the 92 | .Fa scale 93 | flags below. 94 | .Pp 95 | The following flags may be passed in 96 | .Pa scale : 97 | .Bl -tag -width Dv -offset indent 98 | .It Dv HN_AUTOSCALE 99 | Format the buffer using the lowest multiplier possible. 100 | .It Dv HN_GETSCALE 101 | Return the prefix index number (the number of times 102 | .Fa number 103 | must be divided to fit) instead of formatting it to the buffer. 104 | .El 105 | .Pp 106 | The following flags may be passed in 107 | .Pa flags : 108 | .Bl -tag -width Dv -offset indent 109 | .It Dv HN_DECIMAL 110 | If the final result is less than 10, display it using one digit. 111 | .It Dv HN_NOSPACE 112 | Do not put a space between 113 | .Fa number 114 | and the prefix. 115 | .It Dv HN_B 116 | Use 'B' (bytes) as prefix if the original result does not have a prefix. 117 | .It Dv HN_DIVISOR_1000 118 | Divide 119 | .Fa number 120 | with 1000 instead of 1024. 121 | .El 122 | .Pp 123 | The 124 | .Fn dehumanize_number 125 | function parses the string representing an integral value given in 126 | .Fa str 127 | and stores the numerical value in the integer pointed to by 128 | .Fa result . 129 | The provided string may hold one of the suffixes, which will be interpreted 130 | and used to scale up its accompanying numerical value. 131 | .Sh RETURN VALUES 132 | .Fn humanize_number 133 | returns the number of characters stored in 134 | .Fa buffer 135 | (excluding the terminating NUL) upon success, or \-1 upon failure. 136 | If 137 | .Dv HN_GETSCALE 138 | is specified, the prefix index number will be returned instead. 139 | .Pp 140 | .Fn dehumanize_number 141 | returns 0 if the string was parsed correctly. 142 | A \-1 is returned to indicate failure and an error code is stored in 143 | .Va errno . 144 | .Sh ERRORS 145 | .Fn dehumanize_number 146 | will fail and no number will be stored in 147 | .Fa result 148 | if: 149 | .Bl -tag -width Er 150 | .It Bq Er EINVAL 151 | The string in 152 | .Fa str 153 | was empty or carried an unknown suffix. 154 | .It Bq Er ERANGE 155 | The string in 156 | .Fa str 157 | represented a number that does not fit in 158 | .Fa result . 159 | .El 160 | .Sh SEE ALSO 161 | .Xr humanize_number 9 162 | .Sh HISTORY 163 | .Fn humanize_number 164 | first appeared in 165 | .Nx 2.0 . 166 | .Pp 167 | .Fn dehumanize_number 168 | first appeared in 169 | .\" FIXME: This should be in groff, but for now it avoids the warning. 170 | .ds operating-system-NetBSD-5.0 5.0 171 | .Nx 5.0 . 172 | -------------------------------------------------------------------------------- /src/humanize_number.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: humanize_number.c,v 1.14 2008/04/28 20:22:59 martin Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc. 5 | * All rights reserved. 6 | * 7 | * This code is derived from software contributed to The NetBSD Foundation 8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9 | * NASA Ames Research Center, by Luke Mewburn and by Tomas Svensson. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | int 43 | humanize_number(char *buf, size_t len, int64_t bytes, 44 | const char *suffix, int scale, int flags) 45 | { 46 | const char *prefixes, *sep; 47 | int b, i, r, maxscale, s1, s2, sign; 48 | int64_t divisor, max; 49 | size_t baselen; 50 | 51 | assert(buf != NULL); 52 | assert(suffix != NULL); 53 | assert(scale >= 0); 54 | 55 | if (flags & HN_DIVISOR_1000) { 56 | /* SI for decimal multiplies */ 57 | divisor = 1000; 58 | if (flags & HN_B) 59 | prefixes = "B\0k\0M\0G\0T\0P\0E"; 60 | else 61 | prefixes = "\0\0k\0M\0G\0T\0P\0E"; 62 | } else { 63 | /* 64 | * binary multiplies 65 | * XXX IEC 60027-2 recommends Ki, Mi, Gi... 66 | */ 67 | divisor = 1024; 68 | if (flags & HN_B) 69 | prefixes = "B\0K\0M\0G\0T\0P\0E"; 70 | else 71 | prefixes = "\0\0K\0M\0G\0T\0P\0E"; 72 | } 73 | 74 | #define SCALE2PREFIX(scale) (&prefixes[(scale) << 1]) 75 | maxscale = 7; 76 | 77 | if (scale >= maxscale && 78 | (scale & (HN_AUTOSCALE | HN_GETSCALE)) == 0) 79 | return (-1); 80 | 81 | if (buf == NULL || suffix == NULL) 82 | return (-1); 83 | 84 | if (len > 0) 85 | buf[0] = '\0'; 86 | if (bytes < 0) { 87 | sign = -1; 88 | bytes *= -100; 89 | baselen = 3; /* sign, digit, prefix */ 90 | } else { 91 | sign = 1; 92 | bytes *= 100; 93 | baselen = 2; /* digit, prefix */ 94 | } 95 | if (flags & HN_NOSPACE) 96 | sep = ""; 97 | else { 98 | sep = " "; 99 | baselen++; 100 | } 101 | baselen += strlen(suffix); 102 | 103 | /* Check if enough room for `x y' + suffix + `\0' */ 104 | if (len < baselen + 1) 105 | return (-1); 106 | 107 | if (scale & (HN_AUTOSCALE | HN_GETSCALE)) { 108 | /* See if there is additional columns can be used. */ 109 | for (max = 100, i = len - baselen; i-- > 0;) 110 | max *= 10; 111 | 112 | /* 113 | * Divide the number until it fits the given column. 114 | * If there will be an overflow by the rounding below, 115 | * divide once more. 116 | */ 117 | for (i = 0; bytes >= max - 50 && i < maxscale; i++) 118 | bytes /= divisor; 119 | 120 | if (scale & HN_GETSCALE) 121 | return (i); 122 | } else 123 | for (i = 0; i < scale && i < maxscale; i++) 124 | bytes /= divisor; 125 | 126 | /* If a value <= 9.9 after rounding and ... */ 127 | if (bytes < 995 && i > 0 && flags & HN_DECIMAL) { 128 | /* baselen + \0 + .N */ 129 | if (len < baselen + 1 + 2) 130 | return (-1); 131 | b = ((int)bytes + 5) / 10; 132 | s1 = b / 10; 133 | s2 = b % 10; 134 | r = snprintf(buf, len, "%d%s%d%s%s%s", 135 | sign * s1, localeconv()->decimal_point, s2, 136 | sep, SCALE2PREFIX(i), suffix); 137 | } else 138 | r = snprintf(buf, len, "%" PRId64 "%s%s%s", 139 | sign * ((bytes + 50) / 100), 140 | sep, SCALE2PREFIX(i), suffix); 141 | 142 | return (r); 143 | } 144 | -------------------------------------------------------------------------------- /src/inet_net_pton.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996 by Internet Software Consortium. 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS 9 | * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES 10 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE 11 | * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 12 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 13 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 14 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 15 | * SOFTWARE. 16 | */ 17 | 18 | #if defined(LIBC_SCCS) && !defined(lint) 19 | static const char orig_rcsid[] = "From Id: inet_net_pton.c,v 1.8 1996/11/21 10:28:12 vixie Exp $"; 20 | #endif 21 | #include 22 | __FBSDID("$FreeBSD: src/lib/libc/net/inet_net_pton.c,v 1.9 2003/09/15 23:38:06 fenner Exp $"); 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #ifdef SPRINTF_CHAR 37 | # define SPRINTF(x) strlen(sprintf/**/x) 38 | #else 39 | # define SPRINTF(x) ((size_t)sprintf x) 40 | #endif 41 | 42 | static int inet_net_pton_ipv4(const char *src, u_char *dst, size_t size); 43 | 44 | /* 45 | * static int 46 | * inet_net_pton(af, src, dst, size) 47 | * convert network number from presentation to network format. 48 | * accepts hex octets, hex strings, decimal octets, and /CIDR. 49 | * "size" is in bytes and describes "dst". 50 | * return: 51 | * number of bits, either imputed classfully or specified with /CIDR, 52 | * or -1 if some failure occurred (check errno). ENOENT means it was 53 | * not a valid network specification. 54 | * author: 55 | * Paul Vixie (ISC), June 1996 56 | */ 57 | int 58 | inet_net_pton(af, src, dst, size) 59 | int af; 60 | const char *src; 61 | void *dst; 62 | size_t size; 63 | { 64 | switch (af) { 65 | case AF_INET: 66 | return (inet_net_pton_ipv4(src, dst, size)); 67 | default: 68 | errno = EAFNOSUPPORT; 69 | return (-1); 70 | } 71 | } 72 | 73 | /* 74 | * static int 75 | * inet_net_pton_ipv4(src, dst, size) 76 | * convert IPv4 network number from presentation to network format. 77 | * accepts hex octets, hex strings, decimal octets, and /CIDR. 78 | * "size" is in bytes and describes "dst". 79 | * return: 80 | * number of bits, either imputed classfully or specified with /CIDR, 81 | * or -1 if some failure occurred (check errno). ENOENT means it was 82 | * not an IPv4 network specification. 83 | * note: 84 | * network byte order assumed. this means 192.5.5.240/28 has 85 | * 0x11110000 in its fourth octet. 86 | * author: 87 | * Paul Vixie (ISC), June 1996 88 | */ 89 | static int 90 | inet_net_pton_ipv4(src, dst, size) 91 | const char *src; 92 | u_char *dst; 93 | size_t size; 94 | { 95 | static const char 96 | xdigits[] = "0123456789abcdef", 97 | digits[] = "0123456789"; 98 | int n, ch, tmp, dirty, bits; 99 | const u_char *odst = dst; 100 | 101 | ch = *src++; 102 | if (ch == '0' && (src[0] == 'x' || src[0] == 'X') 103 | && isascii(src[1]) && isxdigit(src[1])) { 104 | /* Hexadecimal: Eat nybble string. */ 105 | if (size <= 0) 106 | goto emsgsize; 107 | *dst = 0, dirty = 0; 108 | src++; /* skip x or X. */ 109 | while ((ch = *src++) != '\0' && 110 | isascii(ch) && isxdigit(ch)) { 111 | if (isupper(ch)) 112 | ch = tolower(ch); 113 | n = strchr(xdigits, ch) - xdigits; 114 | assert(n >= 0 && n <= 15); 115 | *dst |= n; 116 | if (!dirty++) 117 | *dst <<= 4; 118 | else if (size-- > 0) 119 | *++dst = 0, dirty = 0; 120 | else 121 | goto emsgsize; 122 | } 123 | if (dirty) 124 | size--; 125 | } else if (isascii(ch) && isdigit(ch)) { 126 | /* Decimal: eat dotted digit string. */ 127 | for (;;) { 128 | tmp = 0; 129 | do { 130 | n = strchr(digits, ch) - digits; 131 | assert(n >= 0 && n <= 9); 132 | tmp *= 10; 133 | tmp += n; 134 | if (tmp > 255) 135 | goto enoent; 136 | } while ((ch = *src++) != '\0' && 137 | isascii(ch) && isdigit(ch)); 138 | if (size-- <= 0) 139 | goto emsgsize; 140 | *dst++ = (u_char) tmp; 141 | if (ch == '\0' || ch == '/') 142 | break; 143 | if (ch != '.') 144 | goto enoent; 145 | ch = *src++; 146 | if (!isascii(ch) || !isdigit(ch)) 147 | goto enoent; 148 | } 149 | } else 150 | goto enoent; 151 | 152 | bits = -1; 153 | if (ch == '/' && isascii(src[0]) && isdigit(src[0]) && dst > odst) { 154 | /* CIDR width specifier. Nothing can follow it. */ 155 | ch = *src++; /* Skip over the /. */ 156 | bits = 0; 157 | do { 158 | n = strchr(digits, ch) - digits; 159 | assert(n >= 0 && n <= 9); 160 | bits *= 10; 161 | bits += n; 162 | } while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch)); 163 | if (ch != '\0') 164 | goto enoent; 165 | if (bits > 32) 166 | goto emsgsize; 167 | } 168 | 169 | /* Firey death and destruction unless we prefetched EOS. */ 170 | if (ch != '\0') 171 | goto enoent; 172 | 173 | /* If nothing was written to the destination, we found no address. */ 174 | if (dst == odst) 175 | goto enoent; 176 | /* If no CIDR spec was given, infer width from net class. */ 177 | if (bits == -1) { 178 | if (*odst >= 240) /* Class E */ 179 | bits = 32; 180 | else if (*odst >= 224) /* Class D */ 181 | bits = 4; 182 | else if (*odst >= 192) /* Class C */ 183 | bits = 24; 184 | else if (*odst >= 128) /* Class B */ 185 | bits = 16; 186 | else /* Class A */ 187 | bits = 8; 188 | /* If imputed mask is narrower than specified octets, widen. */ 189 | if (bits < ((dst - odst) * 8)) 190 | bits = (dst - odst) * 8; 191 | } 192 | /* Extend network to cover the actual mask. */ 193 | while (bits > ((dst - odst) * 8)) { 194 | if (size-- <= 0) 195 | goto emsgsize; 196 | *dst++ = '\0'; 197 | } 198 | return (bits); 199 | 200 | enoent: 201 | errno = ENOENT; 202 | return (-1); 203 | 204 | emsgsize: 205 | errno = EMSGSIZE; 206 | return (-1); 207 | } 208 | 209 | /* 210 | * Weak aliases for applications that use certain private entry points, 211 | * and fail to include . 212 | */ 213 | #undef inet_net_pton 214 | /* __weak_reference(__inet_net_pton, inet_net_pton); */ 215 | -------------------------------------------------------------------------------- /src/local-elf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2009 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef LIBBSD_LOCAL_ELF_H 28 | #define LIBBSD_LOCAL_ELF_H 29 | 30 | #include 31 | 32 | #define IS_ELF(ehdr) \ 33 | ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \ 34 | (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \ 35 | (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \ 36 | (ehdr).e_ident[EI_MAG3] == ELFMAG3) 37 | 38 | #define ELF_TARG_VER EV_CURRENT 39 | 40 | #if defined(__alpha__) 41 | 42 | #define ELF_TARG_MACH EM_ALPHA 43 | #define ELF_TARG_CLASS ELFCLASS64 44 | #define ELF_TARG_DATA ELFDATA2LSB 45 | 46 | #elif defined(__amd64__) 47 | 48 | #define ELF_TARG_MACH EM_X86_64 49 | #define ELF_TARG_CLASS ELFCLASS64 50 | #define ELF_TARG_DATA ELFDATA2LSB 51 | 52 | #elif defined(__arm__) 53 | 54 | #define ELF_TARG_MACH EM_ARM 55 | #define ELF_TARG_CLASS ELFCLASS32 56 | #if defined(__ARMEB__) 57 | #define ELF_TARG_DATA ELFDATA2MSB 58 | #else 59 | #define ELF_TARG_DATA ELFDATA2LSB 60 | #endif 61 | 62 | #elif defined(__avr32__) 63 | 64 | #ifndef EM_AVR32 65 | #define EM_AVR32 0x18ad 66 | #endif 67 | #define ELF_TARG_MACH EM_AVR32 68 | #define ELF_TARG_CLASS ELFCLASS32 69 | #if defined(__LITTLE_ENDIAN__) 70 | #define ELF_TARG_DATA ELFDATA2LSB 71 | #elif defined(__BIG_ENDIAN__) 72 | #define ELF_TARG_DATA ELFDATA2LMSB 73 | #else 74 | #error Unknown AVR32 endianness 75 | #endif 76 | 77 | #elif defined(__hppa__) 78 | 79 | #define ELF_TARG_MACH EM_PARISC 80 | #define ELF_TARG_CLASS ELFCLASS32 81 | #define ELF_TARG_DATA ELFDATA2MSB 82 | 83 | #elif defined(__i386__) 84 | 85 | #define ELF_TARG_MACH EM_386 86 | #define ELF_TARG_CLASS ELFCLASS32 87 | #define ELF_TARG_DATA ELFDATA2LSB 88 | 89 | #elif defined(__ia64__) 90 | 91 | #define ELF_TARG_MACH EM_IA_64 92 | #define ELF_TARG_CLASS ELFCLASS64 93 | #define ELF_TARG_DATA ELFDATA2LSB 94 | 95 | #elif defined(__m32r__) 96 | 97 | #define ELF_TARG_MACH EM_M32R 98 | #define ELF_TARG_CLASS ELFCLASS32 99 | #if defined(__LITTLE_ENDIAN__) 100 | #define ELF_TARG_DATA ELFDATA2LSB 101 | #elif defined(__BIG_ENDIAN__) 102 | #define ELF_TARG_DATA ELFDATA2MSB 103 | #else 104 | #error Unknown M32R endianness 105 | #endif 106 | 107 | #elif defined(__m68k__) 108 | 109 | #define ELF_TARG_MACH EM_68K 110 | #define ELF_TARG_CLASS ELFCLASS32 111 | #define ELF_TARG_DATA ELFDATA2MSB 112 | 113 | #elif defined(__mips__) 114 | 115 | #define ELF_TARG_MACH EM_MIPS 116 | #define ELF_TARG_CLASS ELFCLASS32 117 | #if defined(__MIPSEB__) 118 | #define ELF_TARG_DATA ELFDATA2MSB 119 | #else 120 | #define ELF_TARG_DATA ELFDATA2LSB 121 | #endif 122 | 123 | #elif defined(__powerpc__) 124 | 125 | #define ELF_TARG_MACH EM_PPC 126 | #define ELF_TARG_CLASS ELFCLASS32 127 | #define ELF_TARG_DATA ELFDATA2MSB 128 | 129 | #elif defined(__powerpc64__) 130 | 131 | #define ELF_TARG_MACH EM_PPC64 132 | #define ELF_TARG_CLASS ELFCLASS64 133 | #define ELF_TARG_DATA ELFDATA2MSB 134 | 135 | #elif defined(__sparc__) 136 | 137 | #if defined(__arch64__) 138 | #define ELF_TARG_MACH EM_SPARCV9 139 | #define ELF_TARG_CLASS ELFCLASS64 140 | #else 141 | #define ELF_TARG_MACH EM_SPARC 142 | #define ELF_TARG_CLASS ELFCLASS32 143 | #endif 144 | #define ELF_TARG_DATA ELFDATA2MSB 145 | 146 | #elif defined(__sh__) 147 | 148 | #define ELF_TARG_MACH EM_SH 149 | #define ELF_TARG_CLASS ELFCLASS32 150 | #if defined(__LITTLE_ENDIAN__) 151 | #define ELF_TARG_DATA ELFDATA2LSB 152 | #elif defined(__BIG_ENDIAN__) 153 | #define ELF_TARG_DATA ELFDATA2LMSB 154 | #else 155 | #error Unknown SH endianness 156 | #endif 157 | 158 | #elif defined(__s390__) 159 | 160 | #define ELF_TARG_MACH EM_S390 161 | #if defined(__s390x__) 162 | #define ELF_TARG_CLASS ELFCLASS64 163 | #else 164 | #define ELF_TARG_CLASS ELFCLASS32 165 | #endif 166 | #define ELF_TARG_DATA ELFDATA2MSB 167 | 168 | #else 169 | 170 | #error Unknown ELF machine type 171 | 172 | #endif 173 | 174 | #if ELF_TARG_CLASS == ELFCLASS32 175 | #define ELF_ST_BIND ELF32_ST_BIND 176 | #define ELF_ST_TYPE ELF32_ST_TYPE 177 | #define Elf_Word Elf32_Word 178 | #define Elf_Sword Elf32_Sword 179 | #define Elf_Sym Elf32_Sym 180 | #define Elf_Off Elf32_Off 181 | #define Elf_Shdr Elf32_Shdr 182 | #define Elf_Ehdr Elf32_Ehdr 183 | #elif ELF_TARG_CLASS == ELFCLASS64 184 | #define ELF_ST_BIND ELF64_ST_BIND 185 | #define ELF_ST_TYPE ELF64_ST_TYPE 186 | #define Elf_Word Elf64_Word 187 | #define Elf_Sword Elf64_Sword 188 | #define Elf_Sym Elf64_Sym 189 | #define Elf_Off Elf64_Off 190 | #define Elf_Shdr Elf64_Shdr 191 | #define Elf_Ehdr Elf64_Ehdr 192 | #else 193 | #error Unknown ELF class 194 | #endif 195 | 196 | #endif 197 | -------------------------------------------------------------------------------- /src/mdX.3: -------------------------------------------------------------------------------- 1 | .\" 2 | .\" ---------------------------------------------------------------------------- 3 | .\" "THE BEER-WARE LICENSE" (Revision 42): 4 | .\" wrote this file. As long as you retain this notice you 5 | .\" can do whatever you want with this stuff. If we meet some day, and you think 6 | .\" this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp 7 | .\" ---------------------------------------------------------------------------- 8 | .\" 9 | .\" $MirOS: src/lib/libc/hash/mdX.3,v 1.4 2007/05/07 16:15:56 tg Exp $ 10 | .\" $OpenBSD: mdX.3,v 1.9 2004/08/24 20:10:33 millert Exp $ 11 | .\" 12 | .Dd April 29, 2004 13 | .Dt MDX 3 14 | .Os 15 | .Sh NAME 16 | .Nm MDXInit , 17 | .Nm MDXUpdate , 18 | .Nm MDXPad , 19 | .Nm MDXFinal , 20 | .Nm MDXTransform , 21 | .Nm MDXEnd , 22 | .Nm MDXFile , 23 | .Nm MDXFileChunk , 24 | .Nm MDXData 25 | .Nd calculate the RSA Data Security, Inc., ``MDX'' message digest 26 | .Sh LIBRARY 27 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) 28 | .Lb libbsd 29 | .Sh SYNOPSIS 30 | .Fd #include 31 | .Fd #include 32 | .Ft void 33 | .Fn MDXInit "MDX_CTX *context" 34 | .Ft void 35 | .Fn MDXUpdate "MDX_CTX *context" "const u_int8_t *data" "size_t len" 36 | .Ft void 37 | .Fn MDXPad "MDX_CTX *context" 38 | .Ft void 39 | .Fn MDXFinal "u_int8_t digest[MDX_DIGEST_LENGTH]" "MDX_CTX *context" 40 | .Ft void 41 | .Fn MDXTransform "u_int32_t state[4]" "u_int8_t block[MDX_BLOCK_LENGTH]" 42 | .Ft "char *" 43 | .Fn MDXEnd "MDX_CTX *context" "char *buf" 44 | .Ft "char *" 45 | .Fn MDXFile "const char *filename" "char *buf" 46 | .Ft "char *" 47 | .Fn MDXFileChunk "const char *filename" "char *buf" "off_t offset" "off_t length" 48 | .Ft "char *" 49 | .Fn MDXData "const u_int8_t *data" "size_t len" "char *buf" 50 | .Sh DESCRIPTION 51 | The MDX functions calculate a 128-bit cryptographic checksum (digest) 52 | for any number of input bytes. 53 | A cryptographic checksum is a one-way 54 | hash-function, that is, you cannot find (except by exhaustive search) 55 | the input corresponding to a particular output. 56 | This net result is a 57 | .Dq fingerprint 58 | of the input-data, which doesn't disclose the actual input. 59 | .Pp 60 | MD4 has been broken; it should only be used where necessary for 61 | backward compatibility. 62 | MD5 has not yet (1999-02-11) been broken, but recent attacks have cast 63 | some doubt on its security properties. 64 | The attacks on both MD4 and MD5 65 | are both in the nature of finding 66 | .Dq collisions 67 | \- that is, multiple 68 | inputs which hash to the same value; it is still unlikely for an attacker 69 | to be able to determine the exact original input given a hash value. 70 | .Pp 71 | The 72 | .Fn MDXInit , 73 | .Fn MDXUpdate , 74 | and 75 | .Fn MDXFinal 76 | functions are the core functions. 77 | Allocate an MDX_CTX, initialize it with 78 | .Fn MDXInit , 79 | run over the data with 80 | .Fn MDXUpdate , 81 | and finally extract the result using 82 | .Fn MDXFinal . 83 | .Pp 84 | The 85 | .Fn MDXPad 86 | function can be used to apply padding to the message digest as in 87 | .Fn MDXFinal , 88 | but the current context can still be used with 89 | .Fn MDXUpdate . 90 | .Pp 91 | The 92 | .Fn MDXTransform 93 | function is used by 94 | .Fn MDXUpdate 95 | to hash 512-bit blocks and forms the core of the algorithm. 96 | Most programs should use the interface provided by 97 | .Fn MDXInit , 98 | .Fn MDXUpdate 99 | and 100 | .Fn MDXFinal 101 | instead of calling 102 | .Fn MDXTransform 103 | directly. 104 | .Pp 105 | .Fn MDXEnd 106 | is a wrapper for 107 | .Fn MDXFinal 108 | which converts the return value to an MDX_DIGEST_STRING_LENGTH-character 109 | (including the terminating '\e0') 110 | .Tn ASCII 111 | string which represents the 128 bits in hexadecimal. 112 | .Pp 113 | .Fn MDXFile 114 | calculates the digest of a file, and uses 115 | .Fn MDXEnd 116 | to return the result. 117 | If the file cannot be opened, a null pointer is returned. 118 | .Pp 119 | .Fn MDXFileChunk 120 | behaves like 121 | .Fn MDXFile 122 | but calculates the digest only for that portion of the file starting at 123 | .Fa offset 124 | and continuing for 125 | .Fa length 126 | bytes or until end of file is reached, whichever comes first. 127 | A zero 128 | .Fa length 129 | can be specified to read until end of file. 130 | A negative 131 | .Fa length 132 | or 133 | .Fa offset 134 | will be ignored. 135 | .Fn MDXData 136 | calculates the digest of a chunk of data in memory, and uses 137 | .Fn MDXEnd 138 | to return the result. 139 | .Pp 140 | When using 141 | .Fn MDXEnd , 142 | .Fn MDXFile , 143 | .Fn MDXFileChunk , 144 | or 145 | .Fn MDXData , 146 | the 147 | .Ar buf 148 | argument can be a null pointer, in which case the returned string 149 | is allocated with 150 | .Xr malloc 3 151 | and subsequently must be explicitly deallocated using 152 | .Xr free 3 153 | after use. 154 | If the 155 | .Ar buf 156 | argument is non-null it must point to at least MDX_DIGEST_STRING_LENGTH 157 | characters of buffer space. 158 | .Sh SEE ALSO 159 | .Xr cksum 1 , 160 | .Xr md5 1 , 161 | .Xr adler32 3 , 162 | .Xr mdY 3 , 163 | .Xr rmd160 3 , 164 | .Xr sfv 3 , 165 | .Xr sha1 3 , 166 | .Xr sha2 3 , 167 | .Xr suma 3 , 168 | .Xr tiger 3 , 169 | .Xr whirlpool 3 170 | .Rs 171 | .%A R. Rivest 172 | .%T The MD4 Message-Digest Algorithm 173 | .%O RFC 1186 174 | .Re 175 | .Rs 176 | .%A R. Rivest 177 | .%T The MD5 Message-Digest Algorithm 178 | .%O RFC 1321 179 | .Re 180 | .Rs 181 | .%A RSA Laboratories 182 | .%T Frequently Asked Questions About today's Cryptography 183 | .%O \& 184 | .Re 185 | .Rs 186 | .%A H. Dobbertin 187 | .%T Alf Swindles Ann 188 | .%J CryptoBytes 189 | .%N 1(3):5 190 | .%D 1995 191 | .Re 192 | .Rs 193 | .%A MJ. B. Robshaw 194 | .%T On Recent Results for MD4 and MD5 195 | .%J RSA Laboratories Bulletin 196 | .%N 4 197 | .%D November 12, 1996 198 | .Re 199 | .Rs 200 | .%A Hans Dobbertin 201 | .%T Cryptanalysis of MD5 Compress 202 | .Re 203 | .Sh HISTORY 204 | These functions appeared in 205 | .Ox 2.0 . 206 | .Sh AUTHORS 207 | The original MDX routines were developed by 208 | .Tn RSA 209 | Data Security, Inc., and published in the above references. 210 | This code is derived from a public domain implementation written by Colin Plumb. 211 | .Pp 212 | The 213 | .Fn MDXEnd , 214 | .Fn MDXFile , 215 | .Fn MDXFileChunk , 216 | and 217 | .Fn MDXData 218 | helper functions are derived from code written by Poul-Henning Kamp. 219 | .Sh BUGS 220 | Collisions have been found for the full versions of both MD4 and MD5 221 | as well as strong attacks against the SHA-0 and SHA-1 family. 222 | The use of 223 | .Xr sha2 3 , 224 | or 225 | .Xr rmd160 3 226 | is recommended instead. 227 | -------------------------------------------------------------------------------- /src/mergesort.3: -------------------------------------------------------------------------------- 1 | .so man3/heapsort.3 2 | -------------------------------------------------------------------------------- /src/nlist.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1980, 1991, 1993 2 | .\" The Regents of the University of California. All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 4. Neither the name of the University nor the names of its contributors 13 | .\" may be used to endorse or promote products derived from this software 14 | .\" without specific prior written permission. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | .\" SUCH DAMAGE. 27 | .\" 28 | .\" @(#)nlist.3 8.3 (Berkeley) 4/19/94 29 | .\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/nlist.3,v 1.7 2001/10/01 16:08:51 ru Exp $ 30 | .\" 31 | .Dd April 19, 1994 32 | .Dt NLIST 3 33 | .Os 34 | .Sh NAME 35 | .Nm nlist 36 | .Nd retrieve symbol table name list from an executable file 37 | .Sh LIBRARY 38 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) 39 | .Lb libbsd 40 | .Sh SYNOPSIS 41 | .In bsd/nlist.h 42 | .Ft int 43 | .Fn nlist "const char *filename" "struct nlist *nl" 44 | .Sh DESCRIPTION 45 | The 46 | .Fn nlist 47 | function 48 | retrieves name list entries from the symbol table of an 49 | executable file (see 50 | .Xr a.out 5 ) . 51 | The argument 52 | .Fa \&nl 53 | is set to reference the 54 | beginning of the list. 55 | The list is preened of binary and invalid data; 56 | if an entry in the 57 | name list is valid, the 58 | .Fa n_type 59 | and 60 | .Fa n_value 61 | for the entry are copied into the list 62 | referenced by 63 | .Fa \&nl . 64 | No other data is copied. 65 | The last entry in the list is always 66 | .Dv NULL . 67 | .Sh RETURN VALUES 68 | The number of invalid entries is returned if successful; otherwise, 69 | if the file 70 | .Fa filename 71 | does not exist or is not executable, the returned value is \-1. 72 | .Sh SEE ALSO 73 | .Xr a.out 5 74 | .Sh HISTORY 75 | A 76 | .Fn nlist 77 | function appeared in 78 | .At v6 . 79 | -------------------------------------------------------------------------------- /src/progname.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2006 Robert Millan 3 | * Copyright © 2010-2011 Guillem Jover 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 18 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 19 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | /* 29 | Rejected in glibc (http://sourceware.org/ml/libc-alpha/2006-03/msg00125.html) 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | static const char *__progname = NULL; 37 | 38 | const char * 39 | getprogname(void) 40 | { 41 | #ifdef __GLIBC__ 42 | if (__progname == NULL) 43 | __progname = program_invocation_short_name; 44 | #endif 45 | 46 | return __progname; 47 | } 48 | 49 | void 50 | setprogname(const char *progname) 51 | { 52 | const char *last_slash; 53 | 54 | last_slash = strrchr(progname, '/'); 55 | if (last_slash == NULL) 56 | __progname = progname; 57 | else 58 | __progname = last_slash + 1; 59 | } 60 | -------------------------------------------------------------------------------- /src/radixsort.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1990, 1991, 1993 2 | .\" The Regents of the University of California. All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 4. Neither the name of the University nor the names of its contributors 13 | .\" may be used to endorse or promote products derived from this software 14 | .\" without specific prior written permission. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | .\" SUCH DAMAGE. 27 | .\" 28 | .\" @(#)radixsort.3 8.2 (Berkeley) 1/27/94 29 | .\" $FreeBSD$ 30 | .\" 31 | .Dd January 27, 1994 32 | .Dt RADIXSORT 3 33 | .Os 34 | .Sh NAME 35 | .Nm radixsort , sradixsort 36 | .Nd radix sort 37 | .Sh LIBRARY 38 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) 39 | .Lb libbsd 40 | .Sh SYNOPSIS 41 | .In limits.h 42 | .In bsd/stdlib.h 43 | .Ft int 44 | .Fn radixsort "const unsigned char **base" "int nmemb" "const unsigned char *table" "unsigned endbyte" 45 | .Ft int 46 | .Fn sradixsort "const unsigned char **base" "int nmemb" "const unsigned char *table" "unsigned endbyte" 47 | .Sh DESCRIPTION 48 | The 49 | .Fn radixsort 50 | and 51 | .Fn sradixsort 52 | functions 53 | are implementations of radix sort. 54 | .Pp 55 | These functions sort an array of pointers to byte strings, the initial 56 | member of which is referenced by 57 | .Fa base . 58 | The byte strings may contain any values; the end of each string 59 | is denoted by the user-specified value 60 | .Fa endbyte . 61 | .Pp 62 | Applications may specify a sort order by providing the 63 | .Fa table 64 | argument. 65 | If 66 | .Pf non- Dv NULL , 67 | .Fa table 68 | must reference an array of 69 | .Dv UCHAR_MAX 70 | + 1 bytes which contains the sort 71 | weight of each possible byte value. 72 | The end-of-string byte must have a sort weight of 0 or 255 73 | (for sorting in reverse order). 74 | More than one byte may have the same sort weight. 75 | The 76 | .Fa table 77 | argument 78 | is useful for applications which wish to sort different characters 79 | equally, for example, providing a table with the same weights 80 | for A-Z as for a-z will result in a case-insensitive sort. 81 | If 82 | .Fa table 83 | is NULL, the contents of the array are sorted in ascending order 84 | according to the 85 | .Tn ASCII 86 | order of the byte strings they reference and 87 | .Fa endbyte 88 | has a sorting weight of 0. 89 | .Pp 90 | The 91 | .Fn sradixsort 92 | function is stable, that is, if two elements compare as equal, their 93 | order in the sorted array is unchanged. 94 | The 95 | .Fn sradixsort 96 | function uses additional memory sufficient to hold 97 | .Fa nmemb 98 | pointers. 99 | .Pp 100 | The 101 | .Fn radixsort 102 | function is not stable, but uses no additional memory. 103 | .Pp 104 | These functions are variants of most-significant-byte radix sorting; in 105 | particular, see 106 | .An "D.E. Knuth" Ns 's 107 | .%T "Algorithm R" 108 | and section 5.2.5, exercise 10. 109 | They take linear time relative to the number of bytes in the strings. 110 | .Sh RETURN VALUES 111 | .Rv -std radixsort 112 | .Sh ERRORS 113 | .Bl -tag -width Er 114 | .It Bq Er EINVAL 115 | The value of the 116 | .Fa endbyte 117 | element of 118 | .Fa table 119 | is not 0 or 255. 120 | .El 121 | .Pp 122 | Additionally, the 123 | .Fn sradixsort 124 | function 125 | may fail and set 126 | .Va errno 127 | for any of the errors specified for the library routine 128 | .Xr malloc 3 . 129 | .Sh SEE ALSO 130 | .Xr sort 1 , 131 | .Xr qsort 3 132 | .Pp 133 | .Rs 134 | .%A Knuth, D.E. 135 | .%D 1968 136 | .%B "The Art of Computer Programming" 137 | .%T "Sorting and Searching" 138 | .%V Vol. 3 139 | .%P pp. 170-178 140 | .Re 141 | .Rs 142 | .%A Paige, R. 143 | .%D 1987 144 | .%T "Three Partition Refinement Algorithms" 145 | .%J "SIAM J. Comput." 146 | .%V Vol. 16 147 | .%N No. 6 148 | .Re 149 | .Rs 150 | .%A McIlroy, P. 151 | .%D 1993 152 | .%B "Engineering Radix Sort" 153 | .%T "Computing Systems" 154 | .%V Vol. 6:1 155 | .%P pp. 5-27 156 | .Re 157 | .Sh HISTORY 158 | The 159 | .Fn radixsort 160 | function first appeared in 161 | .Bx 4.4 . 162 | -------------------------------------------------------------------------------- /src/readpassphrase.3: -------------------------------------------------------------------------------- 1 | .\" $OpenBSD: readpassphrase.3,v 1.16 2005/07/22 03:16:58 jaredy Exp $ 2 | .\" 3 | .\" Copyright (c) 2000, 2002 Todd C. Miller 4 | .\" 5 | .\" Permission to use, copy, modify, and distribute this software for any 6 | .\" purpose with or without fee is hereby granted, provided that the above 7 | .\" copyright notice and this permission notice appear in all copies. 8 | .\" 9 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | .\" 17 | .\" Sponsored in part by the Defense Advanced Research Projects 18 | .\" Agency (DARPA) and Air Force Research Laboratory, Air Force 19 | .\" Materiel Command, USAF, under agreement number F39502-99-1-0512. 20 | .\" 21 | .Dd $Mdocdate: May 31 2007 $ 22 | .Dt READPASSPHRASE 3 23 | .Os 24 | .Sh NAME 25 | .Nm readpassphrase 26 | .Nd get a passphrase from the user 27 | .Sh LIBRARY 28 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) 29 | .Lb libbsd 30 | .Sh SYNOPSIS 31 | .Fd #include 32 | .Ft char * 33 | .Fn readpassphrase "const char *prompt" "char *buf" "size_t bufsiz" "int flags" 34 | .Sh DESCRIPTION 35 | The 36 | .Fn readpassphrase 37 | function displays a prompt to, and reads in a passphrase from, 38 | .Pa /dev/tty . 39 | If this file is inaccessible 40 | and the 41 | .Dv RPP_REQUIRE_TTY 42 | flag is not set, 43 | .Fn readpassphrase 44 | displays the prompt on the standard error output and reads from the standard 45 | input. 46 | In this case it is generally not possible to turn off echo. 47 | .Pp 48 | Up to 49 | .Fa bufsiz 50 | - 1 characters (one is for the NUL) are read into the provided buffer 51 | .Fa buf . 52 | Any additional 53 | characters and the terminating newline (or return) character are discarded. 54 | .Pp 55 | .Fn readpassphrase 56 | takes the following optional 57 | .Fa flags : 58 | .Bd -literal -offset indent 59 | RPP_ECHO_OFF turn off echo (default behavior) 60 | RPP_ECHO_ON leave echo on 61 | RPP_REQUIRE_TTY fail if there is no tty 62 | RPP_FORCELOWER force input to lower case 63 | RPP_FORCEUPPER force input to upper case 64 | RPP_SEVENBIT strip the high bit from input 65 | RPP_STDIN force read of passphrase from stdin 66 | .Ed 67 | .Pp 68 | The calling process should zero the passphrase as soon as possible to 69 | avoid leaving the cleartext passphrase visible in the process's address 70 | space. 71 | .Sh RETURN VALUES 72 | Upon successful completion, 73 | .Fn readpassphrase 74 | returns a pointer to the NUL-terminated passphrase. 75 | If an error is encountered, the terminal state is restored and 76 | a null pointer is returned. 77 | .Sh FILES 78 | .Bl -tag -width /dev/tty -compact 79 | .It Pa /dev/tty 80 | .El 81 | .Sh EXAMPLES 82 | The following code fragment will read a passphrase from 83 | .Pa /dev/tty 84 | into the buffer 85 | .Fa passbuf . 86 | .Bd -literal -offset indent 87 | char passbuf[1024]; 88 | 89 | \&... 90 | 91 | if (readpassphrase("Response: ", passbuf, sizeof(passbuf), 92 | RPP_REQUIRE_TTY) == NULL) 93 | errx(1, "unable to read passphrase"); 94 | 95 | if (compare(transform(passbuf), epass) != 0) 96 | errx(1, "bad passphrase"); 97 | 98 | \&... 99 | 100 | memset(passbuf, 0, sizeof(passbuf)); 101 | .Ed 102 | .Sh ERRORS 103 | .Bl -tag -width Er 104 | .It Bq Er EINTR 105 | The 106 | .Fn readpassphrase 107 | function was interrupted by a signal. 108 | .It Bq Er EINVAL 109 | The 110 | .Ar bufsiz 111 | argument was zero. 112 | .It Bq Er EIO 113 | The process is a member of a background process attempting to read 114 | from its controlling terminal, the process is ignoring or blocking 115 | the 116 | .Dv SIGTTIN 117 | signal, or the process group is orphaned. 118 | .It Bq Er EMFILE 119 | The process has already reached its limit for open file descriptors. 120 | .It Bq Er ENFILE 121 | The system file table is full. 122 | .It Bq Er ENOTTY 123 | There is no controlling terminal and the 124 | .Dv RPP_REQUIRE_TTY 125 | flag was specified. 126 | .El 127 | .Sh SIGNALS 128 | .Fn readpassphrase 129 | will catch the following signals: 130 | .Bd -literal -offset indent 131 | SIGALRM SIGHUP SIGINT 132 | SIGPIPE SIGQUIT SIGTERM 133 | SIGTSTP SIGTTIN SIGTTOU 134 | .Ed 135 | .Pp 136 | When one of the above signals is intercepted, terminal echo will 137 | be restored if it had previously been turned off. 138 | If a signal handler was installed for the signal when 139 | .Fn readpassphrase 140 | was called, that handler is then executed. 141 | If no handler was previously installed for the signal then the 142 | default action is taken as per 143 | .Xr sigaction 2 . 144 | .Pp 145 | The 146 | .Dv SIGTSTP , 147 | .Dv SIGTTIN , 148 | and 149 | .Dv SIGTTOU 150 | signals (stop signals generated from keyboard or due to terminal I/O 151 | from a background process) are treated specially. 152 | When the process is resumed after it has been stopped, 153 | .Fn readpassphrase 154 | will reprint the prompt and the user may then enter a passphrase. 155 | .Sh SEE ALSO 156 | .Xr sigaction 2 , 157 | .Xr getpass 3 158 | .Sh STANDARDS 159 | The 160 | .Fn readpassphrase 161 | function is an 162 | .Ox 163 | extension and should not be used if portability is desired. 164 | .Sh HISTORY 165 | The 166 | .Fn readpassphrase 167 | function first appeared in 168 | .Ox 2.9 . 169 | -------------------------------------------------------------------------------- /src/readpassphrase.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: readpassphrase.c,v 1.20 2007/10/30 12:03:48 millert Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2000-2002, 2007 Todd C. Miller 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | * 18 | * Sponsored in part by the Defense Advanced Research Projects 19 | * Agency (DARPA) and Air Force Research Laboratory, Air Force 20 | * Materiel Command, USAF, under agreement number F39502-99-1-0512. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #ifndef TCSASOFT 35 | #define TCSASOFT 0 36 | #endif 37 | 38 | static volatile sig_atomic_t signo; 39 | 40 | static void handler(int); 41 | 42 | char * 43 | readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) 44 | { 45 | ssize_t nr; 46 | int input, output, save_errno; 47 | char ch, *p, *end; 48 | struct termios term, oterm; 49 | struct sigaction sa, savealrm, saveint, savehup, savequit, saveterm; 50 | struct sigaction savetstp, savettin, savettou, savepipe; 51 | 52 | /* I suppose we could alloc on demand in this case (XXX). */ 53 | if (bufsiz == 0) { 54 | errno = EINVAL; 55 | return(NULL); 56 | } 57 | 58 | restart: 59 | signo = 0; 60 | nr = -1; 61 | save_errno = 0; 62 | /* 63 | * Read and write to /dev/tty if available. If not, read from 64 | * stdin and write to stderr unless a tty is required. 65 | */ 66 | if ((flags & RPP_STDIN) || 67 | (input = output = open(_PATH_TTY, O_RDWR)) == -1) { 68 | if (flags & RPP_REQUIRE_TTY) { 69 | errno = ENOTTY; 70 | return(NULL); 71 | } 72 | input = STDIN_FILENO; 73 | output = STDERR_FILENO; 74 | } 75 | 76 | /* 77 | * Catch signals that would otherwise cause the user to end 78 | * up with echo turned off in the shell. Don't worry about 79 | * things like SIGXCPU and SIGVTALRM for now. 80 | */ 81 | sigemptyset(&sa.sa_mask); 82 | sa.sa_flags = 0; /* don't restart system calls */ 83 | sa.sa_handler = handler; 84 | (void)sigaction(SIGALRM, &sa, &savealrm); 85 | (void)sigaction(SIGHUP, &sa, &savehup); 86 | (void)sigaction(SIGINT, &sa, &saveint); 87 | (void)sigaction(SIGPIPE, &sa, &savepipe); 88 | (void)sigaction(SIGQUIT, &sa, &savequit); 89 | (void)sigaction(SIGTERM, &sa, &saveterm); 90 | (void)sigaction(SIGTSTP, &sa, &savetstp); 91 | (void)sigaction(SIGTTIN, &sa, &savettin); 92 | (void)sigaction(SIGTTOU, &sa, &savettou); 93 | 94 | /* Turn off echo if possible. */ 95 | if (input != STDIN_FILENO && tcgetattr(input, &oterm) == 0) { 96 | memcpy(&term, &oterm, sizeof(term)); 97 | if (!(flags & RPP_ECHO_ON)) 98 | term.c_lflag &= ~(ECHO | ECHONL); 99 | #ifdef VSTATUS 100 | if (term.c_cc[VSTATUS] != _POSIX_VDISABLE) 101 | term.c_cc[VSTATUS] = _POSIX_VDISABLE; 102 | #endif 103 | (void)tcsetattr(input, TCSAFLUSH|TCSASOFT, &term); 104 | } else { 105 | memset(&term, 0, sizeof(term)); 106 | term.c_lflag |= ECHO; 107 | memset(&oterm, 0, sizeof(oterm)); 108 | oterm.c_lflag |= ECHO; 109 | } 110 | 111 | /* No I/O if we are already backgrounded. */ 112 | if (signo != SIGTTOU && signo != SIGTTIN) { 113 | if (!(flags & RPP_STDIN)) 114 | (void)write(output, prompt, strlen(prompt)); 115 | end = buf + bufsiz - 1; 116 | p = buf; 117 | while ((nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r') { 118 | if (p < end) { 119 | if ((flags & RPP_SEVENBIT)) 120 | ch &= 0x7f; 121 | if (isalpha(ch)) { 122 | if ((flags & RPP_FORCELOWER)) 123 | ch = (char)tolower(ch); 124 | if ((flags & RPP_FORCEUPPER)) 125 | ch = (char)toupper(ch); 126 | } 127 | *p++ = ch; 128 | } 129 | } 130 | *p = '\0'; 131 | save_errno = errno; 132 | if (!(term.c_lflag & ECHO)) 133 | (void)write(output, "\n", 1); 134 | } 135 | 136 | /* Restore old terminal settings and signals. */ 137 | if (memcmp(&term, &oterm, sizeof(term)) != 0) { 138 | while (tcsetattr(input, TCSAFLUSH|TCSASOFT, &oterm) == -1 && 139 | errno == EINTR) 140 | continue; 141 | } 142 | (void)sigaction(SIGALRM, &savealrm, NULL); 143 | (void)sigaction(SIGHUP, &savehup, NULL); 144 | (void)sigaction(SIGINT, &saveint, NULL); 145 | (void)sigaction(SIGQUIT, &savequit, NULL); 146 | (void)sigaction(SIGPIPE, &savepipe, NULL); 147 | (void)sigaction(SIGTERM, &saveterm, NULL); 148 | (void)sigaction(SIGTSTP, &savetstp, NULL); 149 | (void)sigaction(SIGTTIN, &savettin, NULL); 150 | (void)sigaction(SIGTTOU, &savettou, NULL); 151 | if (input != STDIN_FILENO) 152 | (void)close(input); 153 | 154 | /* 155 | * If we were interrupted by a signal, resend it to ourselves 156 | * now that we have restored the signal handlers. 157 | */ 158 | if (signo) { 159 | kill(getpid(), signo); 160 | switch (signo) { 161 | case SIGTSTP: 162 | case SIGTTIN: 163 | case SIGTTOU: 164 | goto restart; 165 | } 166 | } 167 | 168 | if (save_errno) 169 | errno = save_errno; 170 | return(nr == -1 ? NULL : buf); 171 | } 172 | 173 | #if 0 174 | char * 175 | getpass(const char *prompt) 176 | { 177 | static char buf[_PASSWORD_LEN + 1]; 178 | 179 | return(readpassphrase(prompt, buf, sizeof(buf), RPP_ECHO_OFF)); 180 | } 181 | #endif 182 | 183 | static void handler(int s) 184 | { 185 | 186 | signo = s; 187 | } 188 | -------------------------------------------------------------------------------- /src/reallocf.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1980, 1991, 1993 2 | .\" The Regents of the University of California. All rights reserved. 3 | .\" 4 | .\" This code is derived from software contributed to Berkeley by 5 | .\" the American National Standards Committee X3, on Information 6 | .\" Processing Systems. 7 | .\" 8 | .\" Redistribution and use in source and binary forms, with or without 9 | .\" modification, are permitted provided that the following conditions 10 | .\" are met: 11 | .\" 1. Redistributions of source code must retain the above copyright 12 | .\" notice, this list of conditions and the following disclaimer. 13 | .\" 2. Redistributions in binary form must reproduce the above copyright 14 | .\" notice, this list of conditions and the following disclaimer in the 15 | .\" documentation and/or other materials provided with the distribution. 16 | .\" 3. Neither the name of the University nor the names of its contributors 17 | .\" may be used to endorse or promote products derived from this software 18 | .\" without specific prior written permission. 19 | .\" 20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | .\" SUCH DAMAGE. 31 | .\" 32 | .\" @(#)malloc.3 8.1 (Berkeley) 6/4/93 33 | .\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.80.2.2.2.1 2010/06/14 02:09:06 kensmith Exp $ 34 | .\" 35 | .Dd September 26, 2009 36 | .Dt MALLOC 3 37 | .Os 38 | .Sh NAME 39 | .Nm reallocf 40 | .Nd general purpose memory allocation functions 41 | .Sh LIBRARY 42 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) 43 | .Lb libbsd 44 | .Sh SYNOPSIS 45 | .In bsd/stdlib.h 46 | .Ft void * 47 | .Fn reallocf "void *ptr" "size_t size" 48 | .Sh DESCRIPTION 49 | The 50 | .Fn reallocf 51 | function changes the size of the previously allocated memory referenced by 52 | .Fa ptr 53 | to 54 | .Fa size 55 | bytes. 56 | The contents of the memory are unchanged up to the lesser of the new and 57 | old sizes. 58 | If the new size is larger, 59 | the contents of the newly allocated portion of the memory are undefined. 60 | Upon success, the memory referenced by 61 | .Fa ptr 62 | is freed and a pointer to the newly allocated memory is returned. 63 | Note that 64 | .Fn reallocf 65 | may move the memory allocation, resulting in a different return value than 66 | .Fa ptr . 67 | If 68 | .Fa ptr 69 | is 70 | .Dv NULL , 71 | the 72 | .Fn reallocf 73 | function behaves identically to 74 | .Fn malloc 75 | for the specified size. 76 | Upon failure, when the requested memory cannot be allocated, the passed pointer 77 | is freed to ease the problems with traditional coding styles for 78 | .Fn reallocf 79 | causing memory leaks in libraries. 80 | .Sh RETURN VALUES 81 | The 82 | .Fn reallocf 83 | function returns a pointer, possibly identical to 84 | .Fa ptr , 85 | to the allocated memory 86 | if successful; otherwise a 87 | .Dv NULL 88 | pointer is returned, and 89 | .Va errno 90 | is set to 91 | .Er ENOMEM 92 | if the error was the result of an allocation failure. 93 | The buffer is deallocated in this case. 94 | .Sh SEE ALSO 95 | .Xr brk 2 , 96 | .Xr mmap 2 , 97 | .Xr alloca 3 , 98 | .Xr calloc 3 , 99 | .Xr free 3 , 100 | .Xr malloc 3 , 101 | .Xr posix_memalign 3 , 102 | .Xr realloc 3 , 103 | .Sh HISTORY 104 | The 105 | .Fn reallocf 106 | function first appeared in 107 | .Fx 3.0 . 108 | -------------------------------------------------------------------------------- /src/reallocf.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1998, M. Warner Losh 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | */ 26 | 27 | #include 28 | __FBSDID("$FreeBSD$"); 29 | 30 | #include 31 | 32 | void * 33 | reallocf(void *ptr, size_t size) 34 | { 35 | void *nptr; 36 | 37 | nptr = realloc(ptr, size); 38 | 39 | /* 40 | * When the System V compatibility option (malloc "V" flag) is 41 | * in effect, realloc(ptr, 0) frees the memory and returns NULL. 42 | * So, to avoid double free, call free() only when size != 0. 43 | * realloc(ptr, 0) can't fail when ptr != NULL. 44 | */ 45 | if (!nptr && ptr && size != 0) 46 | free(ptr); 47 | return (nptr); 48 | } 49 | -------------------------------------------------------------------------------- /src/setmode.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1989, 1991, 1993 2 | .\" The Regents of the University of California. All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 4. Neither the name of the University nor the names of its contributors 13 | .\" may be used to endorse or promote products derived from this software 14 | .\" without specific prior written permission. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | .\" SUCH DAMAGE. 27 | .\" 28 | .\" @(#)setmode.3 8.2 (Berkeley) 4/28/95 29 | .\" $FreeBSD: src/lib/libc/gen/setmode.3,v 1.12 2007/01/09 00:27:55 imp Exp $ 30 | .\" 31 | .Dd April 28, 1995 32 | .Dt SETMODE 3 33 | .Os 34 | .Sh NAME 35 | .Nm getmode , 36 | .Nm setmode 37 | .Nd modify mode bits 38 | .Sh LIBRARY 39 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) 40 | .Lb libbsd 41 | .Sh SYNOPSIS 42 | .In bsd/unistd.h 43 | .Ft mode_t 44 | .Fn getmode "const void *set" "mode_t mode" 45 | .Ft void * 46 | .Fn setmode "const char *mode_str" 47 | .Sh DESCRIPTION 48 | The 49 | .Fn getmode 50 | function 51 | returns a copy of the file permission bits 52 | .Fa mode 53 | as altered by the values pointed to by 54 | .Fa set . 55 | While only the mode bits are altered, other parts of the file mode 56 | may be examined. 57 | .Pp 58 | The 59 | .Fn setmode 60 | function 61 | takes an absolute (octal) or symbolic value, as described in 62 | .Xr chmod 1 , 63 | as an argument 64 | and returns a pointer to mode values to be supplied to 65 | .Fn getmode . 66 | Because some of the symbolic values are relative to the file 67 | creation mask, 68 | .Fn setmode 69 | may call 70 | .Xr umask 2 . 71 | If this occurs, the file creation mask will be restored before 72 | .Fn setmode 73 | returns. 74 | If the calling program changes the value of its file creation mask 75 | after calling 76 | .Fn setmode , 77 | .Fn setmode 78 | must be called again if 79 | .Fn getmode 80 | is to modify future file modes correctly. 81 | .Pp 82 | If the mode passed to 83 | .Fn setmode 84 | is invalid or if memory cannot be allocated for the return value, 85 | .Fn setmode 86 | returns 87 | .Dv NULL . 88 | .Pp 89 | The value returned from 90 | .Fn setmode 91 | is obtained from 92 | .Fn malloc 93 | and should be returned to the system with 94 | .Fn free 95 | when the program is done with it, generally after a call to 96 | .Fn getmode . 97 | .Sh ERRORS 98 | The 99 | .Fn setmode 100 | function 101 | may fail and set errno for any of the errors specified for the library 102 | routine 103 | .Xr malloc 3 . 104 | .Sh SEE ALSO 105 | .Xr chmod 1 , 106 | .Xr stat 2 , 107 | .Xr umask 2 , 108 | .Xr malloc 3 109 | .Sh HISTORY 110 | The 111 | .Fn getmode 112 | and 113 | .Fn setmode 114 | functions first appeared in 115 | .Bx 4.4 . 116 | -------------------------------------------------------------------------------- /src/setproctitle.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010 Guillem Jover 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 18 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | void 28 | setproctitle(const char *fmt, ...) 29 | { 30 | /* Stub so that we can implement it later on and programs will 31 | * automatically benefit from it, w/o needing to recompile. */ 32 | } 33 | -------------------------------------------------------------------------------- /src/sradixsort.3: -------------------------------------------------------------------------------- 1 | .so man3/radixsort.3 2 | -------------------------------------------------------------------------------- /src/strlcat.3: -------------------------------------------------------------------------------- 1 | .so man3/strlcpy.3 2 | -------------------------------------------------------------------------------- /src/strlcat.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: strlcat.c,v 1.12 2005/03/30 20:13:52 otto Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 1998 Todd C. Miller 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | /* 23 | * Appends src to string dst of size siz (unlike strncat, siz is the 24 | * full size of dst, not space left). At most siz-1 characters 25 | * will be copied. Always NUL terminates (unless siz <= strlen(dst)). 26 | * Returns strlen(src) + MIN(siz, strlen(initial dst)). 27 | * If retval >= siz, truncation occurred. 28 | */ 29 | size_t 30 | strlcat(char *dst, const char *src, size_t siz) 31 | { 32 | char *d = dst; 33 | const char *s = src; 34 | size_t n = siz; 35 | size_t dlen; 36 | 37 | /* Find the end of dst and adjust bytes left but don't go past end */ 38 | while (n-- != 0 && *d != '\0') 39 | d++; 40 | dlen = d - dst; 41 | n = siz - dlen; 42 | 43 | if (n == 0) 44 | return(dlen + strlen(s)); 45 | while (*s != '\0') { 46 | if (n != 1) { 47 | *d++ = *s; 48 | n--; 49 | } 50 | s++; 51 | } 52 | *d = '\0'; 53 | 54 | return(dlen + (s - src)); /* count does not include NUL */ 55 | } 56 | -------------------------------------------------------------------------------- /src/strlcpy.3: -------------------------------------------------------------------------------- 1 | .\" $OpenBSD: strlcpy.3,v 1.18 2005/08/06 03:24:19 jaredy Exp $ 2 | .\" 3 | .\" Copyright (c) 1998, 2000 Todd C. Miller 4 | .\" 5 | .\" Permission to use, copy, modify, and distribute this software for any 6 | .\" purpose with or without fee is hereby granted, provided that the above 7 | .\" copyright notice and this permission notice appear in all copies. 8 | .\" 9 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | .\" 17 | .Dd $Mdocdate: May 31 2007 $ 18 | .Dt STRLCPY 3 19 | .Os 20 | .Sh NAME 21 | .Nm strlcpy , 22 | .Nm strlcat 23 | .Nd size-bounded string copying and concatenation 24 | .Sh LIBRARY 25 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) 26 | .Lb libbsd 27 | .Sh SYNOPSIS 28 | .In bsd/string.h 29 | .Ft size_t 30 | .Fn strlcpy "char *dst" "const char *src" "size_t size" 31 | .Ft size_t 32 | .Fn strlcat "char *dst" "const char *src" "size_t size" 33 | .Sh DESCRIPTION 34 | The 35 | .Fn strlcpy 36 | and 37 | .Fn strlcat 38 | functions copy and concatenate strings respectively. 39 | They are designed 40 | to be safer, more consistent, and less error prone replacements for 41 | .Xr strncpy 3 42 | and 43 | .Xr strncat 3 . 44 | Unlike those functions, 45 | .Fn strlcpy 46 | and 47 | .Fn strlcat 48 | take the full size of the buffer (not just the length) and guarantee to 49 | NUL-terminate the result (as long as 50 | .Fa size 51 | is larger than 0 or, in the case of 52 | .Fn strlcat , 53 | as long as there is at least one byte free in 54 | .Fa dst ) . 55 | Note that a byte for the NUL should be included in 56 | .Fa size . 57 | Also note that 58 | .Fn strlcpy 59 | and 60 | .Fn strlcat 61 | only operate on true 62 | .Dq C 63 | strings. 64 | This means that for 65 | .Fn strlcpy 66 | .Fa src 67 | must be NUL-terminated and for 68 | .Fn strlcat 69 | both 70 | .Fa src 71 | and 72 | .Fa dst 73 | must be NUL-terminated. 74 | .Pp 75 | The 76 | .Fn strlcpy 77 | function copies up to 78 | .Fa size 79 | - 1 characters from the NUL-terminated string 80 | .Fa src 81 | to 82 | .Fa dst , 83 | NUL-terminating the result. 84 | .Pp 85 | The 86 | .Fn strlcat 87 | function appends the NUL-terminated string 88 | .Fa src 89 | to the end of 90 | .Fa dst . 91 | It will append at most 92 | .Fa size 93 | - strlen(dst) - 1 bytes, NUL-terminating the result. 94 | .Sh RETURN VALUES 95 | The 96 | .Fn strlcpy 97 | and 98 | .Fn strlcat 99 | functions return the total length of the string they tried to create. 100 | For 101 | .Fn strlcpy 102 | that means the length of 103 | .Fa src . 104 | For 105 | .Fn strlcat 106 | that means the initial length of 107 | .Fa dst 108 | plus 109 | the length of 110 | .Fa src . 111 | While this may seem somewhat confusing, it was done to make 112 | truncation detection simple. 113 | .Pp 114 | Note, however, that if 115 | .Fn strlcat 116 | traverses 117 | .Fa size 118 | characters without finding a NUL, the length of the string is considered 119 | to be 120 | .Fa size 121 | and the destination string will not be NUL-terminated (since there was 122 | no space for the NUL). 123 | This keeps 124 | .Fn strlcat 125 | from running off the end of a string. 126 | In practice this should not happen (as it means that either 127 | .Fa size 128 | is incorrect or that 129 | .Fa dst 130 | is not a proper 131 | .Dq C 132 | string). 133 | The check exists to prevent potential security problems in incorrect code. 134 | .Sh EXAMPLES 135 | The following code fragment illustrates the simple case: 136 | .Bd -literal -offset indent 137 | char *s, *p, buf[BUFSIZ]; 138 | 139 | \&... 140 | 141 | (void)strlcpy(buf, s, sizeof(buf)); 142 | (void)strlcat(buf, p, sizeof(buf)); 143 | .Ed 144 | .Pp 145 | To detect truncation, perhaps while building a pathname, something 146 | like the following might be used: 147 | .Bd -literal -offset indent 148 | char *dir, *file, pname[MAXPATHLEN]; 149 | 150 | \&... 151 | 152 | if (strlcpy(pname, dir, sizeof(pname)) >= sizeof(pname)) 153 | goto toolong; 154 | if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname)) 155 | goto toolong; 156 | .Ed 157 | .Pp 158 | Since it is known how many characters were copied the first time, things 159 | can be sped up a bit by using a copy instead of an append: 160 | .Bd -literal -offset indent 161 | char *dir, *file, pname[MAXPATHLEN]; 162 | size_t n; 163 | 164 | \&... 165 | 166 | n = strlcpy(pname, dir, sizeof(pname)); 167 | if (n >= sizeof(pname)) 168 | goto toolong; 169 | if (strlcpy(pname + n, file, sizeof(pname) - n) >= sizeof(pname) - n) 170 | goto toolong; 171 | .Ed 172 | .Pp 173 | However, one may question the validity of such optimizations, as they 174 | defeat the whole purpose of 175 | .Fn strlcpy 176 | and 177 | .Fn strlcat . 178 | As a matter of fact, the first version of this manual page got it wrong. 179 | .Sh SEE ALSO 180 | .Xr snprintf 3 , 181 | .Xr strncat 3 , 182 | .Xr strncpy 3 183 | .Sh HISTORY 184 | The 185 | .Fn strlcpy 186 | and 187 | .Fn strlcat 188 | functions first appeared in 189 | .Ox 2.4 , 190 | and made their appearance in 191 | .Fx 3.3 . 192 | -------------------------------------------------------------------------------- /src/strlcpy.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: strlcpy.c,v 1.10 2005/08/08 08:05:37 espie Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 1998 Todd C. Miller 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | /* 23 | * Copy src to string dst of size siz. At most siz-1 characters 24 | * will be copied. Always NUL terminates (unless siz == 0). 25 | * Returns strlen(src); if retval >= siz, truncation occurred. 26 | */ 27 | size_t 28 | strlcpy(char *dst, const char *src, size_t siz) 29 | { 30 | char *d = dst; 31 | const char *s = src; 32 | size_t n = siz; 33 | 34 | /* Copy as many bytes as will fit */ 35 | if (n != 0) { 36 | while (--n != 0) { 37 | if ((*d++ = *s++) == '\0') 38 | break; 39 | } 40 | } 41 | 42 | /* Not enough room in dst, add NUL and traverse rest of src */ 43 | if (n == 0) { 44 | if (siz != 0) 45 | *d = '\0'; /* NUL-terminate dst */ 46 | while (*s++) 47 | ; 48 | } 49 | 50 | return(s - src - 1); /* count does not include NUL */ 51 | } 52 | -------------------------------------------------------------------------------- /src/strmode.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1990, 1991, 1993 2 | .\" The Regents of the University of California. All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 4. Neither the name of the University nor the names of its contributors 13 | .\" may be used to endorse or promote products derived from this software 14 | .\" without specific prior written permission. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | .\" SUCH DAMAGE. 27 | .\" 28 | .\" @(#)strmode.3 8.3 (Berkeley) 7/28/94 29 | .\" $FreeBSD: src/lib/libc/string/strmode.3,v 1.9 2003/07/01 15:28:05 maxim Exp $ 30 | .\" 31 | .Dd July 28, 1994 32 | .Dt STRMODE 3 33 | .Os 34 | .Sh NAME 35 | .Nm strmode 36 | .Nd convert inode status information into a symbolic string 37 | .Sh LIBRARY 38 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) 39 | .Lb libbsd 40 | .Sh SYNOPSIS 41 | .In bsd/string.h 42 | .Ft void 43 | .Fn strmode "mode_t mode" "char *bp" 44 | .Sh DESCRIPTION 45 | The 46 | .Fn strmode 47 | function 48 | converts a file 49 | .Fa mode 50 | (the type and permission information associated with an inode, see 51 | .Xr stat 2 ) 52 | into a symbolic string which is stored in the location referenced by 53 | .Fa bp . 54 | This stored string is eleven characters in length plus a trailing 55 | .Dv NUL . 56 | .Pp 57 | The first character is the inode type, and will be one of the following: 58 | .Pp 59 | .Bl -tag -width flag -offset indent -compact 60 | .It \- 61 | regular file 62 | .It b 63 | block special 64 | .It c 65 | character special 66 | .It d 67 | directory 68 | .It l 69 | symbolic link 70 | .It p 71 | fifo 72 | .It s 73 | socket 74 | .It w 75 | whiteout 76 | .It ? 77 | unknown inode type 78 | .El 79 | .Pp 80 | The next nine characters encode three sets of permissions, in three 81 | characters each. 82 | The first three characters are the permissions for the owner of the 83 | file, the second three for the group the file belongs to, and the 84 | third for the ``other'', or default, set of users. 85 | .Pp 86 | Permission checking is done as specifically as possible. 87 | If read permission is denied to the owner of a file in the first set 88 | of permissions, the owner of the file will not be able to read the file. 89 | This is true even if the owner is in the file's group and the group 90 | permissions allow reading or the ``other'' permissions allow reading. 91 | .Pp 92 | If the first character of the three character set is an ``r'', the file is 93 | readable for that set of users; if a dash ``\-'', it is not readable. 94 | .Pp 95 | If the second character of the three character set is a ``w'', the file is 96 | writable for that set of users; if a dash ``\-'', it is not writable. 97 | .Pp 98 | The third character is the first of the following characters that apply: 99 | .Bl -tag -width xxxx 100 | .It S 101 | If the character is part of the owner permissions and the file is not 102 | executable or the directory is not searchable by the owner, and the 103 | set-user-id bit is set. 104 | .It S 105 | If the character is part of the group permissions and the file is not 106 | executable or the directory is not searchable by the group, and the 107 | set-group-id bit is set. 108 | .It T 109 | If the character is part of the other permissions and the file is not 110 | executable or the directory is not searchable by others, and the ``sticky'' 111 | .Pq Dv S_ISVTX 112 | bit is set. 113 | .It s 114 | If the character is part of the owner permissions and the file is 115 | executable or the directory searchable by the owner, and the set-user-id 116 | bit is set. 117 | .It s 118 | If the character is part of the group permissions and the file is 119 | executable or the directory searchable by the group, and the set-group-id 120 | bit is set. 121 | .It t 122 | If the character is part of the other permissions and the file is 123 | executable or the directory searchable by others, and the ``sticky'' 124 | .Pq Dv S_ISVTX 125 | bit is set. 126 | .It x 127 | The file is executable or the directory is searchable. 128 | .It \- 129 | None of the above apply. 130 | .El 131 | .Pp 132 | The last character is a plus sign ``+'' if any there are any alternate 133 | or additional access control methods associated with the inode, otherwise 134 | it will be a space. 135 | .Sh SEE ALSO 136 | .Xr chmod 1 , 137 | .Xr find 1 , 138 | .Xr stat 2 , 139 | .Xr getmode 3 , 140 | .Xr setmode 3 141 | .Sh HISTORY 142 | The 143 | .Fn strmode 144 | function first appeared in 145 | .Bx 4.4 . 146 | -------------------------------------------------------------------------------- /src/strmode.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1990, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 4. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #if defined(LIBC_SCCS) && !defined(lint) 31 | static char sccsid[] = "@(#)strmode.c 8.3 (Berkeley) 8/15/94"; 32 | #endif /* LIBC_SCCS and not lint */ 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | void 40 | strmode(mode, p) 41 | mode_t mode; 42 | char *p; 43 | { 44 | /* print type */ 45 | switch (mode & S_IFMT) { 46 | case S_IFDIR: /* directory */ 47 | *p++ = 'd'; 48 | break; 49 | case S_IFCHR: /* character special */ 50 | *p++ = 'c'; 51 | break; 52 | case S_IFBLK: /* block special */ 53 | *p++ = 'b'; 54 | break; 55 | case S_IFREG: /* regular */ 56 | *p++ = '-'; 57 | break; 58 | case S_IFLNK: /* symbolic link */ 59 | *p++ = 'l'; 60 | break; 61 | case S_IFSOCK: /* socket */ 62 | *p++ = 's'; 63 | break; 64 | #ifdef S_IFIFO 65 | case S_IFIFO: /* fifo */ 66 | *p++ = 'p'; 67 | break; 68 | #endif 69 | #ifdef S_IFWHT 70 | case S_IFWHT: /* whiteout */ 71 | *p++ = 'w'; 72 | break; 73 | #endif 74 | default: /* unknown */ 75 | *p++ = '?'; 76 | break; 77 | } 78 | /* usr */ 79 | if (mode & S_IRUSR) 80 | *p++ = 'r'; 81 | else 82 | *p++ = '-'; 83 | if (mode & S_IWUSR) 84 | *p++ = 'w'; 85 | else 86 | *p++ = '-'; 87 | switch (mode & (S_IXUSR | S_ISUID)) { 88 | case 0: 89 | *p++ = '-'; 90 | break; 91 | case S_IXUSR: 92 | *p++ = 'x'; 93 | break; 94 | case S_ISUID: 95 | *p++ = 'S'; 96 | break; 97 | case S_IXUSR | S_ISUID: 98 | *p++ = 's'; 99 | break; 100 | } 101 | /* group */ 102 | if (mode & S_IRGRP) 103 | *p++ = 'r'; 104 | else 105 | *p++ = '-'; 106 | if (mode & S_IWGRP) 107 | *p++ = 'w'; 108 | else 109 | *p++ = '-'; 110 | switch (mode & (S_IXGRP | S_ISGID)) { 111 | case 0: 112 | *p++ = '-'; 113 | break; 114 | case S_IXGRP: 115 | *p++ = 'x'; 116 | break; 117 | case S_ISGID: 118 | *p++ = 'S'; 119 | break; 120 | case S_IXGRP | S_ISGID: 121 | *p++ = 's'; 122 | break; 123 | } 124 | /* other */ 125 | if (mode & S_IROTH) 126 | *p++ = 'r'; 127 | else 128 | *p++ = '-'; 129 | if (mode & S_IWOTH) 130 | *p++ = 'w'; 131 | else 132 | *p++ = '-'; 133 | switch (mode & (S_IXOTH | S_ISVTX)) { 134 | case 0: 135 | *p++ = '-'; 136 | break; 137 | case S_IXOTH: 138 | *p++ = 'x'; 139 | break; 140 | case S_ISVTX: 141 | *p++ = 'T'; 142 | break; 143 | case S_IXOTH | S_ISVTX: 144 | *p++ = 't'; 145 | break; 146 | } 147 | *p++ = ' '; /* will be a '+' if ACL's implemented */ 148 | *p = '\0'; 149 | } 150 | -------------------------------------------------------------------------------- /src/strtonum.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2004 Ted Unangst 2 | .\" 3 | .\" Permission to use, copy, modify, and distribute this software for any 4 | .\" purpose with or without fee is hereby granted, provided that the above 5 | .\" copyright notice and this permission notice appear in all copies. 6 | .\" 7 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | .\" 15 | .\" $OpenBSD: strtonum.3,v 1.12 2005/10/26 11:37:58 jmc Exp $ 16 | .\" $FreeBSD$ 17 | .\" 18 | .Dd April 29, 2004 19 | .Dt STRTONUM 3 20 | .Os 21 | .Sh NAME 22 | .Nm strtonum 23 | .Nd "reliably convert string value to an integer" 24 | .Sh LIBRARY 25 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) 26 | .Lb libbsd 27 | .Sh SYNOPSIS 28 | .In limits.h 29 | .In bsd/stdlib.h 30 | .Ft long long 31 | .Fo strtonum 32 | .Fa "const char *nptr" 33 | .Fa "long long minval" 34 | .Fa "long long maxval" 35 | .Fa "const char **errstr" 36 | .Fc 37 | .Sh DESCRIPTION 38 | The 39 | .Fn strtonum 40 | function converts the string in 41 | .Fa nptr 42 | to a 43 | .Vt "long long" 44 | value. 45 | The 46 | .Fn strtonum 47 | function was designed to facilitate safe, robust programming 48 | and overcome the shortcomings of the 49 | .Xr atoi 3 50 | and 51 | .Xr strtol 3 52 | family of interfaces. 53 | .Pp 54 | The string may begin with an arbitrary amount of whitespace 55 | (as determined by 56 | .Xr isspace 3 ) 57 | followed by a single optional 58 | .Ql + 59 | or 60 | .Ql - 61 | sign. 62 | .Pp 63 | The remainder of the string is converted to a 64 | .Vt "long long" 65 | value according to base 10. 66 | .Pp 67 | The value obtained is then checked against the provided 68 | .Fa minval 69 | and 70 | .Fa maxval 71 | bounds. 72 | If 73 | .Fa errstr 74 | is non-null, 75 | .Fn strtonum 76 | stores an error string in 77 | .Fa *errstr 78 | indicating the failure. 79 | .Sh RETURN VALUES 80 | The 81 | .Fn strtonum 82 | function returns the result of the conversion, 83 | unless the value would exceed the provided bounds or is invalid. 84 | On error, 0 is returned, 85 | .Va errno 86 | is set, and 87 | .Fa errstr 88 | will point to an error message. 89 | On success, 90 | .Fa *errstr 91 | will be set to 92 | .Dv NULL ; 93 | this fact can be used to differentiate 94 | a successful return of 0 from an error. 95 | .Sh EXAMPLES 96 | Using 97 | .Fn strtonum 98 | correctly is meant to be simpler than the alternative functions. 99 | .Bd -literal -offset indent 100 | int iterations; 101 | const char *errstr; 102 | 103 | iterations = strtonum(optarg, 1, 64, &errstr); 104 | if (errstr) 105 | errx(1, "number of iterations is %s: %s", errstr, optarg); 106 | .Ed 107 | .Pp 108 | The above example will guarantee that the value of iterations is between 109 | 1 and 64 (inclusive). 110 | .Sh ERRORS 111 | .Bl -tag -width Er 112 | .It Bq Er ERANGE 113 | The given string was out of range. 114 | .It Bq Er EINVAL 115 | The given string did not consist solely of digit characters. 116 | .It Bq Er EINVAL 117 | The supplied 118 | .Fa minval 119 | was larger than 120 | .Fa maxval . 121 | .El 122 | .Pp 123 | If an error occurs, 124 | .Fa errstr 125 | will be set to one of the following strings: 126 | .Pp 127 | .Bl -tag -width ".Li too large" -compact 128 | .It Li "too large" 129 | The result was larger than the provided maximum value. 130 | .It Li "too small" 131 | The result was smaller than the provided minimum value. 132 | .It Li invalid 133 | The string did not consist solely of digit characters. 134 | .El 135 | .Sh SEE ALSO 136 | .Xr atof 3 , 137 | .Xr atoi 3 , 138 | .Xr atol 3 , 139 | .Xr atoll 3 , 140 | .Xr sscanf 3 , 141 | .Xr strtod 3 , 142 | .Xr strtol 3 , 143 | .Xr strtoul 3 144 | .Sh STANDARDS 145 | The 146 | .Fn strtonum 147 | function is a 148 | .Bx 149 | extension. 150 | The existing alternatives, such as 151 | .Xr atoi 3 152 | and 153 | .Xr strtol 3 , 154 | are either impossible or difficult to use safely. 155 | .Sh HISTORY 156 | The 157 | .Fn strtonum 158 | function first appeared in 159 | .Ox 3.6 . 160 | -------------------------------------------------------------------------------- /src/strtonum.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2004 Ted Unangst and Todd Miller 3 | * All rights reserved. 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | * 17 | * $OpenBSD: strtonum.c,v 1.6 2004/08/03 19:38:01 millert Exp $ 18 | */ 19 | 20 | #include 21 | __FBSDID("$FreeBSD$"); 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #define INVALID 1 28 | #define TOOSMALL 2 29 | #define TOOLARGE 3 30 | 31 | long long 32 | strtonum(const char *numstr, long long minval, long long maxval, 33 | const char **errstrp) 34 | { 35 | long long ll = 0; 36 | char *ep; 37 | int error = 0; 38 | struct errval { 39 | const char *errstr; 40 | int err; 41 | } ev[4] = { 42 | { NULL, 0 }, 43 | { "invalid", EINVAL }, 44 | { "too small", ERANGE }, 45 | { "too large", ERANGE }, 46 | }; 47 | 48 | ev[0].err = errno; 49 | errno = 0; 50 | if (minval > maxval) 51 | error = INVALID; 52 | else { 53 | ll = strtoll(numstr, &ep, 10); 54 | if (errno == EINVAL || numstr == ep || *ep != '\0') 55 | error = INVALID; 56 | else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval) 57 | error = TOOSMALL; 58 | else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval) 59 | error = TOOLARGE; 60 | } 61 | if (errstrp != NULL) 62 | *errstrp = ev[error].errstr; 63 | errno = ev[error].err; 64 | if (error) 65 | ll = 0; 66 | 67 | return (ll); 68 | } 69 | -------------------------------------------------------------------------------- /src/unvis.3: -------------------------------------------------------------------------------- 1 | .\" $OpenBSD: unvis.3,v 1.15 2005/07/22 03:16:58 jaredy Exp $ 2 | .\" 3 | .\" Copyright (c) 1989, 1991, 1993 4 | .\" The Regents of the University of California. All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions 8 | .\" are met: 9 | .\" 1. Redistributions of source code must retain the above copyright 10 | .\" notice, this list of conditions and the following disclaimer. 11 | .\" 2. Redistributions in binary form must reproduce the above copyright 12 | .\" notice, this list of conditions and the following disclaimer in the 13 | .\" documentation and/or other materials provided with the distribution. 14 | .\" 3. Neither the name of the University nor the names of its contributors 15 | .\" may be used to endorse or promote products derived from this software 16 | .\" without specific prior written permission. 17 | .\" 18 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | .\" SUCH DAMAGE. 29 | .\" 30 | .Dd $Mdocdate: May 31 2007 $ 31 | .Dt UNVIS 3 32 | .Os 33 | .Sh NAME 34 | .Nm unvis , 35 | .Nm strunvis , 36 | .Nm strnunvis 37 | .Nd decode a visual representation of characters 38 | .Sh LIBRARY 39 | .ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd) 40 | .Lb libbsd 41 | .Sh SYNOPSIS 42 | .In bsd/vis.h 43 | .Ft int 44 | .Fn unvis "char *cp" "char c" "int *astate" "int flag" 45 | .Ft int 46 | .Fn strunvis "char *dst" "char *src" 47 | .Ft ssize_t 48 | .Fn strnunvis "char *dst" "char *src" "size_t size" 49 | .Sh DESCRIPTION 50 | The 51 | .Fn unvis , 52 | .Fn strunvis 53 | and 54 | .Fn strnunvis 55 | functions are used to decode a visual representation of characters, 56 | as produced by the 57 | .Xr vis 3 58 | function, back into the original form. 59 | .Fn unvis 60 | is called with successive characters in 61 | .Fa c 62 | until a valid 63 | sequence is recognized, at which time the decoded character is 64 | available at the character pointed to by 65 | .Fa cp . 66 | .Pp 67 | .Fn strunvis 68 | decodes the characters pointed to by 69 | .Fa src 70 | into the buffer pointed to by 71 | .Fa dst . 72 | .Pp 73 | .Fn strnunvis 74 | decodes the characters pointed to by 75 | .Fa src 76 | into the buffer pointed to by 77 | .Fa dst , 78 | writing a maximum of 79 | .Fa size 80 | bytes. 81 | The 82 | .Fn strunvis 83 | function simply copies 84 | .Fa src 85 | to 86 | .Fa dst , 87 | decoding any escape sequences along the way, 88 | and returns the number of characters placed into 89 | .Fa dst , 90 | or \-1 if an 91 | invalid escape sequence was detected. 92 | The size of 93 | .Fa dst 94 | should be 95 | equal to the size of 96 | .Fa src 97 | (that is, no expansion takes place during decoding). 98 | .Fn strunvis 99 | terminates the destination string with a trailing NUL byte; 100 | .Fn strnunvis 101 | does so if 102 | .Fa size 103 | is larger than 0. 104 | .Pp 105 | The 106 | .Fn unvis 107 | function implements a state machine that can be used to decode an arbitrary 108 | stream of bytes. 109 | All state associated with the bytes being decoded is stored outside the 110 | .Fn unvis 111 | function (that is, a pointer to the state is passed in), so 112 | calls decoding different streams can be freely intermixed. 113 | To start decoding a stream of bytes, first initialize an integer 114 | to zero. 115 | Call 116 | .Fn unvis 117 | with each successive byte, along with a pointer 118 | to this integer, and a pointer to a destination character. 119 | .Sh RETURN VALUES 120 | The 121 | .Fn unvis 122 | function has several return codes that must be handled properly. 123 | They are: 124 | .Bl -tag -width UNVIS_VALIDPUSH 125 | .It Li \&0 (zero) 126 | Another character is necessary; nothing has been recognized yet. 127 | .It Dv UNVIS_VALID 128 | A valid character has been recognized and is available at the location 129 | pointed to by 130 | .Fa cp . 131 | .It Dv UNVIS_VALIDPUSH 132 | A valid character has been recognized and is available at the location 133 | pointed to by 134 | .Fa cp ; 135 | however, the character currently passed in should be passed in again. 136 | .It Dv UNVIS_NOCHAR 137 | A valid sequence was detected, but no character was produced. 138 | This return code is necessary to indicate a logical break between characters. 139 | .It Dv UNVIS_SYNBAD 140 | An invalid escape sequence was detected, or the decoder is in an 141 | unknown state. 142 | The decoder is placed into the starting state. 143 | .El 144 | .Pp 145 | When all bytes in the stream have been processed, call 146 | .Fn unvis 147 | one more time with 148 | .Fa flag 149 | set to 150 | .Dv UNVIS_END 151 | to extract any remaining character (the character passed in is ignored). 152 | .Pp 153 | The 154 | .Fn strunvis 155 | function returns the number of bytes written (not counting 156 | the trailing NUL byte) or \-1 if an error occurred. 157 | .Pp 158 | The 159 | .Fn strnunvis 160 | function returns the number of bytes (not counting the trailing NUL byte) 161 | that would be needed to fully convert the input string, or \-1 if an 162 | error occurred. 163 | .Sh EXAMPLES 164 | The following code fragment illustrates a proper use of 165 | .Fn unvis . 166 | .Bd -literal -offset indent 167 | int state = 0; 168 | char out; 169 | 170 | while ((ch = getchar()) != EOF) { 171 | again: 172 | switch(unvis(&out, ch, &state, 0)) { 173 | case 0: 174 | case UNVIS_NOCHAR: 175 | break; 176 | case UNVIS_VALID: 177 | (void) putchar(out); 178 | break; 179 | case UNVIS_VALIDPUSH: 180 | (void) putchar(out); 181 | goto again; 182 | case UNVIS_SYNBAD: 183 | (void)fprintf(stderr, "bad sequence!\en"); 184 | exit(1); 185 | } 186 | } 187 | if (unvis(&out, (char)0, &state, UNVIS_END) == UNVIS_VALID) 188 | (void) putchar(out); 189 | .Ed 190 | .Sh SEE ALSO 191 | .Xr unvis 1 , 192 | .Xr vis 1 , 193 | .Xr vis 3 194 | .Sh HISTORY 195 | The 196 | .Fn unvis 197 | function first appeared in 198 | .Bx 4.4 . 199 | --------------------------------------------------------------------------------