[BusyBox] make_directory

Vladimir N. Oleynik dzo at simtreas.ru
Thu Aug 1 09:32:03 UTC 2002


Glenn McGrath wrote:
> 
> On Thu, 01 Aug 2002 18:43:22 +0400
> "Vladimir N. Oleynik" <dzo at simtreas.ru> wrote:
> 
> > Glenn,
> >
> > > I think the libbb make_directory function could be simpler, maybe
> > > something like.
> > >
> > > void make_recursive_directory(char *path, mode_t mode)
> > > {
> > >         const char *path_ptr = strrchr(path, '/');
> > >         if (path_ptr) {
> >
> > Not call mkdir() if not have '/'. Hmm, why?
> 
> Commonly a string will be of the form (directory)/file, so instead of
> seperating the directory component from the file component before calling
> make_recursive_directory, seeprate them after calling it.
> 
> Maybe this isnt an ideal approach, i will think about it some more.
> 
> > May be remove all const keyword for compile without warning? ;)
> 
> I was trying to be clever, but i forgot to compile with -Wall :(

See variant:

int make_recursive_directory(char *path, mode_t mode)
{
        char *path_ptr;
        int ret;

        ret = mkdir(path, mode);
        if (ret != 0 && errno == ENOENT &&
                                (path_ptr = strrchr(path, '/'))!=NULL) {
                *path_ptr = '\0';
                ret = make_recursive_directory(path, mode);
                if(ret)
                        return ret;
                ret = mkdir(path, mode);
                *path_ptr = '/';
        }
        return ret;
}


NOT TERSTING!


--w
vodz



More information about the busybox mailing list