Skip to contentSkip to conversation

diff: generate prettier filenames when using GIT_EXTERNAL_DIFF

PATCH David Aguilar 1 participant 1 message Jun 15, 2016 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 14 lines · David Aguilar
path.c +6 -0
index 8a0a674..c2a0fb6 100644
@@ -140,6 +140,24 @@ int git_mkstemp(char *path, size_t len, const char *template)
 }
 
 
+/* git_mkstemp() - create tmp file with suffix honoring TMPDIR variable */
+int git_mkstemps(char *path, size_t len, const char *template, int suffix_len)
+{
+	const char *tmp;
+	size_t n;
+

path.c int git_mkstemp(char *path, size_t len, const char *template) · line 158

Quoted 10 lines
path.c +10 -0
+	tmp = getenv("TMPDIR");
+	if (!tmp)
+		tmp = "/tmp";
+	n = snprintf(path, len, "%s/%s", tmp, template);
+	if (len <= n) {
+		errno = ENAMETOOLONG;
+		return -1;
+	}
+	return mkstemps(path, suffix_len);
+}

Lured by a mac. I came home and I tried it on linux:

path.c:157: warning: implicit declaration of function ‘mkstemps’

Gah.
Darn you OS X and your non-portable 4.4 BSD extensions. Sorry about that.

The original patch could do without the strbuf_detach and free(), too. Being tricked by an OS X manpage like that is quite unpleasant.

mkstemp() won't do since it doesn't work with suffixes (the templates must end with "XXXX"). I'm sure there has to be another way, but I just can't think of it right now.

It seemed so easy at the time.
Sigh...

Signature · 1 line
	David