apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apr/file_io/win32 dir.c
Date Sun, 29 Dec 2002 22:17:29 GMT
wrowe       2002/12/29 14:17:29

  Modified:    file_io/win32 dir.c
  Log:
    apr_dir_make_recursive is now implemented.  The unix code is a little
    wonky, lots of redundant strdups.  See this code if you care to streamline
    that port a bit.
  
  Revision  Changes    Path
  1.66      +45 -1     apr/file_io/win32/dir.c
  
  Index: dir.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/win32/dir.c,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- dir.c	11 Dec 2002 19:52:06 -0000	1.65
  +++ dir.c	29 Dec 2002 22:17:29 -0000	1.66
  @@ -295,11 +295,55 @@
       return APR_SUCCESS;
   }
   
  +
  +static apr_status_t dir_make_parent(char *path,
  +                                    apr_fileperms_t perm,
  +                                    apr_pool_t *pool)
  +{
  +    apr_status_t rv;
  +    char *ch = strrchr(path, '\\');
  +    if (!ch) {
  +        return APR_ENOENT;
  +    }
  +
  +    *ch = '\0';
  +    rv = apr_dir_make (path, perm, pool); /* Try to make straight off */
  +    
  +    if (APR_STATUS_IS_ENOENT(rv)) { /* Missing an intermediate dir */
  +        rv = dir_make_parent(path, perm, pool);
  +
  +        if (rv == APR_SUCCESS) {
  +            rv = apr_dir_make (path, perm, pool); /* And complete the path */
  +        }
  +    }
  +
  +    *ch = '\\'; /* Always replace the slash before returning */
  +    return rv;
  +}
  +
   APR_DECLARE(apr_status_t) apr_dir_make_recursive(const char *path,
                                                    apr_fileperms_t perm,
                                                    apr_pool_t *pool)
   {
  -    return APR_ENOTIMPL;
  +    apr_status_t rv = 0;
  +    
  +    rv = apr_dir_make (path, perm, pool); /* Try to make PATH right out */
  +    
  +    if (APR_STATUS_IS_EEXIST(rv)) /* It's OK if PATH exists */
  +        return APR_SUCCESS;
  +    
  +    if (APR_STATUS_IS_ENOENT(rv)) { /* Missing an intermediate dir */
  +        char *dir;
  +        
  +        rv = apr_filepath_merge(&dir, "", path, APR_FILEPATH_NATIVE, pool);
  +
  +        if (rv == APR_SUCCESS)
  +            rv = dir_make_parent(dir, perm, pool); /* Make intermediate dirs */
  +        
  +        if (rv == APR_SUCCESS)
  +            rv = apr_dir_make (dir, perm, pool);   /* And complete the path */
  +    }
  +    return rv;
   }
   
   
  
  
  

Mime
View raw message