9
0
Fork 0

add safe_strncpy() function

This commit is contained in:
Sascha Hauer 2007-09-28 10:45:59 +02:00
parent 7596ab2048
commit 5931ed5a14
2 changed files with 10 additions and 0 deletions

View File

@ -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 */

View File

@ -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);
}