Changes in uspace/lib/c/generic/io/io.c [79ae36dd:76d6169] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/io/io.c
r79ae36dd r76d6169 101 101 static LIST_INITIALIZE(files); 102 102 103 void __stdio_init(int filc , fdi_node_t *filv[])103 void __stdio_init(int filc) 104 104 { 105 105 if (filc > 0) { 106 stdin = f open_node(filv[0], "r");106 stdin = fdopen(0, "r"); 107 107 } else { 108 108 stdin = &stdin_null; … … 111 111 112 112 if (filc > 1) { 113 stdout = f open_node(filv[1], "w");113 stdout = fdopen(1, "w"); 114 114 } else { 115 115 stdout = &stdout_klog; … … 118 118 119 119 if (filc > 2) { 120 stderr = f open_node(filv[2], "w");120 stderr = fdopen(2, "w"); 121 121 } else { 122 122 stderr = &stderr_klog; … … 127 127 void __stdio_done(void) 128 128 { 129 link_t *link = files.next; 130 131 while (link != &files) { 132 FILE *file = list_get_instance(link, FILE, link); 129 while (!list_empty(&files)) { 130 FILE *file = list_get_instance(list_first(&files), FILE, link); 133 131 fclose(file); 134 link = files.next;135 132 } 136 133 } … … 288 285 } 289 286 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 322 287 int fclose(FILE *stream) 323 288 { … … 597 562 } 598 563 599 buf+= now;564 data += now; 600 565 stream->buf_head += now; 601 566 buf_free -= now; 602 567 bytes_left -= now; 603 568 total_written += now; 569 stream->buf_state = _bs_write; 604 570 605 571 if (buf_free == 0) { … … 609 575 } 610 576 } 611 612 if (total_written > 0)613 stream->buf_state = _bs_write;614 577 615 578 if (need_flush) … … 717 680 off64_t ftell(FILE *stream) 718 681 { 682 _fflushbuf(stream); 719 683 return lseek(stream->fd, 0, SEEK_CUR); 720 684 } … … 784 748 } 785 749 786 int fnode(FILE *stream, fdi_node_t *node) 787 { 788 if (stream->fd >= 0) 789 return fd_node(stream->fd, node); 750 int fhandle(FILE *stream, int *handle) 751 { 752 if (stream->fd >= 0) { 753 *handle = stream->fd; 754 return EOK; 755 } 790 756 791 757 return ENOENT;
Note:
See TracChangeset
for help on using the changeset viewer.