/uspace/trunk/libc/include/unistd.h |
---|
36,6 → 36,7 |
#define getpagesize() (PAGE_SIZE) |
extern ssize_t write(int fd, const void * buf, size_t count); |
extern ssize_t read(int fd, void * buf, size_t count); |
extern void _exit(int status); |
void *sbrk(ssize_t incr); |
void usleep(unsigned long usec); |
/uspace/trunk/libc/include/io/stream.h |
---|
1,5 → 1,32 |
/* |
* Copyright (C) 2006 Jakub Vana |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <libarch/types.h> |
#include <unistd.h> |
#define EMFILE -17 |
7,6 → 34,6 |
typedef ssize_t (*pwritefn_t)(void *, const void *, size_t); |
typedef char (*preadfn_t)(void); |
typedef ssize_t (*preadfn_t)(void *, void *, size_t); |
fd_t open(const char *fname, int flags); |
/uspace/trunk/libc/include/io/io.h |
---|
34,5 → 34,6 |
int putnchars(const char * buf, size_t count); |
int putstr(const char * str); |
int putchar(int c); |
int getchar(void); |
#endif |
/uspace/trunk/libc/include/stdio.h |
---|
34,6 → 34,8 |
#define EOF (-1) |
extern int getchar(void); |
extern int puts(const char * str); |
extern int putchar(int c); |
/uspace/trunk/libc/generic/io/io.c |
---|
92,3 → 92,15 |
return EOF; |
} |
int getchar(void) |
{ |
unsigned char c; |
if (read(0, (void *)&c , 1) == 1) { |
return c; |
} |
return EOF; |
} |
/uspace/trunk/libc/generic/io/stream.c |
---|
1,3 → 1,33 |
/* |
* Copyright (C) 2006 Josef Cejka |
* Copyright (C) 2006 Jakub Vana |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <io/io.h> |
#include <io/stream.h> |
#include <string.h> |
8,6 → 38,7 |
#include <ipc/fb.h> |
#include <ipc/services.h> |
#include <console.h> |
#include <unistd.h> |
#define FDS 32 |
34,14 → 65,21 |
//return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count); |
} |
static char read_stdin(void) |
static ssize_t read_stdin(void *param, void *buf, size_t count) |
{ |
ipcarg_t r0,r1; |
ipc_call_sync_2(console_phone, CONSOLE_GETCHAR, 0, 0, &r0, &r1); |
return r0; |
size_t i = 0; |
while (i < count) { |
if (ipc_call_sync_2(console_phone, CONSOLE_GETCHAR, 0, 0, &r0, &r1) < 0) { |
return -1; |
} |
((char *)buf)[i++] = r0; |
} |
return i; |
//return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count); |
} |
static ssize_t write_stdout(void *param, const void *buf, size_t count) |
{ |
int i; |
125,3 → 163,12 |
return 0; |
} |
ssize_t read(int fd, void *buf, size_t count) |
{ |
if (fd < FDS) |
return streams[fd].r(streams[fd].param, buf, count); |
return 0; |
} |