summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 51b0fca)
raw | patch | inline | side by side (parent: 51b0fca)
author | Holger Eitzenberger <holger@my-eitzenberger.de> | |
Thu, 4 Aug 2005 20:43:03 +0000 (22:43 +0200) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sat, 6 Aug 2005 06:06:58 +0000 (23:06 -0700) |
Signed-off-by: Junio C Hamano <junkio@cox.net>
cache.h | patch | blob | history | |
path.c | patch | blob | history |
index fd4988ed9a0d8f75c66127a6186aae0d5d76a913..6dbc32a7e60434647020672e677b7bf76a8b9f94 100644 (file)
--- a/cache.h
+++ b/cache.h
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);
index d217ef0b7f04d7e021770cb50a7c58c14bc7920d..7ef0d1b80d926d832816a587ddff721cb03130b3 100644 (file)
--- a/path.c
+++ b/path.c
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;
+}