summaryrefslogtreecommitdiff
path: root/6/main.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-10-04 11:41:48 -0400
committerOri Bernstein <ori@eigenstate.org>2014-10-04 11:41:48 -0400
commita8359030735219db18bc48b4e481c67ad6e48484 (patch)
tree7d6b4ada31d2b0d14257af6a9d864bd319d0f49d /6/main.c
parent6f62df231794edb17630f9f07ffaffe569072f13 (diff)
downloadmc-a8359030735219db18bc48b4e481c67ad6e48484.tar.gz
Start work of porting to Plan 9.
We're missing getopt, but everything else seems to work as far as compiling goes. Remaining work: - Converting assembly syntax - Invoking plan9 executables correctly
Diffstat (limited to '6/main.c')
-rw-r--r--6/main.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/6/main.c b/6/main.c
index 9aafd25..c453dd7 100644
--- a/6/main.c
+++ b/6/main.c
@@ -1,12 +1,11 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
-#include <err.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -70,7 +69,8 @@ static void assem(char *asmsrc, char *path)
if (pid == -1) {
die("couldn't fork");
} else if (pid == 0) {
- execvp(cmd[0], cmd);
+ if (execvp(cmd[0], cmd) == -1)
+ die("Couldn't exec assembler\n");
} else {
waitpid(pid, &status, 0);
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
@@ -93,8 +93,8 @@ static char *gentemp(char *buf, size_t bufsz, char *path, char *suffix)
else
base = path;
gettimeofday(&tv, NULL);
- srandom(tv.tv_usec);
- snprintf(buf, bufsz, "%s/tmp%lx%lx-%s%s", tmpdir, random(), (long)tv.tv_usec, base, suffix);
+ srand(tv.tv_usec);
+ snprintf(buf, bufsz, "%s/tmp%lx%lx-%s%s", tmpdir, (long)rand(), (long)tv.tv_usec, base, suffix);
return buf;
}
@@ -110,8 +110,10 @@ static void genuse(char *path)
else
swapsuffix(buf, 1024, path, ".myr", ".use");
f = fopen(buf, "w");
- if (!f)
- err(1, "Could not open path %s\n", buf);
+ if (!f) {
+ fprintf(stderr, "Could not open path %s\n", buf);
+ exit(1);
+ }
writeuse(f, file);
fclose(f);
}