f8cbe04447
This unbreaks my build in OpenBSD. The old `long lseek()` conflicts
with `off_t lseek()` in OpenBSD headers, because long and off_t are
different types. Commit b4df26e
caused "system.h" to include some
headers where OpenBSD declares lseek().
Manuals for lseek() say to #include <unistd.h>. Do so to be portable
to systems where other headers don't declare lseek().
53 lines
865 B
C
53 lines
865 B
C
/*
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
*/
|
|
/* $Id$ */
|
|
|
|
#include <unistd.h>
|
|
#include "system.h"
|
|
|
|
extern File *_get_entry();
|
|
|
|
int
|
|
sys_open(path, flag, filep)
|
|
char *path;
|
|
int flag;
|
|
File **filep;
|
|
{
|
|
register int fd;
|
|
register File *fp;
|
|
|
|
if ((fp = _get_entry()) == (File *)0)
|
|
return 0;
|
|
switch (flag) {
|
|
case OP_READ:
|
|
if ((fd = open(path, 0)) < 0)
|
|
return 0;
|
|
break;
|
|
case OP_APPEND:
|
|
if ((fd = open(path, 1)) < 0) {
|
|
if (access(path, 0) == 0)
|
|
return 0;
|
|
}
|
|
else {
|
|
if (lseek(fd, 0L, 2) < 0L) {
|
|
close(fd);
|
|
return 0;
|
|
}
|
|
break;
|
|
}
|
|
/* Fall through */
|
|
case OP_WRITE:
|
|
if ((fd = creat(path, 0666)) < 0)
|
|
return 0;
|
|
break;
|
|
default:
|
|
return 0;
|
|
}
|
|
fp->o_flags = flag;
|
|
fp->o_fd = fd;
|
|
*filep = fp;
|
|
return 1;
|
|
}
|