const char* strm_p(strm_value val) { char buf[7]; strm_string str = strm_to_str(val); const char* p = strm_str_cstr(str, buf); fputs(p, stdout); fputs("\n", stdout); return p; }
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; }
static int exec_fread(strm_state* state, 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_RDONLY); if (fd < 0) return STRM_NG; *ret = strm_ptr_value(strm_io_new(fd, STRM_IO_READ)); return STRM_OK; }