avoid assignments in declarations

This commit is contained in:
rsc 2007-08-10 17:17:42 +00:00
parent 6861140a66
commit dca5b5ca2e
8 changed files with 44 additions and 36 deletions

4
main.c
View file

@ -118,13 +118,13 @@ mpmain(void)
void void
process0(void) process0(void)
{ {
struct proc *p0 = &proc[0];
struct proc *p1;
extern struct spinlock proc_table_lock; extern struct spinlock proc_table_lock;
struct proc *p0, *p1;
struct trapframe tf; struct trapframe tf;
release(&proc_table_lock); release(&proc_table_lock);
p0 = &proc[0];
p0->cwd = iget(rootdev, 1); p0->cwd = iget(rootdev, 1);
iunlock(p0->cwd); iunlock(p0->cwd);

View file

@ -11,18 +11,20 @@ putc(int fd, char c)
static void static void
printint(int fd, int xx, int base, int sgn) printint(int fd, int xx, int base, int sgn)
{ {
static char digits[] = "0123456789ABCDEF";
char buf[16]; char buf[16];
char digits[] = "0123456789ABCDEF"; int i, neg;
int i = 0, neg = 0;
uint x; uint x;
neg = 0;
if(sgn && xx < 0){ if(sgn && xx < 0){
neg = 1; neg = 1;
x = 0 - xx; x = -xx;
} else { } else {
x = xx; x = xx;
} }
i = 0;
do { do {
buf[i++] = digits[x % base]; buf[i++] = digits[x % base];
} while((x /= base) != 0); } while((x /= base) != 0);
@ -37,9 +39,12 @@ printint(int fd, int xx, int base, int sgn)
void void
printf(int fd, char *fmt, ...) printf(int fd, char *fmt, ...)
{ {
int i, state = 0, c; char *s;
uint *ap = (uint*)(void*)&fmt + 1; int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){ for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff; c = fmt[i] & 0xff;
if(state == 0){ if(state == 0){
@ -56,7 +61,7 @@ printf(int fd, char *fmt, ...)
printint(fd, *ap, 16, 0); printint(fd, *ap, 16, 0);
ap++; ap++;
} else if(c == 's'){ } else if(c == 's'){
char *s = (char*)*ap; s = (char*)*ap;
ap++; ap++;
while(*s != 0){ while(*s != 0){
putc(fd, *s); putc(fd, *s);

View file

@ -4,8 +4,9 @@
void* void*
memset(void *dst, int c, uint n) memset(void *dst, int c, uint n)
{ {
char *d = (char*) dst; char *d;
d = (char*)dst;
while(n-- > 0) while(n-- > 0)
*d++ = c; *d++ = c;
@ -15,12 +16,13 @@ memset(void *dst, int c, uint n)
int int
memcmp(const void *v1, const void *v2, uint n) memcmp(const void *v1, const void *v2, uint n)
{ {
const uchar *s1 = (const uchar*) v1; const uchar *s1, *s2;
const uchar *s2 = (const uchar*) v2;
s1 = v1;
s2 = v2;
while(n-- > 0) { while(n-- > 0) {
if(*s1 != *s2) if(*s1 != *s2)
return (int) *s1 - (int) *s2; return *s1 - *s2;
s1++, s2++; s1++, s2++;
} }

View file

@ -54,7 +54,7 @@ int
sys_pipe(void) sys_pipe(void)
{ {
int *fd; int *fd;
struct file *rf = 0, *wf = 0; struct file *rf, *wf;
int fd0, fd1; int fd0, fd1;
if(argptr(0, (void*)&fd, 2*sizeof fd[0]) < 0) if(argptr(0, (void*)&fd, 2*sizeof fd[0]) < 0)

11
trap.c
View file

@ -30,9 +30,7 @@ idtinit(void)
void void
trap(struct trapframe *tf) trap(struct trapframe *tf)
{ {
int v = tf->trapno; if(tf->trapno == T_SYSCALL){
if(v == T_SYSCALL){
if(cp->killed) if(cp->killed)
proc_exit(); proc_exit();
cp->tf = tf; cp->tf = tf;
@ -47,7 +45,7 @@ trap(struct trapframe *tf)
// during interrupt handler. Decrement before returning. // during interrupt handler. Decrement before returning.
cpus[cpu()].nlock++; cpus[cpu()].nlock++;
switch(v){ switch(tf->trapno){
case IRQ_OFFSET + IRQ_TIMER: case IRQ_OFFSET + IRQ_TIMER:
lapic_timerintr(); lapic_timerintr();
cpus[cpu()].nlock--; cpus[cpu()].nlock--;
@ -82,12 +80,13 @@ trap(struct trapframe *tf)
if(cp) { if(cp) {
// Assume process divided by zero or dereferenced null, etc. // Assume process divided by zero or dereferenced null, etc.
cprintf("pid %d %s: unhandled trap %d on cpu %d eip %x -- kill proc\n", cprintf("pid %d %s: unhandled trap %d on cpu %d eip %x -- kill proc\n",
cp->pid, cp->name, v, cpu(), tf->eip); cp->pid, cp->name, tf->trapno, cpu(), tf->eip);
proc_exit(); proc_exit();
} }
// Otherwise it's our mistake. // Otherwise it's our mistake.
cprintf("unexpected trap %d from cpu %d eip %x\n", v, cpu(), tf->eip); cprintf("unexpected trap %d from cpu %d eip %x\n",
tf->trapno, cpu(), tf->eip);
panic("trap"); panic("trap");
} }

11
ulib.c
View file

@ -31,7 +31,8 @@ strcmp(const char *p, const char *q)
uint uint
strlen(char *s) strlen(char *s)
{ {
int n = 0; int n;
for(n = 0; s[n]; n++) for(n = 0; s[n]; n++)
; ;
return n; return n;
@ -40,11 +41,11 @@ strlen(char *s)
void* void*
memset(void *dst, int c, uint n) memset(void *dst, int c, uint n)
{ {
char *d = (char*) dst; char *d;
d = dst;
while(n-- > 0) while(n-- > 0)
*d++ = c; *d++ = c;
return dst; return dst;
} }
@ -60,10 +61,10 @@ strchr(const char *s, char c)
char* char*
gets(char *buf, int max) gets(char *buf, int max)
{ {
int i = 0, cc; int i, cc;
char c; char c;
while(i+1 < max){ for(i=0; i+1 < max; ){
cc = read(0, &c, 1); cc = read(0, &c, 1);
if(cc < 1) if(cc < 1)
break; break;

View file

@ -19,7 +19,7 @@ union header {
typedef union header Header; typedef union header Header;
static Header base; static Header base;
static Header *freep = 0; static Header *freep;
void void
free(void *ap) free(void *ap)

View file

@ -203,13 +203,14 @@ void
pipe1(void) pipe1(void)
{ {
int fds[2], pid; int fds[2], pid;
int seq = 0, i, n, cc, total; int seq, i, n, cc, total;
if(pipe(fds) != 0){ if(pipe(fds) != 0){
printf(1, "pipe() failed\n"); printf(1, "pipe() failed\n");
exit(); exit();
} }
pid = fork(); pid = fork();
seq = 0;
if(pid == 0){ if(pid == 0){
close(fds[0]); close(fds[0]);
for(n = 0; n < 5; n++){ for(n = 0; n < 5; n++){
@ -464,8 +465,8 @@ twofiles(void)
void void
createdelete(void) createdelete(void)
{ {
enum { N = 20 };
int pid, i, fd; int pid, i, fd;
int n = 20;
char name[32]; char name[32];
printf(1, "createdelete test\n"); printf(1, "createdelete test\n");
@ -477,7 +478,7 @@ createdelete(void)
name[0] = pid ? 'p' : 'c'; name[0] = pid ? 'p' : 'c';
name[2] = '\0'; name[2] = '\0';
for(i = 0; i < n; i++){ for(i = 0; i < N; i++){
name[1] = '0' + i; name[1] = '0' + i;
fd = open(name, O_CREATE | O_RDWR); fd = open(name, O_CREATE | O_RDWR);
if(fd < 0){ if(fd < 0){
@ -499,14 +500,14 @@ createdelete(void)
// else // else
//exit(); //exit();
for(i = 0; i < n; i++){ for(i = 0; i < N; i++){
name[0] = 'p'; name[0] = 'p';
name[1] = '0' + i; name[1] = '0' + i;
fd = open(name, 0); fd = open(name, 0);
if((i == 0 || i >= n/2) && fd < 0){ if((i == 0 || i >= N/2) && fd < 0){
printf(1, "oops createdelete %s didn't exist\n", name); printf(1, "oops createdelete %s didn't exist\n", name);
exit(); exit();
} else if((i >= 1 && i < n/2) && fd >= 0){ } else if((i >= 1 && i < N/2) && fd >= 0){
printf(1, "oops createdelete %s did exist\n", name); printf(1, "oops createdelete %s did exist\n", name);
exit(); exit();
} }
@ -516,10 +517,10 @@ createdelete(void)
name[0] = 'c'; name[0] = 'c';
name[1] = '0' + i; name[1] = '0' + i;
fd = open(name, 0); fd = open(name, 0);
if((i == 0 || i >= n/2) && fd < 0){ if((i == 0 || i >= N/2) && fd < 0){
printf(1, "oops createdelete %s didn't exist\n", name); printf(1, "oops createdelete %s didn't exist\n", name);
exit(); exit();
} else if((i >= 1 && i < n/2) && fd >= 0){ } else if((i >= 1 && i < N/2) && fd >= 0){
printf(1, "oops createdelete %s did exist\n", name); printf(1, "oops createdelete %s did exist\n", name);
exit(); exit();
} }
@ -527,7 +528,7 @@ createdelete(void)
close(fd); close(fd);
} }
for(i = 0; i < n; i++){ for(i = 0; i < N; i++){
name[0] = 'p'; name[0] = 'p';
name[1] = '0' + i; name[1] = '0' + i;
unlink(name); unlink(name);