Changeset a68f737 in mainline
- Timestamp:
- 2009-06-08T12:34:38Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d9c8c81
- Parents:
- f8ef660
- Location:
- uspace/lib/libc
- Files:
-
- 6 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 -
uspace/lib/libc/generic/libc.c
rf8ef660 ra68f737 80 80 argc = 0; 81 81 argv = NULL; 82 stdio_init(0, NULL); 82 83 } else { 83 84 argc = __pcb->argc; 84 85 argv = __pcb->argv; 85 86 if (__pcb->filc > 0) 87 stdin = fopen_node(__pcb->filv[0], "r"); 88 89 if (__pcb->filc > 1) 90 stdout = fopen_node(__pcb->filv[1], "w"); 91 92 if (__pcb->filc > 2) 93 stderr = fopen_node(__pcb->filv[2], "w"); 86 stdio_init(__pcb->filc, __pcb->filv); 94 87 } 95 88 96 89 main(argc, argv); 97 98 if (stdin != NULL) 99 fclose(stdin); 100 101 if (stdout != NULL) 102 fclose(stdout); 103 104 if (stderr != NULL) 105 fclose(stderr); 90 stdio_done(); 106 91 } 107 92 -
uspace/lib/libc/generic/task.c
rf8ef660 ra68f737 106 106 fdi_node_t stderr_node; 107 107 108 if ((stdin != NULL) && (stdin != &stdin_null)) { 109 fnode(stdin, &stdin_node); 108 if ((stdin != NULL) && (fnode(stdin, &stdin_node) == EOK)) 110 109 files[0] = &stdin_node; 111 }else110 else 112 111 files[0] = NULL; 113 112 114 if ((stdout != NULL) && (stdout != &stdout_klog)) { 115 fnode(stdout, &stdout_node); 113 if ((stdout != NULL) && (fnode(stdout, &stdout_node) == EOK)) 116 114 files[1] = &stdout_node; 117 }else115 else 118 116 files[1] = NULL; 119 117 120 if ((stderr != NULL) && (stderr != &stdout_klog)) { 121 fnode(stderr, &stderr_node); 118 if ((stderr != NULL) && (fnode(stderr, &stderr_node) == EOK)) 122 119 files[2] = &stderr_node; 123 }else120 else 124 121 files[2] = NULL; 125 122 -
uspace/lib/libc/generic/vfs/vfs.c
rf8ef660 ra68f737 333 333 } 334 334 335 voidfd_node(int fildes, fdi_node_t *node)335 int fd_node(int fildes, fdi_node_t *node) 336 336 { 337 337 futex_down(&vfs_phone_futex); … … 352 352 node->dev_handle = (dev_handle_t) dev_handle; 353 353 node->index = (fs_index_t) index; 354 } else { 355 node->fs_handle = 0; 356 node->dev_handle = 0; 357 node->index = 0; 358 } 354 } 355 356 return rc; 359 357 } 360 358 -
uspace/lib/libc/include/stdio.h
rf8ef660 ra68f737 38 38 #include <sys/types.h> 39 39 #include <stdarg.h> 40 #include <libadt/list.h> 40 41 41 42 #define EOF (-1) … … 56 57 57 58 typedef struct { 59 /** Linked list pointer. */ 60 link_t link; 61 58 62 /** Underlying file descriptor. */ 59 63 int fd; … … 71 75 int phone; 72 76 } FILE; 73 74 extern FILE stdin_null;75 extern FILE stdout_klog;76 77 77 78 extern FILE *stdin; -
uspace/lib/libc/include/vfs/vfs.h
rf8ef660 ra68f737 56 56 unsigned int); 57 57 58 extern void stdio_init(int filc, fdi_node_t *filv[]); 59 extern void stdio_done(void); 60 58 61 extern int open_node(fdi_node_t *, int); 59 62 extern int fd_phone(int); 60 extern voidfd_node(int, fdi_node_t *);63 extern int fd_node(int, fdi_node_t *); 61 64 62 65 extern FILE *fopen_node(fdi_node_t *, const char *); 63 66 extern int fphone(FILE *); 64 extern voidfnode(FILE *, fdi_node_t *);67 extern int fnode(FILE *, fdi_node_t *); 65 68 66 69 #endif
Note:
See TracChangeset
for help on using the changeset viewer.