-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathticktock.c
48 lines (41 loc) · 861 Bytes
/
ticktock.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Copyright 2012
* Steven Maresca <[email protected]>
*
* This program serves no useful purpose; that was intentional.
*
*/
#include <setjmp.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
static jmp_buf bandaid;
static void catch_segv() {
longjmp(bandaid, 1);
}
static void adios(int dummy) {
printf("\nByebye, you\n");
exit(1);
}
int main() {
int *iterate_me = NULL;
unsigned int i = 0;
char *ticktock[2];
ticktock[0] = "tick";
ticktock[1] = "tock";
signal(SIGINT, adios);
signal(SIGSEGV, catch_segv);
if (setjmp(bandaid) == 0) {
printf("%s\n", ticktock[i%2]);
i++;
*iterate_me = 11;
} else {
sleep(1);
printf("%s\n", ticktock[i%2]);
i++;
longjmp(bandaid, 0);
}
return 0;
}