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 18, 2010, 20:05 UTC
Message-ID
<20101218200516.GA10031@burratino>
In-Reply-To
<20101218165514.GT25767@bzzt.net>
Hi again,
Arnout Engelen wrote:
> Updated version of the patch
Almost there.  Some remaining nits from my pov:
> , taking into account the feedback from this 
> thread.
[...]

This text above the "---" becomes part of the log message when a patch is committed to git.git, so it is best to make it self-contained. The usual advice is "describe the current behavior, why the proposed behavior is better, and then how the proposed behavior is achieved."

Show 8 quoted lines
> --- /dev/null
> +++ b/test-mktemp.c
> @@ -0,0 +1,15 @@
> +/*
> + * test-mktemp.c: code to exercise the creation of temporary files
> + */
> +#include <string.h>
> +#include "git-compat-util.h"

git-compat-util.h takes care of portably including system headers in the right order. (For example, #include-ing <string.h> before setting _POSIX_SOURCE will cause some symbols not to be defined in _other_ headers on some operating systems, iirc.) I'd suggest removing the redundant #include <string.h>.

See Documentation/CodingGuidelines.
Show 6 quoted lines
> +int main(int argc, char *argv[])
> +{
> +	if (argc != 2)
> +		usage("Expected 1 parameter defining the temporary file template");
> +
> +	xmkstemp(strdup(argv[1]));
Why not xstrdup(), which diagnoses allocation failures?
Show 15 quoted lines
> --- a/wrapper.c
> +++ b/wrapper.c
> @@ -196,10 +196,22 @@ FILE *xfdopen(int fd, const char *mode)
>  int xmkstemp(char *template)
>  {
>  	int fd;
> +	char origtemplate[PATH_MAX];
> +	strlcpy(origtemplate, template, sizeof(origtemplate));
>  
>  	fd = mkstemp(template);
> -	if (fd < 0)
> -		die_errno("Unable to create temporary file");
> +	if (fd < 0) {
> +		int saved_errno = errno;
> +		const char * nonrelative_template;

It would be more usual not to include a space between the '*' and 'nonrelative_template'.

Thanks for your perseverance.
Previous: Arnout EngelenNext: Junio C Hamano
Message 9 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.