This code is totally broken. Setting errno is a no go in glibc, it's a read only variable (on some glibc it is a macro to a function) As a consequence, your mkdir checking is broken, you should really check mkdir returned values and then check errno on failure value. Also you could make a small private static function that does the mkdir and error checking to avoid code duplication.
> Git-Url: > http://git.frugalware.org/gitweb/gitweb.cgi?p=fw32.git;a=commitdiff;h=fd0925f22b65095426dabb9b33162c76c10d86ad > > commit fd0925f22b65095426dabb9b33162c76c10d86ad > Author: James Buren <[email protected]> > Date: Wed Nov 2 04:08:45 2011 -0500 > > fw32.c: simplify error handling in mkdir_parents > > diff --git a/fw32.c b/fw32.c > index 16d1ed7..d4ae7e0 100644 > --- a/fw32.c > +++ b/fw32.c > @@ -5,10 +5,13 @@ > #include <string.h> > #include <sys/stat.h> > #include <limits.h> > +#include <errno.h> > #include <assert.h> > > static const char *FW32_ROOT = "/usr/lib/fw32"; > > +static const char *FW32_CONFIG = "/etc/fw32/pacman-g2.conf"; > + > static const char *FW32_DIRS[] = > { > "/proc", > @@ -47,7 +50,6 @@ static void > mkdir_parents(const char *s) > { > char path[PATH_MAX], *p; > - struct stat st; > > assert(s && *s == '/'); > > @@ -57,28 +59,20 @@ mkdir_parents(const char *s) > { > *p = 0; > > - if(!stat(path,&st)) > - { > - if(S_ISDIR(st.st_mode)) > - continue; > + errno = 0; > > - error("Parent directory exists and is not a directory: %s\n",path); > - } > + mkdir(path,0755); > > - if(mkdir(path,0755)) > - error("Failed to create parent directory: %s\n",path); > + if(errno && errno != EEXIST) > + error("Failed to create parent directory: %s: > %s\n",path,strerror(errno)); > } > > - if(!stat(path,&st)) > - { > - if(S_ISDIR(st.st_mode)) > - return; > + errno = 0; > > - error("Directory exists and is not a directory: %s\n",path); > - } > + mkdir(path,0755); > > - if(mkdir(path,0755)) > - error("Failed to create directory: %s\n",path); > + if(errno && errno != EEXIST) > + error("Failed to create directory: %s: %s\n",path,strerror(errno)); > } > > static bool > _______________________________________________ > Frugalware-git mailing list > [email protected] > http://frugalware.org/mailman/listinfo/frugalware-git > _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
