git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Improved error messages when temporary file creation fails

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Dec 7, 2010, 19:09 UTC
Message-ID
<20101207190920.GA22587@burratino>
In-Reply-To
<20101207181633.GF25767@bzzt.net>
Arnout Engelen wrote:
> +			die_errno("Unable to create temporary file '%s' at %s", 
> +				template, getcwd(NULL, 0));

This is a Linux libc/glibc-specific extension, alas. On other platforms it would print "(null)" or segfault.

Here's some other assorted tweaks. I didn't bother to find your old patch in the mailing list archive to take a fuller change description from.

Hope that helps, Jonathan ---

diff --git a/test-mktemp.c b/test-mktemp.c
index d392fa7..2e3b134 100644
--- a/test-mktemp.c
+++ b/test-mktemp.c
@@ -7,10 +7,9 @@
 
 int main(int argc, char *argv[])
 {
-	if (argc != 2) {
+	if (argc != 2)
 		usage("Expected 1 parameter defining the temporary file template");
-	}
-	xmkstemp(strdup(argv[1]));
+	xmkstemp(xstrdup(argv[1]));
 
 	return 0;
 }
diff --git a/wrapper.c b/wrapper.c
index 6640c87..cb9c9ad 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -197,19 +197,18 @@ FILE *xfdopen(int fd, const char *mode)
 int xmkstemp(char *template)
 {
 	int fd;
-	char origtemplate[255];
-	strlcpy(origtemplate, template, 255);
+	char origtemplate[256];
+	strlcpy(origtemplate, template, sizeof(origtemplate));
 
 	fd = mkstemp(template);
 	if (fd < 0) {
+		int saved_errno = errno;
+
 		if (!template[0])
 			template = origtemplate;
-
-		if (is_absolute_path(template))
-			die_errno("Unable to create temporary file '%s'", template);
-		else
-			die_errno("Unable to create temporary file '%s' at %s", 
-				template, getcwd(NULL, 0));
+		template = make_nonrelative_path(template);
+		errno = saved_errno;
+		die_errno("Unable to create temporary file '%s'", template);
 	}
 	return fd;
 }
@@ -330,19 +329,18 @@ int gitmkstemps(char *pattern, int suffix_len)
 int xmkstemp_mode(char *template, int mode)
 {
 	int fd;
-	char origtemplate[255];
-	strlcpy(origtemplate, template, 255);
+	char origtemplate[256];
+	strlcpy(origtemplate, template, sizeof(origtemplate));
 
 	fd = git_mkstemp_mode(template, mode);
 	if (fd < 0) {
+		int saved_errno = errno;
+
 		if (!template[0])
 			template = origtemplate;
-
-		if (is_absolute_path(template))
-			die_errno("Unable to create temporary file '%s'", template);
-		else
-			die_errno("Unable to create temporary file '%s' at %s", 
-				template, getcwd(NULL, 0));
+		template = make_nonrelative_path(template);
+		errno = saved_errno;
+		die_errno("Unable to create temporary file '%s'", template);
 	}
 	return fd;
 }
Previous: Arnout EngelenNext: Junio C Hamano
Message 2 of 12 in “Improved error messages when temporary file creation fails”
  1. Improved error messages when temporary file creation failsArnout Engelen, Dec 7, 2010
  2. Jonathan NiederDec 7, 2010
  3. Junio C HamanoDec 7, 2010
  4. Arnout EngelenDec 7, 2010
  5. Jakub NarebskiDec 7, 2010
  6. Jonathan NiederDec 8, 2010
  7. Junio C HamanoDec 8, 2010
  8. Arnout EngelenDec 18, 2010
  9. Jonathan NiederDec 18, 2010
  10. Junio C HamanoDec 18, 2010
  11. Junio C HamanoDec 18, 2010
  12. Arnout EngelenDec 18, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.