Changeset ed88c8e in mainline for uspace/lib


Ignore:
Timestamp:
2018-05-29T13:25:07Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fc0b2a8
Parents:
a57fa32
git-author:
Jiri Svoboda <jiri@…> (2018-05-28 17:24:17)
git-committer:
Jiri Svoboda <jiri@…> (2018-05-29 13:25:07)
Message:

fputc, putchar vs. fputwc, putwchar.

Location:
uspace/lib
Files:
10 edited

Legend:

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

    ra57fa32 red88c8e  
    140140 *
    141141 */
    142 sysarg_t chargrid_putchar(chargrid_t *scrbuf, wchar_t ch, bool update)
     142sysarg_t chargrid_putwchar(chargrid_t *scrbuf, wchar_t ch, bool update)
    143143{
    144144        assert(scrbuf->col < scrbuf->cols);
     
    199199
    200200        for (sysarg_t i = 0; i < spaces; i++)
    201                 flush += chargrid_putchar(scrbuf, ' ', true) - 1;
     201                flush += chargrid_putwchar(scrbuf, ' ', true) - 1;
    202202
    203203        return flush;
     
    228228                scrbuf->row--;
    229229
    230                 chargrid_putchar(scrbuf, ' ', false);
     230                chargrid_putwchar(scrbuf, ' ', false);
    231231                return 2;
    232232        }
    233233
    234234        scrbuf->col--;
    235         chargrid_putchar(scrbuf, ' ', false);
     235        chargrid_putwchar(scrbuf, ' ', false);
    236236        return 1;
    237237}
  • uspace/lib/c/generic/io/io.c

    ra57fa32 red88c8e  
    4646#include <ipc/loc.h>
    4747#include <adt/list.h>
     48#include <wchar.h>
    4849#include "../private/io.h"
    4950#include "../private/stdio.h"
     
    702703}
    703704
    704 int fputc(wchar_t c, FILE *stream)
     705wint_t fputwc(wchar_t wc, FILE *stream)
    705706{
    706707        char buf[STR_BOUNDS(1)];
    707708        size_t sz = 0;
    708709
    709         if (chr_encode(c, buf, &sz, STR_BOUNDS(1)) == EOK) {
    710                 size_t wr = fwrite(buf, 1, sz, stream);
    711 
    712                 if (wr < sz)
    713                         return EOF;
    714 
    715                 return (int) c;
    716         }
    717 
    718         return EOF;
    719 }
    720 
    721 int putchar(wchar_t c)
     710        if (chr_encode(wc, buf, &sz, STR_BOUNDS(1)) != EOK) {
     711                errno = EILSEQ;
     712                return WEOF;
     713        }
     714
     715        size_t wr = fwrite(buf, 1, sz, stream);
     716        if (wr < sz)
     717                return WEOF;
     718
     719        return wc;
     720}
     721
     722wint_t putwchar(wchar_t wc)
     723{
     724        return fputwc(wc, stdout);
     725}
     726
     727int fputc(int c, FILE *stream)
     728{
     729        unsigned char b;
     730        size_t wr;
     731
     732        b = (unsigned char) c;
     733        wr = fwrite(&b, sizeof(b), 1, stream);
     734        if (wr < 1)
     735                return EOF;
     736
     737        return b;
     738}
     739
     740int putchar(int c)
    722741{
    723742        return fputc(c, stdout);
  • uspace/lib/c/generic/io/vprintf.c

    ra57fa32 red88c8e  
    5454
    5555        while (offset < size) {
    56                 if (fputc(str[chars], (FILE *) stream) <= 0)
     56                if (fputwc(str[chars], (FILE *) stream) <= 0)
    5757                        break;
    5858
  • uspace/lib/c/include/io/chargrid.h

    ra57fa32 red88c8e  
    7979extern sysarg_t chargrid_get_top_row(chargrid_t *);
    8080
    81 extern sysarg_t chargrid_putchar(chargrid_t *, wchar_t, bool);
     81extern sysarg_t chargrid_putwchar(chargrid_t *, wchar_t, bool);
    8282extern sysarg_t chargrid_newline(chargrid_t *);
    8383extern sysarg_t chargrid_tabstop(chargrid_t *, sysarg_t);
  • uspace/lib/c/include/stdio.h

    ra57fa32 red88c8e  
    4040#include <_bits/size_t.h>
    4141#include <_bits/wchar_t.h>
     42#include <_bits/wint_t.h>
    4243
    4344#define EOF  (-1)
     
    7374
    7475/* Character and string output functions */
    75 extern int fputc(wchar_t, FILE *);
     76extern int fputc(int, FILE *);
    7677extern int fputs(const char *, FILE *);
    7778
    78 // FIXME: putchar and fputc are byte-oriented.
    79 // They shouldn't accept wide characters.
    80 extern int putchar(wchar_t);
     79extern int putchar(int);
    8180extern int puts(const char *);
    8281
    8382extern int ungetc(int, FILE *);
     83
     84extern wint_t fputwc(wchar_t, FILE *);
     85extern wint_t putwchar(wchar_t);
    8486
    8587/* Formatted string output functions */
  • uspace/lib/c/include/wchar.h

    ra57fa32 red88c8e  
    4444#include <_bits/wchar_t.h>
    4545#include <_bits/wint_t.h>
     46#include <_bits/WEOF.h>
    4647
    4748#include <_bits/NULL.h>
  • uspace/lib/clui/tinput.c

    ra57fa32 red88c8e  
    145145
    146146        for (p = 0; p < pad; p++)
    147                 putchar(' ');
     147                putwchar(' ');
    148148
    149149        console_flush(ti->console);
     
    182182        tinput_console_set_lpos(ti, ti->text_coord + ti->nc);
    183183        console_flush(ti->console);
    184         putchar('\n');
     184        putwchar('\n');
    185185}
    186186
  • uspace/lib/fmtutil/fmtutil.c

    ra57fa32 red88c8e  
    9595                for (i = 0; i < width; i++) {
    9696                        if (i < len)
    97                                 putchar(wstr[i]);
     97                                putwchar(wstr[i]);
    9898                        else
    99                                 putchar(' ');
     99                                putwchar(' ');
    100100                }
    101101        } else if (mode == ALIGN_RIGHT) {
    102102                for (i = 0; i < width; i++) {
    103103                        if (i < width - len)
    104                                 putchar(' ');
     104                                putwchar(' ');
    105105                        else
    106                                 putchar(wstr[i - (width - len)]);
     106                                putwchar(wstr[i - (width - len)]);
    107107                }
    108108        } else if (mode == ALIGN_CENTER) {
     
    110110                for (i = 0; i < width; i++) {
    111111                        if ((i < padding) || ((i - padding) >= len))
    112                                 putchar(' ');
     112                                putwchar(' ');
    113113                        else
    114                                 putchar(wstr[i - padding]);
     114                                putwchar(wstr[i - padding]);
    115115                }
    116116        } else if (mode == ALIGN_JUSTIFY) {
     
    146146                                    (words - 1)));
    147147                                for (j = 0; j < spaces; j++) {
    148                                         putchar(' ');
     148                                        putwchar(' ');
    149149                                }
    150150                                done_chars += spaces;
    151151                        }
    152152                        while (i < len && wstr[i] != ' ') {
    153                                 putchar(wstr[i++]);
     153                                putwchar(wstr[i++]);
    154154                                done_chars++;
    155155                        }
     
    158158        skip_words:
    159159                while (done_chars < width) {
    160                         putchar(' ');
     160                        putwchar(' ');
    161161                        done_chars++;
    162162                }
  • uspace/lib/gui/terminal.c

    ra57fa32 red88c8e  
    456456                break;
    457457        default:
    458                 updated = chargrid_putchar(term->frontbuf, ch, true);
     458                updated = chargrid_putwchar(term->frontbuf, ch, true);
    459459        }
    460460
  • uspace/lib/posix/include/posix/stdio.h

    ra57fa32 red88c8e  
    7575extern char *gets(char *, size_t);
    7676
    77 extern int fputc(wchar_t, FILE *);
     77extern int fputc(int, FILE *);
    7878extern int fputs(const char *, FILE *);
    7979
    80 extern int putchar(wchar_t);
     80extern int putchar(int);
    8181extern int puts(const char *);
    8282
Note: See TracChangeset for help on using the changeset viewer.