Changeset 04552a80 in mainline for libc/generic/io/stream.c
- Timestamp:
- 2006-05-17T20:51:08Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 25f9823
- Parents:
- 04a73cdf
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libc/generic/io/stream.c
r04a73cdf r04552a80 11 11 #define FDS 32 12 12 13 typedef struct stream_t 14 { 13 typedef struct stream_t { 15 14 pwritefn_t w; 16 15 preadfn_t r; 17 16 void * param; 18 } stream_t;17 } stream_t; 19 18 20 19 21 typedef struct vfb_descriptor_t 22 { 20 typedef struct vfb_descriptor_t { 23 21 int phone; 24 22 int vfb; 25 } vfb_descriptor_t;23 } vfb_descriptor_t; 26 24 27 25 28 stream_t streams[FDS] ={{0,0,0}};26 stream_t streams[FDS] = {{0, 0, 0}}; 29 27 30 28 /* … … 35 33 }*/ 36 34 37 static void vfb_send_char(vfb_descriptor_t *d, char c)35 static void vfb_send_char(vfb_descriptor_t *d, char c) 38 36 { 39 37 ipcarg_t r0,r1; 40 ipc_call_sync_2(d->phone, FB_PUTCHAR,d->vfb,c,&r0,&r1);38 ipc_call_sync_2(d->phone, FB_PUTCHAR, d->vfb, c, &r0, &r1); 41 39 } 42 40 43 static ssize_t write_vfb(void *param, const void * 41 static ssize_t write_vfb(void *param, const void *buf, size_t count) 44 42 { 45 43 int i; 46 for(i=0;i<count;i++) vfb_send_char((vfb_descriptor_t *)param,((char*)buf)[i]); 44 for (i = 0; i < count; i++) 45 vfb_send_char((vfb_descriptor_t *) param, ((char *) buf)[i]); 47 46 48 47 return count; … … 51 50 52 51 53 static ssize_t write_stderr(void *param, const void * 52 static ssize_t write_stderr(void *param, const void *buf, size_t count) 54 53 { 55 54 return count; … … 58 57 59 58 60 stream_t open_vfb(void);61 59 stream_t open_vfb(void) 62 60 { … … 67 65 ipcarg_t vfb_no; 68 66 69 while((phoneid=ipc_connect_me_to(PHONE_NS,SERVICE_VIDEO,0))<0) 70 { 67 while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) { 71 68 volatile int a; 72 for(a=0;a<1048576;a++); 69 70 for (a = 0; a < 1048576; a++); 73 71 } 74 72 75 ipc_call_sync(phoneid, FB_GET_VFB,0,&vfb_no);76 vfb =malloc(sizeof(vfb_descriptor_t));73 ipc_call_sync(phoneid, FB_GET_VFB, 0, &vfb_no); 74 vfb = malloc(sizeof(vfb_descriptor_t)); 77 75 78 vfb->phone =phoneid;79 vfb->vfb =vfb_no;76 vfb->phone = phoneid; 77 vfb->vfb = vfb_no; 80 78 81 82 stream.w=write_vfb; 83 stream.param=vfb; 79 stream.w = write_vfb; 80 stream.param = vfb; 84 81 return stream; 85 82 } 86 83 87 84 88 fd_t open(const char *fname, int flags)85 fd_t open(const char *fname, int flags) 89 86 { 90 int c=0; 91 while(((streams[c].w)||(streams[c].r))&&(c<FDS))c++; 92 if(c==FDS) return EMFILE; 93 94 95 if(!strcmp(fname,"stdin")) 96 { 97 streams[c].r=(preadfn_t)1; 87 int c = 0; 88 89 while (((streams[c].w) || (streams[c].r)) && (c < FDS)) 90 c++; 91 if (c == FDS) 92 return EMFILE; 93 94 if (!strcmp(fname, "stdin")) { 95 streams[c].r = (preadfn_t)1; 98 96 return c; 99 97 } 100 98 101 if(!strcmp(fname,"stdout")) 102 { 103 //streams[c].w=write_stdout; 99 if (!strcmp(fname, "stdout")) { 100 //streams[c].w = write_stdout; 104 101 //return c; 105 streams[c] =open_vfb();102 streams[c] = open_vfb(); 106 103 return c; 107 104 } 108 105 109 if(!strcmp(fname,"stderr")) 110 { 111 streams[c].w=write_stderr; 106 if (!strcmp(fname, "stderr")) { 107 streams[c].w = write_stderr; 112 108 return c; 113 109 } … … 115 111 116 112 117 ssize_t write(int fd, const void * 113 ssize_t write(int fd, const void *buf, size_t count) 118 114 { 119 if(fd<FDS) return streams[fd].w(streams[fd].param,buf,count); 115 if (fd < FDS) 116 return streams[fd].w(streams[fd].param, buf, count); 117 120 118 return 0; 121 119 } 122 123
Note:
See TracChangeset
for help on using the changeset viewer.