Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 1450 → Rev 1451

/uspace/trunk/libc/generic/io/stream.c
7,6 → 7,7
#include <ipc/ns.h>
#include <ipc/fb.h>
#include <ipc/services.h>
#include <console.h>
 
#define FDS 32
 
16,13 → 17,8
void * param;
} stream_t;
 
int console_phone = -1;
 
typedef struct vfb_descriptor_t {
int phone;
int vfb;
} vfb_descriptor_t;
 
 
stream_t streams[FDS] = {{0, 0, 0}};
 
/*
32,17 → 28,27
return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
}*/
 
static void vfb_send_char(vfb_descriptor_t *d, char c)
static ssize_t write_stderr(void *param, const void *buf, size_t count)
{
return count;
//return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
}
 
static char read_stdin(void)
{
ipcarg_t r0,r1;
ipc_call_sync_2(d->phone, FB_PUTCHAR, d->vfb, c, &r0, &r1);
ipc_call_sync_2(console_phone, CONSOLE_GETCHAR, 0, 0, &r0, &r1);
return r0;
//return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
}
static ssize_t write_vfb(void *param, const void *buf, size_t count)
static ssize_t write_stdout(void *param, const void *buf, size_t count)
{
int i;
ipcarg_t r0,r1;
 
for (i = 0; i < count; i++)
vfb_send_char((vfb_descriptor_t *) param, ((char *) buf)[i]);
ipc_call_sync_2(console_phone, CONSOLE_PUTCHAR, 0, ((const char *)buf)[i], &r0, &r1);
return count;
//return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
49,39 → 55,42
}
 
 
static ssize_t write_stderr(void *param, const void *buf, size_t count)
{
return count;
//return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
}
 
 
stream_t open_vfb(void)
static stream_t open_stdin(void)
{
stream_t stream;
vfb_descriptor_t *vfb;
int phoneid;
int res;
ipcarg_t vfb_no;
while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
volatile int a;
for (a = 0; a < 1048576; a++);
if (console_phone < 0) {
while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) {
volatile int a;
for (a = 0; a < 1048576; a++);
}
}
ipc_call_sync(phoneid, FB_GET_VFB, 0, &vfb_no);
vfb = malloc(sizeof(vfb_descriptor_t));
stream.r = read_stdin;
stream.param = 0;
return stream;
}
 
static stream_t open_stdout(void)
{
stream_t stream;
int res;
vfb->phone = phoneid;
vfb->vfb = vfb_no;
if (console_phone < 0) {
while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) {
volatile int a;
for (a = 0; a < 1048576; a++);
}
}
stream.w = write_vfb;
stream.param = vfb;
stream.w = write_stdout;
stream.param = 0;
return stream;
}
 
 
fd_t open(const char *fname, int flags)
{
int c = 0;
92,7 → 101,7
return EMFILE;
if (!strcmp(fname, "stdin")) {
streams[c].r = (preadfn_t)1;
streams[c] = open_stdin();
return c;
}
99,7 → 108,7
if (!strcmp(fname, "stdout")) {
//streams[c].w = write_stdout;
//return c;
streams[c] = open_vfb();
streams[c] = open_stdout();
return c;
}