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

Diff of /trunk/util.c

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

revision 447 by siliconforks, Wed Feb 18 16:08:33 2009 UTC revision 448 by siliconforks, Tue Aug 11 17:16:32 2009 UTC
# Line 266  Line 266 
266    return strcmp(string + string_length - suffix_length, suffix) == 0;    return strcmp(string + string_length - suffix_length, suffix) == 0;
267  }  }
268    
269    static int is_slash(char c) {
270    #ifdef _WIN32
271      return c == '/' || c == '\\';
272    #else
273      return c == '/';
274    #endif
275    }
276    
277  char * make_path(const char * parent, const char * relative_path) {  char * make_path(const char * parent, const char * relative_path) {
278    size_t parent_length = strlen(parent);    size_t parent_length = strlen(parent);
279    size_t relative_path_length = strlen(relative_path);    size_t relative_path_length = strlen(relative_path);
280      assert(parent_length > 0);
281      assert(relative_path_length > 0);
282    size_t result_length = addst(parent_length, relative_path_length);    size_t result_length = addst(parent_length, relative_path_length);
283    result_length = addst(result_length, 2);    int parent_ends_with_slash = is_slash(parent[parent_length - 1]);
284      if (parent_ends_with_slash) {
285        result_length = addst(result_length, 1);
286      }
287      else {
288        result_length = addst(result_length, 2);
289      }
290    char * result = xmalloc(result_length);    char * result = xmalloc(result_length);
291    strcpy(result, parent);    strcpy(result, parent);
292    result[parent_length] = '/';    char * p = result + parent_length;
293    strcpy(result + parent_length + 1, relative_path);    if (! parent_ends_with_slash) {
294        *p = '/';
295        ++p;
296      }
297      strcpy(p, relative_path);
298    return result;    return result;
299  }  }
300    

Legend:
Removed from v.447  
changed lines
  Added in v.448

  ViewVC Help
Powered by ViewVC 1.1.24