5 env.user[STDIN_ENV] = handle(HANDLE_FD,0);
6 env.user[STDOUT_ENV] = handle(HANDLE_FD,1);
7 env.user[STDERR_ENV] = handle(HANDLE_FD,2);
10 void primitive_close_fd(void)
12 HANDLE* h = untag_handle(HANDLE_FD,env.dt);
17 int fill_buffer(HANDLE* h, int fd, STRING* buf)
19 int amount = read(fd,buf + 1,buf->capacity * 2);
21 h->buf_fill = (amount < 0 ? 0 : amount);
27 void primitive_read_line_fd_8(void)
29 HANDLE* h = untag_handle(HANDLE_FD,env.dt);
36 /* finished line, unicode */
37 SBUF* line = sbuf(LINE_SIZE);
39 /* read ascii from fd */
41 if(h->buf_mode != B_READ)
44 h->buffer = tag_object(string(BUF_SIZE,'\0'));
46 buf = untag_string(h->buffer);
50 if(h->buf_pos >= h->buf_fill)
52 amount = fill_buffer(h,fd,buf);
55 io_error(__FUNCTION__);
61 /* didn't read anything before EOF */
65 env.dt = tag_object(line);
70 for(i = h->buf_pos; i < h->buf_fill; i++)
72 ch = bget((CELL)buf + sizeof(STRING) + i);
76 env.dt = tag_object(line);
80 set_sbuf_nth(line,line->top,ch);
83 /* We've reached the end of the above loop */
84 h->buf_pos = h->buf_fill;
88 void write_fd_char_8(HANDLE* h, FIXNUM ch)
92 int amount = write(h->object,&c,1);
95 io_error(__FUNCTION__);
98 void write_fd_string_8(HANDLE* h, STRING* str)
100 char* c_str = to_c_string(str);
102 int amount = write(h->object,c_str,str->capacity);
105 io_error(__FUNCTION__);
108 void primitive_write_fd_8(void)
110 HANDLE* h = untag_handle(HANDLE_FD,env.dt);
113 CELL type = type_of(text);
118 write_fd_char_8(h,to_fixnum(text));
121 write_fd_string_8(h,untag_string(text));
124 type_error(STRING_TYPE,text);
131 void primitive_flush_fd(void)
133 HANDLE* h = untag_handle(HANDLE_FD,env.dt);
135 if(h->buf_mode == B_WRITE)
140 /* int fd = h->object;
143 io_error(__FUNCTION__); */
148 void primitive_shutdown_fd(void)
150 /* HANDLE* h = untag_handle(HANDLE_FD,env.dt);
153 if(shutdown(fd,SHUT_RDWR) < 0)
154 io_error(__FUNCTION__); */