summaryrefslogtreecommitdiff
path: root/path.c
diff options
context:
space:
mode:
authorPeter Eriksen <s022018@student.dtu.dk>2006-06-11 14:03:28 +0200
committerJunio C Hamano <junkio@cox.net>2006-06-16 22:45:12 -0700
commitbfbd0bb6ecbbbf75a5caaff6afaf5a6af8fa518e (patch)
tree52f36804599a41eafa3a020f06dbe118c6f652f9 /path.c
parent5996ca0836e21ab4e6be0a16a615eff965f18b8b (diff)
downloadgit-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.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/path.c b/path.c
index 5168b5f17d..194e0b553f 100644
--- a/path.c
+++ b/path.c
@@ -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;