mirror of
https://gitlab.freedesktop.org/libbsd/libbsd.git
synced 2025-10-20 14:02:43 +02:00
Compare commits
48 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a11c98a6b5 | ||
![]() |
5745ca0362 | ||
![]() |
9628798d7d | ||
![]() |
f34a5f71d9 | ||
![]() |
72c68868c8 | ||
![]() |
a4323f2b16 | ||
![]() |
4997efa59a | ||
![]() |
96202c6c14 | ||
![]() |
61d378f5e9 | ||
![]() |
9d917aad37 | ||
![]() |
18662cadfc | ||
![]() |
ce53f7c25f | ||
![]() |
24d1f4dd34 | ||
![]() |
e9529d9b4a | ||
![]() |
3aaedb1208 | ||
![]() |
2c754f435b | ||
![]() |
ee4d24970a | ||
![]() |
8d2afa3a9f | ||
![]() |
e9f6faf3aa | ||
![]() |
99320b9168 | ||
![]() |
71c710e9a8 | ||
![]() |
21f4052c5b | ||
![]() |
1899e2c5ab | ||
![]() |
4803340802 | ||
![]() |
f99b8ea527 | ||
![]() |
4bed48398f | ||
![]() |
2e071c3cc1 | ||
![]() |
890699a78b | ||
![]() |
b0ebb0d4c2 | ||
![]() |
73aea4f808 | ||
![]() |
7cfa2d4530 | ||
![]() |
574c7a1365 | ||
![]() |
c2d9d84088 | ||
![]() |
2ebe6d5a02 | ||
![]() |
aeea1f4083 | ||
![]() |
0500a1bd08 | ||
![]() |
3d9c6c08ed | ||
![]() |
b9dee9f69a | ||
![]() |
81c3c3e405 | ||
![]() |
5e0998fa4f | ||
![]() |
8e2d55047c | ||
![]() |
13c32916b4 | ||
![]() |
8e834cd068 | ||
![]() |
e354f9b1d0 | ||
![]() |
4c5e9b478e | ||
![]() |
005b509061 | ||
![]() |
a8531ad051 | ||
![]() |
c4b0fd2c9f |
9
.gitlab-ci.yml
Normal file
9
.gitlab-ci.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
image: debian:stretch
|
||||
|
||||
test:
|
||||
before_script:
|
||||
- apt update -qq
|
||||
- apt install -qq -y --no-install-recommends git gcc make autoconf automake libtool
|
||||
script:
|
||||
- ./autogen && ./configure
|
||||
- make check
|
4
COPYING
4
COPYING
@@ -74,16 +74,18 @@ License: BSD-4-clause-Christopher-G-Demetriou
|
||||
Files:
|
||||
include/bsd/err.h
|
||||
include/bsd/stdlib.h
|
||||
include/bsd/sys/param.h
|
||||
include/bsd/unistd.h
|
||||
src/bsd_getopt.c
|
||||
src/err.c
|
||||
src/fgetln.c
|
||||
src/progname.c
|
||||
Copyright:
|
||||
Copyright © 2005, 2008-2012 Guillem Jover <guillem@hadrons.org>
|
||||
Copyright © 2005, 2008-2012, 2019 Guillem Jover <guillem@hadrons.org>
|
||||
Copyright © 2005 Hector Garcia Alvarez
|
||||
Copyright © 2005 Aurelien Jarno
|
||||
Copyright © 2006 Robert Millan
|
||||
Copyright © 2018 Facebook, Inc.
|
||||
License: BSD-3-clause
|
||||
|
||||
Files:
|
||||
|
2
TODO
2
TODO
@@ -1,3 +1,4 @@
|
||||
* Migrate portable functions from GNU/kFreeBSD's libfreebsd.
|
||||
* Add more functions used by ported packages (check openssh).
|
||||
* Add more unit tests.
|
||||
* Add missing man pages.
|
||||
@@ -5,7 +6,6 @@
|
||||
- timeconv?
|
||||
* Add a README.import file.
|
||||
* Update man pages:
|
||||
- Fix references to a.out(5) and inline needed struct definitions.
|
||||
- Document when each interface was added on every BSD, and libbsd.
|
||||
* Handle LFS properly. By default the library emits LFS objects, but might
|
||||
be used by non-LFS objects. We should either provide foo and foo64
|
||||
|
36
configure.ac
36
configure.ac
@@ -12,8 +12,8 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
|
||||
[AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
|
||||
|
||||
LIBBSD_ABI_MAJOR=0
|
||||
LIBBSD_ABI_MINOR=9
|
||||
LIBBSD_ABI_PATCH=1
|
||||
LIBBSD_ABI_MINOR=10
|
||||
LIBBSD_ABI_PATCH=0
|
||||
|
||||
LIBBSD_ABI="$LIBBSD_ABI_MAJOR:$LIBBSD_ABI_MINOR:$LIBBSD_ABI_PATCH"
|
||||
AC_SUBST([LIBBSD_ABI])
|
||||
@@ -44,11 +44,16 @@ AC_SUBST([TESTU01_LIBS])
|
||||
AM_CONDITIONAL([HAVE_LIBTESTU01],
|
||||
[test "x$ac_cv_lib_testu01_unif01_CreateExternGenBits" = "xyes"])
|
||||
|
||||
is_windows=no
|
||||
AS_CASE([$host_os],
|
||||
[*-gnu*], [
|
||||
# In old glibc versions (< 2.17) clock_gettime() is in librt.
|
||||
saved_LIBS="$LIBS"
|
||||
AC_SEARCH_LIBS([clock_gettime], [rt], [CLOCK_GETTIME_LIBS="-lrt"])
|
||||
AC_SEARCH_LIBS([clock_gettime], [rt], [
|
||||
AS_IF([test "x$ac_cv_search_clock_gettime" != "xnone required"], [
|
||||
CLOCK_GETTIME_LIBS="$ac_cv_search_clock_gettime"
|
||||
])
|
||||
])
|
||||
AC_SUBST([CLOCK_GETTIME_LIBS])
|
||||
LIBS="$saved_LIBS"
|
||||
],
|
||||
@@ -56,10 +61,14 @@ AS_CASE([$host_os],
|
||||
# Upstream refuses to define this, we will do it ourselves then.
|
||||
AC_DEFINE([__MUSL__], [1], [Define to 1 if we are building for musl])
|
||||
],
|
||||
[mingw*], [
|
||||
is_windows=yes
|
||||
],
|
||||
)
|
||||
AM_CONDITIONAL([OS_WINDOWS], [test "x$is_windows" = "xyes"])
|
||||
|
||||
# Checks for header files.
|
||||
AC_CHECK_HEADERS([sys/ndir.h sys/dir.h ndir.h dirent.h])
|
||||
AC_CHECK_HEADERS([sys/ndir.h sys/dir.h ndir.h dirent.h grp.h])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_C_INLINE
|
||||
@@ -87,7 +96,7 @@ AC_CACHE_CHECK(
|
||||
[[
|
||||
static int rc = 1;
|
||||
static void init(int argc) { if (argc == 1) rc = 0; }
|
||||
void (*init_func)(int argc) __attribute__((section(".init_array"))) = init;
|
||||
void (*init_func)(int argc) __attribute__((__section__(".init_array"))) = init;
|
||||
int main() { return rc; }
|
||||
]]
|
||||
)],
|
||||
@@ -141,6 +150,23 @@ AC_LINK_IFELSE(
|
||||
AC_MSG_RESULT([yes])],
|
||||
[AC_MSG_RESULT([no])])
|
||||
|
||||
AC_MSG_CHECKING([for __register_atfork])
|
||||
AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM([[
|
||||
#include <stddef.h>
|
||||
extern void *__dso_handle;
|
||||
extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
|
||||
]], [[
|
||||
__register_atfork(NULL, NULL, NULL, __dso_handle);
|
||||
]])],
|
||||
[AC_DEFINE([HAVE___REGISTER_ATFORK], [1],
|
||||
[Define to 1 if you have __register_atfork])
|
||||
AC_MSG_RESULT([yes])],
|
||||
[ARC4RANDOM_ATFORK_LIBS="-pthread"
|
||||
AC_SUBST([ARC4RANDOM_ATFORK_LIBS])
|
||||
AC_MSG_RESULT([no])
|
||||
])
|
||||
|
||||
AC_CHECK_FUNCS([clearenv dirfd fopencookie __fpurge \
|
||||
getauxval getentropy getexecname getline \
|
||||
pstat_getproc sysconf])
|
||||
|
@@ -4,6 +4,7 @@ nobase_include_HEADERS = \
|
||||
bsd/sys/bitstring.h \
|
||||
bsd/sys/cdefs.h \
|
||||
bsd/sys/endian.h \
|
||||
bsd/sys/param.h \
|
||||
bsd/sys/poll.h \
|
||||
bsd/sys/queue.h \
|
||||
bsd/sys/time.h \
|
||||
|
@@ -26,31 +26,56 @@
|
||||
*/
|
||||
|
||||
#ifdef LIBBSD_OVERLAY
|
||||
#include <sys/cdefs.h>
|
||||
#if __has_include_next(<err.h>)
|
||||
#include_next <err.h>
|
||||
#else
|
||||
#define LIBBSD_NEED_ERR_H_FUNCS
|
||||
#endif
|
||||
#else
|
||||
#include <bsd/sys/cdefs.h>
|
||||
#if __has_include(<err.h>)
|
||||
#include <err.h>
|
||||
#else
|
||||
#define LIBBSD_NEED_ERR_H_FUNCS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef LIBBSD_ERR_H
|
||||
#define LIBBSD_ERR_H
|
||||
|
||||
#ifdef LIBBSD_OVERLAY
|
||||
#include <sys/cdefs.h>
|
||||
#else
|
||||
#include <bsd/sys/cdefs.h>
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
void warnc(int code, const char *format, ...)
|
||||
__printflike(2, 3);
|
||||
void vwarnc(int code, const char *format, va_list ap)
|
||||
__printflike(2, 0);
|
||||
void errc(int status, int code, const char *format, ...)
|
||||
__printflike(3, 4);
|
||||
void warnc(int code, const char *format, ...)
|
||||
__printflike(2, 3);
|
||||
|
||||
void verrc(int status, int code, const char *format, va_list ap)
|
||||
__printflike(3, 0);
|
||||
__printflike(3, 0) __dead2;
|
||||
void errc(int status, int code, const char *format, ...)
|
||||
__printflike(3, 4) __dead2;
|
||||
|
||||
#ifdef LIBBSD_NEED_ERR_H_FUNCS
|
||||
void vwarn(const char *format, va_list ap)
|
||||
__printflike(1, 0);
|
||||
void vwarnx(const char *format, va_list ap)
|
||||
__printflike(1, 0);
|
||||
void warn(const char *format, ...)
|
||||
__printflike(1, 2);
|
||||
void warnx(const char *format, ...)
|
||||
__printflike(1, 2);
|
||||
|
||||
void verr(int status, const char *format, va_list ap)
|
||||
__printflike(2, 0) __dead2;
|
||||
void verrx(int status, const char *format, va_list ap)
|
||||
__printflike(2, 0) __dead2;
|
||||
void err(int status, const char *format, ...)
|
||||
__printflike(2, 3) __dead2;
|
||||
void errx(int status, const char *format, ...)
|
||||
__printflike(2, 3) __dead2;
|
||||
#endif
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
|
@@ -25,9 +25,15 @@
|
||||
*/
|
||||
|
||||
#ifdef LIBBSD_OVERLAY
|
||||
#include <sys/cdefs.h>
|
||||
#if __has_include_next(<getopt.h>)
|
||||
#include_next <getopt.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <bsd/sys/cdefs.h>
|
||||
#if __has_include(<getopt.h>)
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
#include <bsd/unistd.h>
|
||||
#endif
|
||||
|
@@ -36,9 +36,12 @@
|
||||
struct nlist {
|
||||
union {
|
||||
char *n_name;
|
||||
struct n_list *n_next;
|
||||
long n_strx;
|
||||
} n_un;
|
||||
union {
|
||||
char *n_name;
|
||||
struct n_list *n_next;
|
||||
long n_strx;
|
||||
} n_un;
|
||||
};
|
||||
unsigned char n_type;
|
||||
char n_other;
|
||||
short n_desc;
|
||||
|
@@ -30,6 +30,13 @@
|
||||
#ifndef __has_include_next
|
||||
#define __has_include_next(x) 1
|
||||
#endif
|
||||
#ifndef __has_attribute
|
||||
#define __has_attribute(x) 0
|
||||
#endif
|
||||
/* Clang expands this to 1 if an identifier is *not* reserved. */
|
||||
#ifndef __is_identifier
|
||||
#define __is_identifier(x) 1
|
||||
#endif
|
||||
|
||||
#ifdef LIBBSD_OVERLAY
|
||||
/*
|
||||
@@ -85,22 +92,22 @@
|
||||
#define LIBBSD_GCC_VERSION 0
|
||||
#endif
|
||||
|
||||
#if LIBBSD_GCC_VERSION >= 0x0405
|
||||
#define LIBBSD_DEPRECATED(x) __attribute__((deprecated(x)))
|
||||
#if LIBBSD_GCC_VERSION >= 0x0405 || __has_attribute(__deprecated__)
|
||||
#define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__(x)))
|
||||
#elif LIBBSD_GCC_VERSION >= 0x0301
|
||||
#define LIBBSD_DEPRECATED(x) __attribute__((deprecated))
|
||||
#define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__))
|
||||
#else
|
||||
#define LIBBSD_DEPRECATED(x)
|
||||
#endif
|
||||
|
||||
#if LIBBSD_GCC_VERSION >= 0x0200
|
||||
#if LIBBSD_GCC_VERSION >= 0x0200 || defined(__clang__)
|
||||
#define LIBBSD_REDIRECT(name, proto, alias) name proto __asm__(LIBBSD_ASMNAME(#alias))
|
||||
#endif
|
||||
#define LIBBSD_ASMNAME(cname) LIBBSD_ASMNAME_PREFIX(__USER_LABEL_PREFIX__, cname)
|
||||
#define LIBBSD_ASMNAME_PREFIX(prefix, cname) LIBBSD_STRING(prefix) cname
|
||||
|
||||
#ifndef __dead2
|
||||
# if LIBBSD_GCC_VERSION >= 0x0207
|
||||
# if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__noreturn__)
|
||||
# define __dead2 __attribute__((__noreturn__))
|
||||
# else
|
||||
# define __dead2
|
||||
@@ -108,7 +115,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef __pure2
|
||||
# if LIBBSD_GCC_VERSION >= 0x0207
|
||||
# if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__const__)
|
||||
# define __pure2 __attribute__((__const__))
|
||||
# else
|
||||
# define __pure2
|
||||
@@ -116,7 +123,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef __packed
|
||||
# if LIBBSD_GCC_VERSION >= 0x0207
|
||||
# if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__packed__)
|
||||
# define __packed __attribute__((__packed__))
|
||||
# else
|
||||
# define __packed
|
||||
@@ -124,7 +131,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef __aligned
|
||||
# if LIBBSD_GCC_VERSION >= 0x0207
|
||||
# if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__aligned__)
|
||||
# define __aligned(x) __attribute__((__aligned__(x)))
|
||||
# else
|
||||
# define __aligned(x)
|
||||
@@ -137,7 +144,7 @@
|
||||
#if 0
|
||||
#ifndef __unused
|
||||
# if LIBBSD_GCC_VERSION >= 0x0300
|
||||
# define __unused __attribute__((unused))
|
||||
# define __unused __attribute__((__unused__))
|
||||
# else
|
||||
# define __unused
|
||||
# endif
|
||||
@@ -145,15 +152,15 @@
|
||||
#endif
|
||||
|
||||
#ifndef __printflike
|
||||
# if LIBBSD_GCC_VERSION >= 0x0300
|
||||
# define __printflike(x, y) __attribute((format(printf, (x), (y))))
|
||||
# if LIBBSD_GCC_VERSION >= 0x0300 || __has_attribute(__format__)
|
||||
# define __printflike(x, y) __attribute((__format__(__printf__, (x), (y))))
|
||||
# else
|
||||
# define __printflike(x, y)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef __nonnull
|
||||
# if LIBBSD_GCC_VERSION >= 0x0302
|
||||
# if LIBBSD_GCC_VERSION >= 0x0302 || __has_attribute(__nonnull__)
|
||||
# define __nonnull(x) __attribute__((__nonnull__(x)))
|
||||
# else
|
||||
# define __nonnull(x)
|
||||
@@ -175,7 +182,7 @@
|
||||
* require it.
|
||||
*/
|
||||
#ifndef __offsetof
|
||||
# if LIBBSD_GCC_VERSION >= 0x0401
|
||||
# if LIBBSD_GCC_VERSION >= 0x0401 || !__is_identifier(__builtin_offsetof)
|
||||
# define __offsetof(type, field) __builtin_offsetof(type, field)
|
||||
# else
|
||||
# ifndef __cplusplus
|
||||
@@ -200,9 +207,9 @@
|
||||
* compatible with member m.
|
||||
*/
|
||||
#ifndef __containerof
|
||||
# if LIBBSD_GCC_VERSION >= 0x0301
|
||||
# if LIBBSD_GCC_VERSION >= 0x0301 || !__is_identifier(__typeof__)
|
||||
# define __containerof(x, s, m) ({ \
|
||||
const volatile __typeof(((s *)0)->m) *__x = (x); \
|
||||
const volatile __typeof__(((s *)0)->m) *__x = (x); \
|
||||
__DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m)); \
|
||||
})
|
||||
# else
|
||||
|
@@ -27,10 +27,16 @@
|
||||
*/
|
||||
|
||||
#ifdef LIBBSD_OVERLAY
|
||||
#include <sys/cdefs.h>
|
||||
#if __has_include_next(<endian.h>)
|
||||
#include_next <endian.h>
|
||||
#endif
|
||||
#else
|
||||
#include <bsd/sys/cdefs.h>
|
||||
#if __has_include(<endian.h>)
|
||||
#include <endian.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef LIBBSD_SYS_ENDIAN_H
|
||||
#define LIBBSD_SYS_ENDIAN_H
|
||||
|
49
include/bsd/sys/param.h
Normal file
49
include/bsd/sys/param.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright © 2018 Facebook, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef LIBBSD_OVERLAY
|
||||
#include <sys/cdefs.h>
|
||||
#if __has_include_next(<sys/param.h>)
|
||||
#include_next <sys/param.h>
|
||||
#endif
|
||||
#else
|
||||
#include <bsd/sys/cdefs.h>
|
||||
#if __has_include(<sys/param.h>)
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef LIBBSD_SYS_PARAM_H
|
||||
#define LIBBSD_SYS_PARAM_H
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||
#endif
|
||||
#ifndef MAX
|
||||
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
#endif
|
@@ -33,10 +33,16 @@
|
||||
*/
|
||||
|
||||
#ifdef LIBBSD_OVERLAY
|
||||
#include <sys/cdefs.h>
|
||||
#if __has_include_next(<sys/time.h>)
|
||||
#include_next <sys/time.h>
|
||||
#endif
|
||||
#else
|
||||
#include <bsd/sys/cdefs.h>
|
||||
#if __has_include(<sys/time.h>)
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef LIBBSD_SYS_TIME_H
|
||||
#define LIBBSD_SYS_TIME_H
|
||||
|
@@ -26,22 +26,23 @@
|
||||
*/
|
||||
|
||||
#ifdef LIBBSD_OVERLAY
|
||||
#include <sys/cdefs.h>
|
||||
#if __has_include_next(<unistd.h>)
|
||||
#include_next <unistd.h>
|
||||
#endif
|
||||
#else
|
||||
#include <bsd/sys/cdefs.h>
|
||||
#if __has_include(<unistd.h>)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef LIBBSD_UNISTD_H
|
||||
#define LIBBSD_UNISTD_H
|
||||
|
||||
#ifdef LIBBSD_OVERLAY
|
||||
#include <sys/cdefs.h>
|
||||
#else
|
||||
#include <bsd/sys/cdefs.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifndef S_ISTXT
|
||||
#if !defined(S_ISTXT) && defined(S_ISVTX)
|
||||
#define S_ISTXT S_ISVTX
|
||||
#endif
|
||||
|
||||
|
@@ -42,6 +42,7 @@
|
||||
.Nd arc4 random number generator
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In stdlib.h
|
||||
|
@@ -33,6 +33,7 @@
|
||||
.Nd delete open file descriptors
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In unistd.h
|
||||
|
@@ -38,6 +38,7 @@
|
||||
.Nd formatted error messages
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In err.h
|
||||
@@ -144,6 +145,7 @@ if ((fd = open(block_device, O_RDONLY, 0)) == -1)
|
||||
.Xr printf 3 ,
|
||||
.Xr strerror 3
|
||||
.Sh HISTORY
|
||||
.ds doc-operating-system-NetBSD-7.0 7.0
|
||||
The functions
|
||||
.Fn errc ,
|
||||
.Fn verrc ,
|
||||
|
@@ -33,6 +33,7 @@
|
||||
.Nd format a number from human readable form
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In libutil.h
|
||||
|
@@ -37,6 +37,7 @@
|
||||
.Nd write zeroes to a byte string
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
|
@@ -36,6 +36,7 @@
|
||||
.Nd get a line from a stream
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In stdio.h
|
||||
|
@@ -36,6 +36,7 @@
|
||||
.Nd get a line of wide characters from a stream
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In stdio.h
|
||||
|
@@ -34,6 +34,7 @@
|
||||
.Nd "Reliably open and lock a file"
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In sys/fcntl.h
|
||||
|
@@ -34,6 +34,7 @@
|
||||
.Nd sanitizes user-supplied printf(3)-style format string
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In stdio.h
|
||||
|
@@ -30,6 +30,7 @@
|
||||
.Nd return the next logical line from a stream
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In stdio.h
|
||||
|
@@ -39,6 +39,7 @@
|
||||
.Nd flush a stream
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In stdio.h
|
||||
|
@@ -40,6 +40,7 @@
|
||||
.Nd open a stream
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In stdio.h
|
||||
|
@@ -36,6 +36,7 @@
|
||||
.Nd get preferred block size
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In stdlib.h
|
||||
|
@@ -33,6 +33,7 @@
|
||||
.Nd get the effective credentials of a UNIX-domain peer
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In sys/types.h
|
||||
|
@@ -40,6 +40,7 @@
|
||||
.Nd get or set the program name
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In stdlib.h
|
||||
|
@@ -40,6 +40,7 @@
|
||||
.Nd sort functions
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In stdlib.h
|
||||
|
@@ -36,6 +36,7 @@
|
||||
.Nd format a number into a human readable form and viceversa
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In stdlib.h
|
||||
|
38
man/libbsd.7
38
man/libbsd.7
@@ -1,6 +1,6 @@
|
||||
.\" libbsd man page
|
||||
.\"
|
||||
.\" Copyright © 2017-2018 Gullem Jover <guillem@hadrons.org>
|
||||
.\" Copyright © 2017-2018 Guillem Jover <guillem@hadrons.org>
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
@@ -24,7 +24,7 @@
|
||||
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd May 21 2018
|
||||
.Dd May 21, 2018
|
||||
.Dt LIBBSD 7
|
||||
.Os
|
||||
.Sh NAME
|
||||
@@ -33,7 +33,7 @@
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm libbsd
|
||||
library provides a set if compatibility macros and functions commonly found
|
||||
library provides a set of compatibility macros and functions commonly found
|
||||
on BSD-based systems.
|
||||
Its purpose is to make those available on non-BSD based systems to ease
|
||||
portability.
|
||||
@@ -76,7 +76,7 @@ The package also provides a
|
||||
.Pa bsd-ctor
|
||||
static library that can be used to inject automatic constructors into a
|
||||
program so that the
|
||||
.Fn setproctitle
|
||||
.Fn setproctitle_init 3
|
||||
function gets invoked automatically at startup time.
|
||||
This can be done with the
|
||||
.Xr pkg-config 3
|
||||
@@ -134,7 +134,7 @@ or non-buggy way; or because there are better more portable replacements now.
|
||||
.Pp
|
||||
This is the list of currently deprecated macros and functions:
|
||||
.Bl -tag -width 4m
|
||||
.It Fn fgetln
|
||||
.It Fn fgetln 3
|
||||
Unportable, requires assistance from the stdio layer.
|
||||
An implementation has to choose between leaking buffers or being reentrant
|
||||
for a limited amount of streams (this implementation chose the latter with
|
||||
@@ -143,7 +143,7 @@ Use
|
||||
.Fn getline 3
|
||||
instead, which is available in many systems and required by
|
||||
.St -p1003.1-2008 .
|
||||
.It Fn fgetwln
|
||||
.It Fn fgetwln 3
|
||||
Unportable, requires assistance from the stdio layer.
|
||||
An implementation has to choose between leaking buffers or being reentrant
|
||||
for a limited amount of streams (this implementation chose the latter with
|
||||
@@ -154,10 +154,10 @@ instead, which is available in many systems and required by
|
||||
.St -isoC-99
|
||||
and
|
||||
.St -p1003.1-2001 .
|
||||
.It Fn funopen
|
||||
.It Fn funopen 3
|
||||
Unportable, requires assistance from the stdio layer or some hook framework.
|
||||
On GNU systems the
|
||||
.Fn fopencookie
|
||||
.Fn fopencookie 3
|
||||
function can be used.
|
||||
Otherwise the code needs to be prepared for neither of these functions being
|
||||
available.
|
||||
@@ -171,23 +171,23 @@ are present in all major
|
||||
for example.
|
||||
.Pp
|
||||
.Bl -tag -width 4m -compact
|
||||
.It Fn MD5Init
|
||||
.It Fn MD5Update
|
||||
.It Fn MD5Pad
|
||||
.It Fn MD5Final
|
||||
.It Fn MD5Transform
|
||||
.It Fn MD5End
|
||||
.It Fn MD5File
|
||||
.It Fn MD5FileChunk
|
||||
.It Fn MD5Data
|
||||
.It Fn MD5Init 3
|
||||
.It Fn MD5Update 3
|
||||
.It Fn MD5Pad 3
|
||||
.It Fn MD5Final 3
|
||||
.It Fn MD5Transform 3
|
||||
.It Fn MD5End 3
|
||||
.It Fn MD5File 3
|
||||
.It Fn MD5FileChunk 3
|
||||
.It Fn MD5Data 3
|
||||
The set of MD5 digest functions are now provided by the
|
||||
.Nm libmd
|
||||
companion library, so it is advised to use that instead.
|
||||
.It Fn explicit_bzero
|
||||
.It Fn explicit_bzero 3
|
||||
This function is provided by
|
||||
.Nm glibc
|
||||
2.25.
|
||||
.It Fn reallocarray
|
||||
.It Fn reallocarray 3
|
||||
This function is provided by
|
||||
.Nm glibc
|
||||
2.26.
|
||||
|
@@ -25,6 +25,7 @@
|
||||
.Nd calculate the RSA Data Security, Inc., ``MDX'' message digest
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In sys/types.h
|
||||
|
@@ -36,6 +36,7 @@
|
||||
.Nd retrieve symbol table name list from an executable file
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In nlist.h
|
||||
@@ -50,7 +51,7 @@ The
|
||||
function
|
||||
retrieves name list entries from the symbol table of an
|
||||
executable file (see
|
||||
.Xr a.out 5 ) .
|
||||
.Xr elf 5 ) .
|
||||
The argument
|
||||
.Fa \&nl
|
||||
is set to reference the
|
||||
@@ -71,9 +72,12 @@ The last entry in the list is always
|
||||
The number of invalid entries is returned if successful; otherwise,
|
||||
if the file
|
||||
.Fa filename
|
||||
does not exist or is not executable, the returned value is \-1.
|
||||
does not exist or is not executable,
|
||||
or the nl pointer is
|
||||
.Dv NULL ,
|
||||
the returned value is \-1.
|
||||
.Sh SEE ALSO
|
||||
.Xr a.out 5
|
||||
.Xr elf 5
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Fn nlist
|
||||
|
@@ -36,6 +36,7 @@
|
||||
.Nd "library for PID files handling"
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In libutil.h
|
||||
|
@@ -38,6 +38,7 @@
|
||||
.Nd radix sort
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In limits.h
|
||||
|
@@ -26,6 +26,7 @@
|
||||
.Nd get a passphrase from the user
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In readpassphrase.h
|
||||
|
@@ -40,6 +40,7 @@
|
||||
.Nd memory allocation and deallocation
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In stdlib.h
|
||||
|
@@ -40,6 +40,7 @@
|
||||
.Nd general purpose memory allocation functions
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In stdlib.h
|
||||
|
@@ -39,6 +39,7 @@
|
||||
.Nd modify mode bits
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In unistd.h
|
||||
|
@@ -28,6 +28,7 @@
|
||||
.Nd set process title
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In sys/types.h
|
||||
@@ -118,7 +119,7 @@ similar functions.
|
||||
.Pp
|
||||
The
|
||||
.Fn setproctitle_init
|
||||
function is a libbsd extension not present on the BSDs, avoid using it
|
||||
function is a libbsd extension not present on the BSDs; avoid using it
|
||||
in portable code.
|
||||
.Sh AUTHORS
|
||||
.An -nosplit
|
||||
|
@@ -39,6 +39,7 @@
|
||||
.Nd stringlist manipulation functions
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In stringlist.h
|
||||
|
@@ -23,6 +23,7 @@
|
||||
.Nd size-bounded string copying and concatenation
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
|
@@ -36,6 +36,7 @@
|
||||
.Nd convert inode status information into a symbolic string
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
|
@@ -41,6 +41,7 @@
|
||||
.Nd locate a substring in a string
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
|
@@ -44,6 +44,7 @@
|
||||
.Nd convert string value to an intmax_t integer
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In inttypes.h
|
||||
@@ -225,10 +226,11 @@ function is a
|
||||
.Nx
|
||||
extension.
|
||||
.Sh HISTORY
|
||||
.ds doc-operating-system-NetBSD-7.0 7.0
|
||||
The
|
||||
.Fn strtoi
|
||||
function first appeared in
|
||||
.Nx 7 .
|
||||
.Nx 7.0 .
|
||||
.Ox
|
||||
introduced the
|
||||
.Fn strtonum 3bsd
|
||||
|
@@ -23,6 +23,7 @@
|
||||
.Nd reliably convert string value to an integer
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In limits.h
|
||||
@@ -144,13 +145,14 @@ is an
|
||||
.Ox
|
||||
extension.
|
||||
.Sh HISTORY
|
||||
.ds doc-operating-system-NetBSD-8.0 8.0
|
||||
The
|
||||
.Fn strtonum
|
||||
function first appeared in
|
||||
.Ox 3.6 .
|
||||
.Fn strtonum
|
||||
was redesigned in
|
||||
.Nx 8
|
||||
.Nx 8.0
|
||||
as
|
||||
.Fn strtoi 3bsd
|
||||
and
|
||||
|
@@ -44,6 +44,7 @@
|
||||
.Nd convert a string to an uintmax_t integer
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In inttypes.h
|
||||
@@ -219,6 +220,7 @@ the range given was invalid, i.e.
|
||||
.Xr strtoull 3 ,
|
||||
.Xr strtoumax 3
|
||||
.Sh STANDARDS
|
||||
.ds doc-operating-system-NetBSD-7.0 7.0
|
||||
The
|
||||
.Fn strtou
|
||||
function is a
|
||||
@@ -228,7 +230,7 @@ extension.
|
||||
The
|
||||
.Fn strtou
|
||||
function first appeared in
|
||||
.Nx 7 .
|
||||
.Nx 7.0 .
|
||||
.Ox
|
||||
introduced the
|
||||
.Fn strtonum 3bsd
|
||||
|
@@ -47,6 +47,7 @@
|
||||
.Nd operations on time structure
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In sys/time.h
|
||||
|
@@ -36,6 +36,7 @@
|
||||
.Nd time structures
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In sys/time.h
|
||||
|
@@ -41,6 +41,7 @@
|
||||
.Nd decode a visual representation of characters
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In vis.h
|
||||
|
@@ -51,6 +51,7 @@
|
||||
.Nd visually encode characters
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In vis.h
|
||||
|
@@ -44,6 +44,7 @@
|
||||
.Nd wide character string manipulation operations
|
||||
.Sh LIBRARY
|
||||
.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In wchar.h
|
||||
|
@@ -7,6 +7,13 @@ AM_CPPFLAGS = \
|
||||
-DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \
|
||||
-D__REENTRANT
|
||||
|
||||
if OS_WINDOWS
|
||||
AM_CPPFLAGS += \
|
||||
-D_CRT_SECURE_NO_WARNINGS \
|
||||
-D_CRT_NONSTDC_NO_WARNINGS \
|
||||
$(nil)
|
||||
endif
|
||||
|
||||
libbsd_la_included_sources = \
|
||||
hash/helper.c \
|
||||
getentropy_aix.c \
|
||||
@@ -54,7 +61,9 @@ libbsd_la_DEPENDENCIES = \
|
||||
$(libbsd_la_included_sources) \
|
||||
libbsd.map
|
||||
libbsd_la_LIBADD = \
|
||||
$(CLOCK_GETTIME_LIBS)
|
||||
$(CLOCK_GETTIME_LIBS) \
|
||||
$(ARC4RANDOM_ATFORK_LIBS) \
|
||||
$(nil)
|
||||
libbsd_la_LDFLAGS = \
|
||||
-Wl,--version-script=$(srcdir)/libbsd.map \
|
||||
-version-number $(LIBBSD_ABI)
|
||||
|
@@ -39,11 +39,11 @@
|
||||
|
||||
#define minimum(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
#if defined(__GNUC__) || defined(_MSC_VER)
|
||||
#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER)
|
||||
#define inline __inline
|
||||
#else /* __GNUC__ || _MSC_VER */
|
||||
#else /* __GNUC__ || __clang__ || _MSC_VER */
|
||||
#define inline
|
||||
#endif /* !__GNUC__ && !_MSC_VER */
|
||||
#endif /* !__GNUC__ && !__clang__ && !_MSC_VER */
|
||||
|
||||
#define KEYSZ 32
|
||||
#define IVSZ 8
|
||||
|
@@ -32,7 +32,7 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
|
||||
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
|
||||
#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
|
||||
|
||||
#ifdef __GLIBC__
|
||||
#ifdef HAVE___REGISTER_ATFORK
|
||||
extern void *__dso_handle;
|
||||
extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
|
||||
#define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle)
|
||||
|
@@ -32,7 +32,7 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
|
||||
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
|
||||
#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
|
||||
|
||||
#ifdef __GLIBC__
|
||||
#ifdef HAVE___REGISTER_ATFORK
|
||||
extern void *__dso_handle;
|
||||
extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
|
||||
#define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle)
|
||||
|
104
src/err.c
104
src/err.c
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright © 2006 Robert Millan
|
||||
* Copyright © 2011 Guillem Jover <guillem@hadrons.org>
|
||||
* Copyright © 2011, 2019 Guillem Jover <guillem@hadrons.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -26,8 +26,24 @@
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#ifdef LIBBSD_NEED_ERR_H_FUNCS
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void
|
||||
vwarnc(int code, const char *format, va_list ap)
|
||||
{
|
||||
fprintf(stderr, "%s: ", getprogname());
|
||||
if (format) {
|
||||
vfprintf(stderr, format, ap);
|
||||
fprintf(stderr, ": ");
|
||||
}
|
||||
fprintf(stderr, "%s\n", strerror(code));
|
||||
}
|
||||
|
||||
void
|
||||
warnc(int code, const char *format, ...)
|
||||
@@ -40,13 +56,15 @@ warnc(int code, const char *format, ...)
|
||||
}
|
||||
|
||||
void
|
||||
vwarnc(int code, const char *format, va_list ap)
|
||||
verrc(int status, int code, const char *format, va_list ap)
|
||||
{
|
||||
int tmp = errno;
|
||||
|
||||
errno = code;
|
||||
vwarn(format, ap);
|
||||
errno = tmp;
|
||||
fprintf(stderr, "%s: ", getprogname());
|
||||
if (format) {
|
||||
vfprintf(stderr, format, ap);
|
||||
fprintf(stderr, ": ");
|
||||
}
|
||||
fprintf(stderr, "%s\n", strerror(code));
|
||||
exit(status);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -59,9 +77,75 @@ errc(int status, int code, const char *format, ...)
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
#ifdef LIBBSD_NEED_ERR_H_FUNCS
|
||||
void
|
||||
verrc(int status, int code, const char *format, va_list ap)
|
||||
vwarn(const char *format, va_list ap)
|
||||
{
|
||||
errno = code;
|
||||
verr(status, format, ap);
|
||||
vwarnc(errno, format, ap);
|
||||
}
|
||||
|
||||
void
|
||||
warn(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
vwarnc(errno, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
vwarnx(const char *format, va_list ap)
|
||||
{
|
||||
fprintf(stderr, "%s: ", getprogname());
|
||||
if (format)
|
||||
vfprintf(stderr, format, ap);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
void
|
||||
warnx(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
vwarnx(format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
verr(int status, const char *format, va_list ap)
|
||||
{
|
||||
verrc(status, errno, format, ap);
|
||||
}
|
||||
|
||||
void
|
||||
err(int status, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
verrc(status, errno, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
verrx(int eval, const char *format, va_list ap)
|
||||
{
|
||||
fprintf(stderr, "%s: ", getprogname());
|
||||
if (format)
|
||||
vfprintf(stderr, format, ap);
|
||||
fprintf(stderr, "\n");
|
||||
exit(eval);
|
||||
}
|
||||
|
||||
void
|
||||
errx(int eval, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
verrx(eval, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
#endif
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
__attribute__((weak)) void
|
||||
__attribute__((__weak__)) void
|
||||
__explicit_bzero_hook(void *buf, size_t len)
|
||||
{
|
||||
}
|
||||
|
@@ -32,6 +32,7 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@@ -19,6 +19,9 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#include <hashinc>
|
||||
|
||||
|
@@ -19,9 +19,14 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <WinSock2.h>
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
|
@@ -168,3 +168,16 @@ LIBBSD_0.9.1 {
|
||||
strnvis_netbsd;
|
||||
strnunvis_netbsd;
|
||||
} LIBBSD_0.9;
|
||||
|
||||
LIBBSD_0.10.0 {
|
||||
/* These BSD extensions are available on GNU systems, but not on other
|
||||
* systems such as Windows or musl libc based ones. */
|
||||
vwarn;
|
||||
vwarnx;
|
||||
warn;
|
||||
warnx;
|
||||
verr;
|
||||
verrx;
|
||||
err;
|
||||
errx;
|
||||
} LIBBSD_0.9.1;
|
||||
|
@@ -37,6 +37,8 @@
|
||||
|
||||
#define ELF_TARG_VER EV_CURRENT
|
||||
|
||||
/* The following entries are sorted alphabetically. */
|
||||
|
||||
#if defined(__alpha__)
|
||||
|
||||
#define ELF_TARG_MACH EM_ALPHA
|
||||
@@ -53,6 +55,12 @@
|
||||
#endif
|
||||
#define ELF_TARG_DATA ELFDATA2LSB
|
||||
|
||||
#elif defined (__arc__)
|
||||
|
||||
#define ELF_TARG_MACH EM_ARC
|
||||
#define ELF_TARG_CLASS ELFCLASS32
|
||||
#define ELF_TARG_DATA ELFDATA2LSB
|
||||
|
||||
#elif defined(__arm__)
|
||||
|
||||
#define ELF_TARG_MACH EM_ARM
|
||||
@@ -66,7 +74,11 @@
|
||||
#elif defined(__aarch64__)
|
||||
|
||||
#define ELF_TARG_MACH EM_AARCH64
|
||||
#if defined(__ILP32__)
|
||||
#define ELF_TARG_CLASS ELFCLASS32
|
||||
#else
|
||||
#define ELF_TARG_CLASS ELFCLASS64
|
||||
#endif
|
||||
#if defined(__AARCH64EB__)
|
||||
#define ELF_TARG_DATA ELFDATA2MSB
|
||||
#else
|
||||
@@ -88,6 +100,12 @@
|
||||
#error Unknown AVR32 endianness
|
||||
#endif
|
||||
|
||||
#elif defined(__e2k__)
|
||||
|
||||
#define ELF_TARG_MACH EM_MCST_ELBRUS
|
||||
#define ELF_TARG_CLASS ELFCLASS64
|
||||
#define ELF_TARG_DATA ELFDATA2LSB
|
||||
|
||||
#elif defined(__hppa__)
|
||||
|
||||
#define ELF_TARG_MACH EM_PARISC
|
||||
|
@@ -29,5 +29,19 @@
|
||||
|
||||
#define libbsd_link_warning(symbol, msg) \
|
||||
static const char libbsd_emit_link_warning_##symbol[] \
|
||||
__attribute__((used,section(".gnu.warning." #symbol))) = msg;
|
||||
__attribute__((__used__,__section__(".gnu.warning." #symbol))) = msg;
|
||||
|
||||
#ifdef __ELF__
|
||||
#define libbsd_symver_default(alias, symbol, version) \
|
||||
__asm__(".symver " #symbol "," #alias "@@" #version)
|
||||
|
||||
#define libbsd_symver_variant(alias, symbol, version) \
|
||||
__asm__(".symver " #symbol "," #alias "@" #version)
|
||||
#else
|
||||
#define libbsd_symver_default(alias, symbol, version) \
|
||||
extern __typeof(symbol) alias __attribute__((__alias__(#symbol)))
|
||||
|
||||
#define libbsd_symver_variant(alias, symbol, version)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
27
src/nlist.c
27
src/nlist.c
@@ -141,11 +141,17 @@ __fdnlist(int fd, struct nlist *list)
|
||||
fstat(fd, &st) < 0)
|
||||
return (-1);
|
||||
|
||||
if (ehdr.e_shnum == 0 ||
|
||||
ehdr.e_shentsize != sizeof(Elf_Shdr)) {
|
||||
errno = ERANGE;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* calculate section header table size */
|
||||
shdr_size = ehdr.e_shentsize * ehdr.e_shnum;
|
||||
|
||||
/* Make sure it's not too big to mmap */
|
||||
if (shdr_size > SIZE_T_MAX) {
|
||||
if (shdr_size > SIZE_T_MAX || shdr_size > st.st_size) {
|
||||
errno = EFBIG;
|
||||
return (-1);
|
||||
}
|
||||
@@ -155,7 +161,7 @@ __fdnlist(int fd, struct nlist *list)
|
||||
return (-1);
|
||||
|
||||
/* Load section header table. */
|
||||
if (pread(fd, shdr, (size_t)shdr_size, (off_t)ehdr.e_shoff) < 0)
|
||||
if (pread(fd, shdr, (size_t)shdr_size, (off_t)ehdr.e_shoff) != (ssize_t)shdr_size)
|
||||
goto done;
|
||||
|
||||
/*
|
||||
@@ -166,6 +172,9 @@ __fdnlist(int fd, struct nlist *list)
|
||||
*/
|
||||
for (i = 0; i < ehdr.e_shnum; i++) {
|
||||
if (shdr[i].sh_type == SHT_SYMTAB) {
|
||||
if (shdr[i].sh_link >= ehdr.e_shnum)
|
||||
goto done;
|
||||
|
||||
symoff = shdr[i].sh_offset;
|
||||
symsize = shdr[i].sh_size;
|
||||
symstroff = shdr[shdr[i].sh_link].sh_offset;
|
||||
@@ -175,7 +184,7 @@ __fdnlist(int fd, struct nlist *list)
|
||||
}
|
||||
|
||||
/* Check for files too large to mmap. */
|
||||
if (symstrsize > SIZE_T_MAX) {
|
||||
if (symstrsize > SIZE_T_MAX || symstrsize > st.st_size) {
|
||||
errno = EFBIG;
|
||||
goto done;
|
||||
}
|
||||
@@ -189,7 +198,7 @@ __fdnlist(int fd, struct nlist *list)
|
||||
if (strtab == NULL)
|
||||
goto done;
|
||||
|
||||
if (pread(fd, strtab, (size_t)symstrsize, (off_t)symstroff) < 0)
|
||||
if (pread(fd, strtab, (size_t)symstrsize, (off_t)symstroff) != (ssize_t)symstrsize)
|
||||
goto done;
|
||||
|
||||
/*
|
||||
@@ -227,16 +236,18 @@ __fdnlist(int fd, struct nlist *list)
|
||||
symsize -= cc;
|
||||
for (s = sbuf; cc > 0 && nent > 0; ++s, cc -= sizeof(*s)) {
|
||||
char *name;
|
||||
Elf_Word size;
|
||||
struct nlist *p;
|
||||
|
||||
name = strtab + s->st_name;
|
||||
if (name[0] == '\0')
|
||||
continue;
|
||||
size = symstrsize - s->st_name;
|
||||
|
||||
for (p = list; !ISLAST(p); p++) {
|
||||
if ((p->n_un.n_name[0] == '_' &&
|
||||
strcmp(name, p->n_un.n_name+1) == 0)
|
||||
|| strcmp(name, p->n_un.n_name) == 0) {
|
||||
strncmp(name, p->n_un.n_name+1, size) == 0) ||
|
||||
strncmp(name, p->n_un.n_name, size) == 0) {
|
||||
elf_sym_to_nlist(p, s, shdr,
|
||||
ehdr.e_shnum);
|
||||
if (--nent <= 0)
|
||||
@@ -258,6 +269,10 @@ nlist(const char *name, struct nlist *list)
|
||||
{
|
||||
int fd, n;
|
||||
|
||||
if (list == NULL) {
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
}
|
||||
fd = open(name, O_RDONLY, 0);
|
||||
if (fd < 0)
|
||||
return (-1);
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include <err.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include "local-link.h"
|
||||
|
||||
static struct {
|
||||
/* Original value. */
|
||||
@@ -280,16 +281,19 @@ setproctitle_impl(const char *fmt, ...)
|
||||
*++nul = '\0';
|
||||
}
|
||||
}
|
||||
__asm__(".symver setproctitle_impl,setproctitle@@LIBBSD_0.5");
|
||||
libbsd_symver_default(setproctitle, setproctitle_impl, LIBBSD_0.5);
|
||||
|
||||
/* The original function introduced in 0.2 was a stub, it only got implemented
|
||||
* in 0.5, make the implementation available in the old version as an alias
|
||||
* for code linking against that version, and change the default to use the
|
||||
* new version, so that new code depends on the implemented version. */
|
||||
#ifdef HAVE_TYPEOF
|
||||
extern typeof(setproctitle_impl) setproctitle_stub __attribute__((alias("setproctitle_impl")));
|
||||
extern __typeof__(setproctitle_impl)
|
||||
setproctitle_stub
|
||||
__attribute__((__alias__("setproctitle_impl")));
|
||||
#else
|
||||
void setproctitle_stub(const char *fmt, ...)
|
||||
__attribute__((alias("setproctitle_impl")));
|
||||
void
|
||||
setproctitle_stub(const char *fmt, ...)
|
||||
__attribute__((__alias__("setproctitle_impl")));
|
||||
#endif
|
||||
__asm__(".symver setproctitle_stub,setproctitle@LIBBSD_0.2");
|
||||
libbsd_symver_variant(setproctitle, setproctitle_stub, LIBBSD_0.2);
|
||||
|
@@ -49,4 +49,4 @@
|
||||
* move them from .ctors to .init_array.
|
||||
*/
|
||||
void (*libbsd_init_func)(int argc, char *argv[], char *envp[])
|
||||
__attribute__((section(".init_array"))) = setproctitle_init;
|
||||
__attribute__((__section__(".init_array"))) = setproctitle_init;
|
||||
|
@@ -42,6 +42,8 @@
|
||||
#include <vis.h>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#include "local-link.h"
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(strnunvisx,_strnunvisx)
|
||||
#endif
|
||||
@@ -68,7 +70,8 @@ __weak_alias(strnunvisx,_strnunvisx)
|
||||
#define S_NUMBER 14 /* collecting number */
|
||||
#define S_STRING 15 /* collecting string */
|
||||
|
||||
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
|
||||
#define isoctal(c) \
|
||||
(((unsigned char)(c)) >= '0' && ((unsigned char)(c)) <= '7')
|
||||
#define xtod(c) (isdigit(c) ? (c - '0') : ((tolower(c) - 'a') + 10))
|
||||
#define XTOD(c) (isdigit(c) ? (c - '0') : ((c - 'A') + 10))
|
||||
|
||||
@@ -565,11 +568,11 @@ strnunvis_openbsd(char *dst, const char *src, size_t dlen)
|
||||
{
|
||||
return strnunvisx(dst, dlen, src, 0);
|
||||
}
|
||||
__asm__(".symver strnunvis_openbsd,strnunvis@@LIBBSD_0.2");
|
||||
libbsd_symver_default(strnunvis, strnunvis_openbsd, LIBBSD_0.2);
|
||||
|
||||
int
|
||||
strnunvis_netbsd(char *dst, size_t dlen, const char *src)
|
||||
{
|
||||
return strnunvisx(dst, dlen, src, 0);
|
||||
}
|
||||
__asm__(".symver strnunvis_netbsd,strnunvis@LIBBSD_0.9.1");
|
||||
libbsd_symver_variant(strnunvis, strnunvis_netbsd, LIBBSD_0.9.1);
|
||||
|
67
src/vis.c
67
src/vis.c
@@ -57,7 +57,6 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <assert.h>
|
||||
#pragma GCC diagnostic push
|
||||
@@ -78,6 +77,8 @@ __weak_alias(strvisx,_strvisx)
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "local-link.h"
|
||||
|
||||
#define _DIAGASSERT(x)
|
||||
|
||||
/*
|
||||
@@ -117,7 +118,8 @@ iscgraph(int c) {
|
||||
#define ISGRAPH(flags, c) \
|
||||
(((flags) & VIS_NOLOCALE) ? iscgraph(c) : iswgraph(c))
|
||||
|
||||
#define iswoctal(c) (((u_char)(c)) >= L'0' && ((u_char)(c)) <= L'7')
|
||||
#define iswoctal(c) \
|
||||
(((unsigned char)(c)) >= L'0' && ((unsigned char)(c)) <= L'7')
|
||||
#define iswwhite(c) (c == L' ' || c == L'\t' || c == L'\n')
|
||||
#define iswsafe(c) (c == L'\b' || c == BELL || c == L'\r')
|
||||
#define xtoa(c) L"0123456789abcdef"[c]
|
||||
@@ -253,9 +255,11 @@ do_mbyte(wchar_t *dst, wint_t c, int flags, wint_t nextc, int iswextra)
|
||||
}
|
||||
if (iswextra || ((c & 0177) == L' ') || (flags & VIS_OCTAL)) {
|
||||
*dst++ = L'\\';
|
||||
*dst++ = (u_char)(((u_int32_t)(u_char)c >> 6) & 03) + L'0';
|
||||
*dst++ = (u_char)(((u_int32_t)(u_char)c >> 3) & 07) + L'0';
|
||||
*dst++ = (c & 07) + L'0';
|
||||
*dst++ =
|
||||
(unsigned char)(((uint32_t)(unsigned char)c >> 6) & 03) + L'0';
|
||||
*dst++ =
|
||||
(unsigned char)(((uint32_t)(unsigned char)c >> 3) & 07) + L'0';
|
||||
*dst++ = (c & 07) + L'0';
|
||||
} else {
|
||||
if ((flags & VIS_NOSLASH) == 0)
|
||||
*dst++ = L'\\';
|
||||
@@ -305,7 +309,7 @@ do_svis(wchar_t *dst, wint_t c, int flags, wint_t nextc, const wchar_t *extra)
|
||||
/* See comment in istrsenvisx() output loop, below. */
|
||||
wmsk = 0;
|
||||
for (i = sizeof(wmsk) - 1; i >= 0; i--) {
|
||||
shft = i * NBBY;
|
||||
shft = i * CHAR_BIT;
|
||||
bmsk = (uint64_t)0xffLL << shft;
|
||||
wmsk |= bmsk;
|
||||
if ((c & wmsk) || i == 0)
|
||||
@@ -349,7 +353,7 @@ makeextralist(int flags, const char *src)
|
||||
if ((flags & VIS_NOLOCALE) || mbstowcs(dst, src, len) == (size_t)-1) {
|
||||
size_t i;
|
||||
for (i = 0; i < len; i++)
|
||||
dst[i] = (wchar_t)(u_char)src[i];
|
||||
dst[i] = (wchar_t)(unsigned char)src[i];
|
||||
d = dst + len;
|
||||
} else
|
||||
d = dst + wcslen(dst);
|
||||
@@ -452,7 +456,7 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
|
||||
clen = mbtowc(src, mbsrc, MB_LEN_MAX);
|
||||
if (cerr || clen < 0) {
|
||||
/* Conversion error, process as a byte instead. */
|
||||
*src = (wint_t)(u_char)*mbsrc;
|
||||
*src = (wint_t)(unsigned char)*mbsrc;
|
||||
clen = 1;
|
||||
cerr = 1;
|
||||
}
|
||||
@@ -503,7 +507,7 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
|
||||
*/
|
||||
for (start = dst; len > 0; len--) {
|
||||
c = *src++;
|
||||
dst = (*f)(dst, c, flags, len >= 1 ? *src : L'\0', extra);
|
||||
dst = (*f)(dst, c, flags, *src, extra);
|
||||
if (dst == NULL) {
|
||||
errno = ENOSPC;
|
||||
goto out;
|
||||
@@ -536,7 +540,7 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
|
||||
clen = 0;
|
||||
wmsk = 0;
|
||||
for (i = sizeof(wmsk) - 1; i >= 0; i--) {
|
||||
shft = i * NBBY;
|
||||
shft = i * CHAR_BIT;
|
||||
bmsk = (uint64_t)0xffLL << shft;
|
||||
wmsk |= bmsk;
|
||||
if ((*dst & wmsk) || i == 0)
|
||||
@@ -580,10 +584,20 @@ out:
|
||||
}
|
||||
|
||||
static int
|
||||
istrsenvisxl(char **mbdstp, size_t *dlen, const char *mbsrc,
|
||||
istrsenvisxna(char *mbdst, size_t *dlen, const char *mbsrc, size_t mblength,
|
||||
int flags, const char *mbextra, int *cerr_ptr)
|
||||
{
|
||||
return istrsenvisx(mbdstp, dlen, mbsrc,
|
||||
assert(mbdst != NULL);
|
||||
|
||||
return istrsenvisx(&mbdst, dlen, mbsrc, mblength,
|
||||
flags, mbextra, cerr_ptr);
|
||||
}
|
||||
|
||||
static int
|
||||
istrsenvisxl(char *mbdst, size_t *dlen, const char *mbsrc,
|
||||
int flags, const char *mbextra, int *cerr_ptr)
|
||||
{
|
||||
return istrsenvisxna(mbdst, dlen, mbsrc,
|
||||
mbsrc != NULL ? strlen(mbsrc) : 0, flags, mbextra, cerr_ptr);
|
||||
}
|
||||
|
||||
@@ -628,33 +642,33 @@ snvis(char *mbdst, size_t dlen, int c, int flags, int nextc, const char *mbextra
|
||||
int
|
||||
strsvis(char *mbdst, const char *mbsrc, int flags, const char *mbextra)
|
||||
{
|
||||
return istrsenvisxl(&mbdst, NULL, mbsrc, flags, mbextra, NULL);
|
||||
return istrsenvisxl(mbdst, NULL, mbsrc, flags, mbextra, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
strsnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags, const char *mbextra)
|
||||
{
|
||||
return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, mbextra, NULL);
|
||||
return istrsenvisxl(mbdst, &dlen, mbsrc, flags, mbextra, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
strsvisx(char *mbdst, const char *mbsrc, size_t len, int flags, const char *mbextra)
|
||||
{
|
||||
return istrsenvisx(&mbdst, NULL, mbsrc, len, flags, mbextra, NULL);
|
||||
return istrsenvisxna(mbdst, NULL, mbsrc, len, flags, mbextra, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
strsnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags,
|
||||
const char *mbextra)
|
||||
{
|
||||
return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, mbextra, NULL);
|
||||
return istrsenvisxna(mbdst, &dlen, mbsrc, len, flags, mbextra, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
strsenvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags,
|
||||
const char *mbextra, int *cerr_ptr)
|
||||
{
|
||||
return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, mbextra, cerr_ptr);
|
||||
return istrsenvisxna(mbdst, &dlen, mbsrc, len, flags, mbextra, cerr_ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -701,7 +715,7 @@ nvis(char *mbdst, size_t dlen, int c, int flags, int nextc)
|
||||
int
|
||||
strvis(char *mbdst, const char *mbsrc, int flags)
|
||||
{
|
||||
return istrsenvisxl(&mbdst, NULL, mbsrc, flags, "", NULL);
|
||||
return istrsenvisxl(mbdst, NULL, mbsrc, flags, "", NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -721,22 +735,23 @@ strvis(char *mbdst, const char *mbsrc, int flags)
|
||||
int
|
||||
strnvis_openbsd(char *mbdst, const char *mbsrc, size_t dlen, int flags)
|
||||
{
|
||||
return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, "", NULL);
|
||||
return istrsenvisxl(mbdst, &dlen, mbsrc, flags, "", NULL);
|
||||
}
|
||||
__asm__(".symver strnvis_openbsd,strnvis@@LIBBSD_0.2");
|
||||
libbsd_symver_default(strnvis, strnvis_openbsd, LIBBSD_0.2);
|
||||
|
||||
int
|
||||
strnvis_netbsd(char *mbdst, size_t dlen, const char *mbsrc, int flags)
|
||||
{
|
||||
return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, "", NULL);
|
||||
return istrsenvisxl(mbdst, &dlen, mbsrc, flags, "", NULL);
|
||||
}
|
||||
__asm__(".symver strnvis_netbsd,strnvis@LIBBSD_0.9.1");
|
||||
libbsd_symver_variant(strnvis, strnvis_netbsd, LIBBSD_0.9.1);
|
||||
|
||||
int
|
||||
stravis(char **mbdstp, const char *mbsrc, int flags)
|
||||
{
|
||||
*mbdstp = NULL;
|
||||
return istrsenvisxl(mbdstp, NULL, mbsrc, flags, "", NULL);
|
||||
return istrsenvisx(mbdstp, NULL, mbsrc,
|
||||
mbsrc != NULL ? strlen(mbsrc) : 0, flags, "", NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -753,18 +768,18 @@ stravis(char **mbdstp, const char *mbsrc, int flags)
|
||||
int
|
||||
strvisx(char *mbdst, const char *mbsrc, size_t len, int flags)
|
||||
{
|
||||
return istrsenvisx(&mbdst, NULL, mbsrc, len, flags, "", NULL);
|
||||
return istrsenvisxna(mbdst, NULL, mbsrc, len, flags, "", NULL);
|
||||
}
|
||||
|
||||
int
|
||||
strnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags)
|
||||
{
|
||||
return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, "", NULL);
|
||||
return istrsenvisxna(mbdst, &dlen, mbsrc, len, flags, "", NULL);
|
||||
}
|
||||
|
||||
int
|
||||
strenvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags,
|
||||
int *cerr_ptr)
|
||||
{
|
||||
return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, "", cerr_ptr);
|
||||
return istrsenvisxna(mbdst, &dlen, mbsrc, len, flags, "", cerr_ptr);
|
||||
}
|
||||
|
@@ -66,6 +66,8 @@ main(int argc, char **argv)
|
||||
|
||||
assert(*data_pub_ptr == 50);
|
||||
|
||||
assert(nl[0].n_name == nl[0].n_un.n_name);
|
||||
|
||||
rc = nlist(argv[0], nl);
|
||||
assert(rc == 0);
|
||||
|
||||
|
@@ -28,7 +28,9 @@
|
||||
* other headers through magic macros, to check that the overlay is working
|
||||
* properly. */
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_GRP_H
|
||||
#include <grp.h>
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
|
||||
/* Include libbsd overlayed headers that might get partially included. */
|
||||
|
Reference in New Issue
Block a user