12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #pragma once
- #include <stdio.h>
- #include <string.h>
- #include <sys/param.h>
- #define CLAMP(lbound, ubound, value) MIN(MIN(lbound, ubound), MAX(MAX(lbound, ubound), value))
- #define buffered_snprintf(b, s, ...) \
- (snprintf(b, sizeof(b), s, __VA_ARGS__) < (ssize_t)sizeof(b) ? b : NULL)
- #define safe_snprintf(b, s, ...) \
- (snprintf(b, sizeof(b), s, __VA_ARGS__) < (ssize_t)sizeof(b) ? strndup(b, sizeof(b)) : NULL)
- static inline const char *strtail(const char *haystack, const char *needle)
- {
- char *pos = strstr(haystack, needle);
- if (pos && (strlen(pos) == strlen(needle)))
- return pos;
- return NULL;
- }
|