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

Re: [PATCH]: first take at cleanup of #include, xmalloc / xrealloc, git status report usage.

From
ETEdgar Toernig <froese@gmx.de>
Date
Apr 29, 2005, 16:24 UTC
Message-ID
<20050429182407.5f6afd15.froese@gmx.de>
In-Reply-To
<bfbb1f23220e1918afe70d4cf3de24f5@mpe.mpg.de>
Robert Sütterlin wrote:
Show 19 quoted lines
>[...]
> +static int
> +create_directories(const char *path)
>   {
> -	int len = strlen(path);
> -	char *buf = xmalloc(len + 1);
> -	const char *slash = path;
> +	char *buf = (char *)path;
> +	char *slash = buf;
> 
>   	while ((slash = strchr(slash+1, '/')) != NULL) {
> -		len = slash - path;
> -		memcpy(buf, path, len);
> -		buf[len] = 0;
> -		mkdir(buf, 0755);
> +		*slash = '\0';
> +		if (0 != mkdir(buf, 0755))
> +			return error("Unable to mkdir(``%s'', 0755)", buf);
> +		*slash = '/';

You need the temp buffer. Simply casting the const away may shut up the compiler but it's not correct.

> -		if (errno != EEXIST)
> +		if (EEXIST != errno)
Too much Star Wars?  Joda-speak?
Ciao, ET.
PS: the mkdir mode should be 0777 ...
Previous: Robert SütterlinNext: Klaus Robert Suetterlin
Message 2 of 3 in “: first take at cleanup of #include, xmalloc / xrealloc, git status report usage.”
  1. : first take at cleanup of #include, xmalloc / xrealloc, git status report usage.Robert Sütterlin, Apr 29, 2005
  2. Edgar ToernigApr 29, 2005
  3. Klaus Robert SuetterlinApr 29, 2005

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.