add safe_strncpy() function
This commit is contained in:
parent
7596ab2048
commit
5931ed5a14
|
@ -24,4 +24,6 @@ int recursive_action(const char *fileName, unsigned flags,
|
|||
int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData, int depth),
|
||||
void* userData, const unsigned depth);
|
||||
|
||||
char * safe_strncpy(char *dst, const char *src, size_t size);
|
||||
|
||||
#endif /* __LIBBB_H */
|
||||
|
|
|
@ -99,3 +99,11 @@ char* last_char_is(const char *s, int c)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* Like strncpy but make sure the resulting string is always 0 terminated. */
|
||||
char * safe_strncpy(char *dst, const char *src, size_t size)
|
||||
{
|
||||
if (!size) return dst;
|
||||
dst[--size] = '\0';
|
||||
return strncpy(dst, src, size);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue