avoid assignments in declarations
This commit is contained in:
parent
6861140a66
commit
dca5b5ca2e
8 changed files with 44 additions and 36 deletions
4
main.c
4
main.c
|
@ -118,13 +118,13 @@ mpmain(void)
|
|||
void
|
||||
process0(void)
|
||||
{
|
||||
struct proc *p0 = &proc[0];
|
||||
struct proc *p1;
|
||||
extern struct spinlock proc_table_lock;
|
||||
struct proc *p0, *p1;
|
||||
struct trapframe tf;
|
||||
|
||||
release(&proc_table_lock);
|
||||
|
||||
p0 = &proc[0];
|
||||
p0->cwd = iget(rootdev, 1);
|
||||
iunlock(p0->cwd);
|
||||
|
||||
|
|
17
printf.c
17
printf.c
|
@ -11,18 +11,20 @@ putc(int fd, char c)
|
|||
static void
|
||||
printint(int fd, int xx, int base, int sgn)
|
||||
{
|
||||
static char digits[] = "0123456789ABCDEF";
|
||||
char buf[16];
|
||||
char digits[] = "0123456789ABCDEF";
|
||||
int i = 0, neg = 0;
|
||||
int i, neg;
|
||||
uint x;
|
||||
|
||||
neg = 0;
|
||||
if(sgn && xx < 0){
|
||||
neg = 1;
|
||||
x = 0 - xx;
|
||||
x = -xx;
|
||||
} else {
|
||||
x = xx;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
do {
|
||||
buf[i++] = digits[x % base];
|
||||
} while((x /= base) != 0);
|
||||
|
@ -37,9 +39,12 @@ printint(int fd, int xx, int base, int sgn)
|
|||
void
|
||||
printf(int fd, char *fmt, ...)
|
||||
{
|
||||
int i, state = 0, c;
|
||||
uint *ap = (uint*)(void*)&fmt + 1;
|
||||
char *s;
|
||||
int c, i, state;
|
||||
uint *ap;
|
||||
|
||||
state = 0;
|
||||
ap = (uint*)(void*)&fmt + 1;
|
||||
for(i = 0; fmt[i]; i++){
|
||||
c = fmt[i] & 0xff;
|
||||
if(state == 0){
|
||||
|
@ -56,7 +61,7 @@ printf(int fd, char *fmt, ...)
|
|||
printint(fd, *ap, 16, 0);
|
||||
ap++;
|
||||
} else if(c == 's'){
|
||||
char *s = (char*)*ap;
|
||||
s = (char*)*ap;
|
||||
ap++;
|
||||
while(*s != 0){
|
||||
putc(fd, *s);
|
||||
|
|
12
string.c
12
string.c
|
@ -4,8 +4,9 @@
|
|||
void*
|
||||
memset(void *dst, int c, uint n)
|
||||
{
|
||||
char *d = (char*) dst;
|
||||
char *d;
|
||||
|
||||
d = (char*)dst;
|
||||
while(n-- > 0)
|
||||
*d++ = c;
|
||||
|
||||
|
@ -15,12 +16,13 @@ memset(void *dst, int c, uint n)
|
|||
int
|
||||
memcmp(const void *v1, const void *v2, uint n)
|
||||
{
|
||||
const uchar *s1 = (const uchar*) v1;
|
||||
const uchar *s2 = (const uchar*) v2;
|
||||
|
||||
const uchar *s1, *s2;
|
||||
|
||||
s1 = v1;
|
||||
s2 = v2;
|
||||
while(n-- > 0) {
|
||||
if(*s1 != *s2)
|
||||
return (int) *s1 - (int) *s2;
|
||||
return *s1 - *s2;
|
||||
s1++, s2++;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ int
|
|||
sys_pipe(void)
|
||||
{
|
||||
int *fd;
|
||||
struct file *rf = 0, *wf = 0;
|
||||
struct file *rf, *wf;
|
||||
int fd0, fd1;
|
||||
|
||||
if(argptr(0, (void*)&fd, 2*sizeof fd[0]) < 0)
|
||||
|
|
11
trap.c
11
trap.c
|
@ -30,9 +30,7 @@ idtinit(void)
|
|||
void
|
||||
trap(struct trapframe *tf)
|
||||
{
|
||||
int v = tf->trapno;
|
||||
|
||||
if(v == T_SYSCALL){
|
||||
if(tf->trapno == T_SYSCALL){
|
||||
if(cp->killed)
|
||||
proc_exit();
|
||||
cp->tf = tf;
|
||||
|
@ -47,7 +45,7 @@ trap(struct trapframe *tf)
|
|||
// during interrupt handler. Decrement before returning.
|
||||
cpus[cpu()].nlock++;
|
||||
|
||||
switch(v){
|
||||
switch(tf->trapno){
|
||||
case IRQ_OFFSET + IRQ_TIMER:
|
||||
lapic_timerintr();
|
||||
cpus[cpu()].nlock--;
|
||||
|
@ -82,12 +80,13 @@ trap(struct trapframe *tf)
|
|||
if(cp) {
|
||||
// Assume process divided by zero or dereferenced null, etc.
|
||||
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();
|
||||
}
|
||||
|
||||
// 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");
|
||||
}
|
||||
|
||||
|
|
13
ulib.c
13
ulib.c
|
@ -31,7 +31,8 @@ strcmp(const char *p, const char *q)
|
|||
uint
|
||||
strlen(char *s)
|
||||
{
|
||||
int n = 0;
|
||||
int n;
|
||||
|
||||
for(n = 0; s[n]; n++)
|
||||
;
|
||||
return n;
|
||||
|
@ -40,11 +41,11 @@ strlen(char *s)
|
|||
void*
|
||||
memset(void *dst, int c, uint n)
|
||||
{
|
||||
char *d = (char*) dst;
|
||||
|
||||
char *d;
|
||||
|
||||
d = dst;
|
||||
while(n-- > 0)
|
||||
*d++ = c;
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
@ -60,10 +61,10 @@ strchr(const char *s, char c)
|
|||
char*
|
||||
gets(char *buf, int max)
|
||||
{
|
||||
int i = 0, cc;
|
||||
int i, cc;
|
||||
char c;
|
||||
|
||||
while(i+1 < max){
|
||||
for(i=0; i+1 < max; ){
|
||||
cc = read(0, &c, 1);
|
||||
if(cc < 1)
|
||||
break;
|
||||
|
|
|
@ -19,7 +19,7 @@ union header {
|
|||
typedef union header Header;
|
||||
|
||||
static Header base;
|
||||
static Header *freep = 0;
|
||||
static Header *freep;
|
||||
|
||||
void
|
||||
free(void *ap)
|
||||
|
|
19
usertests.c
19
usertests.c
|
@ -203,13 +203,14 @@ void
|
|||
pipe1(void)
|
||||
{
|
||||
int fds[2], pid;
|
||||
int seq = 0, i, n, cc, total;
|
||||
int seq, i, n, cc, total;
|
||||
|
||||
if(pipe(fds) != 0){
|
||||
printf(1, "pipe() failed\n");
|
||||
exit();
|
||||
}
|
||||
pid = fork();
|
||||
seq = 0;
|
||||
if(pid == 0){
|
||||
close(fds[0]);
|
||||
for(n = 0; n < 5; n++){
|
||||
|
@ -464,8 +465,8 @@ twofiles(void)
|
|||
void
|
||||
createdelete(void)
|
||||
{
|
||||
enum { N = 20 };
|
||||
int pid, i, fd;
|
||||
int n = 20;
|
||||
char name[32];
|
||||
|
||||
printf(1, "createdelete test\n");
|
||||
|
@ -477,7 +478,7 @@ createdelete(void)
|
|||
|
||||
name[0] = pid ? 'p' : 'c';
|
||||
name[2] = '\0';
|
||||
for(i = 0; i < n; i++){
|
||||
for(i = 0; i < N; i++){
|
||||
name[1] = '0' + i;
|
||||
fd = open(name, O_CREATE | O_RDWR);
|
||||
if(fd < 0){
|
||||
|
@ -499,14 +500,14 @@ createdelete(void)
|
|||
// else
|
||||
//exit();
|
||||
|
||||
for(i = 0; i < n; i++){
|
||||
for(i = 0; i < N; i++){
|
||||
name[0] = 'p';
|
||||
name[1] = '0' + i;
|
||||
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);
|
||||
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);
|
||||
exit();
|
||||
}
|
||||
|
@ -516,10 +517,10 @@ createdelete(void)
|
|||
name[0] = 'c';
|
||||
name[1] = '0' + i;
|
||||
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);
|
||||
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);
|
||||
exit();
|
||||
}
|
||||
|
@ -527,7 +528,7 @@ createdelete(void)
|
|||
close(fd);
|
||||
}
|
||||
|
||||
for(i = 0; i < n; i++){
|
||||
for(i = 0; i < N; i++){
|
||||
name[0] = 'p';
|
||||
name[1] = '0' + i;
|
||||
unlink(name);
|
||||
|
|
Loading…
Reference in a new issue