1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/* extlib.c
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <stdbool.h>
#ifdef USE_SECURE_MEM
#define free(x) error - use free_secure
/// Automatically zero out a pointer before freeing it
void free_secure (void **__ptr, size_t ptrlen);
/// DEPRECATED: use calloc
/// Automatically initialise the allocated memory with zeros
void *malloc_secure (size_t len);
#endif
#if (__STDC_WANT_LIB_EXT1__ == 1)
#ifndef RSIZE_MAX
#define RSIZE_MAX SIZE_MAX
#endif
typedef int errno_t;
typedef size_t rsize_t;
typedef void (*constraint_handler_t) (const char *__restrict,
void *__restrict, errno_t);
/// Copy the value of c (converted to an unsigned char) into each of the first n
/// characters of the object pointed to by s.
/// Conforms to ISO/IEC 9899:2011 K.3.7.4.1
errno_t memset_s (void *s, rsize_t max, int c, rsize_t n);
constraint_handler_t set_constraint_handler_s (constraint_handler_t handler);
void throw_constraint_handler_s (const char *restrict msg, errno_t error);
_Noreturn void abort_handler_s (const char *__restrict, void *__restrict,
errno_t);
void ignore_handler_s (const char *__restrict, void *__restrict, errno_t);
#endif
/// Copy the data of one filestream to another
/// Returns the amount of bytes copied.
size_t fcopy (FILE * src, FILE * dst);
#if (_XOPEN_SOURCE == 500)
/// Recursively remove a directory pathname.
int rrmdir (char *pathname);
#endif
/// Compare the first n bytes of a memory area str to the value val.
/// Returns 0 if the values the same, any other value if they are not the same.
int memvcmp (void *str, char val, size_t n);
/// Convert a string to lowercase
char *strlwr (char *s);
/// Convert a string to uppercase
char *strupr (char *s);
/// Trim spaces from a string
char *trim (char *s, int *rem_front, int *rem_back);
/// Match string s for old and replace it with string replace
char *replace_str (char *s, char *old, char *replace);
/// Join an array of strings into one string
char *join_str (char **s, size_t len, char *delim);
/// Limit a value to a maximum
float max (float v, float max_v);
/// Limit a value to a minimum
float min (float v, float min_v);
/// Limit a value between min and max
float cap (float v, float min_v, float max_v);
#ifndef STYLESDEF
/// Original 16 terminal colors
enum colors16 {
BLACK,
RED,
GREEN,
YELLOW,
BLUE,
MAGENTA,
CYAN,
WHITE,
GRAY,
BRIGHTRED,
BRIGHTGREEN,
BRIGHTYELLOW,
BRIGHTBLUE,
BRIGHTMAGENTA,
BRIGHTCYAN,
BRIGHTWHITE
};
enum grayscale {
GRAY1 = 232,
GRAY2,
GRAY3,
GRAY4,
GRAY5,
GRAY6,
GRAY7,
GRAY8,
GRAY9,
GRAY10,
GRAY11,
GRAY12,
GRAY13,
GRAY14,
GRAY15,
GRAY16,
GRAY17,
GRAY18,
GRAY19,
GRAY20,
GRAY21,
GRAY22,
GRAY23,
GRAY24
};
enum effects {
BOLD = 1,
DIM = 2,
ITALIC = 4,
UNDERLINE = 8,
BLINKING = 16,
INVERSE = 32,
HIDDEN = 64,
STRIKETHROUGH = 128
};
struct style {
int color;
bool background;
int styles;
};
#define STYLESDEF
#endif
/// Format a string with ANSI escape codes
char *strfmt (char *s, struct style);
|