From: Justin Wind <justin.wind@gmail.com>
Date: Wed, 18 Apr 2012 21:25:27 +0000 (-0700)
Subject: minor portability enhancements
X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=286b0e08bf52ee3eda3d8f73366a786337a7a4bd;p=dcpu16

minor portability enhancements

missed some headers, use sigaction() instead of signal()
---

diff --git a/as-dcpu16.c b/as-dcpu16.c
index 063741d..820b837 100644
--- a/as-dcpu16.c
+++ b/as-dcpu16.c
@@ -2,6 +2,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <string.h>
+#include <strings.h>
 #include <errno.h>
 #include <sysexits.h>
 #include <assert.h>
diff --git a/vm-dcpu16.c b/vm-dcpu16.c
index d60c340..537452a 100644
--- a/vm-dcpu16.c
+++ b/vm-dcpu16.c
@@ -2,6 +2,8 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <string.h>
+#include <strings.h>
+#include <signal.h>
 #include <errno.h>
 #include <assert.h>
 #include <sysexits.h>
@@ -326,14 +328,17 @@ COMMAND_HELP(step) {
 
 
 COMMAND_IMPL(run) {
-    sig_t osig;
+    struct sigaction act;
     (void)arg_count, (void)arg_vector;
 
     running_ = 1;
 
-    /* install our new interrupt signal handler */
-    if ( (osig = signal(SIGINT, sigint_handler_)) == SIG_ERR ) {
-        fprintf(stderr, "%s():%s\n", "signal", strerror(errno));
+    memset(&act, 0, sizeof act);
+    act.sa_handler = sigint_handler_;
+    act.sa_flags = SA_RESETHAND;
+
+    if (sigaction(SIGINT, &act, NULL)) {
+        fprintf(stderr, "%s():%s\n", "sigaction", strerror(errno));
         return -1;
     }
 
@@ -347,12 +352,6 @@ COMMAND_IMPL(run) {
         }
     }
 
-    /* restore the old interrupt signal handler */
-    if (signal(SIGINT, osig) == SIG_ERR) {
-        fprintf(stderr, "%s():%s\n", "signal", strerror(errno));
-        return -1;
-    }
-
     printf("interrupted...\n");
 
     return 0;