summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3eaa38d)
raw | patch | inline | side by side (parent: 3eaa38d)
author | Peter Eriksen <s022018@student.dtu.dk> | |
Sat, 24 Jun 2006 14:01:25 +0000 (16:01 +0200) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sun, 25 Jun 2006 06:16:25 +0000 (23:16 -0700) |
This cleans up the use of safe_strncpy() even more. Since it has the
same semantics as strlcpy() use this name instead. Also move the
definition from inside path.c to its own file compat/strlcpy.c, and use
it conditionally at compile time, since some platforms already has
strlcpy(). It's included in the same way as compat/setenv.c.
Signed-off-by: Peter Eriksen <s022018@student.dtu.dk>
Signed-off-by: Junio C Hamano <junkio@cox.net>
same semantics as strlcpy() use this name instead. Also move the
definition from inside path.c to its own file compat/strlcpy.c, and use
it conditionally at compile time, since some platforms already has
strlcpy(). It's included in the same way as compat/setenv.c.
Signed-off-by: Peter Eriksen <s022018@student.dtu.dk>
Signed-off-by: Junio C Hamano <junkio@cox.net>
12 files changed:
Makefile | patch | blob | history | |
builtin-log.c | patch | blob | history | |
builtin-tar-tree.c | patch | blob | history | |
cache.h | patch | blob | history | |
compat/strlcpy.c | [new file with mode: 0644] | patch | blob |
config.c | patch | blob | history | |
git-compat-util.h | patch | blob | history | |
http-fetch.c | patch | blob | history | |
http-push.c | patch | blob | history | |
ident.c | patch | blob | history | |
path.c | patch | blob | history | |
sha1_name.c | patch | blob | history |
diff --git a/Makefile b/Makefile
index e29e3fa381dd3b36bf235d304d99f254db702492..cde619c498da717ea665430f7d395358d0b1d06e 100644 (file)
--- a/Makefile
+++ b/Makefile
#
# Define NO_STRCASESTR if you don't have strcasestr.
#
+# Define NO_STRLCPY if you don't have strlcpy.
+#
# Define NO_SETENV if you don't have setenv in the C library.
#
# Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link.
# because maintaining the nesting to match is a pain. If
# we had "elif" things would have been much nicer...
+ifeq ($(uname_S),Linux)
+ NO_STRLCPY = YesPlease
+endif
ifeq ($(uname_S),Darwin)
NEEDS_SSL_WITH_CRYPTO = YesPlease
NEEDS_LIBICONV = YesPlease
+ NO_STRLCPY = YesPlease
## fink
ifeq ($(shell test -d /sw/lib && echo y),y)
ALL_CFLAGS += -I/sw/include
NEEDS_NSL = YesPlease
SHELL_PATH = /bin/bash
NO_STRCASESTR = YesPlease
+ NO_STRLCPY = YesPlease
ifeq ($(uname_R),5.8)
NEEDS_LIBICONV = YesPlease
NO_UNSETENV = YesPlease
NO_D_TYPE_IN_DIRENT = YesPlease
NO_D_INO_IN_DIRENT = YesPlease
NO_STRCASESTR = YesPlease
+ NO_STRLCPY = YesPlease
NO_SYMLINK_HEAD = YesPlease
NEEDS_LIBICONV = YesPlease
# There are conflicting reports about this.
endif
ifeq ($(uname_S),AIX)
NO_STRCASESTR=YesPlease
+ NO_STRLCPY = YesPlease
NEEDS_LIBICONV=YesPlease
endif
ifeq ($(uname_S),IRIX64)
NO_IPV6=YesPlease
NO_SETENV=YesPlease
NO_STRCASESTR=YesPlease
+ NO_STRLCPY = YesPlease
NO_SOCKADDR_STORAGE=YesPlease
SHELL_PATH=/usr/gnu/bin/bash
ALL_CFLAGS += -DPATH_MAX=1024
COMPAT_CFLAGS += -DNO_STRCASESTR
COMPAT_OBJS += compat/strcasestr.o
endif
+ifdef NO_STRLCPY
+ COMPAT_CFLAGS += -DNO_STRLCPY
+ COMPAT_OBJS += compat/strlcpy.o
+endif
ifdef NO_SETENV
COMPAT_CFLAGS += -DNO_SETENV
COMPAT_OBJS += compat/setenv.o
diff --git a/builtin-log.c b/builtin-log.c
index 5a8a50b81dabea4ccd9b0ba0fcb5d925a00560d0..44d2d136f585a74e462556a4f756c7a297cadd51 100644 (file)
--- a/builtin-log.c
+++ b/builtin-log.c
int len = 0;
if (output_directory) {
- safe_strncpy(filename, output_directory, 1010);
+ strlcpy(filename, output_directory, 1010);
len = strlen(filename);
if (filename[len - 1] != '/')
filename[len++] = '/';
diff --git a/builtin-tar-tree.c b/builtin-tar-tree.c
index 39a61b629367df9dd274acf5fa310b45dd06f126..f2e48aae2a04822d26d255dddf36002f58f2093c 100644 (file)
--- a/builtin-tar-tree.c
+++ b/builtin-tar-tree.c
/* XXX: should we provide more meaningful info here? */
sprintf(header.uid, "%07o", 0);
sprintf(header.gid, "%07o", 0);
- safe_strncpy(header.uname, "git", sizeof(header.uname));
- safe_strncpy(header.gname, "git", sizeof(header.gname));
+ strlcpy(header.uname, "git", sizeof(header.uname));
+ strlcpy(header.gname, "git", sizeof(header.gname));
sprintf(header.devmajor, "%07o", 0);
sprintf(header.devminor, "%07o", 0);
index efeafea70f61a8496cfd6fd6405793459d3df7a9..14358a872cdb2d8d663dad389897cfa0731d821d 100644 (file)
--- a/cache.h
+++ b/cache.h
int git_config_perm(const char *var, const char *value);
int adjust_shared_perm(const char *path);
int safe_create_leading_directories(char *path);
-size_t safe_strncpy(char *, const char *, size_t);
char *enter_repo(char *path, int strict);
/* Read and unpack a sha1 file into memory, write memory to a sha1 file */
diff --git a/compat/strlcpy.c b/compat/strlcpy.c
--- /dev/null
+++ b/compat/strlcpy.c
@@ -0,0 +1,13 @@
+#include <string.h>
+
+size_t gitstrlcpy(char *dest, const char *src, size_t size)
+{
+ size_t ret = strlen(src);
+
+ if (size) {
+ size_t len = (ret >= size) ? size - 1 : ret;
+ memcpy(dest, src, len);
+ dest[len] = '\0';
+ }
+ return ret;
+}
diff --git a/config.c b/config.c
index 3e077d4c6ca4f7162e3a3254e1b3e90db33270ff..ec44827da4afbcf89a5eed37c7f557a7ffdce35d 100644 (file)
--- a/config.c
+++ b/config.c
}
if (!strcmp(var, "user.name")) {
- safe_strncpy(git_default_name, value, sizeof(git_default_name));
+ strlcpy(git_default_name, value, sizeof(git_default_name));
return 0;
}
if (!strcmp(var, "user.email")) {
- safe_strncpy(git_default_email, value, sizeof(git_default_email));
+ strlcpy(git_default_email, value, sizeof(git_default_email));
return 0;
}
if (!strcmp(var, "i18n.commitencoding")) {
- safe_strncpy(git_commit_encoding, value, sizeof(git_commit_encoding));
+ strlcpy(git_commit_encoding, value, sizeof(git_commit_encoding));
return 0;
}
diff --git a/git-compat-util.h b/git-compat-util.h
index b3d4cf532e5728e6b962d0d65789f6e8e4bd7fe5..93f558056dec457570bf2867dc6c75cd5891d2f2 100644 (file)
--- a/git-compat-util.h
+++ b/git-compat-util.h
extern char *gitstrcasestr(const char *haystack, const char *needle);
#endif
+#ifdef NO_STRLCPY
+#define strlcpy gitstrlcpy
+extern size_t gitstrlcpy(char *, const char *, size_t);
+#endif
+
static inline void *xmalloc(size_t size)
{
void *ret = malloc(size);
diff --git a/http-fetch.c b/http-fetch.c
index 2b63d89501cc8838cca96506b3532d33fc452a15..44eba5fd0df292255dce056ec5aa700186096b39 100644 (file)
--- a/http-fetch.c
+++ b/http-fetch.c
// skip 'objects' at end
if (okay) {
target = xmalloc(serverlen + posn - i - 6);
- safe_strncpy(target, base, serverlen);
- safe_strncpy(target + serverlen, data + i, posn - i - 6);
+ strlcpy(target, base, serverlen);
+ strlcpy(target + serverlen, data + i, posn - i - 6);
if (get_verbosely)
fprintf(stderr,
"Also look at %s\n", target);
if (ctx->cdata)
free(ctx->cdata);
ctx->cdata = xmalloc(len + 1);
- safe_strncpy(ctx->cdata, s, len + 1);
+ strlcpy(ctx->cdata, s, len + 1);
}
static int remote_ls(struct alt_base *repo, const char *path, int flags,
diff --git a/http-push.c b/http-push.c
index 8d472f0202827db726ede451be3fd63940c38c96..3c89a17496dcc72fa8773a0308281364bbf647a8 100644 (file)
--- a/http-push.c
+++ b/http-push.c
if (ctx->cdata)
free(ctx->cdata);
ctx->cdata = xmalloc(len + 1);
- safe_strncpy(ctx->cdata, s, len + 1);
+ strlcpy(ctx->cdata, s, len + 1);
}
static struct remote_lock *lock_remote(char *path, long timeout)
return;
path += 8;
obj_hex = xmalloc(strlen(path));
- safe_strncpy(obj_hex, path, 3);
+ strlcpy(obj_hex, path, 3);
strcpy(obj_hex + 2, path + 3);
one_remote_object(obj_hex);
free(obj_hex);
/* If it's a symref, set the refname; otherwise try for a sha1 */
if (!strncmp((char *)buffer.buffer, "ref: ", 5)) {
*symref = xmalloc(buffer.posn - 5);
- safe_strncpy(*symref, (char *)buffer.buffer + 5, buffer.posn - 5);
+ strlcpy(*symref, (char *)buffer.buffer + 5, buffer.posn - 5);
} else {
get_sha1_hex(buffer.buffer, sha1);
}
index 7b44cbd2cc54c049518b9fb1cb681a88c7aaa6c4..efec97ffd0a9f3aa6573f3476c749d38d6fc388c 100644 (file)
--- a/ident.c
+++ b/ident.c
len = strlen(git_default_email);
git_default_email[len++] = '.';
if (he && (domainname = strchr(he->h_name, '.')))
- safe_strncpy(git_default_email + len, domainname + 1, sizeof(git_default_email) - len);
+ strlcpy(git_default_email + len, domainname + 1, sizeof(git_default_email) - len);
else
- safe_strncpy(git_default_email + len, "(none)", sizeof(git_default_email) - len);
+ strlcpy(git_default_email + len, "(none)", sizeof(git_default_email) - len);
}
/* And set the default date */
datestamp(git_default_date, sizeof(git_default_date));
index 36972fd6df63b3c4eebdcf89238df8ade60d53c3..db8905f3c352592124b2f0bda18fc0ccd048528e 100644 (file)
--- a/path.c
+++ b/path.c
pch += n;
}
- safe_strncpy(pch, template, len);
+ strlcpy(pch, template, len);
return mkstemp(path);
}
-size_t safe_strncpy(char *dest, const char *src, size_t size)
-{
- size_t ret = strlen(src);
-
- 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;
diff --git a/sha1_name.c b/sha1_name.c
index cd85d1fa0f9f2afb4e159cb635db435e75ef3e58..f2cbafa496231e7a9cdbbea2ab4e7d4c4ed761ab 100644 (file)
--- a/sha1_name.c
+++ b/sha1_name.c
if (str[am] == '@' && str[am+1] == '{' && str[len-1] == '}') {
int date_len = len - am - 3;
char *date_spec = xmalloc(date_len + 1);
- safe_strncpy(date_spec, str + am + 2, date_len + 1);
+ strlcpy(date_spec, str + am + 2, date_len + 1);
at_time = approxidate(date_spec);
free(date_spec);
len = am;