factor/native/file.c

26 lines
447 B
C
Raw Normal View History

2004-07-24 00:54:57 -04:00
#include "factor.h"
void primitive_open_file(void)
{
bool write = untag_boolean(env.dt);
bool read = untag_boolean(dpop());
char* path = to_c_string(untag_string(dpop()));
int mode;
int fd;
if(read && write)
mode = O_RDWR | O_CREAT;
else if(read)
mode = O_RDONLY;
else if(write)
mode = O_WRONLY | O_CREAT | O_TRUNC;
2004-07-24 17:37:42 -04:00
else
mode = 0;
2004-07-24 00:54:57 -04:00
fd = open(path,mode);
2004-07-24 17:37:42 -04:00
if(fd < 0)
io_error(__FUNCTION__);
2004-07-24 00:54:57 -04:00
env.dt = handle(HANDLE_FD,fd);
}