ref: cd811b587f42060b2a96557689a0ef8c71561e87
parent: 08abb553ff8277ca156923043c82fc81377ac084
author: Ori Bernstein <[email protected]>
date: Sat Oct 4 07:41:48 EDT 2014
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
--- a/6/insns.def
+++ b/6/insns.def
@@ -18,17 +18,17 @@
For technical reasons, the indexing on use and def statments is 1-based,
instead of 0-based. (0 is the sentinel value).
*/
-
-Insn(Inone, "BAD_INSN", Use(), Def())
+#define None .l={0},.r={0}
+Insn(Inone, "BAD_INSN", Use(None), Def(None))
/* Note, the mov instruction is specified in an overly general manner. */
Insn(Imov, "\tmov%t %x,%x\n", Use(.l={1}), Def(.l={2}))
Insn(Imovt, "PSEUDO: TRUNCATE\n", Use(.l={1}), Def(.l={2}))
Insn(Imovzx, "\tmovz%1t%2t %x,%x\n", Use(.l={1}), Def(.l={2}))
Insn(Imovsx, "\tmovs%1t%2t %x,%x\n", Use(.l={1}), Def(.l={2}))
-Insn(Irepmovsb, "\trep movsb\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def())
-Insn(Irepmovsw, "\trep movsw\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def())
-Insn(Irepmovsl, "\trep movsl\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def())
-Insn(Irepmovsq, "\trep movsq\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def())
+Insn(Irepmovsb, "\trep movsb\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def(None))
+Insn(Irepmovsw, "\trep movsw\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def(None))
+Insn(Irepmovsl, "\trep movsl\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def(None))
+Insn(Irepmovsq, "\trep movsq\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def(None))
Insn(Ilea, "\tlea%2t %m,%r\n", Use(.l={1}), Def(.l={2}))
Insn(Iadd, "\tadd%t %x,%r\n", Use(.l={1,2}), Def(.l={2}))
@@ -47,23 +47,23 @@
Insn(Isar, "\tsar%2t %u,%r\n", Use(.l={1,2}), Def(.l={2}))
Insn(Ishr, "\tshr%2t %u,%r\n", Use(.l={1,2}), Def(.l={2}))
-Insn(Itest, "\ttest%t %x,%r\n", Use(.l={1,2}), Def(.l={}))
-Insn(Icmp, "\tcmp%t %x,%r\n", Use(.l={1,2}), Def(.l={}))
+Insn(Itest, "\ttest%t %x,%r\n", Use(.l={1,2}), Def(None))
+Insn(Icmp, "\tcmp%t %x,%r\n", Use(.l={1,2}), Def(None))
-Insn(Ipush, "\tpush%t %r\n", Use(.l={1}), Def())
-Insn(Ipop, "\tpop%t %r\n", Use(.l={1}), Def())
+Insn(Ipush, "\tpush%t %r\n", Use(.l={1}), Def(None))
+Insn(Ipop, "\tpop%t %r\n", Use(.l={1}), Def(None))
/* branch instructions */
-Insn(Isetz, "\tsetz %v\n", Use(), Def(.l={1}))
-Insn(Isetnz, "\tsetnz %v\n", Use(), Def(.l={1}))
-Insn(Isetl, "\tsetl %v\n", Use(), Def(.l={1}))
-Insn(Isetle, "\tsetle %v\n", Use(), Def(.l={1}))
-Insn(Isetg, "\tsetg %v\n", Use(), Def(.l={1}))
-Insn(Isetge, "\tsetge %v\n", Use(), Def(.l={1}))
-Insn(Isetb, "\tsetb %v\n", Use(), Def(.l={1}))
-Insn(Isetbe, "\tsetbe %v\n", Use(), Def(.l={1}))
-Insn(Iseta, "\tseta %v\n", Use(), Def(.l={1}))
-Insn(Isetae, "\tsetae %v\n", Use(), Def(.l={1}))
+Insn(Isetz, "\tsetz %v\n", Use(None), Def(.l={1}))
+Insn(Isetnz, "\tsetnz %v\n", Use(None), Def(.l={1}))
+Insn(Isetl, "\tsetl %v\n", Use(None), Def(.l={1}))
+Insn(Isetle, "\tsetle %v\n", Use(None), Def(.l={1}))
+Insn(Isetg, "\tsetg %v\n", Use(None), Def(.l={1}))
+Insn(Isetge, "\tsetge %v\n", Use(None), Def(.l={1}))
+Insn(Isetb, "\tsetb %v\n", Use(None), Def(.l={1}))
+Insn(Isetbe, "\tsetbe %v\n", Use(None), Def(.l={1}))
+Insn(Iseta, "\tseta %v\n", Use(None), Def(.l={1}))
+Insn(Isetae, "\tsetae %v\n", Use(None), Def(.l={1}))
/* fp specific instructions */
Insn(Imovs, "\tmovs%1t %x,%x\n", Use(.l={1}), Def(.l={2}))
@@ -75,24 +75,24 @@
Insn(Isubs, "\tsubs%t %x,%f\n", Use(.l={1,2}), Def(.l={2}))
Insn(Imuls, "\tmuls%t %x,%f\n", Use(.l={1,2}), Def(.l={2}))
Insn(Idivs, "\tdivs%t %x,%f\n", Use(.l={1,2}), Def(.l={2}))
-Insn(Icomis, "\tcomis%t %x,%f\n", Use(.l={1,2}), Def())
+Insn(Icomis, "\tcomis%t %x,%f\n", Use(.l={1,2}), Def(None))
Insn(Ixorp, "\tmuls%t %x,%f\n", Use(.l={1,2}), Def(.l={2}))
/* branch instructions */
Insn(Icall, "\tcall %v\n", Use(.l={1}), Def(.r={Rrax,Reax,Rax,Ral,Rah}))
Insn(Icallind, "\tcall *%v\n", Use(.l={1}), Def(.r={Rrax,Reax,Rax,Ral,Rah}))
-Insn(Ijmp, "\tjmp %v\n", Use(.l={1}), Def())
-Insn(Ijz, "\tjz %v\n", Use(.l={1}), Def())
-Insn(Ijnz, "\tjnz %v\n", Use(.l={1}), Def())
-Insn(Ijl, "\tjl %v\n", Use(.l={1}), Def())
-Insn(Ijle, "\tjle %v\n", Use(.l={1}), Def())
-Insn(Ijg, "\tjg %v\n", Use(.l={1}), Def())
-Insn(Ijge, "\tjge %v\n", Use(.l={1}), Def())
-Insn(Ijb, "\tjb %v\n", Use(.l={1}), Def())
-Insn(Ijbe, "\tjbe %v\n", Use(.l={1}), Def())
-Insn(Ija, "\tja %v\n", Use(.l={1}), Def())
-Insn(Ijae, "\tjae %v\n", Use(.l={1}), Def())
-Insn(Iret, "\tret\n", Use(.r={Rrax,Rxmm0d}), Def())
+Insn(Ijmp, "\tjmp %v\n", Use(.l={1}), Def(None))
+Insn(Ijz, "\tjz %v\n", Use(.l={1}), Def(None))
+Insn(Ijnz, "\tjnz %v\n", Use(.l={1}), Def(None))
+Insn(Ijl, "\tjl %v\n", Use(.l={1}), Def(None))
+Insn(Ijle, "\tjle %v\n", Use(.l={1}), Def(None))
+Insn(Ijg, "\tjg %v\n", Use(.l={1}), Def(None))
+Insn(Ijge, "\tjge %v\n", Use(.l={1}), Def(None))
+Insn(Ijb, "\tjb %v\n", Use(.l={1}), Def(None))
+Insn(Ijbe, "\tjbe %v\n", Use(.l={1}), Def(None))
+Insn(Ija, "\tja %v\n", Use(.l={1}), Def(None))
+Insn(Ijae, "\tjae %v\n", Use(.l={1}), Def(None))
+Insn(Iret, "\tret\n", Use(.r={Rrax,Rxmm0d}), Def(None))
/* not really an insn... */
-Insn(Ilbl, "%v:\n", Use(), Def())
+Insn(Ilbl, "%v:\n", Use(None), Def(None))
--- a/6/isel.c
+++ b/6/isel.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <stdarg.h>
#include <inttypes.h>
#include <ctype.h>
@@ -1067,10 +1067,10 @@
case Lflt:
if (tybase(v->lit.type)->type == Tyflt32) {
u.fv = v->lit.fltval;
- fprintf(fd, "\t.long 0x%"PRIx32"\n", u.lv);
+ fprintf(fd, "\t.long 0x%" PRIx32 "\n", u.lv);
} else if (tybase(v->lit.type)->type == Tyflt64) {
u.dv = v->lit.fltval;
- fprintf(fd, "\t.quad 0x%"PRIx64"\n", u.qv);
+ fprintf(fd, "\t.quad 0x%" PRIx64 "\n", u.qv);
}
break;
case Lstr:
@@ -1240,7 +1240,7 @@
is.curbb = is.bb[j];
for (i = 0; i < fn->cfg->bb[j]->nnl; i++) {
/* put in a comment that says where this line comes from */
- snprintf(buf, sizeof buf, "\n\t# bb = %zd, bbidx = %zd, %s:%d",
+ snprintf(buf, sizeof buf, "\n\t# bb = %ld, bbidx = %ld, %s:%d",
j, i, file->file.name, fn->cfg->bb[j]->nl[i]->line);
g(&is, Ilbl, locstrlbl(buf), NULL);
isel(&is, fn->cfg->bb[j]->nl[i]);
--- a/6/locs.c
+++ b/6/locs.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
--- 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 @@
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 @@
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 @@
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);
}
--- a/6/ra.c
+++ b/6/ra.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <stdarg.h>
#include <assert.h>
#include <limits.h>
@@ -24,19 +24,23 @@
/* tables of uses/defs by instruction */
Usemap usetab[] = {
+#define Def(...)
#define Use(...) {__VA_ARGS__}
#define Insn(i, fmt, use, def) use,
#include "insns.def"
#undef Insn
#undef Use
+#undef Def
};
Usemap deftab[] = {
+#define Use(...)
#define Def(...) {__VA_ARGS__}
#define Insn(i, fmt, use, def) def,
#include "insns.def"
#undef Insn
#undef Def
+#undef Use
};
/* A map of which registers interfere */
@@ -618,15 +622,17 @@
if (found)
wldel(s, &s->wlspill, &s->nwlspill, idx);
if (moverelated(s, m)) {
- if (!found)
- assert(wlfind(s->wlfreeze, s->nwlfreeze, m, &idx));
- else
+ if (!found) {
+ assert(wlfind(s->wlfreeze, s->nwlfreeze, m, &idx) != 0);
+ } else {
wlput(&s->wlfreeze, &s->nwlfreeze, locmap[m]);
+ }
} else {
- if (!found)
+ if (!found) {
assert(wlfind(s->wlsimp, s->nwlsimp, m, &idx));
- else
+ } else {
wlput(&s->wlsimp, &s->nwlsimp, locmap[m]);
+ }
}
}
}
@@ -916,7 +922,7 @@
spilled = 0;
while (s->nselstk) {
- bzero(taken, Nreg*sizeof(int));
+ memset(taken, 0, Nreg*sizeof(int));
n = lpop(&s->selstk, &s->nselstk);
for (j = 0; j < s->ngadj[n->reg.id];j++) {
--- a/6/simp.c
+++ b/6/simp.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
@@ -1289,6 +1289,7 @@
static Node *simpuget(Simp *s, Node *n, Node *dst)
{
die("No uget simplification yet");
+ return NULL;
}
/* simplifies
@@ -1338,6 +1339,7 @@
static Node *comparecomplex(Simp *s, Node *n, Op op)
{
fatal(n->line, "Complex comparisons not yet supported\n");
+ return NULL;
}
static Node *compare(Simp *s, Node *n, int fields)
--- a/mk/c.mk
+++ b/mk/c.mk
@@ -50,7 +50,7 @@
); done
clean: subdirs-clean
- rm -f ${BIN} ${OBJ} ${CLEAN}
+ rm -f ${BIN} ${OBJ} ${CLEAN} ${LIB}
install: subdirs-install $(INSTBIN) $(INSTLIB) $(INSTHDR) $(INSTPKG)
@for i in $(INSTBIN); do \
--- a/muse/muse.c
+++ b/muse/muse.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
--- a/myrbuild/myrbuild.c
+++ b/myrbuild/myrbuild.c
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <stdarg.h>
+#include <inttypes.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
@@ -10,8 +11,6 @@
#include <ctype.h>
#include <fcntl.h>
#include <unistd.h>
-#include <regex.h>
-#include <err.h>
#include "parse.h"
@@ -44,10 +43,18 @@
char *sysname;
-regex_t usepat;
Htab *compiled; /* used as string set */
Htab *loopdetect; /* used as string set */
+static void fail(int status, char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ exit(status);
+}
+
static void usage(char *prog)
{
printf("%s [-h] [-I path] [-l lib] [-b bin] inputs...\n", prog);
@@ -125,10 +132,10 @@
pid = fork();
status = 0;
if (pid == -1) {
- err(1, "Could not fork");
+ fail(1, "Could not fork");
} else if (pid == 0) {
if (execvp(cmd[0], cmd) == -1)
- err(1, "Failed to exec %s", cmd[0]);
+ fail(1, "Failed to exec %s", cmd[0]);
} else {
waitpid(pid, &status, 0);
}
@@ -143,7 +150,7 @@
struct stat from_sb, to_sb;
if (stat(from, &from_sb))
- err(1, "Could not find %s", from);
+ fail(1, "Could not find %s", from);
if (stat(to, &to_sb) == -1)
return 0;
@@ -160,11 +167,36 @@
return 0;
}
+int finddep(char *buf, char **dep)
+{
+ char *end, *w, *p;
+ p = buf;
+
+
+ end = buf + strlen(buf);
+ while (isspace(*p) && p != end)
+ p++;
+ if (strncmp(p, "use", 3) != 0)
+ return 0;
+ p += 3;
+ if (!isspace(*p))
+ return 0;
+ while (isspace(*p) && p != end)
+ p++;
+
+ w = p;
+ while (!isspace(*p) && p != end)
+ p++;
+ if (p == w)
+ return 0;
+ *dep = strdupn(w, p - w);
+ return 1;
+}
+
void getdeps(char *file, char **deps, size_t depsz, size_t *ndeps)
{
char buf[2048];
- regmatch_t m[2];
size_t i;
FILE *f;
char *dep;
@@ -171,15 +203,12 @@
f = fopen(file, "r");
if (!f)
- err(1, "Could not open file \"%s\"", file);
+ fail(1, "Could not open file \"%s\"", file);
i = 0;
while (fgets(buf, sizeof buf, f)) {
- if (regexec(&usepat, buf, 2, m, 0) == REG_NOMATCH)
+ if (!finddep(buf, &dep))
continue;
- if (i == depsz)
- die("Too many deps for file %s", file);
- dep = strdupn(&buf[m[1].rm_so], m[1].rm_eo - m[1].rm_so);
if (!inlist(deps, i, dep))
deps[i++] = dep;
else
@@ -205,7 +234,8 @@
f = fopen(buf, "r");
if (f)
return f;
- err(1, "could not open library file %s\n", lib);
+ fail(1, "could not open library file %s\n", lib);
+ return NULL;
}
void scrapelib(Htab *g, char *lib)
@@ -221,7 +251,7 @@
ndeps = 0;
use = openlib(lib);
if (fgetc(use) != 'U')
- err(1, "library \"%s\" is not a usefile.", lib);
+ fail(1, "library \"%s\" is not a usefile.", lib);
/* we don't care about the usefile's name */
free(rdstr(use));
while (fgetc(use) == 'L') {
@@ -358,7 +388,7 @@
char buf[1024];
if (hthas(looped, n))
- err(1, "cycle in library dependency graph involving %s\n", n);
+ fail(1, "cycle in library dependency graph involving %s\n", n);
if (hthas(marked, n))
return;
htput(looped, n, n);
@@ -502,7 +532,6 @@
libgraph = mkht(strhash, streq);
compiled = mkht(strhash, streq);
loopdetect = mkht(strhash, streq);
- regcomp(&usepat, "^[[:space:]]*use[[:space:]]+([^[:space:]]+)", REG_EXTENDED);
for (i = optind; i < argc; i++) {
lappend(&stack, &nstack, argv[i]);
compile(argv[i], &stack, &nstack);
--- a/opt/cfg.c
+++ b/opt/cfg.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
--- a/opt/df.c
+++ b/opt/df.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
--- a/opt/fold.c
+++ b/opt/fold.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
--- a/parse/bitset.c
+++ b/parse/bitset.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <assert.h>
#include <limits.h>
#include <string.h>
--- a/parse/dump.c
+++ b/parse/dump.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
--- a/parse/htab.c
+++ b/parse/htab.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <assert.h>
#include <limits.h>
#include <string.h>
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <inttypes.h>
#include <ctype.h>
#include <string.h>
--- a/parse/names.c
+++ b/parse/names.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
--- a/parse/node.c
+++ b/parse/node.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -1,4 +1,8 @@
-#define FATAL __attribute__((noreturn))
+#ifdef __GNUC__
+# define FATAL __attribute__((noreturn))
+#else
+# define FATAL
+#endif
typedef uint8_t byte;
typedef unsigned int uint;
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
--- a/parse/tok.c
+++ b/parse/tok.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
@@ -8,7 +8,6 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
-#include <err.h>
#include <unistd.h>
#include "parse.h"
@@ -321,7 +320,7 @@
}
/* \u{abc} */
-static int32_t unichar()
+static int32_t unichar(void)
{
uint32_t v;
int c;
@@ -382,7 +381,7 @@
return v;
}
-static Tok *strlit()
+static Tok *strlit(void)
{
Tok *t;
int c;
@@ -442,7 +441,7 @@
return val;
}
-static Tok *charlit()
+static Tok *charlit(void)
{
Tok *t;
int c;
@@ -737,7 +736,7 @@
return t;
}
-static Tok *typaram()
+static Tok *typaram(void)
{
Tok *t;
char buf[1024];
@@ -792,8 +791,10 @@
fd = open(file, O_RDONLY);
- if (fd == -1)
- err(errno, "Unable to open file %s", file);
+ if (fd == -1) {
+ fprintf(stderr, "Unable to open file %s\n", file);
+ exit(1);
+ }
nread = 0;
fbuf = malloc(4096);
--- a/parse/type.c
+++ b/parse/type.c
@@ -1,7 +1,7 @@
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
--- a/parse/use.c
+++ b/parse/use.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
--- a/parse/util.c
+++ b/parse/util.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
@@ -40,7 +40,7 @@
p = xrealloc(mem, sz);
if (sz > oldsz)
- bzero(&p[oldsz], sz - oldsz);
+ memset(&p[oldsz], 0, sz - oldsz);
return p;
}
@@ -210,11 +210,13 @@
return v;
}
-void wrbuf(FILE *fd, void *buf, size_t sz)
+void wrbuf(FILE *fd, void *ptr, size_t sz)
{
size_t n;
+ char *buf;
n = 0;
+ buf = ptr;
while (n < sz) {
n += fwrite(buf + n, 1, sz - n, fd);
if (feof(fd))