diff options
author | Peter Eriksen <s022018@student.dtu.dk> | 2006-06-11 14:03:28 +0200 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-06-16 22:45:12 -0700 |
commit | bfbd0bb6ecbbbf75a5caaff6afaf5a6af8fa518e (patch) | |
tree | 52f36804599a41eafa3a020f06dbe118c6f652f9 /path.c | |
parent | 5996ca0836e21ab4e6be0a16a615eff965f18b8b (diff) | |
download | git-bfbd0bb6ecbbbf75a5caaff6afaf5a6af8fa518e.tar.gz |
Implement safe_strncpy() as strlcpy() and use it more.
Signed-off-by: Peter Eriksen <s022018@student.dtu.dk>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'path.c')
-rw-r--r-- | path.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -83,14 +83,19 @@ int git_mkstemp(char *path, size_t len, const char *template) } -char *safe_strncpy(char *dest, const char *src, size_t n) +size_t safe_strncpy(char *dest, const char *src, size_t size) { - strncpy(dest, src, n); - dest[n - 1] = '\0'; + size_t ret = strlen(src); - return dest; + if (size) { + size_t len = (ret >= size) ? size - 1 : ret; + memcpy(dest, src, len); + dest[len] = '\0'; + } + return ret; } + int validate_symref(const char *path) { struct stat st; |