Changeset 79460ae in mainline for libc/generic/io/stream.c
- Timestamp:
- 2006-05-30T10:40:17Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 44c6d88d
- Parents:
- f25b73d6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libc/generic/io/stream.c
rf25b73d6 r79460ae 8 8 #include <ipc/fb.h> 9 9 #include <ipc/services.h> 10 #include <console.h> 10 11 11 12 #define FDS 32 … … 17 18 } stream_t; 18 19 19 20 typedef struct vfb_descriptor_t { 21 int phone; 22 int vfb; 23 } vfb_descriptor_t; 24 20 int console_phone = -1; 25 21 26 22 stream_t streams[FDS] = {{0, 0, 0}}; … … 33 29 }*/ 34 30 35 static void vfb_send_char(vfb_descriptor_t *d, char c) 31 static ssize_t write_stderr(void *param, const void *buf, size_t count) 32 { 33 return count; 34 //return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count); 35 } 36 37 static char read_stdin(void) 36 38 { 37 39 ipcarg_t r0,r1; 38 ipc_call_sync_2(d->phone, FB_PUTCHAR, d->vfb, c, &r0, &r1); 40 ipc_call_sync_2(console_phone, CONSOLE_GETCHAR, 0, 0, &r0, &r1); 41 42 return r0; 43 //return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count); 39 44 } 40 41 static ssize_t write_vfb(void *param, const void *buf, size_t count) 45 static ssize_t write_stdout(void *param, const void *buf, size_t count) 42 46 { 43 47 int i; 48 ipcarg_t r0,r1; 49 44 50 for (i = 0; i < count; i++) 45 vfb_send_char((vfb_descriptor_t *) param, ((char *) buf)[i]);51 ipc_call_sync_2(console_phone, CONSOLE_PUTCHAR, 0, ((const char *)buf)[i], &r0, &r1); 46 52 47 53 return count; … … 50 56 51 57 52 static ssize_t write_stderr(void *param, const void *buf, size_t count)53 {54 return count;55 //return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);56 }57 58 58 59 stream_t open_vfb(void) 59 static stream_t open_stdin(void) 60 60 { 61 61 stream_t stream; 62 vfb_descriptor_t *vfb;63 62 int phoneid; 64 63 int res; 65 ipcarg_t vfb_no;66 64 67 while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) { 68 volatile int a; 69 70 for (a = 0; a < 1048576; a++); 65 if (console_phone < 0) { 66 while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) { 67 volatile int a; 68 for (a = 0; a < 1048576; a++); 69 } 71 70 } 72 71 73 ipc_call_sync(phoneid, FB_GET_VFB, 0, &vfb_no); 74 vfb = malloc(sizeof(vfb_descriptor_t)); 75 76 vfb->phone = phoneid; 77 vfb->vfb = vfb_no; 78 79 stream.w = write_vfb; 80 stream.param = vfb; 72 stream.r = read_stdin; 73 stream.param = 0; 81 74 return stream; 82 75 } 83 76 77 static stream_t open_stdout(void) 78 { 79 stream_t stream; 80 int res; 81 82 if (console_phone < 0) { 83 while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) { 84 volatile int a; 85 for (a = 0; a < 1048576; a++); 86 } 87 } 88 89 stream.w = write_stdout; 90 stream.param = 0; 91 return stream; 92 } 84 93 85 94 fd_t open(const char *fname, int flags) … … 93 102 94 103 if (!strcmp(fname, "stdin")) { 95 streams[c] .r = (preadfn_t)1;104 streams[c] = open_stdin(); 96 105 return c; 97 106 } … … 100 109 //streams[c].w = write_stdout; 101 110 //return c; 102 streams[c] = open_ vfb();111 streams[c] = open_stdout(); 103 112 return c; 104 113 }
Note:
See TracChangeset
for help on using the changeset viewer.