Skip to content

Commit 5ffdbc6

Browse files
committed
expose dirname and basename
1 parent 09ad0b3 commit 5ffdbc6

File tree

19 files changed

+78
-3
lines changed

19 files changed

+78
-3
lines changed

libc-test/build.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ fn test_apple(target: &str) {
204204
"iconv.h",
205205
"ifaddrs.h",
206206
"langinfo.h",
207+
"libgen.h",
207208
"libproc.h",
208209
"limits.h",
209210
"locale.h",
@@ -417,6 +418,7 @@ fn test_openbsd(target: &str) {
417418
"errno.h",
418419
"execinfo.h",
419420
"fcntl.h",
421+
"libgen.h",
420422
"limits.h",
421423
"link.h",
422424
"locale.h",
@@ -992,6 +994,7 @@ fn test_netbsd(target: &str) {
992994
"elf.h",
993995
"errno.h",
994996
"fcntl.h",
997+
"libgen.h",
995998
"limits.h",
996999
"link.h",
9971000
"locale.h",
@@ -1206,6 +1209,7 @@ fn test_dragonflybsd(target: &str) {
12061209
"ifaddrs.h",
12071210
"kvm.h",
12081211
"langinfo.h",
1212+
"libgen.h",
12091213
"limits.h",
12101214
"link.h",
12111215
"locale.h",
@@ -1505,6 +1509,7 @@ fn test_android(target: &str) {
15051509
"fcntl.h",
15061510
"grp.h",
15071511
"ifaddrs.h",
1512+
"libgen.h",
15081513
"limits.h",
15091514
"link.h",
15101515
"locale.h",
@@ -1866,6 +1871,7 @@ fn test_freebsd(target: &str) {
18661871
"iconv.h",
18671872
"ifaddrs.h",
18681873
"langinfo.h",
1874+
"libgen.h",
18691875
"libutil.h",
18701876
"limits.h",
18711877
"link.h",
@@ -2771,6 +2777,7 @@ fn test_linux(target: &str) {
27712777
"iconv.h",
27722778
"ifaddrs.h",
27732779
"langinfo.h",
2780+
"libgen.h",
27742781
"limits.h",
27752782
"link.h",
27762783
"locale.h",
@@ -3410,6 +3417,22 @@ fn test_linux(target: &str) {
34103417
// it can't be changed from struct.
34113418
"pthread_sigqueue" => true,
34123419

3420+
// There are two versions of basename(3) on Linux with glibc, see
3421+
//
3422+
// https://man7.org/linux/man-pages/man3/basename.3.html
3423+
//
3424+
// If libgen.h is included, then the POSIX version will be available;
3425+
// If _GNU_SOURCE is defined and string.h is included, then the GNU one
3426+
// will be used.
3427+
//
3428+
// libc exposes both of them, providing a prefix to differentiate between
3429+
// them.
3430+
//
3431+
// Because the name with prefix is not a valid symbol in C, we have to
3432+
// skip the tests.
3433+
"posix_basename" if gnu => true,
3434+
"gnu_basename" if gnu => true,
3435+
34133436
_ => false,
34143437
}
34153438
});

libc-test/semver/android.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3548,3 +3548,5 @@ winsize
35483548
wmemchr
35493549
write
35503550
writev
3551+
dirname
3552+
basename

libc-test/semver/apple.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,3 +2227,5 @@ wait4
22272227
waitid
22282228
xsw_usage
22292229
xucred
2230+
dirname
2231+
basename

libc-test/semver/dragonfly.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,3 +1546,5 @@ wait4
15461546
waitid
15471547
xucred
15481548
eaccess
1549+
dirname
1550+
basename

libc-test/semver/freebsd.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1925,4 +1925,6 @@ wait4
19251925
waitid
19261926
xallocx
19271927
xucred
1928-
eaccess
1928+
eaccess
1929+
dirname
1930+
basename

libc-test/semver/linux-gnu.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,4 +657,7 @@ eaccess
657657
asctime_r
658658
ctime_r
659659
strftime
660-
strptime
660+
strptime
661+
dirname
662+
posix_basename
663+
gnu_basename

libc-test/semver/linux-musl.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@ euidaccess
5252
eaccess
5353
asctime_r
5454
strftime
55-
strptime
55+
strptime
56+
dirname
57+
basename

libc-test/semver/netbsd.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,3 +1533,5 @@ uucred
15331533
vm_size_t
15341534
wait4
15351535
waitid
1536+
dirname
1537+
basename

libc-test/semver/openbsd.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,3 +1231,5 @@ utmp
12311231
utrace
12321232
wait4
12331233
xucred
1234+
dirname
1235+
basename

src/unix/bsd/apple/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5870,6 +5870,9 @@ extern "C" {
58705870

58715871
pub fn malloc_size(ptr: *const ::c_void) -> ::size_t;
58725872
pub fn malloc_good_size(size: ::size_t) -> ::size_t;
5873+
5874+
pub fn dirname(path: *mut ::c_char) -> *mut ::c_char;
5875+
pub fn basename(path: *mut ::c_char) -> *mut ::c_char;
58735876
}
58745877

58755878
pub unsafe fn mach_task_self() -> ::mach_port_t {

0 commit comments

Comments
 (0)