diff options
author | Explorer09 <explorer09@gmail.com> | 2023-10-10 11:21:59 +0800 |
---|---|---|
committer | Explorer09 <explorer09@gmail.com> | 2023-10-11 04:23:07 +0800 |
commit | 5736fba7110b460fa0775c008b959467c45e38e0 (patch) | |
tree | 4d757da318773c31cd6e94890931f4a8a39309fa /XUtils.h | |
parent | f541f70d0ecbb9fd80bea9909c1783b92d46d695 (diff) |
Add ATTR_NONNULL to various String_* functions
Note: For xSnprintf function the nonnull attribute is not needed. (The
`buf` argument may be NULL as long as `len` is 0, and `fmt` is implied
by the "format" attribute.)
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Diffstat (limited to 'XUtils.h')
-rw-r--r-- | XUtils.h | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -36,26 +36,33 @@ void* xReallocArrayZero(void* ptr, size_t prevmemb, size_t newmemb, size_t size) * String_startsWith gives better performance if strlen(match) can be computed * at compile time (e.g. when they are immutable string literals). :) */ +ATTR_NONNULL static inline bool String_startsWith(const char* s, const char* match) { return strncmp(s, match, strlen(match)) == 0; } bool String_contains_i(const char* s1, const char* s2, bool multi); +ATTR_NONNULL static inline bool String_eq(const char* s1, const char* s2) { return strcmp(s1, s2) == 0; } +ATTR_NONNULL char* String_cat(const char* s1, const char* s2) ATTR_MALLOC; +ATTR_NONNULL char* String_trim(const char* in) ATTR_MALLOC; +ATTR_NONNULL_N(1) char** String_split(const char* s, char sep, size_t* n); void String_freeArray(char** s); +ATTR_NONNULL char* String_readLine(FILE* fd) ATTR_MALLOC; +ATTR_NONNULL static inline char* String_strchrnul(const char* s, int c) { #ifdef HAVE_STRCHRNUL return strchrnul(s, c); @@ -73,6 +80,7 @@ ATTR_ACCESS3_R(2, 3) size_t String_safeStrncpy(char* restrict dest, const char* restrict src, size_t size); ATTR_FORMAT(printf, 2, 3) +ATTR_NONNULL_N(1, 2) int xAsprintf(char** strp, const char* fmt, ...); ATTR_FORMAT(printf, 3, 4) |