История изменений
Исправление
romeo250501,
(текущая версия)
:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <setjmp.h>
#include <signal.h>
jmp_buf env;
void on_sigint(int sig) {
longjmp(env, 1);
}
int main() {
int fd = open("/dev/null", O_RDONLY);
signal(SIGINT, on_sigint);
if (setjmp(env))
goto clean;
work:
sleep(3);
puts("timeout");
clean:
puts("cleanup");
close(fd);
}
Исходная версия Deleted, :
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <setjmp.h>
#include <signal.h>
jmp_buf env;
void on_sigint(int sig) {
longjmp(env, 1);
}
int main() {
int fd = open("/dev/null", O_RDONLY);
goto clean_setup;
work:
sleep(3);
puts("timeout");
goto clean;
clean_setup:
if (!setjmp(env)) {
signal(SIGINT, on_sigint);
goto work;
}
clean:
puts("cleanup");
close(fd);
}