AgeCommit message (Collapse)AuthorFilesLines
2019-08-08Release libbsd 0.10.0HEAD0.10.0masterGuillem Jover1-2/+2
2019-08-08err: Add err(), warn(), errx() and warnx() familiy of functionsGuillem Jover3-0/+113
Some systems such as Windows or musl-libc based ones do not have these BSD extensions. In addition libbsd itself is making use of the warnx() functions, so we better provide these interfaces in case they are missing.
2019-08-08err: Rewrite warnc() and errc() family functions to be standaloneGuillem Jover3-20/+28
Do not depend on the system vwarn() and verr() functions to implement the *c() variants, as the system might actually lack any of the <err.h> BSD extensions.
2019-08-08err: Mark error functions as non-returning with __dead2Guillem Jover1-2/+3
2019-08-08Add e2k support for nlist()Michael Shigorin1-0/+6
This is a Russian 64-bit LE VLIW architecture named Elbrus (formerly Elbrus 2000). [ - Place the entry in alphabetical order. ] Signed-off-by: Guillem Jover <>
2019-08-08Add AArch64 ILP32 support to nlist()Frank Schaefer1-0/+4
Closes: !7 Signed-off-by: Guillem Jover <>
2019-08-08Add ARC support to nlist()Rosen Penev1-0/+6
Closes: !6 Signed-off-by: Rosen Penev <> Signed-off-by: Guillem Jover <>
2019-08-08Add a comment to note the ELF entries are sorted alphabeticallyGuillem Jover1-0/+2
This should help people wanting to add new entries.
2019-08-08Re-allow direct use of nlist.n_name in <nlist.h>James Clarke2-3/+8
Commit e8d340de ("Remove a.out support from nlist()") introduced a copy of the definition of nlist from a.out.h. However, as well as having n_name inside n_un, on the various BSDs n_name could also be accessed as a direct member of nlist, and this is made use of by FreeBSD's usr.bin/netstat/main.c. Thus we should also add the same enclosing anonymous union. [ - Add a minimal unit test. ] Closes: !4 Signed-off-by: Guillem Jover <>
2019-08-08nlist: Fix out-of-bounds read on strtabGuillem Jover1-2/+4
When doing a string comparison for a symbol name from the string table, we should make sure we do a bounded comparison, otherwise a non-NUL terminated string might make the code read out-of-bounds. Warned-by: coverity
2019-08-08nlist: Fix unbounded malloc() callsGuillem Jover1-2/+2
There are a couple of malloc() calls with unbounded size arguments, coming from the parsed file. We need to make sure the size is not larger than the file being parsed, otherwise we might end up with out of memory conditions. Reported-by: Daniel Hodson <> Signed-off-by: Guillem Jover <>
2019-08-08nlist: Fix pread() return value checkGuillem Jover1-2/+2
We should check for partial reads, and not continue in those cases, as we are not retrying them, otherwise we might end up operating on uninitialized data. Reported-by: Daniel Hodson <> Based-on-patch-by: Daniel Hodson <> Signed-off-by: Guillem Jover <>
2019-08-08nlist: Check whether sh_link is within boundsGuillem Jover1-0/+3
The sh_link members should be >= e_shnum, otherwise we might do out of bounds read accesses on the shdr array. Reported-by: Daniel Hodson <> Based-on-patch-by: Daniel Hodson <> Signed-off-by: Guillem Jover <>
2019-08-08nlist: Check that e_shnum and e_shentsize are within boundsGuillem Jover1-0/+6
The e_shnum must not be 0, otherwise we will do a zero sized allocation and further processing of the executable will lead to out of bounds read/write accesses. The e_shentsize must be equal to sizeof(Elf_Shdr), otherwise we will perform out of bounds read accesses on the shdr array. Reported-by: Daniel Hodson <> Based-on-patch-by: Daniel Hodson <> Signed-off-by: Guillem Jover <>
2019-08-08nlist: Check whether the nl argument is not NULLGuillem Jover2-1/+8
This prevents programming errors. Reported-by: Daniel Hodson <> Based-on-patch-by: Daniel Hodson <> Signed-off-by: Guillem Jover <>
2019-08-08man: Add man page sections to function referencesGuillem Jover1-16/+16
Signed-off-by: Guillem Jover <>
2019-08-08man: Fix typoSebastian1-1/+1
Closes: !5 Signed-off-by: Guillem Jover <>
2019-08-08man: Fix typosGuillem Jover1-2/+2
Signed-off-by: Guillem Jover <>
2019-08-08man: Replace references to a.out(5) with elf(5)Guillem Jover2-3/+2
The a.out(5) support in nlist(3) got removed some time ago, and there is now only elf(5) support. Signed-off-by: Guillem Jover <>
2019-08-08man: Define doc-operating-system-NetBSD string variablesGuillem Jover4-0/+4
This way we do not depend on the installed groff being new enough. Signed-off-by: Guillem Jover <>
2019-08-08man: Use major.minor version for .Nx macrosGuillem Jover3-3/+3
The macro only recognizes this version form, and not just major alone. Signed-off-by: Guillem Jover <>
2019-08-08man: Add doc-str-Lb-libbsd aliases for str-Lb-libbsdGuillem Jover38-0/+38
groff(1) has changed the internal layout for the .Lb doc strings, but to preserve backwards compatibility we cannot simply rename them, we need to create new aliases so that these will work with old and new macros. Signed-off-by: Guillem Jover <>
2019-08-08Update TODOGuillem Jover1-0/+1
Signed-off-by: Guillem Jover <>
2019-08-08Provide a <sys/param.h> with MIN() and MAX()Aaron Dierking3-0/+52
Windows doesn't provide <sys/param.h>. Several libbsd sources require it for MIN(), and these are useful non-system-specific macros anyway. Signed-off-by: Guillem Jover <>
2019-08-08build: Disable CRT warnings on WindowsAaron Dierking1-0/+7
These warnings are not helpful for libbsd. [ - Rename WINDOWS conditional to OS_WINDOWS. - Add a nil terminator to the AM_CPPFLAGS. ] Signed-off-by: Guillem Jover <>
2019-08-08build: Detect Windows/MinGW at configure timeAaron Dierking1-0/+5
Extend the host OS checks to define an OS_WINDOWS automake conditional if the host is MinGW-like. This will be useful for future Windows-specific build tweaks. [ - Rename WINDOWS conditional to OS_WINDOWS. ] Signed-off-by: Guillem Jover <>
2019-08-08build: Support platforms without symbol versioningGuillem Jover1-0/+7
The .symver directive is ELF-specific. On non-ELF platforms, work around this with __attribute__((__alias__)) for the default symbol, and ignore the variant versioned symbols. Based-on-patch-by: Aaron Dierking <> Signed-off-by: Guillem Jover <>
2019-08-08build: Abstract symbol versioning via new libbsd_symver_* macrosGuillem Jover4-6/+18
This makes it more obvious what they are doing. It will make it easier to make these directives more portable, as they are really ELF specific.
2019-08-08build: Use __register_atfork() only if really availableGuillem Jover4-3/+22
This is a glibc-specific symbol that has no public declaration. But is being used by the OpenBSD and this implementation as a hack to avoid having to link against the pthread library. This interface is at least included in LSB 5.0 [L], and using pthread_atfork() is otherwise problematic anyway [P]. [L] <> [P] <> One problem is that we were using it whenever __GLIBC__ is defined, which is supposed to be defined only on an actual glibc, but uClibc defines that macro, but it does not provide the symbol on its noMMU variant. We add a new configure check that will try to link a program that uses that symbol to make sure it is present. Closes: !2 Reported-by: Fabrice Fontaine <>
2019-08-07build: Fix check for clock_gettime() within librtGuillem Jover1-1/+5
The check was always setting the libraries to link to include -lrt, as the success case includes the builtin one. Handle the various values.
2018-06-18Correct Clang feature detectionAaron Dierking2-13/+20
Clang's __GNUC__ and __GNUC_MINOR__ definitions are not reliable and may not be defined at all when targeting the MSVC ABI. Use feature-checking macros when possible or check for __clang__. [ Update for __ protected keyword change. ] Signed-off-by: Guillem Jover <>
2018-06-18Protect C language extensions with two leading and trailing underscoresGuillem Jover6-12/+15
This should make their usage safer against user macros.
2018-06-18Guard non-portable forwarded includesAaron Dierking5-11/+30
These headers are not available on Windows. <bsd/sys/cdefs.h> ensures that __has_include() and __has_include_next() are defined. Signed-off-by: Guillem Jover <>
2018-06-18Windows support for inet_net_pton()Aaron Dierking1-0/+5
Signed-off-by: Guillem Jover <>
2018-06-18Windows support for HASHFileChunk()Aaron Dierking1-0/+3
<io.h> provides the necessary file I/O functions. [ Move include before <hashinc>. ] Signed-off-by: Guillem Jover <>
2018-06-18Don't require <grp.h>Aaron Dierking2-1/+3
This is only used in the overlay test and Windows does not provide it. Signed-off-by: Guillem Jover <>
2018-06-18Only define S_ISTXT if S_ISVTX is definedAaron Dierking1-1/+1
Windows doesn't provide S_ISVTX. Prefer not defining it rather than defining it to something invalid. Signed-off-by: Guillem Jover <>
2018-06-18Use CHAR_BIT instead of NBBY in strnvis()Aaron Dierking1-3/+2
<sys/param.h> is not available on Windows. Signed-off-by: Guillem Jover <>
2018-06-18Replace reintroduced legacy u_* type usage in strnvis() and strnunvis()Aaron Dierking2-7/+11
This fixes a regression caused by 2d7de18. These types are not available on all systems. Fixes: commit 2d7de186e9cb19a756c0630ee85cb3f2d29b3484 Signed-off-by: Guillem Jover <>
2018-06-17Remove dead code in visGuillem Jover1-1/+1
The loop only executes while len > 0, and the trinary operator in the function argument is checking against len >= 1 which will always be true. Warned-by: coverity
2018-06-17Fix vis family of functions to not leakGuillem Jover1-14/+25
The code uses an internal helper function to avoid code repetition. But to get there, the function takes a pointer to a pointer, so that the few functions that require returning an allocated buffer can get hold of it this way. The problem is that the user might pass a NULL pointer and trigger an internal allocation even if the functions are not expected to do so. Add a new internal helper for non-allocations, that will assert that condition, and make any other function that requires this behavior call this one instead. Warned-by: coverity
2018-06-17flopen: Add missing <fcntl.h> includeBaruch Siach1-0/+1
Commit 993828d84ee (Add flopenat() function from FreeBSD) dropped the fcntl.h header. This breaks the build with musl libc: flopen.c: In function ‘vflopenat’: flopen.c:60:14: error: ‘O_CREAT’ undeclared (first use in this function) if (flags & O_CREAT) { ^~~~~~~ Restore the fcntl.h header include to fix the build. Fixes: commit 993828d84eed0468c6c15b2818e534e6b134b8e4 Submitted-also-by: parazyd <> Signed-off-by: Baruch Siach <> Signed-off-by: Guillem Jover <>
2018-05-31build: Simplify gitlab CI configurationGuillem Jover1-19/+6
Merge all stages so that we do not need to pass artifacts around. Quiesce «apt install».
2018-05-31build: Install git in gitlab CI configurationGuillem Jover1-1/+1
2018-05-31build: Fix gitlab CI configurationGuillem Jover1-2/+2
Run «apt install» in non-interactive mode, and do not install Recommends. Replace build-essential, which is rather fat, with gcc and make. Execute autogen instead of autoreconf directly.
2018-05-31build: Add a gitlab CI configuration fileGuillem Jover1-0/+22
2018-05-23man: Fix comma spliceJakub Wilk1-1/+1
Signed-off-by: Guillem Jover <>
2018-05-23man: Fix name of the function injected by libbsd-ctorJakub Wilk1-1/+1
Signed-off-by: Guillem Jover <>
2018-05-22Release libbsd Jover1-1/+1
2018-05-22Fix strnvis() and strnunvis() NetBSD ABI breakGuillem Jover8-4/+189
The NetBSD implementations have different prototypes to the ones coming from OpenBSD, which will break builds, and have caused segfaults at run-time. We provide now both interfaces with different prototypes as different version nodes allow selecting them at compile-time, defaulting for now to the OpenBSD one to avoid build-time breakage, while emitting a compile-time warning. Later on, in 0.10.0, we will be switching the compile-time default to the NetBSD version. Ref: Fixes: