d1a424c002
This will allow us to redefine the exit function.
For example:
```
#define exit(code) { \
fprintf(stderr, "%s:%d: exit(%s) in function ‘%s’\n",
__FILE__, __LINE__, #code, __func__); \
_exit(code); \
}
```
28 lines
577 B
C
28 lines
577 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int main(void) {
|
|
FILE* f = fopen("stdio/stdio.in", "r");
|
|
|
|
flockfile(f);
|
|
|
|
// Commenting this out should cause a deadlock:
|
|
// flockfile(f);
|
|
|
|
if (!ftrylockfile(f)) {
|
|
puts("Mutex unlocked but it shouldn't be");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
funlockfile(f);
|
|
|
|
if (ftrylockfile(f)) {
|
|
puts("Mutex locked but it shouldn't be");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
if (!ftrylockfile(f)) {
|
|
puts("Mutex unlocked but it shouldn't be");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
funlockfile(f);
|
|
}
|