static int exec_fwrite(strm_state* state, int argc, strm_value* args, strm_value* ret) { int fd; strm_string *path; assert(argc == 1); assert(strm_str_p(args[0])); path = strm_value_str(args[0]); fd = open(path->ptr, O_WRONLY|O_CREAT, 0644); if (fd < 0) return STRM_NG; *ret = strm_ptr_value(strm_io_new(fd, STRM_IO_WRITE)); return STRM_OK; }
static int exec_fread(strm_state* state, int argc, strm_value* args, strm_value* ret) { int fd; strm_string *path; assert(argc == 1); assert(strm_str_p(args[0])); path = strm_value_str(args[0]); fd = open(path->ptr, O_RDONLY); if (fd < 0) return STRM_NG; *ret = strm_ptr_value(strm_io_new(fd, STRM_IO_READ)); return STRM_OK; }
static int exec_fwrite(strm_stream* strm, int argc, strm_value* args, strm_value* ret) { int fd; strm_string path; char buf[7]; assert(argc == 1); assert(strm_string_p(args[0])); path = strm_value_str(args[0]); fd = open(strm_str_cstr(path, buf), O_WRONLY|O_CREAT, 0644); if (fd < 0) return STRM_NG; *ret = strm_io_new(fd, STRM_IO_WRITE); return STRM_OK; }