From: Jonathan Nieder <jrnieder@gmail.com>
To: Arnout Engelen <arnouten@bzzt.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Improved error messages when temporary file creation fails
Date: Tue, 7 Dec 2010 13:09:20 -0600 [thread overview]
Message-ID: <20101207190920.GA22587@burratino> (raw)
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;
}
next prev parent reply other threads:[~2010-12-07 19:09 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-07 18:16 [PATCH] Improved error messages when temporary file creation fails Arnout Engelen
2010-12-07 19:09 ` Jonathan Nieder [this message]
2010-12-07 20:56 ` Junio C Hamano
2010-12-07 21:20 ` Arnout Engelen
2010-12-07 23:56 ` Jakub Narebski
2010-12-08 0:12 ` Jonathan Nieder
2010-12-08 2:01 ` Junio C Hamano
2010-12-18 16:55 ` Arnout Engelen
2010-12-18 20:05 ` Jonathan Nieder
2010-12-18 20:47 ` Junio C Hamano
2010-12-18 20:47 ` Junio C Hamano
2010-12-18 21:28 ` Arnout Engelen
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=20101207190920.GA22587@burratino \
--to=jrnieder@gmail.com \
--cc=arnouten@bzzt.net \
--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).