Changeset 907bb49 in mainline for uspace/lib/libc/generic/io/stream.c


Ignore:
Timestamp:
2009-03-18T22:22:31Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
266daf5a
Parents:
eada065e
Message:

Consolidate console interface.

File:
1 edited

Legend:

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

    reada065e r907bb49  
    4444#include <ipc/services.h>
    4545#include <ipc/console.h>
     46#include <console.h>
    4647#include <kbd/kbd.h>
    4748#include <unistd.h>
    4849#include <async.h>
    4950#include <sys/types.h>
    50 
    51 static int console_phone = -1;
    5251
    5352ssize_t write_stderr(const void *buf, size_t count)
     
    5857ssize_t read_stdin(void *buf, size_t count)
    5958{
    60         open_console();
    61         if (console_phone >= 0) {
     59        int cons_phone = console_phone_get();
     60
     61        if (cons_phone >= 0) {
    6262                kbd_event_t ev;
    6363                int rc;
     
    8080ssize_t write_stdout(const void *buf, size_t count)
    8181{
    82         open_console();
    83         if (console_phone >= 0) {
     82        int cons_phone = console_phone_get();
     83
     84        if (cons_phone >= 0) {
    8485                int i;
    85        
     86
    8687                for (i = 0; i < count; i++)
    87                         async_msg_1(console_phone, CONSOLE_PUTCHAR,
    88                             ((const char *) buf)[i]);
    89                
     88                        console_putchar(((const char *) buf)[i]);
     89
    9090                return count;
    9191        } else
    9292                return __SYSCALL3(SYS_KLOG, 1, (sysarg_t) buf, count);
    93 }
    94 
    95 void open_console(void)
    96 {
    97         if (console_phone < 0) {
    98                 int phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0, 0);
    99                 if (phone >= 0)
    100                         console_phone = phone;
    101         }
    102 }
    103 
    104 void close_console(void)
    105 {
    106         if (console_phone >= 0) {
    107                 if (ipc_hangup(console_phone) == 0) {
    108                         console_phone = -1;
    109                 }
    110         }
    11193}
    11294
     
    11698}
    11799
    118 int get_console_phone(void)
    119 {
    120         if (console_phone < 0)
    121                 console_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_CONSOLE, 0, 0);
    122        
    123         return console_phone;
    124 }
    125 
    126 void console_wait(void)
    127 {
    128         while (console_phone < 0)
    129                 get_console_phone();
    130 }
    131 
    132100/** @}
    133101 */
Note: See TracChangeset for help on using the changeset viewer.