Skip to content

Instantly share code, notes, and snippets.

@imaami
Created July 1, 2023 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imaami/9ba643f3ba40b3441a6fda0d8d8ff74b to your computer and use it in GitHub Desktop.
Save imaami/9ba643f3ba40b3441a6fda0d8d8ff74b to your computer and use it in GitHub Desktop.
strerror() but more cursed
#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