Make test files buildable for glibc

This commit is contained in:
Wildan M
2026-03-25 03:11:33 +07:00
parent 186dc66818
commit 46379d7001
34 changed files with 67 additions and 39 deletions
+3
View File
@@ -117,6 +117,8 @@ int main(void) {
continue;
}
// fdclosedir is a BSD extension
#ifndef __GLIBC__
// fdclosedir returns ownership of the original fd.
int returned_fd = fdclosedir(iter);
// Internally, both closedir and fdclosedir consume the boxed DIR.
@@ -133,6 +135,7 @@ int main(void) {
fputs("fdclosedir shouldn't have closed the fd\n", stderr);
goto closedirfd;
}
#endif
status = EXIT_SUCCESS;
closediriter:
+7
View File
@@ -10,6 +10,7 @@
#define BUFFER_SIZE 4096
#ifndef __GLIBC__
void read_and_print_directory(int fd) {
char buffer[BUFFER_SIZE];
long nread;
@@ -44,3 +45,9 @@ int main(void) {
close(fd);
}
#else
int main(void) {
// glibc doesn't support posix_getdents & O_DIRECTORY
}
#endif
+10
View File
@@ -4,6 +4,9 @@
#include <stdlib.h>
#include <stdio.h>
// does not compile with glibc
#ifndef __GLIBC__
__attribute__((nonnull(2)))
static void vwarn_test(int code, const char* fmt, ...) {
va_list ap;
@@ -45,7 +48,14 @@ int main(void) {
// two functions handle everything internally.
errc(EXIT_SUCCESS, EUSERS, "Bye. It's crowded.");
// Unreachable
puts("err did not exit");
return EXIT_FAILURE;
}
#else
int main(void) {
exit(0);
}
#endif
+8
View File
@@ -8,6 +8,8 @@
#include "test_helpers.h"
// does not compile with glibc
#ifndef __GLIBC__
int main(void) {
chdir("nonexistent");
int err = errno;
@@ -50,3 +52,9 @@ int main(void) {
return EXIT_SUCCESS;
}
#else
int main(void) {
exit(0);
}
#endif
-2
View File
@@ -1,5 +1,3 @@
#define _GNU_SOURCE
#include <assert.h>
#include <fcntl.h>
#include <limits.h>
+7
View File
@@ -1,18 +1,25 @@
// These tests are primarily to ensure the macros compile without
// causing any funny business.
// TODO: does not compile with glibc
#include <features.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#ifndef __GLIBC__
__deprecated
#endif
static void legacy(void) {}
#ifndef __GLIBC__
__deprecatedNote("Sometimes deletes user's home (oops); use foobar")
#endif
static void legacy_notes(void) {}
#ifndef __GLIBC__
__nodiscard
#endif
static uint8_t the_answer(void) {
return 42;
}
+3 -1
View File
@@ -9,13 +9,15 @@
#include <arpa/inet.h>
#include <assert.h>
#ifndef __GLIBC__
#include <bits/locale-t.h>
#include <bits/pthread.h>
#include <dl-tls.h>
#endif
#include <crypt.h>
#include <ctype.h>
#include <dirent.h>
#include <dlfcn.h>
#include <dl-tls.h>
#include <elf.h>
#include <endian.h>
#include <err.h>
+4
View File
@@ -22,8 +22,10 @@ int main() {
unsigned int ui_max = UINT_MAX;
unsigned long ul_max = ULONG_MAX;
unsigned long long ull_max = ULLONG_MAX;
#ifndef __GLIBC__
int long_bit = LONG_BIT;
int word_bit = WORD_BIT;
#endif
printf("CHAR : [%d, %d]\n", c_min, c_max);
printf("SCHAR : [%d, %d]\n", sc_min, sc_max);
@@ -37,8 +39,10 @@ int main() {
printf("UINT_MAX : %u\n", ui_max);
printf("ULONG_MAX : %lu\n", ul_max);
printf("ULLONG_MAX : %llu\n\n", ull_max);
#ifndef __GLIBC__
printf("LONG_BIT : %d\n", long_bit);
printf("WORD_BIT : %d\n", word_bit);
#endif
return 0;
}
+7
View File
@@ -6,9 +6,16 @@
#include <pthread.h>
// TODO: glibc requires arg to be not const, but not relibc
#ifndef __GLIBC__
const char *msg1 = "first";
const char *msg2 = "second";
const char *msg3 = "third";
#else
char *msg1 = "first";
char *msg2 = "second";
char *msg3 = "third";
#endif
void cleanup1(void *arg) {
printf("Running %s cleanup callback\n", (const char *)arg);
+2 -1
View File
@@ -40,7 +40,8 @@ int main(void) {
int status;
stack_size = 1024 * 1024; // TODO?
assert(stack_size >= MINSIGSTKSZ * 100);
// in glibc MINSIGSTKSZ is a sysconf(MINSIGSTKSZ) macro
assert(stack_size >= (size_t)MINSIGSTKSZ * 100);
stack_base = mmap(NULL, stack_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
ERROR_IF(mmap, stack_base, == MAP_FAILED);
-2
View File
@@ -1,5 +1,3 @@
#define _XOPEN_SOURCE 700
#include <pthread.h>
#include <stdio.h>
#include <signal.h>
-2
View File
@@ -1,5 +1,3 @@
#define _XOPEN_SOURCE 700
#include "../test_helpers.h"
#include <assert.h>
#include <pthread.h>
-2
View File
@@ -1,5 +1,3 @@
#define _XOPEN_SOURCE 700
#include <assert.h>
#include <pthread.h>
#include <stdio.h>
-2
View File
@@ -1,6 +1,4 @@
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
-2
View File
@@ -9,8 +9,6 @@
#include "signals_list.h"
#include "../test_helpers.h"
#define _XOPEN_SOURCE 700
volatile sig_atomic_t handler_called = 0;
void sig_handler(int signo)
-2
View File
@@ -1,5 +1,3 @@
#define _XOPEN_SOURCE 600
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
-2
View File
@@ -1,5 +1,3 @@
#define _XOPEN_SOURCE 600
#include <assert.h>
#include <signal.h>
#include <stdio.h>
-2
View File
@@ -1,5 +1,3 @@
#define _XOPEN_SOURCE 600
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
-2
View File
@@ -1,5 +1,3 @@
#define _XOPEN_SOURCE 600
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
-2
View File
@@ -1,5 +1,3 @@
#define _XOPEN_SOURCE 600
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
-2
View File
@@ -1,5 +1,3 @@
#define _XOPEN_SOURCE 600
#include <assert.h>
#include <signal.h>
#include <stdbool.h>
-2
View File
@@ -1,5 +1,3 @@
#define _XOPEN_SOURCE 600
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
-2
View File
@@ -1,5 +1,3 @@
#define _GNU_SOURCE
#include <fcntl.h>
#include <limits.h>
#include <stdbool.h>
-1
View File
@@ -16,7 +16,6 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
+1 -1
View File
@@ -21,7 +21,7 @@ int main(void) {
puts("Correct memrchr");
char arr2[51];
memset(arr2, 0, 51); // Compiler builtin, should work
memccpy((void *)arr2, (void *)arr, 1, 100);
memccpy((void *)arr2, (void *)arr, 1, 51);
if (arr[50] != 1) {
puts("Incorrect memccpy");
exit(EXIT_FAILURE);
+3
View File
@@ -48,6 +48,8 @@ int main(void) {
exit(EXIT_FAILURE);
}
// no strnlen_s on glibc
#ifndef __GLIBC__
dest1_len = strnlen_s(dest1, 6);
printf("%d\n", dest1_len);
if(dest1_len != 6) {
@@ -68,6 +70,7 @@ int main(void) {
puts("strnlen_s(NULL, 100) failed");
exit(EXIT_FAILURE);
}
#endif
return 0;
}
+1 -1
View File
@@ -33,7 +33,7 @@ int reader(int fd) {
return 1;
}
int nfds_n1 = epoll_wait(epollfd, events, -1, -1);
int nfds_n1 = epoll_wait(epollfd, events, 8, -1);
if (nfds_n1 != -1 || errno != EINVAL) {
perror("epoll_wait");
return 1;
+1
View File
@@ -26,6 +26,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
int
-2
View File
@@ -1,5 +1,3 @@
#define _GNU_SOURCE // Linux to run locally
#include <fcntl.h>
#include <limits.h>
#include <stdbool.h>
-2
View File
@@ -1,5 +1,3 @@
#define _GNU_SOURCE // Linux for CI
#include <assert.h>
#include <fcntl.h>
#include <limits.h>
-2
View File
@@ -1,5 +1,3 @@
#define _XOPEN_SOURCE 700
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
+2
View File
@@ -7,6 +7,7 @@ int main(void) {
const char flipped_source[] = {1, 0, 3, 2, 5, 4};
const char first_two_source_bytes_flipped[] = {1, 0};
#ifndef __GLIBC__
swab(source, destination, /* nbytes */ -3);
for (size_t i = 0; i < sizeof(destination); ++i) {
if (destination[i] != 0) {
@@ -14,6 +15,7 @@ int main(void) {
return 1;
}
}
#endif
swab(source, destination, /* nbytes */ 0);
for (size_t i = 0; i < sizeof(destination); ++i) {
+4
View File
@@ -1,5 +1,9 @@
#include <sys/types.h>
#include <wchar.h>
// TODO: remove glibc?
#ifdef __GLIBC__
#include <stdio.h>
#endif
void attempt(wchar_t *s) {
wchar_t *end;
+4
View File
@@ -1,6 +1,10 @@
/* swscanf example */
#include <wchar.h>
#include <stdio.h>
// TODO: remove glibc?
#ifdef __GLIBC__
#include <stdarg.h>
#endif
#include "test_helpers.h"