1987-03-09 15:15:03 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1994-06-24 11:31:16 +00:00
|
|
|
/* $Id$ */
|
1987-01-06 11:41:50 +00:00
|
|
|
|
2019-03-22 18:19:02 +00:00
|
|
|
#include <fcntl.h>
|
2019-03-22 17:18:07 +00:00
|
|
|
#include <unistd.h>
|
2022-07-16 23:58:16 +00:00
|
|
|
#include <errno.h>
|
2006-07-18 17:10:29 +00:00
|
|
|
#include "system.h"
|
1987-01-06 11:41:50 +00:00
|
|
|
|
2022-07-17 11:17:24 +00:00
|
|
|
#if !defined WIN32
|
|
|
|
#define O_BINARY 0
|
|
|
|
#endif
|
|
|
|
|
1987-01-06 11:41:50 +00:00
|
|
|
extern File *_get_entry();
|
|
|
|
|
|
|
|
int
|
|
|
|
sys_open(path, flag, filep)
|
|
|
|
char *path;
|
|
|
|
int flag;
|
|
|
|
File **filep;
|
|
|
|
{
|
1987-09-23 14:22:39 +00:00
|
|
|
register int fd;
|
1987-01-06 11:41:50 +00:00
|
|
|
register File *fp;
|
|
|
|
|
1987-09-23 14:22:39 +00:00
|
|
|
if ((fp = _get_entry()) == (File *)0)
|
|
|
|
return 0;
|
1987-01-06 11:41:50 +00:00
|
|
|
switch (flag) {
|
|
|
|
case OP_READ:
|
2022-07-16 23:58:16 +00:00
|
|
|
if ((fd = open(path, O_RDONLY|O_BINARY)) < 0)
|
1987-09-23 14:22:39 +00:00
|
|
|
return 0;
|
1987-01-06 11:41:50 +00:00
|
|
|
break;
|
|
|
|
case OP_APPEND:
|
2022-07-16 23:58:16 +00:00
|
|
|
if ((fd = open(path, O_WRONLY|O_BINARY)) < 0) {
|
1987-09-23 14:22:39 +00:00
|
|
|
if (access(path, 0) == 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (lseek(fd, 0L, 2) < 0L) {
|
|
|
|
close(fd);
|
|
|
|
return 0;
|
|
|
|
}
|
1991-01-11 13:19:36 +00:00
|
|
|
break;
|
1987-09-23 14:22:39 +00:00
|
|
|
}
|
|
|
|
/* Fall through */
|
|
|
|
case OP_WRITE:
|
2022-07-17 18:11:21 +00:00
|
|
|
if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, 0666)) < 0)
|
1987-09-23 14:22:39 +00:00
|
|
|
return 0;
|
1987-01-06 11:41:50 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
fp->o_flags = flag;
|
|
|
|
fp->o_fd = fd;
|
|
|
|
*filep = fp;
|
|
|
|
return 1;
|
|
|
|
}
|