LCOV - code coverage report
Current view: top level - src - pathcmp.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 30 30 100.0 %
Date: 2016-02-29 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include "burp.h"
       2             : #include "pathcmp.h"
       3             : 
       4             : // Return a number indicating the number of directories matched.
       5             : // 0 if it is not a sub-directory.
       6             : // Two paths the same counts as a subdirectory.
       7         222 : int is_subdir(const char *dir, const char *sub)
       8             : {
       9         222 :         int count=1;
      10         222 :         const char *d=NULL;
      11         222 :         const char *s=NULL;
      12         222 :         const char *dl=NULL;
      13         222 :         const char *sl=NULL;
      14         222 :         if(!sub || !dir) return 0;
      15        7327 :         for(s=sl=sub, dl=d=dir; *s && *d; s++, d++)
      16             :         {
      17        7356 :                 if(*s!=*d) break;
      18        7327 :                 sl=s;
      19        7327 :                 dl=d;
      20        7327 :                 if(*s=='/') count++;
      21             :         }
      22         219 :         if(!*d && !*s) return count; // Paths were exactly the same.
      23         194 :         if(!*d && *s=='/')
      24             :                 return count; // 'dir' ended without a slash, for example:
      25             :         // dir=/bin sub=/bin/bash
      26          66 :         if(*dl=='/' && *sl=='/' && *(sl+1) && !*(dl+1)) return count;
      27             :         return 0;
      28             : }
      29             : 
      30      670570 : int pathcmp(const char *a, const char *b)
      31             : {
      32      670570 :         const char *x=NULL;
      33      670570 :         const char *y=NULL;
      34      670570 :         if(!a && !b) return 0; // equal
      35      592845 :         if( a && !b) return 1; // a is longer
      36      590758 :         if(!a &&  b) return -1; // b is longer
      37    10817188 :         for(x=a, y=b; *x && *y ; x++, y++)
      38             :         {
      39    11341075 :                 if(*x==*y) continue;
      40      523887 :                 if(*x=='/' && *y!='/') return -1;
      41      523859 :                 if(*x!='/' && *y=='/') return 1;
      42      523858 :                 if(*x<*y) return -1;
      43      268535 :                 if(*x>*y) return 1;
      44             :         }
      45       66870 :         if(!*x && !*y) return 0; // equal
      46         129 :         if( *x && !*y) return 1; // x is longer
      47           6 :         return -1; // y is longer
      48             : }

Generated by: LCOV version 1.10