Changes in uspace/lib/c/generic/io/io.c [b72efe8:2f72c67a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/io/io.c
rb72efe8 r2f72c67a 45 45 #include <vfs/vfs.h> 46 46 #include <vfs/vfs_sess.h> 47 #include <ipc/ devmap.h>47 #include <ipc/loc.h> 48 48 #include <adt/list.h> 49 49 #include "../private/io.h" … … 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; … … 285 285 } 286 286 287 FILE *fopen_node(fdi_node_t *node, const char *mode)288 {289 int flags;290 if (!parse_mode(mode, &flags))291 return NULL;292 293 /* Open file. */294 FILE *stream = malloc(sizeof(FILE));295 if (stream == NULL) {296 errno = ENOMEM;297 return NULL;298 }299 300 stream->fd = open_node(node, flags);301 if (stream->fd < 0) {302 /* errno was set by open_node() */303 free(stream);304 return NULL;305 }306 307 stream->error = false;308 stream->eof = false;309 stream->klog = false;310 stream->sess = NULL;311 stream->need_sync = false;312 _setvbuf(stream);313 314 list_append(&stream->link, &files);315 316 return stream;317 }318 319 287 int fclose(FILE *stream) 320 288 { … … 450 418 451 419 bytes_used = stream->buf_head - stream->buf_tail; 452 if (bytes_used == 0)453 return;454 420 455 421 /* If buffer has prefetched read data, we need to seek back. */ 456 if ( stream->buf_state == _bs_read)422 if (bytes_used > 0 && stream->buf_state == _bs_read) 457 423 lseek(stream->fd, - (ssize_t) bytes_used, SEEK_CUR); 458 424 459 425 /* If buffer has unwritten data, we need to write them out. */ 460 if ( stream->buf_state == _bs_write)426 if (bytes_used > 0 && stream->buf_state == _bs_write) 461 427 (void) _fwrite(stream->buf_tail, 1, bytes_used, stream); 462 428 … … 594 560 } 595 561 596 buf+= now;562 data += now; 597 563 stream->buf_head += now; 598 564 buf_free -= now; 599 565 bytes_left -= now; 600 566 total_written += now; 567 stream->buf_state = _bs_write; 601 568 602 569 if (buf_free == 0) { … … 606 573 } 607 574 } 608 609 if (total_written > 0)610 stream->buf_state = _bs_write;611 575 612 576 if (need_flush) … … 714 678 off64_t ftell(FILE *stream) 715 679 { 680 _fflushbuf(stream); 716 681 return lseek(stream->fd, 0, SEEK_CUR); 717 682 } … … 781 746 } 782 747 783 int fnode(FILE *stream, fdi_node_t *node) 784 { 785 if (stream->fd >= 0) 786 return fd_node(stream->fd, node); 748 int fhandle(FILE *stream, int *handle) 749 { 750 if (stream->fd >= 0) { 751 *handle = stream->fd; 752 return EOK; 753 } 787 754 788 755 return ENOENT;
Note:
See TracChangeset
for help on using the changeset viewer.