From 1a81e38b17144624415d252a521fd5a06079d681 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 11 Jan 2011 13:01:13 -0500 Subject: make new code like old code Variable declarations at top of function, separate from initialization. Use == 0 instead of ! for checking pointers. Consistent spacing around {, *, casts. Declare 0-parameter functions as (void) not (). Integer valued functions return -1 on failure, 0 on success. --- exec.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'exec.c') diff --git a/exec.c b/exec.c index 1673a38..209bc79 100644 --- a/exec.c +++ b/exec.c @@ -10,16 +10,17 @@ int exec(char *path, char **argv) { char *s, *last; - int i, off; - uint sz = 0; + int i, off, argc; + uint sz, sp, strings[MAXARG]; struct elfhdr elf; - struct inode *ip = 0; + struct inode *ip; struct proghdr ph; - pde_t *pgdir = 0, *oldpgdir; + pde_t *pgdir, *oldpgdir; if((ip = namei(path)) == 0) return -1; ilock(ip); + pgdir = 0; // Check ELF header if(readi(ip, (char*)&elf, 0, sizeof(elf)) < sizeof(elf)) @@ -27,10 +28,11 @@ exec(char *path, char **argv) if(elf.magic != ELF_MAGIC) goto bad; - if(!(pgdir = setupkvm())) + if((pgdir = setupkvm()) == 0) goto bad; // Load program into memory. + sz = 0; for(i=0, off=elf.phoff; i= MAXARG) goto bad; // push strings and remember where they are - uint strings[MAXARG]; for(i = argc - 1; i >= 0; --i){ sp -= strlen(argv[i]) + 1; strings[i] = sp; copyout(pgdir, sp, argv[i], strlen(argv[i]) + 1); } -#define PUSH(x) { int xx = (int)(x); sp -= 4; copyout(pgdir, sp, &xx, 4); } +#define PUSH(x){ int xx = (int)(x); sp -= 4; copyout(pgdir, sp, &xx, 4); } PUSH(0); // argv[argc] is zero -- cgit v1.2.3