72 assert(strlen(from) >= strlen(to) &&
"Longer dst pattern than src!");
73 assert(strlen(from) > 0 &&
"From pattern should be non-empty!");
75 while ((tmp = strstr(tmp, from)) != NULL) {
76 memcpy(tmp, to, strlen(to));
77 if (strlen(to) < strlen(from)) {
78 size_t len = strlen(tmp + strlen(from));
79 char *src = tmp + strlen(from);
80 char *dst = tmp + strlen(to);
81 memmove(dst, src,
len);
92 return strncasecmp(haystack, needle, strlen(needle)) == 0;
96 char *end = s + strlen(s) - 1;
98 const char *accept_it = accept;
99 while (*accept_it !=
'\0') {
100 if (*accept_it++ == *end) {
109bool ends_with(
const char *haystick,
const char *needle) {
110 if (strlen(haystick) < strlen(needle)) {
113 return strcmp(haystick + strlen(haystick) - strlen(needle), needle) == 0;
135void strappend(
char **ptr,
const char *ptr_end,
const char *src) {
136 while (*src !=
'\0') {
137 if (*ptr == ptr_end) {
145 const char *ptr =
msg;
147 ssize_t written = write(fd, ptr,
len);
167#define SIGERR(x) [x] = #x
169 const char *signames[NSIG] = {
170 SIGERR(SIGINT), SIGERR(SIGILL), SIGERR(SIGABRT_COMPAT),
171 SIGERR(SIGFPE), SIGERR(SIGSEGV), SIGERR(SIGTERM),
172 SIGERR(SIGBREAK), SIGERR(SIGABRT),
175 if (signames[signum] == NULL) {
178 strappend(ptr, ptr_end, signames[signum]);
180#elif __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 32)
181 strappend(ptr, ptr_end, sigabbrev_np(signum));
183 strappend(ptr, ptr_end, sigdescr_np(signum));
185 strappend(ptr, ptr_end, sys_siglist[signum]);
203 CHARS =
sizeof(uint32_t),
204 MAX_LEN = CHARS * CHAR_LEN + 1 ,
206 _Thread_local
static char out[MAX_LEN];
208 const unsigned char *fourcc = fcc;
210 for (
int i = 0; i < CHARS; ++i) {
211 if (isprint(fourcc[i])) {
215 snprintf(
out_ptr, CHAR_LEN + 1,
"[%hhu]", fourcc[i]);
static ssize_t write_all(fd_t fd, const void *buf, size_t count)
static void strappend(char **dst, size_t *dst_alloc_len, const char *src)
bool is_prefix_of(const char *haystack, const char *needle)
char * strrpbrk(char *s, const char *accept)
same as strpbrk but finds in a reverse order (last occurence returned)
bool ends_with(const char *haystick, const char *needle)
void replace_all(char *in, const char *from, const char *to)
Replaces all occurencies of 'from' to 'to' in string 'in'.
const char * pretty_print_fourcc(const void *fcc)
void append_sig_desc(char **ptr, const char *ptr_end, int signum)