Implement confstr (unistd.h)

The implementation for confstr is straightforward. Most of the constants
return 1 on both musl and glibc. The only constant that doesn't is
required for Fish.

I also switched an #[unsafe(no_mangle)] from my last patch back
to a #[no_mangle] because we need to bump cbindgen. #[unsafe(no_mangle)]
is required for Rust 2024.
This commit is contained in:
Josh Megnauth
2025-08-21 02:47:45 -04:00
parent 4758685217
commit 9d2f5d95dc
8 changed files with 98 additions and 4 deletions
+1
View File
@@ -124,6 +124,7 @@ EXPECT_NAMES=\
unistd/access \
unistd/brk \
unistd/constants \
unistd/confstr \
unistd/dup \
unistd/exec \
unistd/fchdir \
+34
View File
@@ -0,0 +1,34 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define CSPATHSZ 9
#define BADSIZ 4
int main(void) {
char actual[CSPATHSZ] = {0};
assert(confstr(_CS_PATH, actual, CSPATHSZ) == CSPATHSZ);
const char expected[] = "/usr/bin";
assert(strncmp(expected, actual, CSPATHSZ) == 0);
// The constants other than _CS_PATH just return an empty str (no support).
char empty[] = "";
assert(
confstr(
_CS_POSIX_V6_LP64_OFF64_LIBS,
empty,
0
) == 1
);
// Buffers that are too small should return the expected size.
char small[BADSIZ] = {0};
assert(confstr(_CS_PATH, small, BADSIZ) == CSPATHSZ);
// Null buffer and zero length should return the expected size
// for the constant.
assert(confstr(_CS_PATH, NULL, 0) == CSPATHSZ);
return EXIT_SUCCESS;
}