git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Holger Eitzenberger <holger@my-eitzenberger.de>
To: git <git@vger.kernel.org>
Subject: [PATCH 1/1] git: add git_mkstemp()
Date: Thu, 04 Aug 2005 22:43:03 +0200	[thread overview]
Message-ID: <42F27DD7.2080301@my-eitzenberger.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 75 bytes --]

Hi,

the following snippet adds git_mkstemp() to libgit (path.c).

/holger

[-- Attachment #2: git_add_git_mkstemp.patch --]
[-- Type: text/x-patch, Size: 1720 bytes --]

add git_mkstemp() to libgit

---
commit 1a1f2cb5c27ed26e6ef8dd34209e561bdf256c22
tree 868b67b55978394d288ac4f2ca8edcbbad4355bd
parent 10833f5e7d0da63ca976607864282d41b5faff1b
author Holger Eitzenberger <holger@my-eitzenberger.de> Thu, 04 Aug 2005 22:28:32 +0200
committer Holger Eitzenberger <holger@elmo.intranet.astaro.de> Thu, 04 Aug 2005 22:28:32 +0200

 cache.h |    3 +++
 path.c  |   26 ++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/cache.h b/cache.h
--- a/cache.h
+++ b/cache.h
@@ -174,7 +174,10 @@ extern char *mkpath(const char *fmt, ...
 extern char *git_path(const char *fmt, ...);
 extern char *sha1_file_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
--- 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;
+}

                 reply	other threads:[~2005-08-04 23:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42F27DD7.2080301@my-eitzenberger.de \
    --to=holger@my-eitzenberger.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).