Skip to content

Commit d95a149

Browse files
committed
btrfs-progs: use POSIX semantics of basename
This is a followup to 884a609 ("btrfs-progs: add basename wrappers for unified semantics"). Test cli/019-subvolume-create-parents fails as there are paths with trailing slashes. The GNU semantics does not change the argument of basename(3) but this is problematic with trailing slashes. This is not uncommon and could potentially break things. To minimize impact of the basename behaviour depending on the include of libgen.h use the single wrapper in path utils that has to include libgen anyway for dirname. Our code passes writable buffers to basename. Issue: #778 Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 884a609 commit d95a149

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

common/path-utils.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,15 +491,19 @@ int test_issubvolname(const char *name)
491491
* Unified GNU semantics basename helper, never changing the argument. Always
492492
* use this instead of basename().
493493
*/
494-
const char *path_basename(const char *path)
494+
char *path_basename(char *path)
495495
{
496+
#if 0
496497
const char *tmp = strrchr(path, '/');
497498

498499
/* Special case when the whole path is just "/". */
499500
if (path[0] == '/' && path[1] == 0)
500501
return path;
501502

502503
return tmp ? tmp + 1 : path;
504+
#else
505+
return basename(path);
506+
#endif
503507
}
504508

505509
/*

common/path-utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int path_is_dir(const char *path);
3939
int is_same_loop_file(const char *a, const char *b);
4040
int path_is_reg_or_block_device(const char *filename);
4141
int path_is_in_dir(const char *parent, const char *path);
42-
const char *path_basename(const char *path);
42+
char *path_basename(char *path);
4343
char *path_dirname(char *path);
4444

4545
int test_issubvolname(const char *name);

0 commit comments

Comments
 (0)