openblt

a hobby OS from the late 90s
git clone http://frotz.net/git/openblt.git
Log | Files | Refs | LICENSE

stdio.c (1085B)


      1 /* Copyright 1999, Sidney Cammeresi. All rights reserved.
      2 ** Distributed under the terms of the OpenBLT License
      3 */
      4 
      5 #include <stdio.h>
      6 #include <stdlib.h>
      7 #include <unistd.h>
      8 #include <blt/fdl.h>
      9 #include <blt/syscall.h>
     10 #include <blt/namer.h>
     11 #include <blt/libsyms.h>
     12 
     13 int __libc_bind_console(void);
     14 ssize_t __libc_write_console(const void *buf, ssize_t len);
     15 ssize_t __libc_read_console(void *buf, ssize_t);
     16 
     17 static fdl_type console_input_fdl_imp = { "console_input", _console_read,
     18     NULL, NULL, NULL };
     19 
     20 FILE *stdin, *stdout, *stderr;
     21 
     22 weak_alias (_getc, getc)
     23 weak_alias (_getchar, getchar)
     24 
     25 void __libc_init_console_input ()
     26 {
     27 	int fd;
     28 
     29 	__libc_bind_console();
     30 	
     31 	fd = _fdl_alloc_descriptor (&console_input_fdl_imp, NULL);
     32 	if (fd)
     33 		_printf ("__libc_init_input: console input not on fd 0\n");
     34 	stdin = malloc (sizeof (FILE));
     35 	stdin->fd = 0;
     36 }
     37 
     38 int _console_read (void *cookie, void *buf, size_t count)
     39 {
     40 	return __libc_read_console(buf, count);
     41 }
     42 
     43 int _getc (FILE *stream)
     44 {
     45 	char c;
     46 
     47 	_read (stream->fd, &c, 1);
     48 	return c;
     49 }
     50 
     51 int _getchar (void)
     52 {
     53 	return _getc (stdin);
     54 }
     55