Changes in uspace/lib/c/generic/io/io.c [47b7006:76d6169] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/io/io.c
r47b7006 r76d6169 44 44 #include <io/klog.h> 45 45 #include <vfs/vfs.h> 46 #include <vfs/vfs_sess.h> 46 47 #include <ipc/devmap.h> 47 48 #include <adt/list.h> 48 49 #include "../private/io.h" 50 #include "../private/stdio.h" 49 51 50 52 static void _ffillbuf(FILE *stream); … … 56 58 .eof = true, 57 59 .klog = false, 58 . phone = -1,60 .sess = NULL, 59 61 .btype = _IONBF, 60 62 .buf = NULL, … … 70 72 .eof = false, 71 73 .klog = true, 72 . phone = -1,74 .sess = NULL, 73 75 .btype = _IOLBF, 74 76 .buf = NULL, … … 84 86 .eof = false, 85 87 .klog = true, 86 . phone = -1,88 .sess = NULL, 87 89 .btype = _IONBF, 88 90 .buf = NULL, … … 99 101 static LIST_INITIALIZE(files); 100 102 101 void __stdio_init(int filc , fdi_node_t *filv[])103 void __stdio_init(int filc) 102 104 { 103 105 if (filc > 0) { 104 stdin = f open_node(filv[0], "r");106 stdin = fdopen(0, "r"); 105 107 } else { 106 108 stdin = &stdin_null; … … 109 111 110 112 if (filc > 1) { 111 stdout = f open_node(filv[1], "w");113 stdout = fdopen(1, "w"); 112 114 } else { 113 115 stdout = &stdout_klog; … … 116 118 117 119 if (filc > 2) { 118 stderr = f open_node(filv[2], "w");120 stderr = fdopen(2, "w"); 119 121 } else { 120 122 stderr = &stderr_klog; … … 125 127 void __stdio_done(void) 126 128 { 127 link_t *link = files.next; 128 129 while (link != &files) { 130 FILE *file = list_get_instance(link, FILE, link); 129 while (!list_empty(&files)) { 130 FILE *file = list_get_instance(list_first(&files), FILE, link); 131 131 fclose(file); 132 link = files.next;133 132 } 134 133 } … … 173 172 } 174 173 *flags = (O_APPEND | O_CREAT) | (plus ? O_RDWR : O_WRONLY); 174 break; 175 175 default: 176 176 errno = EINVAL; … … 254 254 stream->eof = false; 255 255 stream->klog = false; 256 stream-> phone = -1;256 stream->sess = NULL; 257 257 stream->need_sync = false; 258 258 _setvbuf(stream); … … 276 276 stream->eof = false; 277 277 stream->klog = false; 278 stream-> phone = -1;278 stream->sess = NULL; 279 279 stream->need_sync = false; 280 280 _setvbuf(stream); … … 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->phone = -1;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 { … … 323 291 fflush(stream); 324 292 325 if (stream-> phone >= 0)326 async_hangup(stream-> phone);293 if (stream->sess != NULL) 294 async_hangup(stream->sess); 327 295 328 296 if (stream->fd >= 0) … … 594 562 } 595 563 596 buf+= now;564 data += now; 597 565 stream->buf_head += now; 598 566 buf_free -= now; 599 567 bytes_left -= now; 600 568 total_written += now; 569 stream->buf_state = _bs_write; 601 570 602 571 if (buf_free == 0) { … … 606 575 } 607 576 } 608 609 if (total_written > 0)610 stream->buf_state = _bs_write;611 577 612 578 if (need_flush) … … 714 680 off64_t ftell(FILE *stream) 715 681 { 682 _fflushbuf(stream); 716 683 return lseek(stream->fd, 0, SEEK_CUR); 717 684 } … … 731 698 } 732 699 733 if ( stream->fd >= 0 && stream->need_sync) {700 if ((stream->fd >= 0) && (stream->need_sync)) { 734 701 /** 735 702 * Better than syncing always, but probably still not the … … 769 736 } 770 737 771 int fphone(FILE *stream)738 async_sess_t *fsession(exch_mgmt_t mgmt, FILE *stream) 772 739 { 773 740 if (stream->fd >= 0) { 774 if (stream->phone < 0) 775 stream->phone = fd_phone(stream->fd); 776 777 return stream->phone; 778 } 779 780 return -1; 781 } 782 783 int fnode(FILE *stream, fdi_node_t *node) 784 { 785 if (stream->fd >= 0) 786 return fd_node(stream->fd, node); 741 if (stream->sess == NULL) 742 stream->sess = fd_session(mgmt, stream->fd); 743 744 return stream->sess; 745 } 746 747 return NULL; 748 } 749 750 int fhandle(FILE *stream, int *handle) 751 { 752 if (stream->fd >= 0) { 753 *handle = stream->fd; 754 return EOK; 755 } 787 756 788 757 return ENOENT;
Note:
See TracChangeset
for help on using the changeset viewer.