summaryrefslogtreecommitdiff
path: root/include/libHX
diff options
context:
space:
mode:
Diffstat (limited to 'include/libHX')
-rw-r--r--include/libHX/defs.h4
-rw-r--r--include/libHX/intdiff.hpp24
-rw-r--r--include/libHX/io.h3
-rw-r--r--include/libHX/misc.h8
-rw-r--r--include/libHX/option.h6
-rw-r--r--include/libHX/proc.h12
-rw-r--r--include/libHX/socket.h20
-rw-r--r--include/libHX/string.h14
8 files changed, 82 insertions, 9 deletions
diff --git a/include/libHX/defs.h b/include/libHX/defs.h
index 1ace518..49ca7d1 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)
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..9d35cdc 100644
--- a/include/libHX/io.h
+++ b/include/libHX/io.h
@@ -35,6 +35,9 @@ 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);
diff --git a/include/libHX/misc.h b/include/libHX/misc.h
index adebf22..211bc96 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;
diff --git a/include/libHX/option.h b/include/libHX/option.h
index 82255d3..5b4bf6f 100644
--- a/include/libHX/option.h
+++ b/include/libHX/option.h
@@ -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..b151682
--- /dev/null
+++ b/include/libHX/socket.h
@@ -0,0 +1,20 @@
+#ifndef _LIBHX_SOCKET_H
+#define _LIBHX_SOCKET_H 1
+
+#ifdef _WIN32
+# include <ws2tcpip.h>
+#else
+# include <netdb.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int HX_socket_from_env(const struct addrinfo *, const char *intf);
+
+#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)
{