Changes in uspace/lib/c/generic/io/io.c [76d6169:79ae36dd] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/io/io.c
r76d6169 r79ae36dd 101 101 static LIST_INITIALIZE(files); 102 102 103 void __stdio_init(int filc )103 void __stdio_init(int filc, fdi_node_t *filv[]) 104 104 { 105 105 if (filc > 0) { 106 stdin = f dopen(0, "r");106 stdin = fopen_node(filv[0], "r"); 107 107 } else { 108 108 stdin = &stdin_null; … … 111 111 112 112 if (filc > 1) { 113 stdout = f dopen(1, "w");113 stdout = fopen_node(filv[1], "w"); 114 114 } else { 115 115 stdout = &stdout_klog; … … 118 118 119 119 if (filc > 2) { 120 stderr = f dopen(2, "w");120 stderr = fopen_node(filv[2], "w"); 121 121 } else { 122 122 stderr = &stderr_klog; … … 127 127 void __stdio_done(void) 128 128 { 129 while (!list_empty(&files)) { 130 FILE *file = list_get_instance(list_first(&files), FILE, link); 129 link_t *link = files.next; 130 131 while (link != &files) { 132 FILE *file = list_get_instance(link, FILE, link); 131 133 fclose(file); 134 link = files.next; 132 135 } 133 136 } … … 285 288 } 286 289 290 FILE *fopen_node(fdi_node_t *node, const char *mode) 291 { 292 int flags; 293 if (!parse_mode(mode, &flags)) 294 return NULL; 295 296 /* Open file. */ 297 FILE *stream = malloc(sizeof(FILE)); 298 if (stream == NULL) { 299 errno = ENOMEM; 300 return NULL; 301 } 302 303 stream->fd = open_node(node, flags); 304 if (stream->fd < 0) { 305 /* errno was set by open_node() */ 306 free(stream); 307 return NULL; 308 } 309 310 stream->error = false; 311 stream->eof = false; 312 stream->klog = false; 313 stream->sess = NULL; 314 stream->need_sync = false; 315 _setvbuf(stream); 316 317 list_append(&stream->link, &files); 318 319 return stream; 320 } 321 287 322 int fclose(FILE *stream) 288 323 { … … 562 597 } 563 598 564 data+= now;599 buf += now; 565 600 stream->buf_head += now; 566 601 buf_free -= now; 567 602 bytes_left -= now; 568 603 total_written += now; 569 stream->buf_state = _bs_write;570 604 571 605 if (buf_free == 0) { … … 575 609 } 576 610 } 611 612 if (total_written > 0) 613 stream->buf_state = _bs_write; 577 614 578 615 if (need_flush) … … 680 717 off64_t ftell(FILE *stream) 681 718 { 682 _fflushbuf(stream);683 719 return lseek(stream->fd, 0, SEEK_CUR); 684 720 } … … 748 784 } 749 785 750 int fhandle(FILE *stream, int *handle) 751 { 752 if (stream->fd >= 0) { 753 *handle = stream->fd; 754 return EOK; 755 } 786 int fnode(FILE *stream, fdi_node_t *node) 787 { 788 if (stream->fd >= 0) 789 return fd_node(stream->fd, node); 756 790 757 791 return ENOENT;
Note:
See TracChangeset
for help on using the changeset viewer.