Changeset a68f737 in mainline for uspace/lib/libc/generic/io/io.c
- Timestamp:
- 2009-06-08T12:34:38Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d9c8c81
- Parents:
- f8ef660
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/io/io.c
rf8ef660 ra68f737 43 43 #include <vfs/vfs.h> 44 44 #include <ipc/devmap.h> 45 46 FILE stdin_null = { 45 #include <libadt/list.h> 46 47 static FILE stdin_null = { 47 48 .fd = -1, 48 49 .error = true, … … 52 53 }; 53 54 54 FILE stdout_klog = {55 static FILE stdout_klog = { 55 56 .fd = -1, 56 57 .error = false, … … 60 61 }; 61 62 62 FILE *stdin = &stdin_null; 63 FILE *stdout = &stdout_klog; 64 FILE *stderr = &stdout_klog; 63 static FILE stderr_klog = { 64 .fd = -1, 65 .error = false, 66 .eof = false, 67 .klog = true, 68 .phone = -1 69 }; 70 71 FILE *stdin = NULL; 72 FILE *stdout = NULL; 73 FILE *stderr = NULL; 74 75 static LIST_INITIALIZE(files); 76 77 void stdio_init(int filc, fdi_node_t *filv[]) 78 { 79 if (filc > 0) { 80 stdin = fopen_node(filv[0], "r"); 81 } else { 82 stdin = &stdin_null; 83 list_append(&stdin->link, &files); 84 } 85 86 if (filc > 1) { 87 stdout = fopen_node(filv[1], "w"); 88 } else { 89 stdout = &stdout_klog; 90 list_append(&stdout->link, &files); 91 } 92 93 if (filc > 2) { 94 stderr = fopen_node(filv[2], "w"); 95 } else { 96 stderr = &stderr_klog; 97 list_append(&stderr->link, &files); 98 } 99 } 100 101 void stdio_done(void) 102 { 103 link_t *link = files.next; 104 105 while (link != &files) { 106 FILE *file = list_get_instance(link, FILE, link); 107 fclose(file); 108 link = files.next; 109 } 110 } 65 111 66 112 static bool parse_mode(const char *mode, int *flags) … … 142 188 stream->phone = -1; 143 189 190 list_append(&stream->link, &files); 191 144 192 return stream; 145 193 } … … 170 218 stream->phone = -1; 171 219 220 list_append(&stream->link, &files); 221 172 222 return stream; 173 223 } … … 185 235 rc = close(stream->fd); 186 236 187 if ((stream != &stdin_null) && (stream != &stdout_klog)) 237 list_remove(&stream->link); 238 239 if ((stream != &stdin_null) 240 && (stream != &stdout_klog) 241 && (stream != &stderr_klog)) 188 242 free(stream); 189 243 … … 354 408 } 355 409 356 void fnode(FILE *stream, fdi_node_t *node) 357 { 358 if (stream->fd >= 0) { 359 fd_node(stream->fd, node); 360 } else { 361 node->fs_handle = 0; 362 node->dev_handle = 0; 363 node->index = 0; 364 } 410 int fnode(FILE *stream, fdi_node_t *node) 411 { 412 if (stream->fd >= 0) 413 return fd_node(stream->fd, node); 414 415 return ENOENT; 365 416 } 366 417
Note:
See TracChangeset
for help on using the changeset viewer.