Changeset 2595dab in mainline for uspace/lib/libc/generic/io/vprintf.c


Ignore:
Timestamp:
2009-06-03T19:26:28Z (16 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d00ae4c
Parents:
ca3ba3a
Message:

I/O subsystem overhaul:

  • add more POSIX-like file and stream functions (with real functionality of stdin, stdout, stderr)
  • cleanup console access methods (now generic to any console-like device)
  • remove unsafe stream functions
  • add special open_node(), fd_node(), fd_phone() (file) and fopen_node(), fnode(), fphone() (stream) functions for HelenOS-specific I/O operations
File:
1 edited

Legend:

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

    rca3ba3a r2595dab  
    3939#include <futex.h>
    4040#include <async.h>
    41 #include <console.h>
     41#include <string.h>
    4242
    4343static atomic_t printf_futex = FUTEX_INITIALIZER;
    4444
    45 static int vprintf_str_write(const char *str, size_t size, void *data)
     45static int vprintf_str_write(const char *str, size_t size, void *stream)
     46{
     47        size_t wr = fwrite(str, 1, size, (FILE *) stream);
     48        return str_nlength(str, wr);
     49}
     50
     51static int vprintf_wstr_write(const wchar_t *str, size_t size, void *stream)
    4652{
    4753        size_t offset = 0;
    48         size_t prev;
    49         count_t chars = 0;
     54        size_t chars = 0;
    5055       
    5156        while (offset < size) {
    52                 prev = offset;
    53                 str_decode(str, &offset, size);
    54                 console_write(str + prev, offset - prev);
    55                 chars++;
    56         }
    57        
    58         return chars;
    59 }
    60 
    61 static int vprintf_wstr_write(const wchar_t *str, size_t size, void *data)
    62 {
    63         size_t offset = 0;
    64         size_t boff;
    65         count_t chars = 0;
    66         char buf[4];
    67        
    68         while (offset < size) {
    69                 boff = 0;
    70                 chr_encode(str[chars], buf, &boff, 4);
    71                 console_write(buf, boff);
     57                if (fputc(str[chars], (FILE *) stream) <= 0)
     58                        break;
     59               
    7260                chars++;
    7361                offset += sizeof(wchar_t);
     
    7765}
    7866
    79 
    8067/** Print formatted text.
    81  * @param fmt   format string
    82  * @param ap    format parameters
     68 *
     69 * @param stream Output stream
     70 * @param fmt    Format string
     71 * @param ap     Format parameters
     72 *
    8373 * \see For more details about format string see printf_core.
     74 *
    8475 */
    85 int vprintf(const char *fmt, va_list ap)
     76int vfprintf(FILE *stream, const char *fmt, va_list ap)
    8677{
    8778        struct printf_spec ps = {
    8879                vprintf_str_write,
    8980                vprintf_wstr_write,
    90                  NULL
     81                stream
    9182        };
     83       
    9284        /*
    9385         * Prevent other threads to execute printf_core()
    9486         */
    9587        futex_down(&printf_futex);
     88       
    9689        /*
    9790         * Prevent other pseudo threads of the same thread
     
    9992         */
    10093        async_serialize_start();
     94       
    10195        int ret = printf_core(fmt, &ps, ap);
     96       
    10297        async_serialize_end();
    10398        futex_up(&printf_futex);
     99       
    104100        return ret;
     101}
     102
     103/** Print formatted text to stdout.
     104 *
     105 * @param file Output stream
     106 * @param fmt  Format string
     107 * @param ap   Format parameters
     108 *
     109 * \see For more details about format string see printf_core.
     110 *
     111 */
     112int vprintf(const char *fmt, va_list ap)
     113{
     114        return vfprintf(stdout, fmt, ap);
    105115}
    106116
Note: See TracChangeset for help on using the changeset viewer.