Skip to content

Commit

Permalink
expose both basename(3) on Linux with glibc
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveLauC committed Oct 25, 2022
1 parent c3b9a8d commit d1e20b1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
16 changes: 16 additions & 0 deletions libc-test/build.rs
Expand Up @@ -3417,6 +3417,22 @@ fn test_linux(target: &str) {
// it can't be changed from struct.
"pthread_sigqueue" => true,

// There are two versions of basename(3) on Linux with glibc, see
//
// https://man7.org/linux/man-pages/man3/basename.3.html
//
// If libgen.h is included, then the POSIX version will be available;
// If _GNU_SOURCE is defined and string.h is included, then the GNU one
// will be used.
//
// libc exposes both of them, providing a prefix to differentiate between
// them.
//
// Because the name with prefix is not a valid symbol in C, we have to
// skip the tests.
"posix_basename" if gnu => true,
"gnu_basename" if gnu => true,

_ => false,
}
});
Expand Down
3 changes: 2 additions & 1 deletion libc-test/semver/linux-gnu.txt
Expand Up @@ -659,4 +659,5 @@ ctime_r
strftime
strptime
dirname
basename
posix_basename
gnu_basename
7 changes: 6 additions & 1 deletion src/unix/linux_like/linux/gnu/mod.rs
Expand Up @@ -1348,7 +1348,12 @@ extern "C" {
pub fn strptime(s: *const ::c_char, format: *const ::c_char, tm: *mut ::tm) -> *mut ::c_char;

pub fn dirname(path: *mut ::c_char) -> *mut ::c_char;
pub fn basename(path: *mut ::c_char) -> *mut ::c_char;
/// POSIX version of `basename(3)`, defined in `libgen.h`.
#[link_name = "__xpg_basename"]
pub fn posix_basename(path: *mut ::c_char) -> *mut ::c_char;
/// GNU version of `basename(3)`, defined in `string.h`.
#[link_name = "basename"]
pub fn gnu_basename(path: *const ::c_char) -> *mut ::c_char;
}

extern "C" {
Expand Down

0 comments on commit d1e20b1

Please sign in to comment.