more consistent spacing
This commit is contained in:
parent
c1b100e930
commit
e4d6a21165
2
cat.c
2
cat.c
|
@ -22,7 +22,7 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int fd, i;
|
int fd, i;
|
||||||
|
|
||||||
if(argc <= 1) {
|
if(argc <= 1){
|
||||||
cat(0);
|
cat(0);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,13 +91,13 @@ printint(int xx, int base, int sgn)
|
||||||
if(sgn && xx < 0){
|
if(sgn && xx < 0){
|
||||||
neg = 1;
|
neg = 1;
|
||||||
x = 0 - xx;
|
x = 0 - xx;
|
||||||
} else {
|
}else{
|
||||||
x = xx;
|
x = xx;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do{
|
||||||
buf[i++] = digits[x % base];
|
buf[i++] = digits[x % base];
|
||||||
} while((x /= base) != 0);
|
}while((x /= base) != 0);
|
||||||
if(neg)
|
if(neg)
|
||||||
buf[i++] = '-';
|
buf[i++] = '-';
|
||||||
|
|
||||||
|
|
36
fs.c
36
fs.c
|
@ -237,7 +237,7 @@ void
|
||||||
iput(struct inode *ip)
|
iput(struct inode *ip)
|
||||||
{
|
{
|
||||||
acquire(&icache.lock);
|
acquire(&icache.lock);
|
||||||
if(ip->ref == 1 && (ip->flags & I_VALID) && ip->nlink == 0) {
|
if(ip->ref == 1 && (ip->flags & I_VALID) && ip->nlink == 0){
|
||||||
// inode is no longer used: truncate and free inode.
|
// inode is no longer used: truncate and free inode.
|
||||||
if(ip->flags & I_BUSY)
|
if(ip->flags & I_BUSY)
|
||||||
panic("iput busy");
|
panic("iput busy");
|
||||||
|
@ -273,10 +273,10 @@ ialloc(uint dev, short type)
|
||||||
struct superblock sb;
|
struct superblock sb;
|
||||||
|
|
||||||
readsb(dev, &sb);
|
readsb(dev, &sb);
|
||||||
for(inum = 1; inum < sb.ninodes; inum++) { // loop over inode blocks
|
for(inum = 1; inum < sb.ninodes; inum++){ // loop over inode blocks
|
||||||
bp = bread(dev, IBLOCK(inum));
|
bp = bread(dev, IBLOCK(inum));
|
||||||
dip = (struct dinode*)bp->data + inum%IPB;
|
dip = (struct dinode*)bp->data + inum%IPB;
|
||||||
if(dip->type == 0) { // a free inode
|
if(dip->type == 0){ // a free inode
|
||||||
memset(dip, 0, sizeof(*dip));
|
memset(dip, 0, sizeof(*dip));
|
||||||
dip->type = type;
|
dip->type = type;
|
||||||
bwrite(bp); // mark it allocated on the disk
|
bwrite(bp); // mark it allocated on the disk
|
||||||
|
@ -323,8 +323,8 @@ bmap(struct inode *ip, uint bn, int alloc)
|
||||||
uint addr, *a;
|
uint addr, *a;
|
||||||
struct buf *bp;
|
struct buf *bp;
|
||||||
|
|
||||||
if(bn < NDIRECT) {
|
if(bn < NDIRECT){
|
||||||
if((addr = ip->addrs[bn]) == 0) {
|
if((addr = ip->addrs[bn]) == 0){
|
||||||
if(!alloc)
|
if(!alloc)
|
||||||
return -1;
|
return -1;
|
||||||
ip->addrs[bn] = addr = balloc(ip->dev);
|
ip->addrs[bn] = addr = balloc(ip->dev);
|
||||||
|
@ -333,9 +333,9 @@ bmap(struct inode *ip, uint bn, int alloc)
|
||||||
}
|
}
|
||||||
bn -= NDIRECT;
|
bn -= NDIRECT;
|
||||||
|
|
||||||
if(bn < NINDIRECT) {
|
if(bn < NINDIRECT){
|
||||||
// Load indirect block, allocating if necessary.
|
// Load indirect block, allocating if necessary.
|
||||||
if((addr = ip->addrs[INDIRECT]) == 0) {
|
if((addr = ip->addrs[INDIRECT]) == 0){
|
||||||
if(!alloc)
|
if(!alloc)
|
||||||
return -1;
|
return -1;
|
||||||
ip->addrs[INDIRECT] = addr = balloc(ip->dev);
|
ip->addrs[INDIRECT] = addr = balloc(ip->dev);
|
||||||
|
@ -343,8 +343,8 @@ bmap(struct inode *ip, uint bn, int alloc)
|
||||||
bp = bread(ip->dev, addr);
|
bp = bread(ip->dev, addr);
|
||||||
a = (uint*)bp->data;
|
a = (uint*)bp->data;
|
||||||
|
|
||||||
if((addr = a[bn]) == 0) {
|
if((addr = a[bn]) == 0){
|
||||||
if(!alloc) {
|
if(!alloc){
|
||||||
brelse(bp);
|
brelse(bp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -367,17 +367,17 @@ itrunc(struct inode *ip)
|
||||||
struct buf *bp;
|
struct buf *bp;
|
||||||
uint *a;
|
uint *a;
|
||||||
|
|
||||||
for(i = 0; i < NDIRECT; i++) {
|
for(i = 0; i < NDIRECT; i++){
|
||||||
if(ip->addrs[i]) {
|
if(ip->addrs[i]){
|
||||||
bfree(ip->dev, ip->addrs[i]);
|
bfree(ip->dev, ip->addrs[i]);
|
||||||
ip->addrs[i] = 0;
|
ip->addrs[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ip->addrs[INDIRECT]) {
|
if(ip->addrs[INDIRECT]){
|
||||||
bp = bread(ip->dev, ip->addrs[INDIRECT]);
|
bp = bread(ip->dev, ip->addrs[INDIRECT]);
|
||||||
a = (uint*)bp->data;
|
a = (uint*)bp->data;
|
||||||
for(j = 0; j < NINDIRECT; j++) {
|
for(j = 0; j < NINDIRECT; j++){
|
||||||
if(a[j])
|
if(a[j])
|
||||||
bfree(ip->dev, a[j]);
|
bfree(ip->dev, a[j]);
|
||||||
}
|
}
|
||||||
|
@ -408,7 +408,7 @@ readi(struct inode *ip, char *dst, uint off, uint n)
|
||||||
uint tot, m;
|
uint tot, m;
|
||||||
struct buf *bp;
|
struct buf *bp;
|
||||||
|
|
||||||
if(ip->type == T_DEV) {
|
if(ip->type == T_DEV){
|
||||||
if(ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].read)
|
if(ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].read)
|
||||||
return -1;
|
return -1;
|
||||||
return devsw[ip->major].read(ip, dst, n);
|
return devsw[ip->major].read(ip, dst, n);
|
||||||
|
@ -419,7 +419,7 @@ readi(struct inode *ip, char *dst, uint off, uint n)
|
||||||
if(off + n > ip->size)
|
if(off + n > ip->size)
|
||||||
n = ip->size - off;
|
n = ip->size - off;
|
||||||
|
|
||||||
for(tot=0; tot<n; tot+=m, off+=m, dst+=m) {
|
for(tot=0; tot<n; tot+=m, off+=m, dst+=m){
|
||||||
bp = bread(ip->dev, bmap(ip, off/BSIZE, 0));
|
bp = bread(ip->dev, bmap(ip, off/BSIZE, 0));
|
||||||
m = min(n - tot, BSIZE - off%BSIZE);
|
m = min(n - tot, BSIZE - off%BSIZE);
|
||||||
memmove(dst, bp->data + off%BSIZE, m);
|
memmove(dst, bp->data + off%BSIZE, m);
|
||||||
|
@ -436,7 +436,7 @@ writei(struct inode *ip, char *src, uint off, uint n)
|
||||||
uint tot, m;
|
uint tot, m;
|
||||||
struct buf *bp;
|
struct buf *bp;
|
||||||
|
|
||||||
if(ip->type == T_DEV) {
|
if(ip->type == T_DEV){
|
||||||
if(ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].write)
|
if(ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].write)
|
||||||
return -1;
|
return -1;
|
||||||
return devsw[ip->major].write(ip, src, n);
|
return devsw[ip->major].write(ip, src, n);
|
||||||
|
@ -447,7 +447,7 @@ writei(struct inode *ip, char *src, uint off, uint n)
|
||||||
if(off + n > MAXFILE*BSIZE)
|
if(off + n > MAXFILE*BSIZE)
|
||||||
n = MAXFILE*BSIZE - off;
|
n = MAXFILE*BSIZE - off;
|
||||||
|
|
||||||
for(tot=0; tot<n; tot+=m, off+=m, src+=m) {
|
for(tot=0; tot<n; tot+=m, off+=m, src+=m){
|
||||||
bp = bread(ip->dev, bmap(ip, off/BSIZE, 1));
|
bp = bread(ip->dev, bmap(ip, off/BSIZE, 1));
|
||||||
m = min(n - tot, BSIZE - off%BSIZE);
|
m = min(n - tot, BSIZE - off%BSIZE);
|
||||||
memmove(bp->data + off%BSIZE, src, m);
|
memmove(bp->data + off%BSIZE, src, m);
|
||||||
|
@ -455,7 +455,7 @@ writei(struct inode *ip, char *src, uint off, uint n)
|
||||||
brelse(bp);
|
brelse(bp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(n > 0 && off > ip->size) {
|
if(n > 0 && off > ip->size){
|
||||||
ip->size = off;
|
ip->size = off;
|
||||||
iupdate(ip);
|
iupdate(ip);
|
||||||
}
|
}
|
||||||
|
|
8
kbd.c
8
kbd.c
|
@ -17,15 +17,15 @@ kbd_getc(void)
|
||||||
return -1;
|
return -1;
|
||||||
data = inb(KBDATAP);
|
data = inb(KBDATAP);
|
||||||
|
|
||||||
if(data == 0xE0) {
|
if(data == 0xE0){
|
||||||
shift |= E0ESC;
|
shift |= E0ESC;
|
||||||
return 0;
|
return 0;
|
||||||
} else if(data & 0x80) {
|
}else if(data & 0x80){
|
||||||
// Key released
|
// Key released
|
||||||
data = (shift & E0ESC ? data : data & 0x7F);
|
data = (shift & E0ESC ? data : data & 0x7F);
|
||||||
shift &= ~(shiftcode[data] | E0ESC);
|
shift &= ~(shiftcode[data] | E0ESC);
|
||||||
return 0;
|
return 0;
|
||||||
} else if(shift & E0ESC) {
|
}else if(shift & E0ESC){
|
||||||
// Last character was an E0 escape; or with 0x80
|
// Last character was an E0 escape; or with 0x80
|
||||||
data |= 0x80;
|
data |= 0x80;
|
||||||
shift &= ~E0ESC;
|
shift &= ~E0ESC;
|
||||||
|
@ -34,7 +34,7 @@ kbd_getc(void)
|
||||||
shift |= shiftcode[data];
|
shift |= shiftcode[data];
|
||||||
shift ^= togglecode[data];
|
shift ^= togglecode[data];
|
||||||
c = charcode[shift & (CTL | SHIFT)][data];
|
c = charcode[shift & (CTL | SHIFT)][data];
|
||||||
if(shift & CAPSLOCK) {
|
if(shift & CAPSLOCK){
|
||||||
if('a' <= c && c <= 'z')
|
if('a' <= c && c <= 'z')
|
||||||
c += 'A' - 'a';
|
c += 'A' - 'a';
|
||||||
else if('A' <= c && c <= 'Z')
|
else if('A' <= c && c <= 'Z')
|
||||||
|
|
2
mkdir.c
2
mkdir.c
|
@ -13,7 +13,7 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 1; i < argc; i++){
|
for(i = 1; i < argc; i++){
|
||||||
if(mkdir(argv[i]) < 0) {
|
if(mkdir(argv[i]) < 0){
|
||||||
printf(2, "mkdir: %s failed to create\n", argv[i]);
|
printf(2, "mkdir: %s failed to create\n", argv[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
2
mp.c
2
mp.c
|
@ -134,7 +134,7 @@ mp_init(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mp->imcrp) {
|
if(mp->imcrp){
|
||||||
// Bochs doesn't support IMCR, so this doesn't run on Bochs.
|
// Bochs doesn't support IMCR, so this doesn't run on Bochs.
|
||||||
// But it would on real hardware.
|
// But it would on real hardware.
|
||||||
outb(0x22, 0x70); // Select IMCR
|
outb(0x22, 0x70); // Select IMCR
|
||||||
|
|
2
pipe.c
2
pipe.c
|
@ -65,7 +65,7 @@ pipeclose(struct pipe *p, int writable)
|
||||||
if(writable){
|
if(writable){
|
||||||
p->writeopen = 0;
|
p->writeopen = 0;
|
||||||
wakeup(&p->readp);
|
wakeup(&p->readp);
|
||||||
} else {
|
}else{
|
||||||
p->readopen = 0;
|
p->readopen = 0;
|
||||||
wakeup(&p->writep);
|
wakeup(&p->writep);
|
||||||
}
|
}
|
||||||
|
|
20
printf.c
20
printf.c
|
@ -20,14 +20,14 @@ printint(int fd, int xx, int base, int sgn)
|
||||||
if(sgn && xx < 0){
|
if(sgn && xx < 0){
|
||||||
neg = 1;
|
neg = 1;
|
||||||
x = -xx;
|
x = -xx;
|
||||||
} else {
|
}else{
|
||||||
x = xx;
|
x = xx;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
do {
|
do{
|
||||||
buf[i++] = digits[x % base];
|
buf[i++] = digits[x % base];
|
||||||
} while((x /= base) != 0);
|
}while((x /= base) != 0);
|
||||||
if(neg)
|
if(neg)
|
||||||
buf[i++] = '-';
|
buf[i++] = '-';
|
||||||
|
|
||||||
|
@ -50,17 +50,17 @@ printf(int fd, char *fmt, ...)
|
||||||
if(state == 0){
|
if(state == 0){
|
||||||
if(c == '%'){
|
if(c == '%'){
|
||||||
state = '%';
|
state = '%';
|
||||||
} else {
|
}else{
|
||||||
putc(fd, c);
|
putc(fd, c);
|
||||||
}
|
}
|
||||||
} else if(state == '%'){
|
}else if(state == '%'){
|
||||||
if(c == 'd'){
|
if(c == 'd'){
|
||||||
printint(fd, *ap, 10, 1);
|
printint(fd, *ap, 10, 1);
|
||||||
ap++;
|
ap++;
|
||||||
} else if(c == 'x' || c == 'p'){
|
}else if(c == 'x' || c == 'p'){
|
||||||
printint(fd, *ap, 16, 0);
|
printint(fd, *ap, 16, 0);
|
||||||
ap++;
|
ap++;
|
||||||
} else if(c == 's'){
|
}else if(c == 's'){
|
||||||
s = (char*)*ap;
|
s = (char*)*ap;
|
||||||
ap++;
|
ap++;
|
||||||
if(s == 0)
|
if(s == 0)
|
||||||
|
@ -69,12 +69,12 @@ printf(int fd, char *fmt, ...)
|
||||||
putc(fd, *s);
|
putc(fd, *s);
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
} else if(c == 'c'){
|
}else if(c == 'c'){
|
||||||
putc(fd, *ap);
|
putc(fd, *ap);
|
||||||
ap++;
|
ap++;
|
||||||
} else if(c == '%'){
|
}else if(c == '%'){
|
||||||
putc(fd, c);
|
putc(fd, c);
|
||||||
} else {
|
}else{
|
||||||
// Unknown % sequence. Print it to draw attention.
|
// Unknown % sequence. Print it to draw attention.
|
||||||
putc(fd, '%');
|
putc(fd, '%');
|
||||||
putc(fd, c);
|
putc(fd, c);
|
||||||
|
|
6
proc.c
6
proc.c
|
@ -86,7 +86,7 @@ setupsegs(struct proc *p)
|
||||||
if(p){
|
if(p){
|
||||||
c->gdt[SEG_UCODE] = SEG(STA_X|STA_R, (uint)p->mem, p->sz-1, DPL_USER);
|
c->gdt[SEG_UCODE] = SEG(STA_X|STA_R, (uint)p->mem, p->sz-1, DPL_USER);
|
||||||
c->gdt[SEG_UDATA] = SEG(STA_W, (uint)p->mem, p->sz-1, DPL_USER);
|
c->gdt[SEG_UDATA] = SEG(STA_W, (uint)p->mem, p->sz-1, DPL_USER);
|
||||||
} else {
|
}else{
|
||||||
c->gdt[SEG_UCODE] = SEG_NULL;
|
c->gdt[SEG_UCODE] = SEG_NULL;
|
||||||
c->gdt[SEG_UDATA] = SEG_NULL;
|
c->gdt[SEG_UDATA] = SEG_NULL;
|
||||||
}
|
}
|
||||||
|
@ -444,7 +444,7 @@ procdump(void)
|
||||||
char *state;
|
char *state;
|
||||||
uint pc[10];
|
uint pc[10];
|
||||||
|
|
||||||
for(i = 0; i < NPROC; i++) {
|
for(i = 0; i < NPROC; i++){
|
||||||
p = &proc[i];
|
p = &proc[i];
|
||||||
if(p->state == UNUSED)
|
if(p->state == UNUSED)
|
||||||
continue;
|
continue;
|
||||||
|
@ -453,7 +453,7 @@ procdump(void)
|
||||||
else
|
else
|
||||||
state = "???";
|
state = "???";
|
||||||
cprintf("%d %s %s", p->pid, state, p->name);
|
cprintf("%d %s %s", p->pid, state, p->name);
|
||||||
if(p->state == SLEEPING) {
|
if(p->state == SLEEPING){
|
||||||
getcallerpcs((uint*)p->context.ebp+2, pc);
|
getcallerpcs((uint*)p->context.ebp+2, pc);
|
||||||
for(j=0; j<10 && pc[j] != 0; j++)
|
for(j=0; j<10 && pc[j] != 0; j++)
|
||||||
cprintf(" %p", pc[j]);
|
cprintf(" %p", pc[j]);
|
||||||
|
|
2
rm.c
2
rm.c
|
@ -13,7 +13,7 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 1; i < argc; i++){
|
for(i = 1; i < argc; i++){
|
||||||
if(unlink(argv[i]) < 0) {
|
if(unlink(argv[i]) < 0){
|
||||||
printf(2, "rm: %s failed to delete\n", argv[i]);
|
printf(2, "rm: %s failed to delete\n", argv[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
2
sh.c
2
sh.c
|
@ -156,7 +156,7 @@ main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read and run input commands.
|
// Read and run input commands.
|
||||||
while(getcmd(buf, sizeof(buf)) >= 0) {
|
while(getcmd(buf, sizeof(buf)) >= 0){
|
||||||
if(fork1() == 0)
|
if(fork1() == 0)
|
||||||
runcmd(parsecmd(buf));
|
runcmd(parsecmd(buf));
|
||||||
wait();
|
wait();
|
||||||
|
|
6
string.c
6
string.c
|
@ -19,7 +19,7 @@ memcmp(const void *v1, const void *v2, uint n)
|
||||||
|
|
||||||
s1 = v1;
|
s1 = v1;
|
||||||
s2 = v2;
|
s2 = v2;
|
||||||
while(n-- > 0) {
|
while(n-- > 0){
|
||||||
if(*s1 != *s2)
|
if(*s1 != *s2)
|
||||||
return *s1 - *s2;
|
return *s1 - *s2;
|
||||||
s1++, s2++;
|
s1++, s2++;
|
||||||
|
@ -36,12 +36,12 @@ memmove(void *dst, const void *src, uint n)
|
||||||
|
|
||||||
s = src;
|
s = src;
|
||||||
d = dst;
|
d = dst;
|
||||||
if(s < d && s + n > d) {
|
if(s < d && s + n > d){
|
||||||
s += n;
|
s += n;
|
||||||
d += n;
|
d += n;
|
||||||
while(n-- > 0)
|
while(n-- > 0)
|
||||||
*--d = *--s;
|
*--d = *--s;
|
||||||
} else
|
}else
|
||||||
while(n-- > 0)
|
while(n-- > 0)
|
||||||
*d++ = *s++;
|
*d++ = *s++;
|
||||||
|
|
||||||
|
|
|
@ -128,7 +128,7 @@ syscall(void)
|
||||||
num = cp->tf->eax;
|
num = cp->tf->eax;
|
||||||
if(num >= 0 && num < NELEM(syscalls) && syscalls[num])
|
if(num >= 0 && num < NELEM(syscalls) && syscalls[num])
|
||||||
cp->tf->eax = syscalls[num]();
|
cp->tf->eax = syscalls[num]();
|
||||||
else {
|
else{
|
||||||
cprintf("%d %s: unknown sys call %d\n",
|
cprintf("%d %s: unknown sys call %d\n",
|
||||||
cp->pid, cp->name, num);
|
cp->pid, cp->name, num);
|
||||||
cp->tf->eax = -1;
|
cp->tf->eax = -1;
|
||||||
|
|
|
@ -335,7 +335,7 @@ sys_chdir(void)
|
||||||
if(argstr(0, &path) < 0 || (ip = namei(path)) == 0)
|
if(argstr(0, &path) < 0 || (ip = namei(path)) == 0)
|
||||||
return -1;
|
return -1;
|
||||||
ilock(ip);
|
ilock(ip);
|
||||||
if(ip->type != T_DIR) {
|
if(ip->type != T_DIR){
|
||||||
iunlockput(ip);
|
iunlockput(ip);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
2
trap.c
2
trap.c
|
@ -72,7 +72,7 @@ trap(struct trapframe *tf)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if(cp == 0) {
|
if(cp == 0){
|
||||||
// Otherwise it's our mistake.
|
// Otherwise it's our mistake.
|
||||||
cprintf("unexpected trap %d from cpu %d eip %x\n",
|
cprintf("unexpected trap %d from cpu %d eip %x\n",
|
||||||
tf->trapno, cpu(), tf->eip);
|
tf->trapno, cpu(), tf->eip);
|
||||||
|
|
16
umalloc.c
16
umalloc.c
|
@ -30,15 +30,15 @@ free(void *ap)
|
||||||
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
|
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
|
||||||
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
|
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
|
||||||
break;
|
break;
|
||||||
if(bp + bp->s.size == p->s.ptr) {
|
if(bp + bp->s.size == p->s.ptr){
|
||||||
bp->s.size += p->s.ptr->s.size;
|
bp->s.size += p->s.ptr->s.size;
|
||||||
bp->s.ptr = p->s.ptr->s.ptr;
|
bp->s.ptr = p->s.ptr->s.ptr;
|
||||||
} else
|
}else
|
||||||
bp->s.ptr = p->s.ptr;
|
bp->s.ptr = p->s.ptr;
|
||||||
if(p + p->s.size == bp) {
|
if(p + p->s.size == bp){
|
||||||
p->s.size += bp->s.size;
|
p->s.size += bp->s.size;
|
||||||
p->s.ptr = bp->s.ptr;
|
p->s.ptr = bp->s.ptr;
|
||||||
} else
|
}else
|
||||||
p->s.ptr = bp;
|
p->s.ptr = bp;
|
||||||
freep = p;
|
freep = p;
|
||||||
}
|
}
|
||||||
|
@ -67,15 +67,15 @@ malloc(uint nbytes)
|
||||||
uint nunits;
|
uint nunits;
|
||||||
|
|
||||||
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
|
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
|
||||||
if((prevp = freep) == 0) {
|
if((prevp = freep) == 0){
|
||||||
base.s.ptr = freep = prevp = &base;
|
base.s.ptr = freep = prevp = &base;
|
||||||
base.s.size = 0;
|
base.s.size = 0;
|
||||||
}
|
}
|
||||||
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr) {
|
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
|
||||||
if(p->s.size >= nunits) {
|
if(p->s.size >= nunits){
|
||||||
if(p->s.size == nunits)
|
if(p->s.size == nunits)
|
||||||
prevp->s.ptr = p->s.ptr;
|
prevp->s.ptr = p->s.ptr;
|
||||||
else {
|
else{
|
||||||
p->s.size -= nunits;
|
p->s.size -= nunits;
|
||||||
p += p->s.size;
|
p += p->s.size;
|
||||||
p->s.size = nunits;
|
p->s.size = nunits;
|
||||||
|
|
Loading…
Reference in a new issue