Changeset 04552a80 in mainline for libc/generic/io/stream.c


Ignore:
Timestamp:
2006-05-17T20:51:08Z (19 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
25f9823
Parents:
04a73cdf
Message:

code cleanup (somebody should read the coding style guide)
remove DONT_OPEN_STDIO (this has to be done in a different way, ppc32 linker segfaults on initiating extern variable)
remove deprecated libipc stuff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libc/generic/io/stream.c

    r04a73cdf r04552a80  
    1111#define FDS 32
    1212
    13 typedef struct stream_t
    14 {
     13typedef struct stream_t {
    1514        pwritefn_t w;
    1615        preadfn_t r;
    1716        void * param;
    18 }stream_t;
     17} stream_t;
    1918
    2019
    21 typedef struct vfb_descriptor_t
    22 {
     20typedef struct vfb_descriptor_t {
    2321        int phone;
    2422        int vfb;
    25 }vfb_descriptor_t;
     23} vfb_descriptor_t;
    2624
    2725
    28 stream_t streams[FDS]={{0,0,0}};
     26stream_t streams[FDS] = {{0, 0, 0}};
    2927
    3028/*
     
    3533}*/
    3634
    37 static void vfb_send_char(vfb_descriptor_t *d,char c)
     35static void vfb_send_char(vfb_descriptor_t *d, char c)
    3836{
    3937        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);
    4139}
    4240                               
    43 static ssize_t write_vfb(void *param, const void * buf, size_t count)
     41static ssize_t write_vfb(void *param, const void *buf, size_t count)
    4442{
    4543        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]);
    4746       
    4847        return count;
     
    5150
    5251
    53 static ssize_t write_stderr(void *param, const void * buf, size_t count)
     52static ssize_t write_stderr(void *param, const void *buf, size_t count)
    5453{
    5554        return count;
     
    5857
    5958
    60 stream_t open_vfb(void);
    6159stream_t open_vfb(void)
    6260{
     
    6765        ipcarg_t vfb_no;
    6866       
    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) {
    7168                volatile int a;
    72                 for(a=0;a<1048576;a++);
     69               
     70                for (a = 0; a < 1048576; a++);
    7371        }
    7472       
    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));
    7775       
    78         vfb->phone=phoneid;
    79         vfb->vfb=vfb_no;
     76        vfb->phone = phoneid;
     77        vfb->vfb = vfb_no;
    8078       
    81        
    82         stream.w=write_vfb;
    83         stream.param=vfb;
     79        stream.w = write_vfb;
     80        stream.param = vfb;
    8481        return stream;
    8582}
    8683
    8784
    88 fd_t open(const char *fname,int flags)
     85fd_t open(const char *fname, int flags)
    8986{
    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;
    9896                return c;
    9997        }
    10098       
    101         if(!strcmp(fname,"stdout"))
    102         {
    103                 //streams[c].w=write_stdout;
     99        if (!strcmp(fname, "stdout")) {
     100                //streams[c].w = write_stdout;
    104101                //return c;
    105                 streams[c]=open_vfb();
     102                streams[c] = open_vfb();
    106103                return c;
    107104        }
    108105       
    109         if(!strcmp(fname,"stderr"))
    110         {
    111                 streams[c].w=write_stderr;
     106        if (!strcmp(fname, "stderr")) {
     107                streams[c].w = write_stderr;
    112108                return c;
    113109        }
     
    115111
    116112
    117 ssize_t write(int fd, const void * buf, size_t count)
     113ssize_t write(int fd, const void *buf, size_t count)
    118114{
    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       
    120118        return 0;
    121119}
    122 
    123 
Note: See TracChangeset for help on using the changeset viewer.