Re: [PATCH]: first take at cleanup of #include, xmalloc / xrealloc, git status report usage.
- From
- Edgar 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 ...