02_errno_touch.c (503B)
1 /* Tier 2: touch errno. We deliberately call a function that fails 2 * (close(-1) → EBADF) and read errno after. errno's lowering varies 3 * by libc — in musl it's `__thread int errno;` (exercises 4 * R_AARCH64_TLSLE_* and PT_TLS emission); in glibc it's 5 * `(*__errno_location())` (a per-thread function call, no TLS reloc 6 * on the caller side). Either way the test asserts the value. */ 7 8 #include <errno.h> 9 #include <unistd.h> 10 11 int main(void) { 12 (void)close(-1); 13 return errno == EBADF ? 0 : 1; 14 }