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;
{
char *sbrk();
char *brk = sbrk(incr);
register char *brk = sbrk(incr);
if (brk == (char *) 0 || brk == (char *)-1)
return ILL_BREAK;

View file

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