Logo Search packages:      
Sourcecode: rapple version File versions  Download package

void rpl_fs_mkdir ( rpl_c_str_t  pathname  ) 

Recursively creates the directory tree indicated by pathname (akin to the mkdir command with the -p option).

Parameters:
pathname 

Definition at line 163 of file fsutil.c.

References fs_create_dir(), fs_dir_stat(), rpl_fs_get_cwd(), rpl_me_free(), and rpl_me_malloc().

Referenced by rpl_mod_init_init(), and rpl_mod_init_process().

                                   {
    rpl_str_t path, sp, ep, cwd;
    size_t length;

    /* for security reasons do not permit the creation of absolute paths */
    assert((pathname != NULL)); /* && (pathname[0] != '/')); */

    /* note the directory from which this function was called (you'll have to return to it later) */
    cwd = rpl_fs_get_cwd();

    /* make a copy of the path since we intend to alter it during processing */
    length = strlen(pathname) + 1;
    path = (rpl_str_t)rpl_me_malloc(length);
    snprintf(path, length, "%s", pathname);

    /* set sp to support both absolute and relative directory trees */
    sp = path;
    if(path[0] == '/')
        sp++;

    if((ep = strchr(sp, '/')) != NULL) {
        /* multiple consecutive "/" are permitted in paths but we still have to step over them
        while(*(ep+1) == '/')
            ep++;
        */
        *ep = '\0';

        /* if the pathname does not exist then create it */
        if(fs_dir_stat(path) < 0)
            fs_create_dir(path);
        (void)chdir(path);
        rpl_fs_mkdir(ep + 1);
        (void)chdir("..");
    } else {
        if(fs_dir_stat(path) < 0)
            fs_create_dir(path);
    }

    /* tidy up before you leave */
    rpl_me_free(path);
    chdir(cwd);
    rpl_me_free(cwd);
}


Generated by  Doxygen 1.6.0   Back to index