(get_pathname): Make sure no extra slash is inserted.
Showing
1 changed file
with
10 additions
and
3 deletions
... | @@ -446,10 +446,17 @@ get_pathname (const char *dirname, const char *basename) | ... | @@ -446,10 +446,17 @@ get_pathname (const char *dirname, const char *basename) |
446 | /* Relative. */ | 446 | /* Relative. */ |
447 | else | 447 | else |
448 | { | 448 | { |
449 | size_t len = strlen (basename); | 449 | size_t baselen = strlen (basename); |
450 | pathname = calloc (strlen (dirname) + len + 2, sizeof (char)); | 450 | size_t dirlen = strlen (dirname); |
451 | while (dirlen > 0 && dirname[dirlen-1] == '/') | ||
452 | dirlen--; | ||
453 | pathname = calloc (dirname + baselen + 2, sizeof (char)); | ||
451 | if (pathname) | 454 | if (pathname) |
452 | sprintf (pathname, "%s/%s", dirname, basename); | 455 | { |
456 | memcpy (pathname, dirname, dirlen); | ||
457 | pathname[dirlen] = '/'; | ||
458 | strcpy (pathname + dirlen + 1, basename); | ||
459 | } | ||
453 | } | 460 | } |
454 | return pathname; | 461 | return pathname; |
455 | } | 462 | } | ... | ... |
-
Please register or sign in to post a comment