diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2021-01-05 14:44:09 +0100 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2021-01-11 20:12:34 +0100 |
commit | a118928dee0874eef98be81531a98577c1ae3f7d (patch) | |
tree | b37d56ceded1d8ccf7551ae148f5594129851299 /XUtils.h | |
parent | 3715301fe3d49a0255788d1157a4c8e12ee97711 (diff) |
XUtils: add safe strncpy implementation
The standard strncpy fails to null-terminate the destination in case
the source is longer than the passed size.
Diffstat (limited to 'XUtils.h')
-rw-r--r-- | XUtils.h | 3 |
1 files changed, 3 insertions, 0 deletions
@@ -59,6 +59,9 @@ char* String_getToken(const char* line, unsigned short int numMatch); char* String_readLine(FILE* fd); +/* Always null-terminates dest. Caller must pass a strictly positive size. */ +size_t String_safeStrncpy(char *restrict dest, const char *restrict src, size_t size); + ATTR_FORMAT(printf, 2, 3) int xAsprintf(char** strp, const char* fmt, ...); |