to avoid undefined behavior use close(2) in the signal handler
#include <errno.h>
#include <signal.h>
#include <setjmp.h>
+#include <unistd.h>
static struct swit switches[] = {
#define PREPSW 0
};
-static int wtuser = 0;
-static int sigint = 0;
+volatile sig_atomic_t wtuser = 0;
+volatile sig_atomic_t sigint = 0;
static jmp_buf sigenv;
/*
getln(char *buffer, int n)
{
int c;
+ sig_atomic_t psigint;
char *cp;
cp = buffer;
switch (setjmp(sigenv)) {
case 0:
wtuser = 1;
+ psigint = sigint;
break;
- case DONE:
- wtuser = 0;
- return 0;
-
default:
wtuser = 0;
- return NOTOK;
+ if (sigint == psigint) {
+ return 0;
+ } else {
+ sigint = psigint;
+ return NOTOK;
+ }
}
for (;;) {
static void
intrser(int i)
{
- if (wtuser)
- longjmp(sigenv, NOTOK);
+ if (wtuser) {
+ close(STDIN_FILENO);
+ }
sigint++;
}