projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
$ ); echo $? echoed 0,all other shells echo 2.
[unix-history]
/
usr
/
src
/
bin
/
sh
/
memalloc.c
diff --git
a/usr/src/bin/sh/memalloc.c
b/usr/src/bin/sh/memalloc.c
index
9fe373f
..
94f5859
100644
(file)
--- a/
usr/src/bin/sh/memalloc.c
+++ b/
usr/src/bin/sh/memalloc.c
@@
-1,6
+1,6
@@
/*-
/*-
- * Copyright (c) 1991
The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1991
, 1993
+ *
The Regents of the University of California.
All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Kenneth Almquist.
*
* This code is derived from software contributed to Berkeley by
* Kenneth Almquist.
@@
-9,7
+9,7
@@
*/
#ifndef lint
*/
#ifndef lint
-static char sccsid[] = "@(#)memalloc.c
5.1
(Berkeley) %G%";
+static char sccsid[] = "@(#)memalloc.c
8.3
(Berkeley) %G%";
#endif /* not lint */
#include "shell.h"
#endif /* not lint */
#include "shell.h"
@@
-18,15
+18,18
@@
static char sccsid[] = "@(#)memalloc.c 5.1 (Berkeley) %G%";
#include "error.h"
#include "machdep.h"
#include "mystring.h"
#include "error.h"
#include "machdep.h"
#include "mystring.h"
+#include <stdlib.h>
+#include <unistd.h>
/*
* Like malloc, but returns an error when out of space.
*/
pointer
/*
* Like malloc, but returns an error when out of space.
*/
pointer
-ckmalloc(nbytes) {
+ckmalloc(nbytes)
+ int nbytes;
+{
register pointer p;
register pointer p;
- pointer malloc();
if ((p = malloc(nbytes)) == NULL)
error("Out of space");
if ((p = malloc(nbytes)) == NULL)
error("Out of space");
@@
-41,8
+44,8
@@
ckmalloc(nbytes) {
pointer
ckrealloc(p, nbytes)
register pointer p;
pointer
ckrealloc(p, nbytes)
register pointer p;
- {
- pointer realloc();
+ int nbytes;
+{
if ((p = realloc(p, nbytes)) == NULL)
error("Out of space");
if ((p = realloc(p, nbytes)) == NULL)
error("Out of space");
@@
-93,7
+96,9
@@
int herefd = -1;
pointer
pointer
-stalloc(nbytes) {
+stalloc(nbytes)
+ int nbytes;
+{
register char *p;
nbytes = ALIGN(nbytes);
register char *p;
nbytes = ALIGN(nbytes);
@@
-179,7
+184,7
@@
growstackblock() {
int oldlen = stacknleft;
struct stack_block *sp;
int oldlen = stacknleft;
struct stack_block *sp;
- if (stacknxt == stackp->space) {
+ if (stacknxt == stackp->space
&& stackp != &stackbase
) {
INTOFF;
sp = stackp;
stackp = sp->prev;
INTOFF;
sp = stackp;
stackp = sp->prev;
@@
-191,16
+196,18
@@
growstackblock() {
INTON;
} else {
p = stalloc(newlen);
INTON;
} else {
p = stalloc(newlen);
-
bcopy(oldspace, p
, oldlen);
+
memcpy(p, oldspace
, oldlen);
stacknxt = p; /* free the space */
stacknxt = p; /* free the space */
- stacknleft +=
newlen;
/* we just allocated */
+ stacknleft +=
ALIGN(newlen);
/* we just allocated */
}
}
void
}
}
void
-grabstackblock(len) {
+grabstackblock(len)
+ int len;
+{
len = ALIGN(len);
stacknxt += len;
stacknleft -= len;
len = ALIGN(len);
stacknxt += len;
stacknleft -= len;
@@
-230,7
+237,7
@@
grabstackblock(len) {
char *
growstackstr() {
int len = stackblocksize();
char *
growstackstr() {
int len = stackblocksize();
- if (herefd && len >= 1024) {
+ if (herefd
>= 0
&& len >= 1024) {
xwrite(herefd, stackblock(), len);
sstrnleft = len - 1;
return stackblock();
xwrite(herefd, stackblock(), len);
sstrnleft = len - 1;
return stackblock();