diff options
Diffstat (limited to 'utils/utils.c')
-rw-r--r-- | utils/utils.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/utils/utils.c b/utils/utils.c index e76c112..13d61cc 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -340,3 +340,23 @@ gbStrdup(char **dest, const char *src, return 0; } + + +char * +gbStrcpy(char *dest, const char *src, size_t destbytes, + const char *filename, const char *funcname, size_t linenr) +{ + char *ret; + size_t n = strlen(src); + + if (n > (destbytes - 1)) + return NULL; + + ret = strncpy(dest, src, n); + /* strncpy NULL terminates if the last character is \0. Therefore + * force the last byte to be \0 + */ + dest[n] = '\0'; + + return ret; +} |