2004-07-24 00:54:57 -04:00
|
|
|
#include "factor.h"
|
|
|
|
|
|
|
|
|
|
void primitive_open_file(void)
|
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
bool write = untag_boolean(dpop());
|
2004-07-24 00:54:57 -04:00
|
|
|
bool read = untag_boolean(dpop());
|
|
|
|
|
char* path = to_c_string(untag_string(dpop()));
|
|
|
|
|
int mode;
|
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
|
|
if(read && write)
|
2004-08-15 21:50:44 -04:00
|
|
|
mode = O_RDWR | O_CREAT;
|
2004-07-24 00:54:57 -04:00
|
|
|
else if(read)
|
2004-08-15 21:50:44 -04:00
|
|
|
mode = O_RDONLY;
|
2004-07-24 00:54:57 -04:00
|
|
|
else if(write)
|
2004-08-15 21:50:44 -04:00
|
|
|
mode = O_WRONLY | O_CREAT | O_TRUNC;
|
2004-07-24 17:37:42 -04:00
|
|
|
else
|
2004-08-15 21:50:44 -04:00
|
|
|
mode = 0;
|
2004-07-24 00:54:57 -04:00
|
|
|
|
2004-08-15 22:45:08 -04:00
|
|
|
fd = open(path,mode,FILE_MODE);
|
2004-07-24 17:37:42 -04:00
|
|
|
if(fd < 0)
|
2004-08-15 21:50:44 -04:00
|
|
|
io_error(NULL,__FUNCTION__);
|
2004-07-24 17:37:42 -04:00
|
|
|
|
2004-08-16 19:29:07 -04:00
|
|
|
dpush(read ? tag_object(port(PORT_READ,fd)) : F);
|
|
|
|
|
dpush(write ? tag_object(port(PORT_WRITE,fd)) : F);
|
2004-07-24 00:54:57 -04:00
|
|
|
}
|