summaryrefslogtreecommitdiff
path: root/6
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-11-06 21:56:42 -0800
committerOri Bernstein <ori@eigenstate.org>2018-11-06 21:56:42 -0800
commit2ebbc72744b18b0e76d2aacb154bd0e4630bebc1 (patch)
tree634f43f8f4a94d61d1658c44b02fb803cbe2a225 /6
parent0556b63c0c444d2d77b270c7d51beb7e94f0d30a (diff)
downloadmc-2ebbc72744b18b0e76d2aacb154bd0e4630bebc1.tar.gz
Clean up.
Diffstat (limited to '6')
-rw-r--r--6/main.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/6/main.c b/6/main.c
index e699f3f..8e1f299 100644
--- a/6/main.c
+++ b/6/main.c
@@ -67,11 +67,26 @@ swapout(char* buf, size_t sz, char* suf) {
}
static void
+mkpath(char *p)
+{
+ char *e, path[256];
+
+ e = p;
+ assert(strlen(p) < sizeof(path));
+ while ((e = strstr(e, "/")) != NULL) {
+ memcpy(path, p, (e - p));
+ path[e - p] = 0;
+ mkdir(path, 0755);
+ e++;
+ }
+}
+
+static void
assemble(char *asmsrc, char *path)
{
char *asmcmd[] = Asmcmd;
- char objfile[256], dirpath[256];
- char *psuffix, *e;
+ char objfile[256];
+ char *psuffix;
char **p, **cmd;
size_t ncmd, i;
int pid, status;
@@ -88,12 +103,7 @@ assemble(char *asmsrc, char *path)
else
swapsuffix(objfile + i, sizeof objfile - i, path, ".myr", Objsuffix);
}
- e = objfile;
- while ((e = strstr(e, "/")) != NULL) {
- memcpy(dirpath, objfile, (e - objfile));
- mkdir(dirpath, 0755);
- e++;
- }
+ mkpath(objfile);
cmd = NULL;
ncmd = 0;
@@ -173,7 +183,7 @@ static void
genuse(char *path)
{
FILE *f;
- char buf[1024];
+ char buf[256];
char *psuffix;
size_t i;
@@ -189,6 +199,7 @@ genuse(char *path)
else
swapsuffix(buf + i, sizeof buf - i, path, ".myr", ".use");
}
+ mkpath(buf);
f = fopen(buf, "w");
if (!f) {
fprintf(stderr, "could not open path %s\n", buf);