Added register decl, re-arranged some code

This commit is contained in:
ceriel 1987-09-23 14:22:39 +00:00
parent 1655b2521f
commit 1eda133f01
2 changed files with 20 additions and 26 deletions

View file

@ -13,7 +13,7 @@ sys_break(incr)
int incr; int incr;
{ {
char *sbrk(); char *sbrk();
char *brk = sbrk(incr); register char *brk = sbrk(incr);
if (brk == (char *) 0 || brk == (char *)-1) if (brk == (char *) 0 || brk == (char *)-1)
return ILL_BREAK; return ILL_BREAK;

View file

@ -14,42 +14,36 @@ sys_open(path, flag, filep)
int flag; int flag;
File **filep; File **filep;
{ {
register fd; register int fd;
register File *fp; register File *fp;
int open_mode;
long lseek(); long lseek();
if ((fp = _get_entry()) == (File *)0)
return 0;
switch (flag) { switch (flag) {
case OP_READ: case OP_READ:
open_mode = 0; if ((fd = open(path, 0)) < 0)
return 0;
break; break;
case OP_WRITE:
case OP_APPEND: case OP_APPEND:
open_mode = 1; if ((fd = open(path, 1)) < 0) {
if (access(path, 0) == 0)
return 0;
}
else {
if (lseek(fd, 0L, 2) < 0L) {
close(fd);
return 0;
}
}
/* Fall through */
case OP_WRITE:
if ((fd = creat(path, 0644)) < 0)
return 0;
break; break;
default: default:
return 0; return 0;
} }
if ((fp = _get_entry()) == (File *)0)
return 0;
if (flag == OP_WRITE) {
if ((fd = creat(path, 0644)) < 0)
return 0;
}
else /* OP_READ or OP_APPEND */
if ((fd = open(path, open_mode)) < 0) {
if (flag == OP_READ || access(path, 0) == 0)
return 0;
/* now: flag == OP_APPEND */
if ((fd = creat(path, 0644)) < 0)
return 0;
}
else {
if (flag == OP_APPEND && (lseek(fd, 0L, 2) < 0L)) {
close(fd);
return 0;
}
}
fp->o_flags = flag; fp->o_flags = flag;
fp->o_fd = fd; fp->o_fd = fd;
*filep = fp; *filep = fp;