Changeset 163e34c in mainline for uspace/lib/c


Ignore:
Timestamp:
2025-04-13T19:33:48Z (3 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
f5e1692
Parents:
97f6b71
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2025-04-13 18:56:51)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2025-04-13 19:33:48)
Message:

Actually convert the printf outputs everywhere

Location:
uspace/lib/c
Files:
1 deleted
5 edited

Legend:

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

    r97f6b71 r163e34c  
    4040#include <str.h>
    4141#include <printf_core.h>
    42 
    43 static int asprintf_str_write(const char *str, size_t count, void *unused)
    44 {
    45         return str_nlength(str, count);
    46 }
    47 
    48 static int asprintf_wstr_write(const char32_t *str, size_t count, void *unused)
    49 {
    50         return wstr_nlength(str, count);
    51 }
    52 
    53 int vprintf_length(const char *fmt, va_list args)
    54 {
    55         printf_spec_t ps = {
    56                 asprintf_str_write,
    57                 asprintf_wstr_write,
    58                 NULL
    59         };
    60 
    61         return printf_core(fmt, &ps, args);
    62 }
    63 
    64 int printf_length(const char *fmt, ...)
    65 {
    66         va_list args;
    67         va_start(args, fmt);
    68         int ret = vprintf_length(fmt, args);
    69         va_end(args);
    70 
    71         return ret;
    72 }
    7342
    7443/** Allocate and print to string.
     
    11584        int ret = vasprintf(strp, fmt, args);
    11685        va_end(args);
    117 
    11886        return ret;
    11987}
  • uspace/lib/c/generic/io/kio.c

    r97f6b71 r163e34c  
    131131}
    132132
    133 static int kio_vprintf_str_write(const char *str, size_t size, void *data)
     133static errno_t kio_vprintf_str_write(const char *str, size_t size, void *data)
    134134{
    135         size_t wr;
    136 
    137         wr = 0;
    138         (void) kio_write(str, size, &wr);
    139         return str_nlength(str, wr);
    140 }
    141 
    142 static int kio_vprintf_wstr_write(const char32_t *str, size_t size, void *data)
    143 {
    144         size_t offset = 0;
    145         size_t chars = 0;
    146         size_t wr;
    147 
    148         while (offset < size) {
    149                 char buf[STR_BOUNDS(1)];
    150                 size_t sz = 0;
    151 
    152                 if (chr_encode(str[chars], buf, &sz, STR_BOUNDS(1)) == EOK)
    153                         kio_write(buf, sz, &wr);
    154 
    155                 chars++;
    156                 offset += sizeof(char32_t);
    157         }
    158 
    159         return chars;
     135        size_t wr = 0;
     136        return kio_write(str, size, &wr);
    160137}
    161138
     
    172149        printf_spec_t ps = {
    173150                kio_vprintf_str_write,
    174                 kio_vprintf_wstr_write,
    175151                NULL
    176152        };
  • uspace/lib/c/generic/io/vprintf.c

    r97f6b71 r163e34c  
    4242static FIBRIL_MUTEX_INITIALIZE(printf_mutex);
    4343
    44 static int vprintf_str_write(const char *str, size_t size, void *stream)
     44static errno_t vprintf_str_write(const char *str, size_t size, void *stream)
    4545{
    46         size_t wr = fwrite(str, 1, size, (FILE *) stream);
    47         return str_nlength(str, wr);
    48 }
     46        errno_t old_errno = errno;
    4947
    50 static int vprintf_wstr_write(const char32_t *str, size_t size, void *stream)
    51 {
    52         size_t offset = 0;
    53         size_t chars = 0;
     48        errno = EOK;
     49        size_t written = fwrite(str, 1, size, (FILE *) stream);
    5450
    55         while (offset < size) {
    56                 if (fputuc(str[chars], (FILE *) stream) <= 0)
    57                         break;
     51        if (errno == EOK && written != size)
     52                errno = EIO;
    5853
    59                 chars++;
    60                 offset += sizeof(char32_t);
    61         }
     54        if (errno != EOK)
     55                return errno;
    6256
    63         return chars;
     57        errno = old_errno;
     58        return EOK;
    6459}
    6560
     
    7772        printf_spec_t ps = {
    7873                vprintf_str_write,
    79                 vprintf_wstr_write,
    8074                stream
    8175        };
  • uspace/lib/c/include/stdio.h

    r97f6b71 r163e34c  
    209209};
    210210
    211 extern int vprintf_length(const char *, va_list);
    212 extern int printf_length(const char *, ...)
    213     _HELENOS_PRINTF_ATTRIBUTE(1, 2);
    214211extern FILE *fdopen(int, const char *);
    215212extern int fileno(FILE *);
  • uspace/lib/c/meson.build

    r97f6b71 r163e34c  
    7272        'common/stdc/mem.c',
    7373        'common/stdc/qsort.c',
     74        'common/stdc/snprintf.c',
    7475        'common/stdc/uchar.c',
     76        'common/stdc/vsnprintf.c',
    7577        'common/stdc/wchar.c',
    7678        'common/str.c',
     
    113115        'generic/io/logctl.c',
    114116        'generic/io/printf.c',
    115         'generic/io/snprintf.c',
    116117        'generic/io/table.c',
    117118        'generic/io/vprintf.c',
    118         'generic/io/vsnprintf.c',
    119119        'generic/ipc.c',
    120120        'generic/irq.c',
Note: See TracChangeset for help on using the changeset viewer.