/[jscoverage]/trunk/util.c
ViewVC logotype

Diff of /trunk/util.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 427 by siliconforks, Wed Feb 18 16:08:33 2009 UTC revision 450 by siliconforks, Tue Aug 11 18:39:03 2009 UTC
# Line 90  Line 90 
90  #else  #else
91    printf("none\n");    printf("none\n");
92  #endif  #endif
93      printf("Copyright (C) 2009 siliconforks.com\n");
94      printf("License GPLv2+: GNU GPL version 2 or later <http://siliconforks.com/jscoverage/license.html>\n");
95      printf("This is free software: you are free to change and redistribute it.\n");
96      printf("There is NO WARRANTY, to the extent permitted by law.\n");
97    exit(EXIT_SUCCESS);    exit(EXIT_SUCCESS);
98  }  }
99    
# Line 266  Line 270 
270    return strcmp(string + string_length - suffix_length, suffix) == 0;    return strcmp(string + string_length - suffix_length, suffix) == 0;
271  }  }
272    
273    static int is_slash(char c) {
274    #ifdef _WIN32
275      return c == '/' || c == '\\';
276    #else
277      return c == '/';
278    #endif
279    }
280    
281  char * make_path(const char * parent, const char * relative_path) {  char * make_path(const char * parent, const char * relative_path) {
282    size_t parent_length = strlen(parent);    size_t parent_length = strlen(parent);
283    size_t relative_path_length = strlen(relative_path);    size_t relative_path_length = strlen(relative_path);
284    size_t result_length = addst(parent_length, relative_path_length);    size_t result_length = addst(parent_length, relative_path_length);
285    result_length = addst(result_length, 2);    int parent_ends_with_slash = parent_length > 0 && is_slash(parent[parent_length - 1]);
286      if (parent_ends_with_slash) {
287        result_length = addst(result_length, 1);
288      }
289      else {
290        result_length = addst(result_length, 2);
291      }
292    char * result = xmalloc(result_length);    char * result = xmalloc(result_length);
293    strcpy(result, parent);    strcpy(result, parent);
294    result[parent_length] = '/';    char * p = result + parent_length;
295    strcpy(result + parent_length + 1, relative_path);    if (! parent_ends_with_slash) {
296        *p = '/';
297        ++p;
298      }
299      strcpy(p, relative_path);
300    return result;    return result;
301  }  }
302    

Legend:
Removed from v.427  
changed lines
  Added in v.450

  ViewVC Help
Powered by ViewVC 1.1.24