apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stri...@apache.org
Subject cvs commit: apr/file_io/unix filepath.c
Date Fri, 26 Jul 2002 07:55:57 GMT
striker     2002/07/26 00:55:57

  Modified:    file_io/unix filepath.c
  Log:
  Style Police patrolling again.
  
  Revision  Changes    Path
  1.16      +37 -42    apr/file_io/unix/filepath.c
  
  Index: filepath.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/unix/filepath.c,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- filepath.c	12 Jun 2002 01:42:35 -0000	1.15
  +++ filepath.c	26 Jul 2002 07:55:57 -0000	1.16
  @@ -75,6 +75,7 @@
                                              apr_pool_t *p)
   {
       char path[APR_PATH_MAX];
  +
       if (!getcwd(path, sizeof(path))) {
           if (errno == ERANGE)
               return APR_ENAMETOOLONG;
  @@ -82,8 +83,9 @@
               return errno;
       }
       *defpath = apr_pstrdup(p, path);
  +
       return APR_SUCCESS;
  -}    
  +}
   
   
   /* Any OS that requires/refuses trailing slashes should be dealt with here
  @@ -92,29 +94,30 @@
   {
       if (chdir(path) != 0)
           return errno;
  +
       return APR_SUCCESS;
  -}    
  +}
   
  -APR_DECLARE(apr_status_t) apr_filepath_root(const char **rootpath, 
  +APR_DECLARE(apr_status_t) apr_filepath_root(const char **rootpath,
                                               const char **inpath,
                                               apr_int32_t flags,
                                               apr_pool_t *p)
   {
  -    if (**inpath == '/') 
  -    {
  +    if (**inpath == '/') {
           *rootpath = apr_pstrdup(p, "/");
           do {
               ++(*inpath);
           } while (**inpath == '/');
  +
           return APR_SUCCESS;
       }
   
       return APR_ERELATIVE;
   }
   
  -APR_DECLARE(apr_status_t) apr_filepath_merge(char **newpath, 
  -                                             const char *rootpath, 
  -                                             const char *addpath, 
  +APR_DECLARE(apr_status_t) apr_filepath_merge(char **newpath,
  +                                             const char *rootpath,
  +                                             const char *addpath,
                                                apr_int32_t flags,
                                                apr_pool_t *p)
   {
  @@ -131,8 +134,7 @@
       if (!addpath)
           addpath = "";
   
  -    if (addpath[0] == '/') 
  -    {
  +    if (addpath[0] == '/') {
           /* If addpath is rooted, then rootpath is unused.
            * Ths violates any APR_FILEPATH_SECUREROOTTEST and
            * APR_FILEPATH_NOTABSOLUTE flags specified.
  @@ -149,15 +151,13 @@
           if (!rootpath && !(flags & APR_FILEPATH_NOTABOVEROOT))
               rootpath = "";
       }
  -    else 
  -    {
  -        /* If APR_FILEPATH_NOTABSOLUTE is specified, the caller 
  +    else {
  +        /* If APR_FILEPATH_NOTABSOLUTE is specified, the caller
            * requires a relative result.  If the rootpath is
            * ommitted, we do not retrieve the working path,
            * if rootpath was supplied as absolute then fail.
            */
  -        if (flags & APR_FILEPATH_NOTABSOLUTE) 
  -        {
  +        if (flags & APR_FILEPATH_NOTABSOLUTE) {
               if (!rootpath)
                   rootpath = "";
               else if (rootpath[0] == '/')
  @@ -165,8 +165,7 @@
           }
       }
   
  -    if (!rootpath) 
  -    {
  +    if (!rootpath) {
           /* Start with the current working path.  This is bass akwards,
            * but required since the compiler (at least vc) doesn't like
            * passing the address of a char const* for a char** arg.
  @@ -176,7 +175,7 @@
           rootpath = getpath;
           if (rv != APR_SUCCESS)
               return errno;
  -    
  +
           /* XXX: Any kernel subject to goofy, uncanonical results
            * must run the rootpath against the user's given flags.
            * Simplest would be a recursive call to apr_filepath_merge
  @@ -193,9 +192,8 @@
       }
       path = (char *)apr_palloc(p, maxlen);
   
  -    if (addpath[0] == '/') 
  -    {
  -        /* Ignore the given root path, strip off leading 
  +    if (addpath[0] == '/') {
  +        /* Ignore the given root path, strip off leading
            * '/'s to a single leading '/' from the addpath,
            * and leave addpath at the first non-'/' character.
            */
  @@ -205,18 +203,17 @@
           path[0] = '/';
           pathlen = 1;
       }
  -    else
  -    {
  +    else {
           /* If both paths are relative, fail early
            */
           if (rootpath[0] != '/' && (flags & APR_FILEPATH_NOTRELATIVE))
  -                return APR_ERELATIVE;
  +            return APR_ERELATIVE;
   
           /* Base the result path on the rootpath
            */
           keptlen = rootlen;
           memcpy(path, rootpath, rootlen);
  -        
  +
           /* Always '/' terminate the given root path
            */
           if (keptlen && path[keptlen - 1] != '/') {
  @@ -225,9 +222,8 @@
           pathlen = keptlen;
       }
   
  -    while (*addpath) 
  -    {
  -        /* Parse each segment, find the closing '/' 
  +    while (*addpath) {
  +        /* Parse each segment, find the closing '/'
            */
           const char *next = addpath;
           while (*next && (*next != '/')) {
  @@ -236,13 +232,13 @@
           seglen = next - addpath;
   
           if (seglen == 0 || (seglen == 1 && addpath[0] == '.')) {
  -            /* noop segment (/ or ./) so skip it 
  +            /* noop segment (/ or ./) so skip it
                */
           }
           else if (seglen == 2 && addpath[0] == '.' && addpath[1] == '.')
{
               /* backpath (../) */
               if (pathlen == 1 && path[0] == '/') {
  -                /* Attempt to move above root.  Always die if the 
  +                /* Attempt to move above root.  Always die if the
                    * APR_FILEPATH_SECUREROOTTEST flag is specified.
                    */
                   if (flags & APR_FILEPATH_SECUREROOTTEST) {
  @@ -254,9 +250,11 @@
                    */
                   keptlen = 0;
               }
  -            else if (pathlen == 0 
  -                  || (pathlen == 3 && !memcmp(path + pathlen - 3, "../", 3))
  -                  || (pathlen  > 3 && !memcmp(path + pathlen - 4, "/../", 4)))
{
  +            else if (pathlen == 0
  +                     || (pathlen == 3
  +                         && !memcmp(path + pathlen - 3, "../", 3))
  +                     || (pathlen  > 3
  +                         && !memcmp(path + pathlen - 4, "/../", 4))) {
                   /* Path is already backpathed or empty, if the
                    * APR_FILEPATH_SECUREROOTTEST.was given die now.
                    */
  @@ -269,9 +267,8 @@
                   memcpy(path + pathlen, "../", 3);
                   pathlen += 3;
               }
  -            else 
  -            {
  -                /* otherwise crop the prior segment 
  +            else {
  +                /* otherwise crop the prior segment
                    */
                   do {
                       --pathlen;
  @@ -281,16 +278,14 @@
               /* Now test if we are above where we started and back up
                * the keptlen offset to reflect the added/altered path.
                */
  -            if (pathlen < keptlen) 
  -            {
  +            if (pathlen < keptlen) {
                   if (flags & APR_FILEPATH_SECUREROOTTEST) {
                       return APR_EABOVEROOT;
                   }
                   keptlen = pathlen;
               }
           }
  -        else 
  -        {
  +        else {
               /* An actual segment, append it to the destination path
                */
               if (*next) {
  @@ -309,7 +304,7 @@
           addpath = next;
       }
       path[pathlen] = '\0';
  -    
  +
       /* keptlen will be the rootlen unless the addpath contained
        * backpath elements.  If so, and APR_FILEPATH_NOTABOVEROOT
        * is specified (APR_FILEPATH_SECUREROOTTEST was caught above),
  @@ -325,7 +320,7 @@
               return APR_EABOVEROOT;
           }
       }
  -    
  +
       *newpath = path;
       return APR_SUCCESS;
   }
  
  
  

Mime
View raw message