diff options
author | Holger Eitzenberger <holger@my-eitzenberger.de> | 2005-08-04 22:43:03 +0200 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2005-08-05 23:06:58 -0700 |
commit | f2db68eda89f2fbe7e4c1a69a3c10b25ea43667c (patch) | |
tree | 59c2442b47c88b273f3688dd573e97ad3e87aa43 /path.c | |
parent | 51b0fca012310910783de76f2eacfd10b0f2f9fc (diff) | |
download | git-f2db68eda89f2fbe7e4c1a69a3c10b25ea43667c.tar.gz git-f2db68eda89f2fbe7e4c1a69a3c10b25ea43667c.tar.xz |
[PATCH] git: add git_mkstemp()
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'path.c')
-rw-r--r-- | path.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -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; +} |