diff options
Diffstat (limited to 'libidu/idfile.h')
-rw-r--r-- | libidu/idfile.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/libidu/idfile.h b/libidu/idfile.h index 739819d..3775d7a 100644 --- a/libidu/idfile.h +++ b/libidu/idfile.h @@ -225,4 +225,19 @@ extern off_t largest_member_file; #define DEFAULT_ID_FILE_NAME "ID" +/* Like stpncpy, but do ensure that the result is NUL-terminated, + and do not NUL-pad out to LEN. I.e., when strnlen (src, len) == len, + this function writes a NUL byte into dest[len]. Thus, the length + of the destination buffer must be at least LEN + 1. + The DEST and SRC buffers must not overlap. */ +static inline char * +stzncpy (char *restrict dest, char const *restrict src, size_t len) +{ + char const *src_end = src + len; + while (src < src_end && *src) + *dest++ = *src++; + *dest = 0; + return dest; +} + #endif /* not _idfile_h_ */ |