diff --git a/sys/src/cmd/rc/code.c b/sys/src/cmd/rc/code.c index 7aad38bc1..3618838e3 100644 --- a/sys/src/cmd/rc/code.c +++ b/sys/src/cmd/rc/code.c @@ -22,10 +22,7 @@ int morecode(void) { ncode+=100; - codebuf = (code *)realloc((char *)codebuf, ncode*sizeof codebuf[0]); - if(codebuf==0) - panic("Can't realloc %d bytes in morecode!", - ncode*sizeof codebuf[0]); + codebuf = (code *)erealloc((char *)codebuf, ncode*sizeof codebuf[0]); return 0; } diff --git a/sys/src/cmd/rc/havefork.c b/sys/src/cmd/rc/havefork.c index 04921c61c..4cf148fd3 100644 --- a/sys/src/cmd/rc/havefork.c +++ b/sys/src/cmd/rc/havefork.c @@ -71,15 +71,6 @@ Xpipe(void) } } -char* -erealloc(char *p, long n) -{ - p = realloc(p, n); /* botch, should be Realloc */ - if(p==0) - panic("Can't realloc %d bytes\n", n); - return p; -} - /* * Who should wait for the exit from the fork? */ diff --git a/sys/src/cmd/rc/haventfork.c b/sys/src/cmd/rc/haventfork.c index 914e85f8c..ed184b573 100644 --- a/sys/src/cmd/rc/haventfork.c +++ b/sys/src/cmd/rc/haventfork.c @@ -51,15 +51,6 @@ Xasync(void) setvar("apid", newword(buf, (word *)0)); } -char* -erealloc(char *p, long n) -{ - p = realloc(p, n); /* botch, should be Realloc */ - if(p==0) - panic("Can't realloc %d bytes\n", n); - return p; -} - enum { Stralloc = 100, }; void @@ -227,4 +218,4 @@ execforkexec(void) } free(argv); return -1; -} \ No newline at end of file +} diff --git a/sys/src/cmd/rc/io.c b/sys/src/cmd/rc/io.c index 5480265cf..8b2ba97ee 100644 --- a/sys/src/cmd/rc/io.c +++ b/sys/src/cmd/rc/io.c @@ -178,9 +178,7 @@ flush(io *f) if(f->strp){ n = f->ebuf - f->strp; - f->strp = realloc(f->strp, n+Stralloc+1); - if(f->strp==0) - panic("Can't realloc %d bytes in flush!", n+Stralloc+1); + f->strp = erealloc(f->strp, n+Stralloc+1); f->bufp = f->strp + n; f->ebuf = f->bufp + Stralloc; memset(f->bufp, '\0', Stralloc+1); diff --git a/sys/src/cmd/rc/plan9.c b/sys/src/cmd/rc/plan9.c index d71ca675c..6ad3ba3bd 100644 --- a/sys/src/cmd/rc/plan9.c +++ b/sys/src/cmd/rc/plan9.c @@ -10,7 +10,7 @@ #include "getflags.h" enum { - Maxenvname = 256, /* undocumented limit */ + Maxenvname = 128, /* undocumented limit */ }; char *Signame[] = { @@ -622,15 +622,19 @@ Malloc(ulong n) return malloc(n); } +void* +Realloc(void *p, ulong n) +{ + return realloc(p, n); +} + int *waitpids; int nwaitpids; void addwaitpid(int pid) { - waitpids = realloc(waitpids, (nwaitpids+1)*sizeof waitpids[0]); - if(waitpids == 0) - panic("Can't realloc %d waitpids", nwaitpids+1); + waitpids = erealloc(waitpids, (nwaitpids+1)*sizeof waitpids[0]); waitpids[nwaitpids++] = pid; } diff --git a/sys/src/cmd/rc/rc.h b/sys/src/cmd/rc/rc.h index 8ccdc344b..242a9b5ea 100644 --- a/sys/src/cmd/rc/rc.h +++ b/sys/src/cmd/rc/rc.h @@ -97,8 +97,11 @@ var *gvar[NVAR]; /* hash for globals */ #define new(type) ((type *)emalloc(sizeof(type))) -void *emalloc(long); void *Malloc(ulong); +void *Realloc(void *, ulong); + +void *emalloc(long); +void *erealloc(void *, long); void efree(void *); #define NOFILE 128 /* should come from */ diff --git a/sys/src/cmd/rc/subr.c b/sys/src/cmd/rc/subr.c index 48e8cb091..b0fc80005 100644 --- a/sys/src/cmd/rc/subr.c +++ b/sys/src/cmd/rc/subr.c @@ -7,13 +7,21 @@ void * emalloc(long n) { void *p = Malloc(n); - if(p==0) panic("Can't malloc %d bytes", n); /* if(err){ pfmt(err, "malloc %d->%p\n", n, p); flush(err); } /**/ return p; } +void* +erealloc(void *p, long n) +{ + p = Realloc(p, n); /* botch, should be Realloc */ + if(p==0) + panic("Can't realloc %d bytes\n", n); + return p; +} + void efree(void *p) { diff --git a/sys/src/cmd/rc/unix.c b/sys/src/cmd/rc/unix.c index 3be938148..1a5a4a8c0 100644 --- a/sys/src/cmd/rc/unix.c +++ b/sys/src/cmd/rc/unix.c @@ -467,3 +467,9 @@ Malloc(n) { return (void *)malloc(n); } + +void* +Realloc(void *p, ulong n) +{ + return realloc(p, n); +} diff --git a/sys/src/cmd/rc/win32.c b/sys/src/cmd/rc/win32.c index b7fcece61..d19629644 100644 --- a/sys/src/cmd/rc/win32.c +++ b/sys/src/cmd/rc/win32.c @@ -558,3 +558,9 @@ Malloc(ulong n) { return malloc(n); } + +void* +Realloc(void *p, ulong n) +{ + return realloc(p, n); +}