# [PATCH 1/2] wrapper.c: remove unused git_mkstemp() function

2 messages from 2017-02-28 to 2017-02-28. Participants: Ramsay Jones, Jeff King.
Thread: https://gitlist.dev/t/45242

## Ramsay Jones, 2017-02-28 01:24

Subject: [PATCH 1/2] wrapper.c: remove unused git_mkstemp() function
Message-ID: <976c40d1-42dc-1fc5-45d5-05bdcf04d97e@ramsayjones.plus.com>
URL: https://gitlist.dev/e/976c40d1-42dc-1fc5-45d5-05bdcf04d97e%40ramsayjones.plus.com

```

The last caller of git_mkstemp() was removed in commit 6fec0a89
("verify_signed_buffer: use tempfile object", 16-06-2016). Since
the introduction of the 'tempfile' APIs, along with git_mkstemp_mode,
it is unlikely that new callers will materialize. Remove the dead
code.

Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
---
 cache.h   |  3 ---
 wrapper.c | 17 -----------------
 2 files changed, 20 deletions(-)

diff --git a/cache.h b/cache.h
index 61fc86e6d..a575684a9 100644
--- a/cache.h
+++ b/cache.h
@@ -1045,9 +1045,6 @@ static inline int is_empty_tree_oid(const struct object_id *oid)
 	return !hashcmp(oid->hash, EMPTY_TREE_SHA1_BIN);
 }
 
-
-int git_mkstemp(char *path, size_t n, const char *template);
-
 /* set default permissions by passing mode arguments to open(2) */
 int git_mkstemps_mode(char *pattern, int suffix_len, int mode);
 int git_mkstemp_mode(char *pattern, int mode);
diff --git a/wrapper.c b/wrapper.c
index e7f197996..1a140639f 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -440,23 +440,6 @@ int xmkstemp(char *template)
 	return fd;
 }
 
-/* git_mkstemp() - create tmp file honoring TMPDIR variable */
-int git_mkstemp(char *path, size_t len, const char *template)
-{
-	const char *tmp;
-	size_t n;
-
-	tmp = getenv("TMPDIR");
-	if (!tmp)
-		tmp = "/tmp";
-	n = snprintf(path, len, "%s/%s", tmp, template);
-	if (len <= n) {
-		errno = ENAMETOOLONG;
-		return -1;
-	}
-	return mkstemp(path);
-}
-
 /* Adapted from libiberty's mkstemp.c. */
 
 #undef TMP_MAX
-- 
2.12.0

```

## Jeff King, 2017-02-28 13:12

Subject: Re: [PATCH 1/2] wrapper.c: remove unused git_mkstemp() function
Message-ID: <20170228131255.ufpoexm55ovpwka3@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20170228131255.ufpoexm55ovpwka3%40sigill.intra.peff.net
In-Reply-To: <976c40d1-42dc-1fc5-45d5-05bdcf04d97e@ramsayjones.plus.com>

```
On Tue, Feb 28, 2017 at 01:24:10AM +0000, Ramsay Jones wrote:

> The last caller of git_mkstemp() was removed in commit 6fec0a89
> ("verify_signed_buffer: use tempfile object", 16-06-2016). Since
> the introduction of the 'tempfile' APIs, along with git_mkstemp_mode,
> it is unlikely that new callers will materialize. Remove the dead
> code.

Yeah, I think the tempfile API is a better choice for anybody who wants
to add a new call. Removing the temptation (and the dead code) is a good
move.

-Peff

```
