summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Holger Eitzenberger <holger@my-eitzenberger.de>2005-08-04 22:43:03 +0200
committerLibravatar Junio C Hamano <junkio@cox.net>2005-08-05 23:06:58 -0700
commitf2db68eda89f2fbe7e4c1a69a3c10b25ea43667c (patch)
tree59c2442b47c88b273f3688dd573e97ad3e87aa43
parentFix ref_newer() in send-pack. (diff)
downloadtgif-f2db68eda89f2fbe7e4c1a69a3c10b25ea43667c.tar.xz
[PATCH] git: add git_mkstemp()
Signed-off-by: Junio C Hamano <junkio@cox.net>
-rw-r--r--cache.h3
-rw-r--r--path.c26
2 files changed, 29 insertions, 0 deletions
diff --git a/cache.h b/cache.h
index fd4988ed9a..6dbc32a7e6 100644
--- a/cache.h
+++ b/cache.h
@@ -181,7 +181,10 @@ extern char *sha1_file_name(const unsigned char *sha1);
extern char *sha1_pack_name(const unsigned char *sha1);
extern char *sha1_pack_index_name(const unsigned char *sha1);
+int git_mkstemp(char *path, size_t n, const char *template);
+
int safe_create_leading_directories(char *path);
+char *safe_strncpy(char *, const char *, size_t);
/* Read and unpack a sha1 file into memory, write memory to a sha1 file */
extern int unpack_sha1_header(z_stream *stream, void *map, unsigned long mapsize, void *buffer, unsigned long size);
diff --git a/path.c b/path.c
index d217ef0b7f..7ef0d1b80d 100644
--- a/path.c
+++ b/path.c
@@ -58,3 +58,29 @@ char *git_path(const char *fmt, ...)
return bad_path;
return cleanup_path(pathname);
}
+
+
+/* git_mkstemp() - create tmp file honoring TMPDIR variable */
+int git_mkstemp(char *path, size_t len, const char *template)
+{
+ char *env, *pch = path;
+
+ if ((env = getenv("TMPDIR")) == NULL) {
+ strcpy(pch, "/tmp/");
+ len -= 5;
+ } else
+ len -= snprintf(pch, len, "%s/", env);
+
+ safe_strncpy(pch, template, len);
+
+ return mkstemp(path);
+}
+
+
+char *safe_strncpy(char *dest, const char *src, size_t n)
+{
+ strncpy(dest, src, n);
+ dest[n - 1] = '\0';
+
+ return dest;
+}