add strtonum
[single-header-libcext.git] / README.md
1 A collection of portable, strict C99, single-header implementations of common libc extensions.
2
3 All functions are implemented as macros expanding to an internal function reference, this allows to use the headers with no meta build system - it compiles even if the extensions are already present, see _How to_ on disabling this behaviour.
4
5 ### How to
6
7 Include the header in every file needed as usual:
8
9 ```
10 #include "<ext-func-name>.h"
11 ```
12
13 In the file chosen for the function implementation:
14
15 ```
16 #define <EXT-FUNC-NAME>_IMPLEMENTATION
17 #include "<ext-func-name.h>"
18 ```
19
20 By default, the header won't have any stdlib includes, change that with:
21
22 ```
23 #define <EXT-FUNC-NAME>_INCLUDE_LIBC
24 ```
25
26 Or disable function, type and variable override with:
27
28 ```
29 #define HAVE_<EXT-FUNC-NAME>
30 ```
31
32 ### Specifics
33
34 ---
35
36 ### asprintf
37
38 includes `vasprintf()` and `asprintf()`
39
40 ---
41
42 ### fgetln
43
44 includes `fgetln()`
45
46 ---
47
48 ### getopt\_long
49
50 includes `getopt()`, `getsubopt()`, `getopt_long()` and `getopt_long_only()`
51
52 `getopt_long.h` has additional macros related to argument
53 permuting, defining those enables it per function (GNU behaviour, can still be disabled at runtime by setting `$POSIXLY_CORRECT`):
54
55 ```
56 #define GETOPT_PERMUTE_ARGS
57 #define GETOPT_LONG_PERMUTE_ARGS
58 #define GETOPT_LONG_ONLY_PERMUTE_ARGS
59 ```
60
61 ---
62
63 ### strdup
64
65 includes `strdup()` and `strndup()`
66
67 `strndup()` follows the latest standard, meaning that it copies at most _n_ chars, not _n_ + 1.
68 Also, no standard specifies that `strndup()` should return less than _n_ if `strlen(s) + 1` < _n_, but this implementation does so.
69
70 ---
71
72 ### strlcat
73
74 includes `strlcat()` and `strlcpy()`
75
76 ---
77
78 ### strtonum
79
80 includes `strtonum()`