summaryrefslogtreecommitdiff
path: root/include/libHX
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2023-02-10 15:27:06 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2023-02-10 15:27:06 +0100
commit7501bff8432444b7ae8e7f3d9289c0d61f3f0b64 (patch)
treebd53603f464c3747e897a8996158a0fef7b41bc3 /include/libHX
parent0f124df68d87c9073f76efeff1a901a69b1f3e13 (diff)
parent9e9336185f86bd97ff22f54e4d561c2cccccecf5 (diff)
Merge branch 'release/debian/4.10-1'debian/4.10-1
Diffstat (limited to 'include/libHX')
-rw-r--r--include/libHX/defs.h12
-rw-r--r--include/libHX/intdiff.hpp24
-rw-r--r--include/libHX/io.h8
-rw-r--r--include/libHX/misc.h11
-rw-r--r--include/libHX/option.h18
-rw-r--r--include/libHX/proc.h12
-rw-r--r--include/libHX/socket.h23
-rw-r--r--include/libHX/string.h14
8 files changed, 103 insertions, 19 deletions
diff --git a/include/libHX/defs.h b/include/libHX/defs.h
index 1ace518..9d17019 100644
--- a/include/libHX/defs.h
+++ b/include/libHX/defs.h
@@ -10,8 +10,8 @@
# endif
# ifndef containerof
# include <cstddef>
-# define containerof(var, type, member) reinterpret_cast<type *>( \
- reinterpret_cast<char *>(var) - offsetof(type, member))
+# include <type_traits>
+# define containerof(var, T, member) reinterpret_cast<std::conditional<std::is_const<std::remove_pointer<decltype(var)>::type>::value, std::add_const<T>::type, T>::type *>(reinterpret_cast<std::conditional<std::is_const<std::remove_pointer<decltype(var)>::type>::value, const char, char>::type *>(var) - offsetof(T, member))
# endif
# ifndef static_cast
# define static_cast(T, x) static_cast<T>(x)
@@ -213,15 +213,15 @@ static __inline__ new_type signed_cast(unsigned char *expr)
# define container_of(v, s, m) containerof((v), s, m)
#endif
-#ifdef _WIN32
+#if !defined(_WIN32) || (defined(__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO + 0 > 0)
/*
* Sufficiently old versions of the VC runtime do not even support %ll.
*/
-# define HX_LONGLONG_FMT "I64"
-# define HX_SIZET_FMT "I"
-#else
# define HX_LONGLONG_FMT "ll"
# define HX_SIZET_FMT "z"
+#else
+# define HX_LONGLONG_FMT "I64"
+# define HX_SIZET_FMT "I"
#endif
#endif /* _LIBHX_DEFS_H */
diff --git a/include/libHX/intdiff.hpp b/include/libHX/intdiff.hpp
new file mode 100644
index 0000000..17300a1
--- /dev/null
+++ b/include/libHX/intdiff.hpp
@@ -0,0 +1,24 @@
+#ifndef LIBHX_INTDIFF_HPP
+#define LIBHX_INTDIFF_HPP 1
+#include <algorithm>
+namespace HX {
+template<typename AIter, typename BIter, typename XIter,
+ typename YIter, typename ZIter>
+void set_intersect_diff(AIter a_first, AIter a_last, BIter b_first,
+ BIter b_last, XIter xptr, YIter yptr, ZIter zptr)
+{
+ while ((a_first != a_last) && (b_first != b_last)) {
+ if (*a_first < *b_first)
+ *xptr++ = *a_first++;
+ else if (*b_first < *a_first)
+ *yptr++ = *b_first++;
+ else {
+ *zptr++ = *a_first++;
+ ++b_first;
+ }
+ }
+ std::copy(a_first, a_last, xptr);
+ std::copy(b_first, b_last, yptr);
+}
+}
+#endif
diff --git a/include/libHX/io.h b/include/libHX/io.h
index c86af72..7e0c7d3 100644
--- a/include/libHX/io.h
+++ b/include/libHX/io.h
@@ -1,6 +1,7 @@
#ifndef _LIBHX_IO_H
#define _LIBHX_IO_H 1
+#include <stdio.h>
#include <sys/types.h>
#ifdef __cplusplus
@@ -35,9 +36,16 @@ extern int HX_mkdir(const char *, unsigned int);
extern int HX_readlink(hxmc_t **, const char *);
extern int HX_realpath(hxmc_t **, const char *, unsigned int);
extern int HX_rrmdir(const char *);
+extern ssize_t HX_sendfile(int dst, int src, size_t count);
+extern char *HX_slurp_fd(int fd, size_t *outsize);
+extern char *HX_slurp_file(const char *file, size_t *outsize);
extern ssize_t HXio_fullread(int, void *, size_t);
extern ssize_t HXio_fullwrite(int, const void *, size_t);
+#ifndef HX_HEXDUMP_DECLARATION
+#define HX_HEXDUMP_DECLARATION 1
+extern void HX_hexdump(FILE *, const void *, unsigned int);
+#endif
#ifdef __cplusplus
} /* extern "C" */
diff --git a/include/libHX/misc.h b/include/libHX/misc.h
index adebf22..23607d2 100644
--- a/include/libHX/misc.h
+++ b/include/libHX/misc.h
@@ -35,11 +35,11 @@ extern "C" {
#define HX_TIMESPEC_FMT "%ld.%09ld"
#define HX_TIMEVAL_FMT "%ld.%06ld"
#ifdef __cplusplus
-# define HX_TIMESPEC_EXP(p) static_cast<long>((p)->tv_sec), (p)->tv_nsec
-# define HX_TIMEVAL_EXP(p) static_cast<long>((p)->tv_sec), (p)->tv_usec
+# define HX_TIMESPEC_EXP(p) static_cast<long>((p)->tv_sec), static_cast<long>((p)->tv_nsec)
+# define HX_TIMEVAL_EXP(p) static_cast<long>((p)->tv_sec), static_cast<long>((p)->tv_usec)
#else
-# define HX_TIMESPEC_EXP(p) static_cast(long, (p)->tv_sec), (p)->tv_nsec
-# define HX_TIMEVAL_EXP(p) static_cast(long, (p)->tv_sec), (p)->tv_usec
+# define HX_TIMESPEC_EXP(p) static_cast(long, (p)->tv_sec), static_cast(long, (p)->tv_nsec)
+# define HX_TIMEVAL_EXP(p) static_cast(long, (p)->tv_sec), static_cast(long, (p)->tv_usec)
#endif
struct stat;
@@ -59,7 +59,10 @@ extern const char *HX_dlerror(void);
*/
extern int HX_ffs(unsigned long);
extern int HX_fls(unsigned long);
+#ifndef HX_HEXDUMP_DECLARATION
+#define HX_HEXDUMP_DECLARATION 1
extern void HX_hexdump(FILE *, const void *, unsigned int);
+#endif
extern bool HX_timespec_isneg(const struct timespec *);
extern struct timespec *HX_timespec_neg(struct timespec *,
const struct timespec *);
diff --git a/include/libHX/option.h b/include/libHX/option.h
index 82255d3..40cc6e7 100644
--- a/include/libHX/option.h
+++ b/include/libHX/option.h
@@ -27,12 +27,12 @@ extern struct HXformat_map *HXformat_init(void);
extern void HXformat_free(struct HXformat_map *);
extern int HXformat_add(struct HXformat_map *, const char *, const void *,
unsigned int);
-extern int HXformat_aprintf(const struct HXformat_map *,
- hxmc_t **, const char *);
-extern int HXformat_sprintf(const struct HXformat_map *,
- char *, size_t, const char *);
-extern int HXformat_fprintf(const struct HXformat_map *,
- FILE *, const char *);
+#define HXformat_aprintf(a, b, c) HXformat3_aprintf((a), (b), (c))
+#define HXformat_fprintf(a, b, c) HXformat3_fprintf((a), (b), (c))
+#define HXformat_sprintf(a, b, c, d) HXformat3_sprintf((a), (b), (c), (d))
+extern ssize_t HXformat3_aprintf(const struct HXformat_map *, hxmc_t **, const char *);
+extern ssize_t HXformat3_fprintf(const struct HXformat_map *, FILE *, const char *);
+extern ssize_t HXformat3_sprintf(const struct HXformat_map *, char *, size_t, const char *);
/*
* OPT.C
@@ -77,7 +77,7 @@ extern int HXformat_fprintf(const struct HXformat_map *,
* Type expected of struct HXoption.ptr is given in ().
* HX_getopt (o) and HXformat_* (f) support different sets, marked with [].
*/
-enum HX_option_type {
+enum {
HXTYPE_NONE = 0,
HXTYPE_VAL,
HXTYPE_SVAL,
@@ -110,7 +110,6 @@ enum HX_option_type {
HXTYPE_XSNTMARK,
HXTYPE_XHELP, /* 30 */
HXTYPE_SIZE_T,
-};
/**
* Extra flags to be OR'ed into struct HXoption.type.
@@ -125,7 +124,6 @@ enum HX_option_type {
* %HXOPT_AND: AND *ptr by argument
* %HXOPT_XOR: XOR *ptr by argument
*/
-enum {
HXOPT_OPTIONAL = 1 << 6,
HXOPT_INC = 1 << 7,
HXOPT_DEC = 1 << 8,
@@ -144,6 +142,7 @@ enum {
* %HXOPT_USAGEONERR: print out short usage when a parsing error occurs
* %HXOPT_RQ_ORDER: require option order/POSIX mode:
* first non-option terminates option processing
+ * %HXOPT_KEEP_ARGV: do not replace argc/argv at all
*/
enum {
HXOPT_PTHRU = 1 << 0,
@@ -152,6 +151,7 @@ enum {
HXOPT_HELPONERR = 1 << 3,
HXOPT_USAGEONERR = 1 << 4,
HXOPT_RQ_ORDER = 1 << 5,
+ HXOPT_KEEP_ARGV = 1 << 6,
};
/**
diff --git a/include/libHX/proc.h b/include/libHX/proc.h
index cb682ed..fb17d5e 100644
--- a/include/libHX/proc.h
+++ b/include/libHX/proc.h
@@ -21,6 +21,16 @@ enum {
HXPROC_NULL_STDERR = 1 << 8,
};
+enum HXproc_su_status {
+ HXPROC_INITGROUPS_FAILED = -5,
+ HXPROC_SETGID_FAILED = -4,
+ HXPROC_SETUID_FAILED = -3,
+ HXPROC_GROUP_NOT_FOUND = -2,
+ HXPROC_USER_NOT_FOUND = -1,
+ HXPROC_SU_NOOP = 0,
+ HXPROC_SU_SUCCESS = 1,
+};
+
struct HXproc_ops {
void (*p_prefork)(void *);
void (*p_postfork)(void *);
@@ -41,6 +51,8 @@ struct HXproc {
extern int HXproc_run_async(const char *const *, struct HXproc *);
extern int HXproc_run_sync(const char *const *, unsigned int);
extern int HXproc_wait(struct HXproc *);
+extern enum HXproc_su_status HXproc_switch_user(const char *user, const char *group);
+extern int HXproc_top_fd(void);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/include/libHX/socket.h b/include/libHX/socket.h
new file mode 100644
index 0000000..e9db77f
--- /dev/null
+++ b/include/libHX/socket.h
@@ -0,0 +1,23 @@
+#ifndef _LIBHX_SOCKET_H
+#define _LIBHX_SOCKET_H 1
+
+#ifdef _WIN32
+# include <ws2tcpip.h>
+#else
+# include <netdb.h>
+# include <sys/socket.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int HX_socket_from_env(const struct addrinfo *, const char *intf);
+extern int HX_sockaddr_is_local(const struct sockaddr *, socklen_t, unsigned int flags);
+extern int HX_ipaddr_is_local(const char *, unsigned int flags);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* _LIBHX_SOCKET_H */
diff --git a/include/libHX/string.h b/include/libHX/string.h
index 4dc4c11..9e78cd0 100644
--- a/include/libHX/string.h
+++ b/include/libHX/string.h
@@ -28,9 +28,17 @@ enum {
HXQUOTE_URIENC,
HXQUOTE_SQLSQUOTE,
HXQUOTE_SQLBQUOTE,
+ HXQUOTE_BASE64URL,
+ HXQUOTE_BASE64IMAP,
_HXQUOTE_MAX,
};
+enum {
+ HXUNIT_YEARS = 0x1U,
+ HXUNIT_MONTHS = 0x2U,
+ HXUNIT_WEEKS = 0x4U,
+};
+
#ifndef __libhx_internal_hxmc_t_defined
#define __libhx_internal_hxmc_t_defined 1
typedef char hxmc_t;
@@ -90,6 +98,12 @@ extern size_t HX_strrtrim(char *);
extern char *HX_strsep(char **, const char *);
extern char *HX_strsep2(char **, const char *);
extern char *HX_strupper(char *);
+extern double HX_strtod_unit(const char *, char **, unsigned int exponent);
+extern unsigned long long HX_strtoull_unit(const char *, char **, unsigned int exponent);
+extern char *HX_unit_size(char *out, size_t bufsize, unsigned long long size, unsigned int divisor, unsigned int cutoff);
+extern char *HX_unit_size_cu(char *out, size_t bufsize, unsigned long long size, unsigned int divisor);
+extern unsigned long long HX_strtoull_sec(const char *s, char **);
+extern char *HX_unit_seconds(char *out, size_t bufsize, unsigned long long seconds, unsigned int flags);
static __inline__ void *HX_memdup(const void *buf, size_t len)
{