Merge branch 'feature/upstream' into develop
Jörg Frings-Fürst
1 year, 2 months ago
0 | Permission is hereby granted, free of charge, to any person obtaining | |
1 | a copy of this software and associated documentation files (the | |
2 | "Software"), to deal in the Software without restriction, including | |
3 | without limitation the rights to use, copy, modify, merge, publish, | |
4 | distribute, sublicense, and/or sell copies of the Software, and to | |
5 | permit persons to whom the Software is furnished to do so, subject to | |
6 | the following conditions: | |
7 | ||
8 | The above copyright notice and this permission notice (including the | |
9 | next paragraph) shall be included in all copies or substantial | |
10 | portions of the Software. | |
11 | ||
12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
13 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
14 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
15 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | |
16 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
17 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
19 | SOFTWARE. |
0 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
1 | Version 2, December 2004 | |
2 | ||
3 | Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> | |
4 | ||
5 | Everyone is permitted to copy and distribute verbatim or modified | |
6 | copies of this license document, and changing it is allowed as long | |
7 | as the name is changed. | |
8 | ||
9 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
10 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
11 | ||
12 | 0. You just DO WHAT THE FUCK YOU WANT TO. | |
13 |
92 | 92 | /* Define to 1 if you have the <sys/types.h> header file. */ |
93 | 93 | #undef HAVE_SYS_TYPES_H |
94 | 94 | |
95 | /* Define to 1 if you have the <sys/un.h> header file. */ | |
96 | #undef HAVE_SYS_UN_H | |
97 | ||
95 | 98 | /* Define to 1 if you have the <unistd.h> header file. */ |
96 | 99 | #undef HAVE_UNISTD_H |
97 | 100 |
0 | 0 | #! /bin/sh |
1 | 1 | # Guess values for system-dependent variables and create Makefiles. |
2 | # Generated by GNU Autoconf 2.71 for libHX 4.8. | |
2 | # Generated by GNU Autoconf 2.71 for libHX 4.10. | |
3 | 3 | # |
4 | 4 | # |
5 | 5 | # Copyright (C) 1992-1996, 1998-2017, 2020-2021 Free Software Foundation, |
617 | 617 | # Identity of this package. |
618 | 618 | PACKAGE_NAME='libHX' |
619 | 619 | PACKAGE_TARNAME='libhx' |
620 | PACKAGE_VERSION='4.8' | |
621 | PACKAGE_STRING='libHX 4.8' | |
620 | PACKAGE_VERSION='4.10' | |
621 | PACKAGE_STRING='libHX 4.10' | |
622 | 622 | PACKAGE_BUGREPORT='' |
623 | 623 | PACKAGE_URL='' |
624 | 624 | |
1374 | 1374 | # Omit some internal or obsolete options to make the list less imposing. |
1375 | 1375 | # This message is too long to be a string in the A/UX 3.1 sh. |
1376 | 1376 | cat <<_ACEOF |
1377 | \`configure' configures libHX 4.8 to adapt to many kinds of systems. | |
1377 | \`configure' configures libHX 4.10 to adapt to many kinds of systems. | |
1378 | 1378 | |
1379 | 1379 | Usage: $0 [OPTION]... [VAR=VALUE]... |
1380 | 1380 | |
1445 | 1445 | |
1446 | 1446 | if test -n "$ac_init_help"; then |
1447 | 1447 | case $ac_init_help in |
1448 | short | recursive ) echo "Configuration of libHX 4.8:";; | |
1448 | short | recursive ) echo "Configuration of libHX 4.10:";; | |
1449 | 1449 | esac |
1450 | 1450 | cat <<\_ACEOF |
1451 | 1451 | |
1560 | 1560 | test -n "$ac_init_help" && exit $ac_status |
1561 | 1561 | if $ac_init_version; then |
1562 | 1562 | cat <<\_ACEOF |
1563 | libHX configure 4.8 | |
1563 | libHX configure 4.10 | |
1564 | 1564 | generated by GNU Autoconf 2.71 |
1565 | 1565 | |
1566 | 1566 | Copyright (C) 2021 Free Software Foundation, Inc. |
2194 | 2194 | This file contains any messages produced by compilers while |
2195 | 2195 | running configure, to aid debugging if configure makes a mistake. |
2196 | 2196 | |
2197 | It was created by libHX $as_me 4.8, which was | |
2197 | It was created by libHX $as_me 4.10, which was | |
2198 | 2198 | generated by GNU Autoconf 2.71. Invocation command line was |
2199 | 2199 | |
2200 | 2200 | $ $0$ac_configure_args_raw |
3683 | 3683 | |
3684 | 3684 | # Define the identity of the package. |
3685 | 3685 | PACKAGE='libhx' |
3686 | VERSION='4.8' | |
3686 | VERSION='4.10' | |
3687 | 3687 | |
3688 | 3688 | |
3689 | 3689 | printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h |
17594 | 17594 | printf "%s\n" "#define HAVE_SYS_RESOURCE_H 1" >>confdefs.h |
17595 | 17595 | |
17596 | 17596 | fi |
17597 | ac_fn_c_check_header_compile "$LINENO" "sys/un.h" "ac_cv_header_sys_un_h" "$ac_includes_default" | |
17598 | if test "x$ac_cv_header_sys_un_h" = xyes | |
17599 | then : | |
17600 | printf "%s\n" "#define HAVE_SYS_UN_H 1" >>confdefs.h | |
17601 | ||
17602 | fi | |
17597 | 17603 | |
17598 | 17604 | if test "$ac_cv_header_dlfcn_h" = "yes"; then |
17599 | 17605 | HAVE_DLFCN_H_TRUE= |
18764 | 18770 | # report actual input values of CONFIG_FILES etc. instead of their |
18765 | 18771 | # values after options handling. |
18766 | 18772 | ac_log=" |
18767 | This file was extended by libHX $as_me 4.8, which was | |
18773 | This file was extended by libHX $as_me 4.10, which was | |
18768 | 18774 | generated by GNU Autoconf 2.71. Invocation command line was |
18769 | 18775 | |
18770 | 18776 | CONFIG_FILES = $CONFIG_FILES |
18832 | 18838 | cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 |
18833 | 18839 | ac_cs_config='$ac_cs_config_escaped' |
18834 | 18840 | ac_cs_version="\\ |
18835 | libHX config.status 4.8 | |
18841 | libHX config.status 4.10 | |
18836 | 18842 | configured by $0, generated by GNU Autoconf 2.71, |
18837 | 18843 | with options \\"\$ac_cs_config\\" |
18838 | 18844 |
0 | AC_INIT([libHX], [4.8]) | |
0 | AC_INIT([libHX], [4.10]) | |
1 | 1 | AC_CONFIG_AUX_DIR([build-aux]) |
2 | 2 | AC_CONFIG_HEADERS([config.h]) |
3 | 3 | AC_CONFIG_MACRO_DIR([m4]) |
64 | 64 | AM_CONDITIONAL([WITH_GNU_LD], [test "$with_gnu_ld" = yes]) |
65 | 65 | |
66 | 66 | LIBS_system="$LIBS" |
67 | AC_CHECK_HEADERS([dlfcn.h sys/resource.h]) | |
67 | AC_CHECK_HEADERS([dlfcn.h sys/resource.h sys/un.h]) | |
68 | 68 | AM_CONDITIONAL([HAVE_DLFCN_H], [test "$ac_cv_header_dlfcn_h" = "yes"]) |
69 | 69 | AC_SEARCH_LIBS([dlopen], [dl], [libdl_LIBS="$LIBS"; LIBS="$LIBS_system"]) |
70 | 70 | AC_SUBST([libdl_LIBS]) |
8 | 8 | ====== ====== ====== ======================================== |
9 | 9 | RMV MinVer FirstA Name |
10 | 10 | ====== ====== ====== ======================================== |
11 | 4.9 4.9 4.9 HX_sockaddr_is_local | |
12 | 4.9 4.9 4.9 HX_ipaddr_is_local | |
11 | 13 | 4.7 4.7 4.7 HXQUOTE_BASE64IMAP |
12 | 14 | 4.7 4.7 4.7 HXQUOTE_BASE64URL |
13 | 15 | 4.3 4.3 4.3 HX_unit_seconds |
0 | v4.10 (2023-01-29) | |
1 | ================== | |
2 | ||
3 | Fixes: | |
4 | ||
5 | * format: plug a memory leak relating to func_entry_clone | |
6 | * Resolve mingw build failure | |
7 | ||
8 | ||
9 | v4.9 (2023-01-23) | |
10 | ================= | |
11 | ||
12 | Enhancements: | |
13 | ||
14 | * socket: add sockaddr_is_local, ipaddr_is_local functions | |
15 | ||
16 | Fixes: | |
17 | ||
18 | * format: avoid return value truncation from HXformat_aprintf, HXformat_sprintf | |
19 | * format: avoid calling HXmc_length on a non-hxmc object | |
20 | * format: add new variations of printf functions returning ssize_t | |
21 | * Resolve Coverity-SCAN reports | |
22 | ||
23 | ||
0 | 24 | v4.8 (2022-12-03) |
1 | 25 | ================= |
2 | 26 |
7 | 7 | |
8 | 8 | int HX_ffs(unsigned long z); |
9 | 9 | int HX_fls(unsigned long z); |
10 | void HX_hexdump(FILE *fp, const void *ptr, unsigned int len); | |
11 | 10 | |
12 | 11 | void HX_zvecfree(char **); |
13 | 12 | unsigned int HX_zveclen(const char *const *); |
20 | 19 | Finds the last (most-significant) bit in a value and returns its |
21 | 20 | position, or ``-1`` to indicate failure. |
22 | 21 | |
23 | ``HX_hexdump`` | |
24 | Outputs a nice pretty-printed hex and ASCII dump to the filedescriptor | |
25 | ``fp``. ``ptr`` is the memory area, of which ``len`` bytes will be | |
26 | dumped. | |
27 | ||
28 | 22 | ``HX_zvecfree`` |
29 | 23 | Frees the supplied Z-vector array. (Frees all array elements from the |
30 | 24 | first element to (excluding) the first ``NULL`` element.) |
32 | 26 | ``HX_zveclen`` |
33 | 27 | Counts the number of array elements until the first ``NULL`` array |
34 | 28 | element is seen, and returns this number. |
29 | ||
30 | .. code-block:: c | |
31 | ||
32 | #include <libHX/io.h> | |
33 | void HX_hexdump(FILE *fp, const void *ptr, unsigned int len); | |
34 | ||
35 | ``HX_hexdump`` | |
36 | Outputs a nice pretty-printed hex and ASCII dump to the filedescriptor | |
37 | ``fp``. ``ptr`` is the memory area, of which ``len`` bytes will be | |
38 | dumped. |
6 | 6 | #include <libHX/socket.h> |
7 | 7 | |
8 | 8 | int HX_socket_from_env(const struct addrinfo *ai, const char *intf); |
9 | int HX_sockaddr_is_local(const struct sockaddr *, socklen_t, unsigned int flags); | |
10 | int HX_ipaddr_is_local(const char *, unsigned int flags); | |
9 | 11 | |
10 | 12 | ``HX_socket_from_env`` |
11 | 13 | The function looks up the current process's file descriptors for a |
13 | 15 | (optionally) intf if the latter is not NULL``. Upon success, the fd |
14 | 16 | number is returned, or -1 if no file descriptor matched. No errors are |
15 | 17 | signalled. |
18 | ||
19 | ``HX_sockaddr_is_local`` | |
20 | Attempts to determine if the given socket address refers to a local | |
21 | address. This function may be helpful in determining whether a process | |
22 | should spend any time (or not) on compressing data before sending to a | |
23 | peer. The definition of "local" is generally dependent upon the network | |
24 | APIs. The ``flags`` parameter can contain ``AI_V4MAPPED`` if | |
25 | IPv4-mapped IPv6 addresses should be recognized. The function returns | |
26 | >0 if the address is considered local, 0 if not, and any other | |
27 | negative value for a system error that makes the result | |
28 | indeterminate. | |
29 | ||
30 | ``HX_ipaddr_is_local`` | |
31 | Takes a text representation of an IPv6/IPv4 address and, after | |
32 | transformation, calls ``HX_sockaddr_is_local``. ``flags`` and | |
33 | return value behave the same as that. |
115 | 115 | Does substituion and directly outputs the expansion to the given stdio |
116 | 116 | stream. |
117 | 117 | |
118 | On success, the length of the expanded string is returned, excluding the | |
119 | trailing ``\0``. While ``HXformat_sprintf`` will not write more than ``size`` | |
120 | bytes (including the ``\0``), the length it would have taken is returned, | |
121 | similar to what sprintf does. On error, ``-errno`` is returned. | |
118 | On success, the length of the expanded string is returned (only up to a maximum | |
119 | of SSIZE_MAX), excluding the trailing ``\0``. While ``HXformat_sprintf`` will | |
120 | not write more than ``size`` bytes (including the ``\0``), the length it would | |
121 | have taken is returned, similar to what sprintf does. On error, ``-errno`` is | |
122 | returned. | |
122 | 123 | |
123 | 124 | The HXformat function family recognizes make-style like functions and recursive |
124 | 125 | expansion, described below. |
212 | 212 | # define container_of(v, s, m) containerof((v), s, m) |
213 | 213 | #endif |
214 | 214 | |
215 | #ifdef _WIN32 | |
215 | #if !defined(_WIN32) || (defined(__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO + 0 > 0) | |
216 | 216 | /* |
217 | 217 | * Sufficiently old versions of the VC runtime do not even support %ll. |
218 | 218 | */ |
219 | # define HX_LONGLONG_FMT "ll" | |
220 | # define HX_SIZET_FMT "z" | |
221 | #else | |
219 | 222 | # define HX_LONGLONG_FMT "I64" |
220 | 223 | # define HX_SIZET_FMT "I" |
221 | #else | |
222 | # define HX_LONGLONG_FMT "ll" | |
223 | # define HX_SIZET_FMT "z" | |
224 | 224 | #endif |
225 | 225 | |
226 | 226 | #endif /* _LIBHX_DEFS_H */ |
0 | 0 | #ifndef _LIBHX_IO_H |
1 | 1 | #define _LIBHX_IO_H 1 |
2 | 2 | |
3 | #include <stdio.h> | |
3 | 4 | #include <sys/types.h> |
4 | 5 | |
5 | 6 | #ifdef __cplusplus |
40 | 41 | |
41 | 42 | extern ssize_t HXio_fullread(int, void *, size_t); |
42 | 43 | extern ssize_t HXio_fullwrite(int, const void *, size_t); |
44 | #ifndef HX_HEXDUMP_DECLARATION | |
45 | #define HX_HEXDUMP_DECLARATION 1 | |
46 | extern void HX_hexdump(FILE *, const void *, unsigned int); | |
47 | #endif | |
43 | 48 | |
44 | 49 | #ifdef __cplusplus |
45 | 50 | } /* extern "C" */ |
58 | 58 | */ |
59 | 59 | extern int HX_ffs(unsigned long); |
60 | 60 | extern int HX_fls(unsigned long); |
61 | #ifndef HX_HEXDUMP_DECLARATION | |
62 | #define HX_HEXDUMP_DECLARATION 1 | |
61 | 63 | extern void HX_hexdump(FILE *, const void *, unsigned int); |
64 | #endif | |
62 | 65 | extern bool HX_timespec_isneg(const struct timespec *); |
63 | 66 | extern struct timespec *HX_timespec_neg(struct timespec *, |
64 | 67 | const struct timespec *); |
26 | 26 | extern void HXformat_free(struct HXformat_map *); |
27 | 27 | extern int HXformat_add(struct HXformat_map *, const char *, const void *, |
28 | 28 | unsigned int); |
29 | extern int HXformat_aprintf(const struct HXformat_map *, | |
30 | hxmc_t **, const char *); | |
31 | extern int HXformat_sprintf(const struct HXformat_map *, | |
32 | char *, size_t, const char *); | |
33 | extern int HXformat_fprintf(const struct HXformat_map *, | |
34 | FILE *, const char *); | |
29 | #define HXformat_aprintf(a, b, c) HXformat3_aprintf((a), (b), (c)) | |
30 | #define HXformat_fprintf(a, b, c) HXformat3_fprintf((a), (b), (c)) | |
31 | #define HXformat_sprintf(a, b, c, d) HXformat3_sprintf((a), (b), (c), (d)) | |
32 | extern ssize_t HXformat3_aprintf(const struct HXformat_map *, hxmc_t **, const char *); | |
33 | extern ssize_t HXformat3_fprintf(const struct HXformat_map *, FILE *, const char *); | |
34 | extern ssize_t HXformat3_sprintf(const struct HXformat_map *, char *, size_t, const char *); | |
35 | 35 | |
36 | 36 | /* |
37 | 37 | * OPT.C |
4 | 4 | # include <ws2tcpip.h> |
5 | 5 | #else |
6 | 6 | # include <netdb.h> |
7 | # include <sys/socket.h> | |
7 | 8 | #endif |
8 | 9 | |
9 | 10 | #ifdef __cplusplus |
11 | 12 | #endif |
12 | 13 | |
13 | 14 | extern int HX_socket_from_env(const struct addrinfo *, const char *intf); |
15 | extern int HX_sockaddr_is_local(const struct sockaddr *, socklen_t, unsigned int flags); | |
16 | extern int HX_ipaddr_is_local(const char *, unsigned int flags); | |
14 | 17 | |
15 | 18 | #ifdef __cplusplus |
16 | 19 | } /* extern "C" */ |
18 | 18 | /t?-rand |
19 | 19 | /t?-realpath |
20 | 20 | /t?-shconfig |
21 | /t?-socket | |
21 | 22 | /t?-strchr2 |
22 | 23 | /t?-string |
23 | 24 | /t?-strquote |
12 | 12 | mc.c misc.c opt.c proc.c \ |
13 | 13 | rand.c socket.c string.c time.c |
14 | 14 | libHX_la_LIBADD = ${libdl_LIBS} -lm ${libpthread_LIBS} ${librt_LIBS} |
15 | libHX_la_LDFLAGS = -no-undefined -version-info 35:0:3 | |
15 | libHX_la_LDFLAGS = -no-undefined -version-info 36:0:4 | |
16 | 16 | if WITH_GNU_LD |
17 | 17 | libHX_la_LDFLAGS += -Wl,--version-script=${srcdir}/libHX.map |
18 | 18 | endif |
35 | 35 | check_PROGRAMS = tc-compile tc-cast tc-deque tc-dir tc-format tc-io \ |
36 | 36 | tc-list tc-list2 tc-map tc-memmem tc-misc tc-netio \ |
37 | 37 | tc-option tc-proc tc-rand tc-realpath \ |
38 | tc-shconfig tc-strchr2 tc-string tc-strquote \ | |
38 | tc-shconfig tc-socket tc-strchr2 tc-string tc-strquote \ | |
39 | 39 | tc-switchuser tc-time |
40 | TESTS = tc-strchr2 tc-strquote | |
40 | TESTS = tc-format tc-strchr2 tc-strquote | |
41 | 41 | tc_cast_CFLAGS = ${AM_CFLAGS} -std=gnu99 |
42 | 42 | tc_cast_LDADD = libHX.la -lm |
43 | 43 | tc_compile_LDADD = libHX.la |
56 | 56 | tc_rand_LDADD = libHX.la |
57 | 57 | tc_realpath_LDADD = libHX.la |
58 | 58 | tc_shconfig_LDADD = libHX.la |
59 | tc_socket_LDADD = libHX.la | |
59 | 60 | tc_strchr2_LDADD = libHX.la |
60 | 61 | tc_string_LDADD = libHX.la |
61 | 62 | tc_strquote_LDADD = libHX.la |
100 | 100 | tc-map$(EXEEXT) tc-memmem$(EXEEXT) tc-misc$(EXEEXT) \ |
101 | 101 | tc-netio$(EXEEXT) tc-option$(EXEEXT) tc-proc$(EXEEXT) \ |
102 | 102 | tc-rand$(EXEEXT) tc-realpath$(EXEEXT) tc-shconfig$(EXEEXT) \ |
103 | tc-strchr2$(EXEEXT) tc-string$(EXEEXT) tc-strquote$(EXEEXT) \ | |
104 | tc-switchuser$(EXEEXT) tc-time$(EXEEXT) $(am__EXEEXT_1) | |
105 | TESTS = tc-strchr2$(EXEEXT) tc-strquote$(EXEEXT) $(am__EXEEXT_2) | |
103 | tc-socket$(EXEEXT) tc-strchr2$(EXEEXT) tc-string$(EXEEXT) \ | |
104 | tc-strquote$(EXEEXT) tc-switchuser$(EXEEXT) tc-time$(EXEEXT) \ | |
105 | $(am__EXEEXT_1) | |
106 | TESTS = tc-format$(EXEEXT) tc-strchr2$(EXEEXT) tc-strquote$(EXEEXT) \ | |
107 | $(am__EXEEXT_2) | |
106 | 108 | @HAVE_CXX_TRUE@am__append_6 = tx-compile tx-cast tx-deque tx-dir \ |
107 | 109 | @HAVE_CXX_TRUE@ tx-intdiff tx-list tx-list2 \ |
108 | 110 | @HAVE_CXX_TRUE@ tx-misc tx-netio \ |
243 | 245 | tc_shconfig_SOURCES = tc-shconfig.c |
244 | 246 | tc_shconfig_OBJECTS = tc-shconfig.$(OBJEXT) |
245 | 247 | tc_shconfig_DEPENDENCIES = libHX.la |
248 | tc_socket_SOURCES = tc-socket.c | |
249 | tc_socket_OBJECTS = tc-socket.$(OBJEXT) | |
250 | tc_socket_DEPENDENCIES = libHX.la | |
246 | 251 | tc_strchr2_SOURCES = tc-strchr2.c |
247 | 252 | tc_strchr2_OBJECTS = tc-strchr2.$(OBJEXT) |
248 | 253 | tc_strchr2_DEPENDENCIES = libHX.la |
353 | 358 | ./$(DEPDIR)/tc-netio.Po ./$(DEPDIR)/tc-option.Po \ |
354 | 359 | ./$(DEPDIR)/tc-proc.Po ./$(DEPDIR)/tc-rand.Po \ |
355 | 360 | ./$(DEPDIR)/tc-realpath.Po ./$(DEPDIR)/tc-shconfig.Po \ |
356 | ./$(DEPDIR)/tc-strchr2.Po ./$(DEPDIR)/tc-string.Po \ | |
357 | ./$(DEPDIR)/tc-strquote.Po ./$(DEPDIR)/tc-switchuser.Po \ | |
358 | ./$(DEPDIR)/tc-time.Po ./$(DEPDIR)/tc_cast-tc-cast.Po \ | |
361 | ./$(DEPDIR)/tc-socket.Po ./$(DEPDIR)/tc-strchr2.Po \ | |
362 | ./$(DEPDIR)/tc-string.Po ./$(DEPDIR)/tc-strquote.Po \ | |
363 | ./$(DEPDIR)/tc-switchuser.Po ./$(DEPDIR)/tc-time.Po \ | |
364 | ./$(DEPDIR)/tc_cast-tc-cast.Po \ | |
359 | 365 | ./$(DEPDIR)/tc_list2-tc-list2.Po ./$(DEPDIR)/time.Plo \ |
360 | 366 | ./$(DEPDIR)/tx-cast.Po ./$(DEPDIR)/tx-compile.Po \ |
361 | 367 | ./$(DEPDIR)/tx-deque.Po ./$(DEPDIR)/tx-dir.Po \ |
407 | 413 | tc-compile.c tc-deque.c tc-dir.c tc-format.c tc-io.c tc-list.c \ |
408 | 414 | tc-list2.c tc-map.c tc-memmem.c tc-misc.c tc-netio.c \ |
409 | 415 | tc-option.c tc-proc.c tc-rand.c tc-realpath.c tc-shconfig.c \ |
410 | tc-strchr2.c tc-string.c tc-strquote.c tc-switchuser.c \ | |
411 | tc-time.c $(tx_cast_SOURCES) $(tx_compile_SOURCES) \ | |
412 | $(tx_deque_SOURCES) $(tx_dir_SOURCES) $(tx_intdiff_SOURCES) \ | |
413 | $(tx_list_SOURCES) $(tx_list2_SOURCES) $(tx_misc_SOURCES) \ | |
414 | $(tx_netio_SOURCES) $(tx_option_SOURCES) $(tx_proc_SOURCES) \ | |
415 | $(tx_rand_SOURCES) $(tx_strchr2_SOURCES) $(tx_string_SOURCES) \ | |
416 | $(tx_strquote_SOURCES) $(tx_time_SOURCES) | |
416 | tc-socket.c tc-strchr2.c tc-string.c tc-strquote.c \ | |
417 | tc-switchuser.c tc-time.c $(tx_cast_SOURCES) \ | |
418 | $(tx_compile_SOURCES) $(tx_deque_SOURCES) $(tx_dir_SOURCES) \ | |
419 | $(tx_intdiff_SOURCES) $(tx_list_SOURCES) $(tx_list2_SOURCES) \ | |
420 | $(tx_misc_SOURCES) $(tx_netio_SOURCES) $(tx_option_SOURCES) \ | |
421 | $(tx_proc_SOURCES) $(tx_rand_SOURCES) $(tx_strchr2_SOURCES) \ | |
422 | $(tx_string_SOURCES) $(tx_strquote_SOURCES) $(tx_time_SOURCES) | |
417 | 423 | DIST_SOURCES = $(am__libHX_la_SOURCES_DIST) \ |
418 | 424 | $(libHX_rtcheck_la_SOURCES) tc-cast.c tc-compile.c tc-deque.c \ |
419 | 425 | tc-dir.c tc-format.c tc-io.c tc-list.c tc-list2.c tc-map.c \ |
420 | 426 | tc-memmem.c tc-misc.c tc-netio.c tc-option.c tc-proc.c \ |
421 | tc-rand.c tc-realpath.c tc-shconfig.c tc-strchr2.c tc-string.c \ | |
422 | tc-strquote.c tc-switchuser.c tc-time.c \ | |
427 | tc-rand.c tc-realpath.c tc-shconfig.c tc-socket.c tc-strchr2.c \ | |
428 | tc-string.c tc-strquote.c tc-switchuser.c tc-time.c \ | |
423 | 429 | $(am__tx_cast_SOURCES_DIST) $(am__tx_compile_SOURCES_DIST) \ |
424 | 430 | $(am__tx_deque_SOURCES_DIST) $(am__tx_dir_SOURCES_DIST) \ |
425 | 431 | $(am__tx_intdiff_SOURCES_DIST) $(am__tx_list_SOURCES_DIST) \ |
773 | 779 | proc.c rand.c socket.c string.c time.c $(am__append_3) |
774 | 780 | libHX_la_LIBADD = ${libdl_LIBS} -lm ${libpthread_LIBS} ${librt_LIBS} \ |
775 | 781 | $(am__append_4) |
776 | libHX_la_LDFLAGS = -no-undefined -version-info 35:0:3 $(am__append_2) | |
782 | libHX_la_LDFLAGS = -no-undefined -version-info 36:0:4 $(am__append_2) | |
777 | 783 | EXTRA_libHX_la_DEPENDENCIES = libHX.map |
778 | 784 | libHX_rtcheck_la_SOURCES = rtcheck.c |
779 | 785 | libHX_rtcheck_la_LIBADD = ${libdl_LIBS} |
798 | 804 | tc_rand_LDADD = libHX.la |
799 | 805 | tc_realpath_LDADD = libHX.la |
800 | 806 | tc_shconfig_LDADD = libHX.la |
807 | tc_socket_LDADD = libHX.la | |
801 | 808 | tc_strchr2_LDADD = libHX.la |
802 | 809 | tc_string_LDADD = libHX.la |
803 | 810 | tc_strquote_LDADD = libHX.la |
986 | 993 | @rm -f tc-shconfig$(EXEEXT) |
987 | 994 | $(AM_V_CCLD)$(LINK) $(tc_shconfig_OBJECTS) $(tc_shconfig_LDADD) $(LIBS) |
988 | 995 | |
996 | tc-socket$(EXEEXT): $(tc_socket_OBJECTS) $(tc_socket_DEPENDENCIES) $(EXTRA_tc_socket_DEPENDENCIES) | |
997 | @rm -f tc-socket$(EXEEXT) | |
998 | $(AM_V_CCLD)$(LINK) $(tc_socket_OBJECTS) $(tc_socket_LDADD) $(LIBS) | |
999 | ||
989 | 1000 | tc-strchr2$(EXEEXT): $(tc_strchr2_OBJECTS) $(tc_strchr2_DEPENDENCIES) $(EXTRA_tc_strchr2_DEPENDENCIES) |
990 | 1001 | @rm -f tc-strchr2$(EXEEXT) |
991 | 1002 | $(AM_V_CCLD)$(LINK) $(tc_strchr2_OBJECTS) $(tc_strchr2_LDADD) $(LIBS) |
1104 | 1115 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tc-rand.Po@am__quote@ # am--include-marker |
1105 | 1116 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tc-realpath.Po@am__quote@ # am--include-marker |
1106 | 1117 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tc-shconfig.Po@am__quote@ # am--include-marker |
1118 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tc-socket.Po@am__quote@ # am--include-marker | |
1107 | 1119 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tc-strchr2.Po@am__quote@ # am--include-marker |
1108 | 1120 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tc-string.Po@am__quote@ # am--include-marker |
1109 | 1121 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tc-strquote.Po@am__quote@ # am--include-marker |
1426 | 1438 | am__force_recheck=am--force-recheck \ |
1427 | 1439 | TEST_LOGS="$$log_list"; \ |
1428 | 1440 | exit $$? |
1441 | tc-format.log: tc-format$(EXEEXT) | |
1442 | @p='tc-format$(EXEEXT)'; \ | |
1443 | b='tc-format'; \ | |
1444 | $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ | |
1445 | --log-file $$b.log --trs-file $$b.trs \ | |
1446 | $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ | |
1447 | "$$tst" $(AM_TESTS_FD_REDIRECT) | |
1429 | 1448 | tc-strchr2.log: tc-strchr2$(EXEEXT) |
1430 | 1449 | @p='tc-strchr2$(EXEEXT)'; \ |
1431 | 1450 | b='tc-strchr2'; \ |
1579 | 1598 | -rm -f ./$(DEPDIR)/tc-rand.Po |
1580 | 1599 | -rm -f ./$(DEPDIR)/tc-realpath.Po |
1581 | 1600 | -rm -f ./$(DEPDIR)/tc-shconfig.Po |
1601 | -rm -f ./$(DEPDIR)/tc-socket.Po | |
1582 | 1602 | -rm -f ./$(DEPDIR)/tc-strchr2.Po |
1583 | 1603 | -rm -f ./$(DEPDIR)/tc-string.Po |
1584 | 1604 | -rm -f ./$(DEPDIR)/tc-strquote.Po |
1678 | 1698 | -rm -f ./$(DEPDIR)/tc-rand.Po |
1679 | 1699 | -rm -f ./$(DEPDIR)/tc-realpath.Po |
1680 | 1700 | -rm -f ./$(DEPDIR)/tc-shconfig.Po |
1701 | -rm -f ./$(DEPDIR)/tc-socket.Po | |
1681 | 1702 | -rm -f ./$(DEPDIR)/tc-strchr2.Po |
1682 | 1703 | -rm -f ./$(DEPDIR)/tc-string.Po |
1683 | 1704 | -rm -f ./$(DEPDIR)/tc-strquote.Po |
15 | 15 | #include <unistd.h> |
16 | 16 | #include <libHX.h> |
17 | 17 | #include "internal.h" |
18 | #undef HXformat_aprintf | |
19 | #undef HXformat_fprintf | |
20 | #undef HXformat_sprintf | |
21 | extern int HXformat_aprintf(const struct HXformat_map *, hxmc_t **, const char *); | |
22 | extern int HXformat_sprintf(const struct HXformat_map *, char *, size_t, const char *); | |
23 | extern int HXformat_fprintf(const struct HXformat_map *, FILE *, const char *); | |
18 | 24 | |
19 | 25 | /* To make it easier on the highlighter */ |
20 | 26 | #define C_OPEN '(' |
96 | 102 | |
97 | 103 | static const struct HXmap_ops func_entry_ops = { |
98 | 104 | .d_clone = func_entry_clone, |
105 | .d_free = free, | |
99 | 106 | }; |
100 | 107 | |
101 | 108 | EXPORT_SYMBOL void HXformat_free(struct HXformat_map *blk) |
296 | 303 | static hxmc_t *HXformat2_substr(int argc, const hxmc_t *const *argv, |
297 | 304 | const struct HXformat_map *blk) |
298 | 305 | { |
299 | ssize_t offset, length, z; | |
300 | 306 | hxmc_t *ret; |
301 | 307 | char *end; |
302 | 308 | |
305 | 311 | return &HXformat2_nexp; |
306 | 312 | } |
307 | 313 | |
308 | offset = strtoll(argv[1], &end, 0); | |
314 | long w = LONG_MAX, v = strtol(argv[1], &end, 0); | |
309 | 315 | if (*end != '\0') { |
310 | 316 | fprintf(stderr, "HXformat2-substr: found garbage in " |
311 | 317 | "offset specification\n"); |
312 | 318 | return &HXformat2_nexp; |
313 | 319 | } |
314 | ||
315 | z = strlen(argv[0]); | |
316 | if (offset < 0) | |
317 | offset = z + offset; | |
318 | if (offset >= z) | |
319 | return &HXformat2_nexp; | |
320 | ||
321 | if (argc == 2) { | |
322 | if (offset < 0) | |
323 | offset = 0; | |
324 | length = z - offset; | |
325 | } else { | |
326 | length = strtoll(argv[2], &end, 0); | |
320 | if (argc >= 3) { | |
321 | w = strtol(argv[2], &end, 0); | |
327 | 322 | if (*end != '\0') { |
328 | 323 | fprintf(stderr, "HXformat2-substr; found garbage in " |
329 | 324 | "length specification\n"); |
330 | 325 | return &HXformat2_nexp; |
331 | 326 | } |
332 | if (length < 0) | |
333 | length/*end*/ = z + length; | |
334 | else | |
335 | length/*end*/ = offset + length; | |
336 | if (offset < 0) | |
337 | offset = 0; | |
338 | } | |
339 | if (length <= 0) | |
340 | return &HXformat2_nexp; | |
341 | ||
342 | ret = HXmc_meminit(NULL, length); | |
327 | } | |
328 | size_t start = 0, tocopy = HX_substr_helper(strlen(argv[0]), v, w, &start); | |
329 | if (tocopy == 0) | |
330 | return &HXformat2_nexp; | |
331 | ret = HXmc_meminit(NULL, tocopy); | |
343 | 332 | if (ret == NULL) |
344 | 333 | return &HXformat2_nexp; |
345 | if (HXmc_memcpy(&ret, &argv[0][offset], length) == NULL) { | |
334 | if (HXmc_memcpy(&ret, &argv[0][start], tocopy) == NULL) { | |
346 | 335 | HXmc_free(ret); |
347 | 336 | return &HXformat2_nexp; |
348 | 337 | } |
642 | 631 | EXPORT_SYMBOL int HXformat_aprintf(const struct HXformat_map *blk, |
643 | 632 | hxmc_t **resultp, const char *fmt) |
644 | 633 | { |
634 | ssize_t ret = HXformat3_aprintf(blk, resultp, fmt); | |
635 | return ret > INT_MAX ? INT_MAX : ret; | |
636 | } | |
637 | ||
638 | EXPORT_SYMBOL ssize_t HXformat3_aprintf(const struct HXformat_map *blk, | |
639 | hxmc_t **resultp, const char *fmt) | |
640 | { | |
645 | 641 | hxmc_t *ex, *ts, *out; |
646 | 642 | const char *current; |
647 | 643 | int ret = 0; |
678 | 674 | } |
679 | 675 | |
680 | 676 | *resultp = out; |
681 | return HXmc_length(out); | |
677 | size_t xl = HXmc_length(out); | |
678 | return xl > SSIZE_MAX ? SSIZE_MAX : xl; | |
682 | 679 | |
683 | 680 | out: |
684 | 681 | ret = -errno; |
689 | 686 | EXPORT_SYMBOL int HXformat_fprintf(const struct HXformat_map *ftable, |
690 | 687 | FILE *filp, const char *fmt) |
691 | 688 | { |
689 | ssize_t ret = HXformat3_fprintf(ftable, filp, fmt); | |
690 | return ret > INT_MAX ? INT_MAX : ret; | |
691 | } | |
692 | ||
693 | EXPORT_SYMBOL ssize_t HXformat3_fprintf(const struct HXformat_map *ftable, | |
694 | FILE *filp, const char *fmt) | |
695 | { | |
692 | 696 | hxmc_t *str; |
693 | int ret; | |
694 | ||
695 | if ((ret = HXformat_aprintf(ftable, &str, fmt)) <= 0) | |
697 | ssize_t ret; | |
698 | ||
699 | if ((ret = HXformat3_aprintf(ftable, &str, fmt)) <= 0) | |
696 | 700 | return ret; |
697 | 701 | errno = 0; |
698 | 702 | if (fputs(str, filp) < 0) |
704 | 708 | EXPORT_SYMBOL int HXformat_sprintf(const struct HXformat_map *ftable, |
705 | 709 | char *dest, size_t size, const char *fmt) |
706 | 710 | { |
711 | ssize_t ret = HXformat3_sprintf(ftable, dest, size, fmt); | |
712 | return ret > INT_MAX ? INT_MAX : ret; | |
713 | } | |
714 | ||
715 | EXPORT_SYMBOL ssize_t HXformat3_sprintf(const struct HXformat_map *ftable, | |
716 | char *dest, size_t size, const char *fmt) | |
717 | { | |
707 | 718 | hxmc_t *str; |
708 | int ret; | |
719 | ssize_t ret; | |
709 | 720 | |
710 | 721 | if ((ret = HXformat_aprintf(ftable, &str, fmt)) < 0) |
711 | 722 | return ret; |
714 | 725 | return 0; |
715 | 726 | } |
716 | 727 | strncpy(dest, str, size); |
717 | ret = HXmc_length(dest); | |
728 | size_t xl = strlen(dest); | |
718 | 729 | HXmc_free(str); |
719 | return ret; | |
720 | } | |
730 | return xl > SSIZE_MAX ? SSIZE_MAX : xl; | |
731 | } |
9 | 9 | #define LIBHX_INTERNAL_H 1 |
10 | 10 | |
11 | 11 | #include "config.h" |
12 | #include <stdint.h> | |
12 | 13 | #include <libHX/defs.h> |
13 | 14 | #include <libHX/string.h> |
14 | 15 | |
55 | 56 | struct timeval; |
56 | 57 | |
57 | 58 | extern hxmc_t *HXparse_dequote_fmt(const char *, const char *, const char **); |
59 | extern size_t HX_substr_helper(size_t, long, long, size_t *); | |
58 | 60 | |
59 | 61 | #endif /* LIBHX_INTERNAL_H */ |
56 | 56 | static int mkdir_gen(const char *d, unsigned int mode) |
57 | 57 | { |
58 | 58 | struct stat sb; |
59 | if (lstat(d, &sb) < 0) { | |
60 | 59 | #if defined(_WIN32) |
61 | if (mkdir(d) < 0) | |
62 | #else | |
63 | if (mkdir(d, mode) < 0) /* use umask() for permissions */ | |
64 | #endif | |
65 | return -errno; | |
66 | } else { | |
60 | if (mkdir(d) == 0) | |
61 | #else | |
62 | if (mkdir(d, mode) == 0) /* use umask() for permissions */ | |
63 | #endif | |
64 | return 1; | |
65 | if (errno != EEXIST) | |
66 | return -errno; | |
67 | if (lstat(d, &sb) == 0) { | |
67 | 68 | #if defined(_WIN32) |
68 | if ((sb.st_mode & S_IFDIR) != S_IFDIR) | |
69 | #else | |
70 | if (!S_ISDIR(sb.st_mode)) | |
71 | #endif | |
72 | return -errno; | |
73 | } | |
74 | return 1; | |
69 | if (sb.st_mode & S_IFDIR) | |
70 | #else | |
71 | if (S_ISDIR(sb.st_mode)) | |
72 | #endif | |
73 | return 0; | |
74 | } | |
75 | return -EEXIST; | |
75 | 76 | } |
76 | 77 | |
77 | 78 | EXPORT_SYMBOL struct HXdir *HXdir_open(const char *s) |
203 | 204 | unlink(dest); |
204 | 205 | close(dstfd); |
205 | 206 | close(srcfd); |
207 | free(buf); | |
208 | va_end(argp); | |
206 | 209 | return -(errno = saved_errno); |
207 | 210 | } |
208 | 211 | uid = sb.st_uid; |
215 | 218 | unlink(dest); |
216 | 219 | close(dstfd); |
217 | 220 | close(srcfd); |
221 | free(buf); | |
222 | va_end(argp); | |
218 | 223 | return -(errno = saved_errno); |
219 | 224 | } |
220 | 225 | va_end(argp); |
228 | 233 | int saved_errno = errno; |
229 | 234 | close(srcfd); |
230 | 235 | close(dstfd); |
236 | free(buf); | |
231 | 237 | return -(errno = saved_errno); |
232 | 238 | } |
233 | 239 | } |
263 | 269 | continue; |
264 | 270 | snprintf(fsrc, MAXFNLEN, "%s/%s", src, fn); |
265 | 271 | snprintf(fdest, MAXFNLEN, "%s/%s", dest, fn); |
266 | ||
267 | lstat(fsrc, &sb); | |
272 | if (lstat(fsrc, &sb) < 0) | |
273 | continue; | |
268 | 274 | sb.st_mode &= 0777; /* clear SUID/GUID/Sticky bits */ |
269 | 275 | |
270 | 276 | if (S_ISREG(sb.st_mode)) { |
277 | 283 | memset(pt, '\0', MAXFNLEN); |
278 | 284 | if (readlink(fsrc, pt, MAXFNLEN - 1) < MAXFNLEN - 1) |
279 | 285 | if (symlink(pt, fdest) < 0) |
280 | {}; | |
286 | /* ignore */; | |
281 | 287 | } else if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) { |
282 | mknod(fdest, sb.st_mode, sb.st_dev); | |
288 | if (mknod(fdest, sb.st_mode, sb.st_dev) < 0) | |
289 | /* ignore */; | |
283 | 290 | } else if (S_ISFIFO(sb.st_mode)) { |
284 | mkfifo(fdest, sb.st_mode); | |
291 | if (mkfifo(fdest, sb.st_mode) < 0) | |
292 | /* ignore */; | |
285 | 293 | } |
286 | 294 | |
287 | 295 | if (lchown(fdest, uid, gid) < 0) |
288 | {}; | |
296 | /* ignore */; | |
289 | 297 | if (!S_ISLNK(sb.st_mode)) |
290 | chmod(fdest, sb.st_mode); | |
298 | if (chmod(fdest, sb.st_mode) < 0) | |
299 | /* ignore */; | |
291 | 300 | } |
292 | 301 | |
293 | 302 | HXdir_close(dt); |
320 | 329 | if (dir[i] == '/') { |
321 | 330 | strncpy(buf, dir, i); |
322 | 331 | buf[i] = '\0'; |
323 | if ((v = mkdir_gen(buf, mode)) <= 0) | |
332 | if ((v = mkdir_gen(buf, mode)) < 0) | |
324 | 333 | return v; |
325 | 334 | } else if (i == len - 1) { |
326 | 335 | strncpy(buf, dir, len); |
327 | 336 | buf[len] = '\0'; |
328 | if ((v = mkdir_gen(buf, mode)) <= 0) | |
337 | if ((v = mkdir_gen(buf, mode)) < 0) | |
329 | 338 | return v; |
330 | 339 | } |
331 | 340 | } |
357 | 366 | return -(errno = saved_errno); |
358 | 367 | } |
359 | 368 | if (static_cast(size_t, ret) < linkbuf_size) { |
360 | HXmc_setlen(target, ret); | |
369 | (*target)[ret] = '\0'; // please cov-scan | |
370 | HXmc_setlen(target, ret); // \0 set here anyway | |
361 | 371 | return ret; |
362 | 372 | } |
363 | 373 | linkbuf_size *= 2; |
499 | 509 | ret = HX_realpath_symres(&state, path); |
500 | 510 | if (ret == -EINVAL) |
501 | 511 | continue; |
502 | else if (ret < 0) | |
512 | else if (ret <= 0) | |
503 | 513 | goto out; |
504 | 514 | path = state.path; |
505 | 515 | } |
667 | 677 | xferd += ret; |
668 | 678 | count -= ret; |
669 | 679 | } |
680 | free(buf); | |
670 | 681 | if (xferd > 0) |
671 | 682 | return xferd; |
672 | 683 | if (ret < 0) |
149 | 149 | HX_unit_seconds; |
150 | 150 | HX_strtoull_sec; |
151 | 151 | } LIBHX_4.2; |
152 | ||
153 | LIBHX_4.9 { | |
154 | global: | |
155 | HXformat3_aprintf; | |
156 | HXformat3_fprintf; | |
157 | HXformat3_sprintf; | |
158 | HX_ipaddr_is_local; | |
159 | HX_sockaddr_is_local; | |
160 | } LIBHX_4.3; |
1303 | 1303 | trav->current = trav->path[--trav->depth]; |
1304 | 1304 | if (trav->current == NULL) |
1305 | 1305 | fprintf(stderr, "btrav_rewalk: problem: current==NULL\n"); |
1306 | HXrbtrav_checkpoint(trav, trav->current); | |
1306 | else | |
1307 | HXrbtrav_checkpoint(trav, trav->current); | |
1307 | 1308 | } |
1308 | 1309 | |
1309 | 1310 | trav->tid = btree->tid; |
1310 | if (go_next) | |
1311 | if (trav->current != nullptr && go_next) | |
1311 | 1312 | return HXrbtrav_next(trav); |
1312 | 1313 | else |
1313 | 1314 | return trav->current; |
7 | 7 | * either version 2.1 or (at your option) any later version. |
8 | 8 | */ |
9 | 9 | #include <stddef.h> |
10 | #include <stdint.h> | |
10 | 11 | #include <stdio.h> |
11 | 12 | #include <stdlib.h> |
12 | 13 | #include <string.h> |
19 | 20 | return sizeof(struct memcont) + len + 1; |
20 | 21 | } |
21 | 22 | |
22 | static __inline__ void HXmc_check(const struct memcont *c) | |
23 | { | |
24 | if (c->id != HXMC_IDENT) | |
23 | static __inline__ int HXmc_check(const struct memcont *c) | |
24 | { | |
25 | int err = c->id != HXMC_IDENT; | |
26 | if (err != 0) | |
25 | 27 | fprintf(stderr, "libHX-mc error: not a hxmc object!\n"); |
28 | return err; | |
26 | 29 | } |
27 | 30 | |
28 | 31 | static __inline__ struct memcont *HXmc_base(const hxmc_t *p) |
60 | 63 | struct memcont *ctx; |
61 | 64 | if (*vp != NULL) { |
62 | 65 | ctx = HXmc_base(*vp); |
63 | HXmc_check(ctx); | |
66 | if (HXmc_check(ctx) != 0) | |
67 | return nullptr; | |
64 | 68 | if (ctx->alloc < len) { |
65 | 69 | ctx = realloc(ctx, __HXmc_request(len)); |
66 | 70 | if (ctx == NULL) |
95 | 99 | if (vp == NULL) |
96 | 100 | return 0; |
97 | 101 | ctx = HXmc_base(vp); |
98 | HXmc_check(ctx); | |
102 | if (HXmc_check(ctx) != 0) | |
103 | return SIZE_MAX; | |
99 | 104 | return ctx->length; |
100 | 105 | } |
101 | 106 | |
114 | 119 | { |
115 | 120 | struct memcont *ctx = HXmc_base(*vp); |
116 | 121 | |
117 | HXmc_check(ctx); | |
122 | if (HXmc_check(ctx) != 0) | |
123 | return nullptr; | |
118 | 124 | if (len > ctx->alloc) { |
119 | 125 | ctx = realloc(ctx, __HXmc_request(len)); |
120 | 126 | if (ctx == NULL) |
140 | 146 | struct memcont *ctx = HXmc_base(*vp); |
141 | 147 | size_t nl = ctx->length + len; |
142 | 148 | |
143 | HXmc_check(ctx); | |
149 | if (HXmc_check(ctx) != 0) | |
150 | return nullptr; | |
144 | 151 | if (nl > ctx->alloc) { |
145 | 152 | ctx = realloc(ctx, __HXmc_request(nl)); |
146 | 153 | if (ctx == NULL) |
190 | 197 | struct memcont *ctx = HXmc_base(*vp); |
191 | 198 | size_t nl = ctx->length + len; |
192 | 199 | |
193 | HXmc_check(ctx); | |
200 | if (HXmc_check(ctx) != 0) | |
201 | return nullptr; | |
194 | 202 | if (ctx->alloc < nl) { |
195 | 203 | ctx = realloc(ctx, __HXmc_request(nl)); |
196 | 204 | if (ctx == NULL) |
211 | 219 | EXPORT_SYMBOL hxmc_t *HXmc_memdel(hxmc_t *vp, size_t pos, size_t len) |
212 | 220 | { |
213 | 221 | struct memcont *ctx = HXmc_base(vp); |
214 | HXmc_check(ctx); | |
215 | ||
222 | if (HXmc_check(ctx) != 0) | |
223 | return nullptr; | |
216 | 224 | if (pos + len > ctx->length) |
217 | 225 | len = ctx->length - pos; |
218 | 226 | |
229 | 237 | if (vp == NULL) |
230 | 238 | return; |
231 | 239 | ctx = HXmc_base(vp); |
232 | HXmc_check(ctx); | |
240 | if (HXmc_check(ctx) != 0) | |
241 | return; | |
233 | 242 | free(ctx); |
234 | 243 | } |
235 | 244 |
546 | 546 | key = HX_strdup(cur); |
547 | 547 | if (key == NULL) |
548 | 548 | return -errno; |
549 | ||
550 | 549 | value = strchr(key, '='); |
550 | if (value == nullptr) { | |
551 | /* Cannot happen because state is always !S_TWOLONG */ | |
552 | free(key); | |
553 | return -EINVAL; | |
554 | } | |
551 | 555 | *value++ = '\0'; |
552 | 556 | par->cbi.current = lookup_long_pfx(par->cbi.table, key + 2); |
553 | 557 | if (par->cbi.current == &HXopt_ambig_prefix) { |
698 | 702 | struct HX_getopt_vars ps; |
699 | 703 | const char **opt = *argv; |
700 | 704 | int state = HXOPT_S_NORMAL; |
701 | int ret = HXOPT_ERR_SUCCESS; | |
705 | int ret = -ENOMEM; | |
702 | 706 | unsigned int argk; |
703 | 707 | const char *cur; |
704 | 708 | |
705 | 709 | memset(&ps, 0, sizeof(ps)); |
706 | 710 | ps.remaining = HXdeque_init(); |
707 | if (ps.remaining == NULL) | |
711 | if (ps.remaining == NULL) { | |
712 | ret = -errno; | |
708 | 713 | goto out; |
714 | } | |
709 | 715 | ps.flags = flags; |
710 | 716 | ps.arg0 = **argv; |
711 | 717 | ps.cbi.table = table; |
713 | 719 | if (*opt != NULL) { |
714 | 720 | /* put argv[0] back */ |
715 | 721 | char *arg = HX_strdup(*opt++); |
716 | if (arg == NULL) | |
717 | goto out_errno; | |
722 | if (arg == NULL) { | |
723 | ret = -errno; | |
724 | goto out; | |
725 | } | |
718 | 726 | if (HXdeque_push(ps.remaining, arg) == NULL) { |
719 | 727 | free(arg); |
720 | goto out_errno; | |
728 | ret = -errno; | |
729 | goto out; | |
721 | 730 | } |
722 | 731 | } |
723 | 732 | |
724 | 733 | if (posix_me_harder()) |
725 | 734 | ps.flags |= HXOPT_RQ_ORDER; |
726 | ||
727 | 735 | for (cur = *opt; cur != NULL; ) { |
728 | 736 | if (state == HXOPT_S_TWOLONG) |
729 | 737 | state = HX_getopt_twolong(opt, &ps); |
738 | 746 | |
739 | 747 | if (state < 0) { |
740 | 748 | ret = state; |
741 | break; | |
749 | goto out; | |
742 | 750 | } |
743 | 751 | if (state & HXOPT_I_ERROR) { |
744 | 752 | ret = state & ~HXOPT_I_ERROR; |
745 | break; | |
753 | goto out; | |
746 | 754 | } |
747 | 755 | if (state & HXOPT_I_ASSIGN) |
748 | 756 | do_assign(&ps.cbi, ps.arg0); |
755 | 763 | state &= ~HXOPT_I_MASK; |
756 | 764 | } |
757 | 765 | |
758 | out: | |
759 | if (ret == HXOPT_ERR_SUCCESS) { | |
760 | if (!(ps.flags & HXOPT_KEEP_ARGV)) { | |
766 | if (!(ps.flags & HXOPT_KEEP_ARGV)) { | |
761 | 767 | const char **nvec = reinterpret_cast(const char **, |
762 | 768 | HXdeque_to_vec(ps.remaining, &argk)); |
763 | if (nvec == NULL) | |
764 | goto out_errno; | |
769 | if (nvec == NULL) { | |
770 | ret = -errno; | |
771 | goto out; | |
772 | } | |
765 | 773 | if (ps.flags & HXOPT_DESTROY_OLD) |
766 | 774 | /* |
767 | 775 | * Only the "true, original" argv is stored on the |
779 | 787 | /* pointers are owned by nvec/argv now */ |
780 | 788 | HXdeque_free(ps.remaining); |
781 | 789 | ps.remaining = nullptr; |
782 | } | |
790 | } | |
791 | ret = HXOPT_ERR_SUCCESS; | |
792 | ||
793 | out: | |
794 | if (ret == HXOPT_ERR_SUCCESS) { | |
783 | 795 | } else if (ret < 0) { |
784 | 796 | if (!(ps.flags & HXOPT_QUIET)) |
785 | 797 | fprintf(stderr, "%s: %s\n", __func__, strerror(errno)); |
793 | 805 | if (ps.remaining != nullptr) |
794 | 806 | HXdeque_genocide2(ps.remaining, free); |
795 | 807 | return ret; |
796 | ||
797 | out_errno: | |
798 | ret = -errno; | |
799 | goto out; | |
800 | 808 | } |
801 | 809 | |
802 | 810 | EXPORT_SYMBOL void HX_getopt_help(const struct HXoptcb *cbi, FILE *nfp) |
16 | 16 | #ifdef _WIN32 |
17 | 17 | # include <ws2tcpip.h> |
18 | 18 | #else |
19 | # include <netdb.h> | |
20 | # include <unistd.h> | |
21 | # include <netinet/in.h> | |
19 | 22 | # include <sys/socket.h> |
20 | # include <netdb.h> | |
23 | #endif | |
24 | #ifdef HAVE_SYS_UN_H | |
25 | # include <sys/un.h> | |
26 | #endif | |
27 | #ifdef __linux__ | |
28 | # include <linux/rtnetlink.h> | |
29 | #endif | |
30 | #ifdef __OpenBSD__ | |
31 | # include <net/route.h> | |
21 | 32 | #endif |
22 | 33 | #include <libHX/proc.h> |
23 | 34 | #include <libHX/socket.h> |
29 | 40 | #endif |
30 | 41 | #if defined(__sunos__) && !defined(SO_PROTOCOL) |
31 | 42 | # define SO_PROTOCOL SO_PROTOTYPE |
43 | #endif | |
44 | #ifndef AI_V4MAPPED | |
45 | # define AI_V4MAPPED 0 | |
32 | 46 | #endif |
33 | 47 | |
34 | 48 | static int try_sk_from_env(int fd, const struct addrinfo *ai, const char *intf) |
121 | 135 | errno = ENOENT; |
122 | 136 | return -1; |
123 | 137 | } |
138 | ||
139 | #ifdef __linux__ | |
140 | static int linux_sockaddr_local3(int sk, const void *buf, size_t bufsize) | |
141 | { | |
142 | if (send(sk, buf, bufsize, 0) < 0) | |
143 | return -errno; | |
144 | char rsp[4096]; | |
145 | ssize_t ret = recv(sk, rsp, sizeof(rsp), 0); | |
146 | if (ret < 0) | |
147 | return -errno; | |
148 | else if (static_cast(size_t, ret) < sizeof(struct nlmsghdr)) | |
149 | return -EIO; | |
150 | struct nlmsghdr nlh; | |
151 | memcpy(&nlh, rsp, sizeof(nlh)); | |
152 | if (!NLMSG_OK(&nlh, ret)) | |
153 | return -EIO; | |
154 | const struct rtmsg *rtm = static_cast(void *, rsp + NLMSG_HDRLEN); | |
155 | return rtm->rtm_type == RTN_LOCAL; | |
156 | } | |
157 | ||
158 | static int linux_sockaddr_local2(const struct sockaddr *sa, socklen_t sl) | |
159 | { | |
160 | int sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); | |
161 | if (sk < 0) | |
162 | return -errno; | |
163 | struct { | |
164 | struct nlmsghdr nh; | |
165 | struct rtmsg rth; | |
166 | char attrbuf[4096]; | |
167 | } req; | |
168 | memset(&req, 0, sizeof(req)); | |
169 | req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(req.rth)); | |
170 | req.nh.nlmsg_flags = NLM_F_REQUEST; | |
171 | req.nh.nlmsg_type = RTM_GETROUTE; | |
172 | req.rth.rtm_family = sa->sa_family; | |
173 | req.rth.rtm_protocol = RTPROT_UNSPEC; | |
174 | req.rth.rtm_type = RTN_UNSPEC; | |
175 | req.rth.rtm_scope = RT_SCOPE_UNIVERSE; | |
176 | req.rth.rtm_table = RT_TABLE_UNSPEC; | |
177 | struct rtattr *rta = reinterpret_cast(struct rtattr *, | |
178 | reinterpret_cast(char *, &req) + NLMSG_ALIGN(req.nh.nlmsg_len)); | |
179 | rta->rta_type = RTA_DST; | |
180 | ||
181 | int ret = -ENODATA; | |
182 | if (sa->sa_family == AF_INET6) { | |
183 | const struct in6_addr *ad = &reinterpret_cast(const struct sockaddr_in6 *, sa)->sin6_addr; | |
184 | req.rth.rtm_dst_len = 16; | |
185 | rta->rta_len = RTA_LENGTH(16); | |
186 | req.nh.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) + rta->rta_len; | |
187 | memcpy(RTA_DATA(rta), ad, 16); | |
188 | } else if (sa->sa_family == AF_INET) { | |
189 | struct in_addr ad = reinterpret_cast(const struct sockaddr_in *, sa)->sin_addr; | |
190 | req.rth.rtm_dst_len = 4; | |
191 | rta->rta_len = RTA_LENGTH(4); | |
192 | req.nh.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) + rta->rta_len; | |
193 | memcpy(RTA_DATA(rta), &ad, 4); | |
194 | } | |
195 | ret = linux_sockaddr_local3(sk, &req, req.nh.nlmsg_len); | |
196 | close(sk); | |
197 | return ret; | |
198 | } | |
199 | #endif | |
200 | ||
201 | #ifdef __OpenBSD__ | |
202 | static int openbsd_sockaddr_local3(int rsk, const void *buf, size_t bufsize) | |
203 | { | |
204 | ssize_t ret = send(rsk, buf, bufsize, 0); | |
205 | if (ret < 0) | |
206 | return -errno; | |
207 | else if (ret != bufsize) | |
208 | return -EIO; | |
209 | struct rt_msghdr rsp; | |
210 | do { | |
211 | ret = recv(rsk, &rsp, sizeof(rsp), 0); | |
212 | } while (ret > 0 && (rsp.rtm_version != RTM_VERSION || | |
213 | rsp.rtm_seq != 1 || rsp.rtm_pid != getpid())); | |
214 | return rsp.rtm_flags & RTF_LOCAL; | |
215 | } | |
216 | ||
217 | static int openbsd_sockaddr_local2(const struct sockaddr *sa, socklen_t sl) | |
218 | { | |
219 | int sk = socket(AF_ROUTE, SOCK_RAW, AF_UNSPEC); | |
220 | if (sk < 0) | |
221 | return -errno; | |
222 | struct { | |
223 | struct rt_msghdr rtm; | |
224 | char ab[512]; | |
225 | } req; | |
226 | memset(&req, 0, sizeof(req)); | |
227 | req.rtm.rtm_type = RTM_GET; | |
228 | req.rtm.rtm_version = RTM_VERSION; | |
229 | req.rtm.rtm_flags = RTF_STATIC | RTF_UP | RTF_HOST | RTF_GATEWAY; | |
230 | req.rtm.rtm_seq = 1; | |
231 | req.rtm.rtm_addrs = /*RTA_IFP |*/ RTA_DST; | |
232 | req.rtm.rtm_tableid = getrtable(); | |
233 | req.rtm.rtm_hdrlen = sizeof(req.rtm); | |
234 | memcpy(req.ab, sa, sl); | |
235 | req.rtm.rtm_msglen = sizeof(req.rtm) + sl; | |
236 | int ret = openbsd_sockaddr_local3(sk, &req, req.rtm.rtm_msglen); | |
237 | close(sk); | |
238 | return ret; | |
239 | } | |
240 | #endif | |
241 | ||
242 | EXPORT_SYMBOL int HX_sockaddr_is_local(const struct sockaddr *sa, socklen_t sl, | |
243 | unsigned int flags) | |
244 | { | |
245 | struct sockaddr_in xl = {}; | |
246 | ||
247 | if (sa->sa_family == AF_INET6) { | |
248 | if (sl < sizeof(struct sockaddr_in6)) | |
249 | return -EINVAL; | |
250 | } else if (sa->sa_family == AF_INET) { | |
251 | if (sl < sizeof(struct sockaddr_in)) | |
252 | return -EINVAL; | |
253 | } | |
254 | #ifdef HAVE_SYS_UN_H | |
255 | else if (sa->sa_family == AF_UNIX) { | |
256 | if (sl < sizeof(struct sockaddr_un)) | |
257 | return 1; | |
258 | } | |
259 | #endif | |
260 | else { | |
261 | return -EPROTONOSUPPORT; | |
262 | } | |
263 | if (flags & AI_V4MAPPED && sa->sa_family == AF_INET6) { | |
264 | /* | |
265 | * Preprocess mapped addresses, becuase kernel interfaces do | |
266 | * not support them. | |
267 | */ | |
268 | const struct in6_addr *ad = &reinterpret_cast(const struct sockaddr_in6 *, sa)->sin6_addr; | |
269 | static const uint8_t mappedv4[] = {0,0,0,0, 0,0,0,0, 0,0,0xff,0xff}; | |
270 | if (memcmp(ad, mappedv4, 12) == 0) { | |
271 | xl.sin_family = AF_INET; | |
272 | memcpy(&xl.sin_addr, &ad->s6_addr[12], 4); | |
273 | sa = reinterpret_cast(struct sockaddr *, &xl); | |
274 | sl = sizeof(xl); | |
275 | } | |
276 | } | |
277 | #if defined(__linux__) | |
278 | return linux_sockaddr_local2(sa, sl); | |
279 | #elif defined(__OpenBSD__) | |
280 | return openbsd_sockaddr_local2(sa, sl); | |
281 | #else | |
282 | if (sa->sa_family == AF_INET) { | |
283 | struct in_addr a = reinterpret_cast(const struct sockaddr_in *, sa)->sin_addr; | |
284 | return ntohl(a.s_addr) >> 24 == 127; | |
285 | } else if (sa->sa_family == AF_INET6) { | |
286 | return IN6_IS_ADDR_LOOPBACK(&reinterpret_cast(const struct sockaddr_in6 *, sa)->sin6_addr); | |
287 | } | |
288 | #endif | |
289 | return -EPROTONOSUPPORT; | |
290 | } | |
291 | ||
292 | EXPORT_SYMBOL int HX_ipaddr_is_local(const char *addr, unsigned int flags) | |
293 | { | |
294 | struct addrinfo hints = {.ai_flags = flags & AI_V4MAPPED}; | |
295 | struct addrinfo *r = nullptr; | |
296 | int err = getaddrinfo(addr, nullptr, &hints, &r); | |
297 | if (err != 0) { | |
298 | freeaddrinfo(r); | |
299 | return 0; | |
300 | } | |
301 | int lcl = HX_sockaddr_is_local(r->ai_addr, r->ai_addrlen, hints.ai_flags); | |
302 | freeaddrinfo(r); | |
303 | return lcl; | |
304 | } |
26 | 26 | * all others pass through |
27 | 27 | */ |
28 | 28 | enum HX_quote_selector { |
29 | HXQUOTE_ALWAYS, | |
29 | 30 | HXQUOTE_ACCEPT, |
30 | 31 | HXQUOTE_REJECT, |
31 | 32 | }; |
210 | 211 | *cp = max; |
211 | 212 | |
212 | 213 | ret = malloc(sizeof(char *) * (*cp + 1)); |
214 | if (ret == nullptr) | |
215 | return nullptr; | |
213 | 216 | ret[*cp] = NULL; |
214 | 217 | |
215 | 218 | { |
377 | 380 | return const_cast1(char *, p); |
378 | 381 | } |
379 | 382 | |
383 | /** | |
384 | * Helper for substr() function for dealing with negative off/len values | |
385 | * @z: total length of string | |
386 | * @offset: n>=0 specifies offset from the start, | |
387 | * n<0 specifies offset from the end | |
388 | * @len: "length"; n>=0 specifies length to copy (from @offset), | |
389 | * n<0 specifies the byte relative to the end at which to stop | |
390 | * | |
391 | * @abstart: (result) absolute start | |
392 | * @retval: (result) absolute length to copy (from *@abstart) | |
393 | */ | |
394 | size_t HX_substr_helper(size_t z, long offset, long len, size_t *start) | |
395 | { | |
396 | if (offset >= 0) | |
397 | *start = offset; | |
398 | else if (offset == LONG_MIN) | |
399 | *start = z + -static_cast(size_t, LONG_MIN); | |
400 | else | |
401 | *start = z >= static_cast(unsigned long, -offset) ? z + offset : z; | |
402 | ||
403 | size_t end; | |
404 | if (len >= 0) | |
405 | end = *start < SIZE_MAX - len ? *start + len : SIZE_MAX; | |
406 | else if (len == LONG_MIN) | |
407 | end = z + -static_cast(unsigned long, LONG_MIN); | |
408 | else | |
409 | end = z >= static_cast(unsigned long, -len) ? z + len : 0; | |
410 | if (end > z) | |
411 | end = z; | |
412 | return end > *start ? end - *start : 0; | |
413 | } | |
414 | ||
380 | 415 | /* supports negative offsets like scripting languages */ |
381 | 416 | EXPORT_SYMBOL char *HX_strmid(const char *expr, long offset, long length) |
382 | 417 | { |
383 | char *buffer; | |
384 | ||
385 | if (offset < 0) | |
386 | offset = strlen(expr) + offset; | |
387 | if (length < 0) | |
388 | length = strlen(expr) - offset + length; | |
389 | if ((buffer = malloc(length + 1)) == NULL) | |
390 | return NULL; | |
391 | ||
392 | expr += offset; | |
393 | return HX_strlcpy(buffer, expr, length + 1); | |
418 | size_t start = 0, tocopy = HX_substr_helper(strlen(expr), offset, length, &start); | |
419 | char *buffer = malloc(tocopy + 1); | |
420 | if (buffer == nullptr) | |
421 | return NULL; | |
422 | memcpy(buffer, &expr[start], tocopy); | |
423 | buffer[tocopy] = '\0'; | |
424 | return buffer; | |
394 | 425 | } |
395 | 426 | |
396 | 427 | EXPORT_SYMBOL char *HX_strndup(const char *src, size_t size) |
772 | 803 | EXPORT_SYMBOL char *HX_strquote(const char *src, unsigned int type, |
773 | 804 | char **free_me) |
774 | 805 | { |
775 | const struct HX_quote_rule *rule; | |
806 | const struct HX_quote_rule *rule = nullptr; | |
776 | 807 | bool do_quote; |
777 | 808 | char *tmp; |
778 | 809 | |
781 | 812 | return NULL; |
782 | 813 | } |
783 | 814 | /* If quote_chars is NULL, it is clear all chars are to be encoded. */ |
784 | rule = &HX_quote_rules[type]; | |
785 | if (type >= ARRAY_SIZE(HX_quote_rules) || rule->chars == NULL) | |
815 | if (type >= ARRAY_SIZE(HX_quote_rules)) { | |
786 | 816 | do_quote = true; |
787 | else if (rule->selector == HXQUOTE_REJECT) | |
788 | do_quote = strpbrk(src, rule->chars) != NULL; | |
789 | else if (rule->selector == HXQUOTE_ACCEPT) | |
790 | do_quote = HX_strchr2(src, rule->chars) != NULL; | |
791 | else | |
792 | do_quote = false; | |
817 | } else { | |
818 | rule = &HX_quote_rules[type]; | |
819 | if (rule->selector == HXQUOTE_ALWAYS) | |
820 | do_quote = true; | |
821 | else if (rule->selector == HXQUOTE_REJECT) | |
822 | do_quote = strpbrk(src, rule->chars) != NULL; | |
823 | else if (rule->selector == HXQUOTE_ACCEPT) | |
824 | do_quote = HX_strchr2(src, rule->chars) != NULL; | |
825 | else | |
826 | do_quote = false; | |
827 | } | |
793 | 828 | /* |
794 | 829 | * free_me == NULL implies that we always allocate, even if |
795 | 830 | * there is nothing to quote. |
0 | /* | |
1 | * Testing for compile error in the cast helpers | |
2 | * written by Jan Engelhardt | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the WTF Public License version 2 or | |
6 | * (at your option) any later version. | |
7 | */ | |
0 | // SPDX-License-Identifier: MIT | |
8 | 1 | #include <math.h> |
9 | 2 | #include <stdint.h> |
10 | 3 | #include <stdio.h> |
0 | /* | |
1 | * Copyright Jan Engelhardt | |
2 | * | |
3 | * This program is free software; you can redistribute it and/or | |
4 | * modify it under the terms of the WTF Public License version 2 or | |
5 | * (at your option) any later version. | |
6 | */ | |
0 | // SPDX-License-Identifier: MIT | |
7 | 1 | #ifndef __cplusplus |
8 | 2 | # include <stdio.h> |
9 | 3 | # include <stdlib.h> |
0 | /* | |
1 | * formatter test program | |
2 | * Copyright by Jan Engelhardt | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the WTF Public License version 2 or | |
6 | * (at your option) any later version. | |
7 | */ | |
0 | // SPDX-License-Identifier: MIT | |
8 | 1 | #include <stdint.h> |
9 | 2 | #include <stdio.h> |
10 | 3 | #include <stdlib.h> |
54 | 47 | NULL, |
55 | 48 | }; |
56 | 49 | |
57 | static void t_format(int argc) | |
50 | static int t_format(int argc) | |
58 | 51 | { |
59 | 52 | struct HXformat_map *fmt = HXformat_init(); |
60 | 53 | const char *const *s; |
69 | 62 | HXformat_add(fmt, "TWOARG", "a, b", HXTYPE_STRING | HXFORMAT_IMMED); |
70 | 63 | ++argc; |
71 | 64 | printf("# HXformat2\n"); |
72 | for (s = fmt2_strings; *s != NULL; ++s) | |
73 | HXformat_fprintf(fmt, stdout, *s); | |
65 | for (s = fmt2_strings; *s != NULL; ++s) { | |
66 | char buf[80]; | |
67 | if (HXformat_sprintf(fmt, buf, ARRAY_SIZE(buf), *s) < 0 || | |
68 | HXformat_fprintf(fmt, stdout, *s) < 0) | |
69 | return EXIT_FAILURE; | |
70 | } | |
74 | 71 | HXformat_free(fmt); |
72 | return EXIT_SUCCESS; | |
75 | 73 | } |
76 | 74 | |
77 | 75 | int main(int argc, const char **argv) |
83 | 81 | fprintf(stderr, "HX_init: %s\n", strerror(-ret)); |
84 | 82 | return EXIT_FAILURE; |
85 | 83 | } |
86 | t_format(argc); | |
84 | ret = t_format(argc); | |
87 | 85 | HX_exit(); |
88 | return EXIT_SUCCESS; | |
86 | return ret; | |
89 | 87 | } |
0 | // SPDX-License-Identifier: MIT | |
0 | 1 | #include <errno.h> |
1 | 2 | #include <fcntl.h> |
2 | 3 | #include <stdint.h> |
0 | /* | |
1 | * Copyright Jan Engelhardt | |
2 | * | |
3 | * This program is free software; you can redistribute it and/or | |
4 | * modify it under the terms of the WTF Public License version 2 or | |
5 | * (at your option) any later version. | |
6 | */ | |
0 | // SPDX-License-Identifier: MIT | |
7 | 1 | #ifdef __cplusplus |
8 | 2 | # include <cstdio> |
9 | 3 | # include <cstdlib> |
0 | /* | |
1 | * Copyright Jan Engelhardt | |
2 | * | |
3 | * This program is free software; you can redistribute it and/or | |
4 | * modify it under the terms of the WTF Public License version 2 or | |
5 | * (at your option) any later version. | |
6 | */ | |
0 | // SPDX-License-Identifier: MIT | |
7 | 1 | #include <stdio.h> |
8 | 2 | #include <stdlib.h> |
9 | 3 | #include <libHX/list.h> |
0 | /* | |
1 | * Test for libHX's maps | |
2 | * Copyright Jan Engelhardt | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the WTF Public License version 2 or | |
6 | * (at your option) any later version. | |
7 | */ | |
0 | // SPDX-License-Identifier: MIT | |
8 | 1 | #include "config.h" |
9 | 2 | #include <errno.h> |
10 | 3 | #include <math.h> |
0 | // SPDX-License-Identifier: MIT | |
0 | 1 | /* |
1 | 2 | * speed test HX_memmem |
2 | * Copyright Jan Engelhardt | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the WTF Public License version 2 or | |
6 | * (at your option) any later version. | |
7 | 3 | */ |
8 | 4 | #include <stdio.h> |
9 | 5 | #include <stdlib.h> |
0 | /* | |
1 | * Copyright Jan Engelhardt | |
2 | * | |
3 | * This program is free software; you can redistribute it and/or | |
4 | * modify it under the terms of the WTF Public License version 2 or | |
5 | * (at your option) any later version. | |
6 | */ | |
0 | // SPDX-License-Identifier: MIT | |
7 | 1 | #ifndef __cplusplus |
8 | 2 | # include <stdlib.h> |
9 | 3 | #else |
37 | 31 | if (stat(argv[1], &sa) < 0 || |
38 | 32 | stat(argv[2], &sb) < 0) |
39 | 33 | perror("stat"); |
40 | printf("Difference: %ld\n", HX_time_compare(&sa, &sb, 'm')); | |
34 | else | |
35 | printf("Difference: %ld\n", HX_time_compare(&sa, &sb, 'm')); | |
41 | 36 | } |
42 | 37 | |
43 | 38 | HX_exit(); |
0 | /* | |
1 | * Copyright Jan Engelhardt | |
2 | * | |
3 | * This program is free software; you can redistribute it and/or | |
4 | * modify it under the terms of the WTF Public License version 2 or | |
5 | * (at your option) any later version. | |
6 | */ | |
0 | // SPDX-License-Identifier: MIT | |
7 | 1 | #define WIN32_LEAN_AND_MEAN 1 |
8 | 2 | #ifdef __cplusplus |
9 | 3 | # include <cstdlib> |
0 | // SPDX-License-Identifier: MIT | |
1 | // SPDX-FileCopyrightText: 2022 Jan Engelhardt | |
0 | 2 | /* |
1 | 3 | * option parser test program |
2 | * Copyright Jan Engelhardt | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the WTF Public License version 2 or | |
6 | * (at your option) any later version. | |
7 | 4 | */ |
8 | 5 | #include <errno.h> |
9 | 6 | #include <stdio.h> |
0 | /* | |
1 | * Copyright Jan Engelhardt | |
2 | * | |
3 | * This program is free software; you can redistribute it and/or | |
4 | * modify it under the terms of the WTF Public License version 2 or | |
5 | * (at your option) any later version. | |
6 | */ | |
0 | // SPDX-License-Identifier: MIT | |
7 | 1 | #ifdef __cplusplus |
8 | 2 | # include <cerrno> |
9 | 3 | # include <cstdio> |
0 | /* | |
1 | * Copyright Jan Engelhardt | |
2 | * | |
3 | * This program is free software; you can redistribute it and/or | |
4 | * modify it under the terms of the WTF Public License version 2 or | |
5 | * (at your option) any later version. | |
6 | */ | |
0 | // SPDX-License-Identifier: MIT | |
7 | 1 | #include <stdio.h> |
8 | 2 | #include <stdlib.h> |
9 | 3 | #include <time.h> |
0 | // SPDX-License-Identifier: MIT | |
0 | 1 | /* |
1 | 2 | * Test utility for libHX's realpath |
2 | * Copyright Jan Engelhardt | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the WTF Public License version 2 or | |
6 | * (at your option) any later version. | |
7 | 3 | */ |
8 | 4 | #include <stdbool.h> |
9 | 5 | #include <stdio.h> |
0 | 0 | /* |
1 | 1 | A=b;C="d" ; E="F;" ; F= G=Z |
2 | 2 | */ |
3 | // SPDX-License-Identifier: MIT | |
3 | 4 | /* |
4 | 5 | * shconfig test program |
5 | * Copyright Jan Engelhardt | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the WTF Public License version 2 or | |
9 | * (at your option) any later version. | |
10 | 6 | */ |
11 | 7 | #include <errno.h> |
12 | 8 | #include <stdio.h> |
0 | // SPDX-License-Identifier: MIT | |
1 | #include <errno.h> | |
2 | #include <stdio.h> | |
3 | #include <stdlib.h> | |
4 | #include <string.h> | |
5 | #include <libHX/defs.h> | |
6 | #include <libHX/socket.h> | |
7 | #ifndef _WIN32 | |
8 | # include <netdb.h> | |
9 | #endif | |
10 | #ifndef AI_V4MAPPED | |
11 | # define AI_V4MAPPED 0 | |
12 | #endif | |
13 | ||
14 | int main(void) | |
15 | { | |
16 | static const char *addrs[] = { | |
17 | "::1", "::2", "::ffff:127.0.0.1", "::", | |
18 | "127.0.0.1", "127.0.0.2", "1.1.1.1", "255.255.255.255", | |
19 | }; | |
20 | for (size_t i = 0; i < ARRAY_SIZE(addrs); ++i) { | |
21 | printf("%-16s\t", addrs[i]); | |
22 | int lcl = HX_ipaddr_is_local(addrs[i], AI_V4MAPPED); | |
23 | if (lcl < 0) { | |
24 | printf("%s\n", strerror(-lcl)); | |
25 | return EXIT_FAILURE; | |
26 | } | |
27 | printf("%d\n", lcl); | |
28 | } | |
29 | return EXIT_SUCCESS; | |
30 | } |
0 | // SPDX-License-Identifier: MIT | |
0 | 1 | /* |
1 | 2 | * Behavior Correctness Test for HX_strchr2 |
2 | * Copyright Jan Engelhardt, 2013 | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the WTF Public License version 2 or | |
6 | * (at your option) any later version. | |
7 | 3 | */ |
8 | 4 | #include <libHX/string.h> |
9 | 5 |
0 | 0 | /* long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing long line for testing */ |
1 | /* | |
2 | * Copyright Jan Engelhardt | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the WTF Public License version 2 or | |
6 | * (at your option) any later version. | |
7 | */ | |
1 | // SPDX-License-Identifier: MIT | |
8 | 2 | #ifndef __cplusplus |
9 | 3 | # include <assert.h> |
10 | 4 | # include <errno.h> |
479 | 473 | } |
480 | 474 | } |
481 | 475 | |
476 | static int t_strmid(void) | |
477 | { | |
478 | #define T(spar,opar,lpar,xpar) do { \ | |
479 | char *s = HX_strmid((spar), (opar), (lpar)); \ | |
480 | if (s == nullptr) \ | |
481 | return EXIT_FAILURE; \ | |
482 | int ret = strcmp(s, (xpar)); \ | |
483 | if (ret != 0) { \ | |
484 | fprintf(stderr, "Faillure: substr %s,%d,%d = %s\n", \ | |
485 | (spar), static_cast(int, (opar)), static_cast(int, (lpar)), s); \ | |
486 | free(s); \ | |
487 | return ret; \ | |
488 | } \ | |
489 | free(s); \ | |
490 | } while (false) | |
491 | ||
492 | T("Hello World", -12, 5, ""); | |
493 | T("bark", -3, -1, "ar"); | |
494 | T("cake", -3, -3, ""); | |
495 | T("cake", -3, -4, ""); | |
496 | T("fun", 0, 0, ""); | |
497 | T("bark", 0, 1, "b"); | |
498 | T("bark", 0, 5, "bark"); | |
499 | T("bark", -4, 1, "b"); | |
500 | T("bark", -4, 5, "bark"); | |
501 | return EXIT_SUCCESS; | |
502 | #undef T | |
503 | } | |
504 | ||
482 | 505 | int main(int argc, const char **argv) |
483 | 506 | { |
484 | 507 | hxmc_t *tx = NULL; |
487 | 510 | |
488 | 511 | if (HX_init() <= 0) |
489 | 512 | abort(); |
513 | int ret = t_strmid(); | |
514 | if (ret != EXIT_SUCCESS) | |
515 | return EXIT_FAILURE; | |
490 | 516 | |
491 | 517 | fp = fopen(file, "r"); |
492 | 518 | if (fp == NULL) { |
0 | // SPDX-License-Identifier: MIT | |
0 | 1 | /* |
1 | 2 | * Behavior Correctness Test for HX_strquote |
2 | * Copyright Jan Engelhardt, 2013 | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the WTF Public License version 2 or | |
6 | * (at your option) any later version. | |
7 | 3 | */ |
8 | 4 | #include <stdbool.h> |
9 | 5 | #include <stdio.h> |
0 | /* | |
1 | * Copyright Jan Engelhardt | |
2 | * | |
3 | * This program is free software; you can redistribute it and/or | |
4 | * modify it under the terms of the WTF Public License version 2 or | |
5 | * (at your option) any later version. | |
6 | */ | |
0 | // SPDX-License-Identifier: MIT | |
7 | 1 | #ifdef HAVE_CONFIG_H |
8 | 2 | # include "config.h" |
9 | 3 | #endif |
10 | #if defined(HAVE_INITGROUPS) | |
11 | 4 | #include <errno.h> |
12 | 5 | #include <stdio.h> |
13 | 6 | #include <stdlib.h> |
16 | 9 | #include <libHX/defs.h> |
17 | 10 | #include <libHX/option.h> |
18 | 11 | #include <libHX/proc.h> |
12 | #if defined(HAVE_INITGROUPS) | |
19 | 13 | |
20 | 14 | static char *user_name, *group_name; |
21 | 15 | static const struct HXoption options_table[] = { |
69 | 63 | } |
70 | 64 | return EXIT_SUCCESS; |
71 | 65 | } |
66 | #else | |
67 | int main(void) | |
68 | { | |
69 | return EXIT_SUCCESS; | |
70 | } | |
72 | 71 | #endif |
0 | /* | |
1 | * Copyright Jan Engelhardt, 2012 | |
2 | * | |
3 | * This program is free software; you can redistribute it and/or | |
4 | * modify it under the terms of the WTF Public License version 2 or | |
5 | * (at your option) any later version. | |
6 | */ | |
0 | // SPDX-License-Identifier: MIT | |
7 | 1 | #include <assert.h> |
8 | 2 | #include <math.h> |
9 | 3 | #include <stdio.h> |
26 | 20 | static const long long NANOSECOND_LL = 1000000000; |
27 | 21 | static const unsigned int clock_id = CLOCK_THREAD_CPUTIME_ID; |
28 | 22 | static const unsigned int step = 1000; |
29 | static const unsigned int step_mul = 10000000; | |
23 | static const long step_mul = 10000000; | |
30 | 24 | |
31 | 25 | static const struct timespec pairs[] = { |
32 | 26 | {-1, 700000000}, {-1, 400000000}, {-1, 0}, |
0 | /* | |
1 | * Copyright Jan Engelhardt | |
2 | * | |
3 | * This program is free software; you can redistribute it and/or | |
4 | * modify it under the terms of the WTF Public License version 2 or | |
5 | * (at your option) any later version. | |
6 | */ | |
0 | // SPDX-License-Identifier: MIT | |
7 | 1 | #include <stdbool.h> |
8 | 2 | #include <stdio.h> |
9 | 3 | #include <libxml/parser.h> |