btrfs-progs: use POSIX semantics of basename

This is a followup to 884a609a77 ("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>
This commit is contained in:
David Sterba 2024-04-30 21:34:50 +02:00
parent 884a609a77
commit d95a14949d
2 changed files with 6 additions and 2 deletions

View File

@ -491,8 +491,9 @@ int test_issubvolname(const char *name)
* Unified GNU semantics basename helper, never changing the argument. Always
* use this instead of basename().
*/
const char *path_basename(const char *path)
char *path_basename(char *path)
{
#if 0
const char *tmp = strrchr(path, '/');
/* Special case when the whole path is just "/". */
@ -500,6 +501,9 @@ const char *path_basename(const char *path)
return path;
return tmp ? tmp + 1 : path;
#else
return basename(path);
#endif
}
/*

View File

@ -39,7 +39,7 @@ int path_is_dir(const char *path);
int is_same_loop_file(const char *a, const char *b);
int path_is_reg_or_block_device(const char *filename);
int path_is_in_dir(const char *parent, const char *path);
const char *path_basename(const char *path);
char *path_basename(char *path);
char *path_dirname(char *path);
int test_issubvolname(const char *name);