Files
RedBear-OS/tests/unistd/confstr.c
T
Josh Megnauth 9d2f5d95dc 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.
2025-08-22 22:13:51 -04:00

35 lines
880 B
C

#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;
}