Changeset 566f4cfb in mainline for uspace/lib/libc/generic/io


Ignore:
Timestamp:
2009-04-24T08:01:05Z (16 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
402de0c
Parents:
ab1861a
Message:

use buffering for klog output (this can be used to avoid the ugly usleeps while starting tasks)
unify and cleanup console.c and related files

Location:
uspace/lib/libc/generic/io
Files:
3 edited

Legend:

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

    rab1861a r566f4cfb  
    3939#include <string.h>
    4040#include <errno.h>
     41#include <console.h>
    4142
    4243const static char nl = '\n';
     
    5051       
    5152        for (count = 0; str[count] != 0; count++);
    52         if (write_stdout((void *) str, count) == count) {
    53                 if (write_stdout(&nl, 1) == 1)
     53       
     54        if (console_write((void *) str, count) == count) {
     55                if (console_write(&nl, 1) == 1)
    5456                        return 0;
    5557        }
     
    6567int putnchars(const char *buf, size_t count)
    6668{
    67         if (write_stdout((void *) buf, count) == count)
     69        if (console_write((void *) buf, count) == count)
    6870                return 0;
    6971       
     
    8284
    8385        for (count = 0; str[count] != 0; count++);
    84         if (write_stdout((void *) str, count) == count)
     86        if (console_write((void *) str, count) == count)
    8587                return 0;
    8688       
     
    9799                return EOF;
    98100
    99         if (write_stdout((void *) buf, offs) == offs)
     101        if (console_write((void *) buf, offs) == offs)
    100102                return c;
    101103
     
    106108{
    107109        unsigned char c;
    108 
    109         flush_stdout();
     110       
     111        console_flush();
    110112        if (read_stdin((void *) &c, 1) == 1)
    111113                return c;
     
    116118int fflush(FILE *f)
    117119{
     120        /* Dummy implementation */
    118121        (void) f;
    119         return flush_stdout();
     122        console_flush();
     123        return 0;
    120124}
    121125
  • uspace/lib/libc/generic/io/stream.c

    rab1861a r566f4cfb  
    5050#include <sys/types.h>
    5151
    52 ssize_t write_stderr(const void *buf, size_t count)
    53 {
    54         return count;
    55 }
    56 
    5752ssize_t read_stdin(void *buf, size_t count)
    5853{
    59         int cons_phone = console_phone_get(false);
    60 
     54        int cons_phone = console_open(false);
     55       
    6156        if (cons_phone >= 0) {
    6257                kbd_event_t ev;
    6358                int rc;
    6459                size_t i = 0;
    65        
     60               
    6661                while (i < count) {
    6762                        do {
     
    6964                                if (rc < 0) return -1;
    7065                        } while (ev.c == 0 || ev.type == KE_RELEASE);
    71 
     66                       
    7267                        ((char *) buf)[i++] = ev.c;
    7368                }
    7469                return i;
    75         } else {
     70        } else
    7671                return -1;
    77         }
    78 }
    79 
    80 ssize_t write_stdout(const void *buf, size_t count)
    81 {
    82         int cons_phone = console_phone_get(false);
    83         int left, rc;
    84 
    85         if (cons_phone >= 0) {
    86                 int i;
    87 
    88                 left = count;
    89                 while (left > 0) {
    90                         rc = console_write(buf, left);
    91                         if (rc < 0)
    92                                 break;
    93                         buf += rc;
    94                         left -= rc;
    95                 }
    96 
    97                 return count;
    98         } else
    99                 return __SYSCALL3(SYS_KLOG, 1, (sysarg_t) buf, count);
    100 }
    101 
    102 int flush_stdout(void)
    103 {
    104         console_flush();
    105         return 0;
    10672}
    10773
  • uspace/lib/libc/generic/io/vprintf.c

    rab1861a r566f4cfb  
    3939#include <futex.h>
    4040#include <async.h>
     41#include <console.h>
    4142
    4243static atomic_t printf_futex = FUTEX_INITIALIZER;
     
    5152                prev = offset;
    5253                str_decode(str, &offset, size);
    53                 write_stdout(str + prev, offset - prev);
     54                console_write(str + prev, offset - prev);
    5455                chars++;
    5556        }
     
    6869                boff = 0;
    6970                chr_encode(str[chars], buf, &boff, 4);
    70                 write_stdout(buf, boff);
     71                console_write(buf, boff);
    7172                chars++;
    7273                offset += sizeof(wchar_t);
Note: See TracChangeset for help on using the changeset viewer.