Created
July 1, 2023 11:38
-
-
Save imaami/9ba643f3ba40b3441a6fda0d8d8ff74b to your computer and use it in GitHub Desktop.
strerror() but more cursed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <pthread.h> | |
#include <string.h> | |
#include <stddef.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
static void *fn (void *p) | |
{ | |
pthread_detach(pthread_self()); | |
clock_nanosleep(CLOCK_MONOTONIC, 0, | |
&(struct timespec) | |
{0, 100000000}, NULL); | |
free(p); | |
return NULL; | |
} | |
extern char const *terror (int e); | |
char const *terror (int e) | |
{ | |
char *s = strdup(strerror(e)); | |
pthread_create(&(pthread_t){0}, NULL, fn, s); | |
return s; | |
} | |
int main (void) | |
{ | |
printf("%s\n%s\n%s\n", | |
strerror(-1), | |
strerror(-2), | |
strerror(-3)); | |
#define strerror terror | |
printf("\n%s\n%s\n%s\n", | |
strerror(-1), | |
strerror(-2), | |
strerror(-3)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment