Changeset 8565a42 in mainline for uspace/lib/c/generic/io


Ignore:
Timestamp:
2018-03-02T20:34:50Z (8 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a1a81f69, d5e5fd1
Parents:
3061bc1 (diff), 34e1206 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:34:50)
git-committer:
GitHub <noreply@…> (2018-03-02 20:34:50)
Message:

Remove all trailing whitespace, everywhere.

See individual commit messages for details.

Location:
uspace/lib/c/generic/io
Files:
13 edited

Legend:

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

    r3061bc1 r8565a42  
    5858                NULL
    5959        };
    60        
     60
    6161        return printf_core(fmt, &ps, args);
    6262}
     
    6868        int ret = vprintf_size(fmt, args);
    6969        va_end(args);
    70        
     70
    7171        return ret;
    7272}
     
    8888        int ret = vprintf_size(fmt, args2);
    8989        va_end(args2);
    90        
     90
    9191        if (ret > 0) {
    9292                *strp = malloc(STR_BOUNDS(ret) + 1);
    9393                if (*strp == NULL)
    9494                        return -1;
    95                
     95
    9696                vsnprintf(*strp, STR_BOUNDS(ret) + 1, fmt, args);
    9797        }
    98        
     98
    9999        return ret;
    100100}
     
    115115        int ret = vasprintf(strp, fmt, args);
    116116        va_end(args);
    117        
     117
    118118        return ret;
    119119}
  • uspace/lib/c/generic/io/chargrid.c

    r3061bc1 r8565a42  
    5757            sizeof(chargrid_t) + cols * rows * sizeof(charfield_t);
    5858        chargrid_t *scrbuf;
    59        
     59
    6060        if ((flags & CHARGRID_FLAG_SHARED) == CHARGRID_FLAG_SHARED) {
    6161                scrbuf = (chargrid_t *) as_area_create(AS_AREA_ANY, size,
     
    6969                        return NULL;
    7070        }
    71        
     71
    7272        scrbuf->size = size;
    7373        scrbuf->flags = flags;
     
    7575        scrbuf->rows = rows;
    7676        scrbuf->cursor_visible = false;
    77        
     77
    7878        scrbuf->attrs.type = CHAR_ATTR_STYLE;
    7979        scrbuf->attrs.val.style = STYLE_NORMAL;
    80        
     80
    8181        scrbuf->top_row = 0;
    8282        chargrid_clear(scrbuf);
    83        
     83
    8484        return scrbuf;
    8585}
     
    107107                scrbuf->top_row = (scrbuf->top_row + 1) % scrbuf->rows;
    108108                chargrid_clear_row(scrbuf, scrbuf->row);
    109                
     109
    110110                return scrbuf->rows;
    111111        }
    112        
     112
    113113        return 2;
    114114}
     
    122122                return chargrid_update_rows(scrbuf);
    123123        }
    124        
     124
    125125        return 1;
    126126}
     
    144144        assert(scrbuf->col < scrbuf->cols);
    145145        assert(scrbuf->row < scrbuf->rows);
    146        
     146
    147147        charfield_t *field =
    148148            chargrid_charfield_at(scrbuf, scrbuf->col, scrbuf->row);
    149        
     149
    150150        field->ch = ch;
    151151        field->attrs = scrbuf->attrs;
    152152        field->flags |= CHAR_FLAG_DIRTY;
    153        
     153
    154154        if (update) {
    155155                scrbuf->col++;
    156156                return chargrid_update_cols(scrbuf);
    157157        }
    158        
     158
    159159        return 1;
    160160}
     
    173173        assert(scrbuf->col < scrbuf->cols);
    174174        assert(scrbuf->row < scrbuf->rows);
    175        
     175
    176176        scrbuf->col = 0;
    177177        scrbuf->row++;
    178        
     178
    179179        return chargrid_update_rows(scrbuf);
    180180}
     
    194194        assert(scrbuf->col < scrbuf->cols);
    195195        assert(scrbuf->row < scrbuf->rows);
    196        
     196
    197197        sysarg_t spaces = tab_size - scrbuf->cols % tab_size;
    198198        sysarg_t flush = 1;
    199        
     199
    200200        for (sysarg_t i = 0; i < spaces; i++)
    201201                flush += chargrid_putchar(scrbuf, ' ', true) - 1;
    202        
     202
    203203        return flush;
    204204}
     
    220220        assert(scrbuf->col < scrbuf->cols);
    221221        assert(scrbuf->row < scrbuf->rows);
    222        
     222
    223223        if ((scrbuf->col == 0) && (scrbuf->row == 0))
    224224                return 0;
    225        
     225
    226226        if (scrbuf->col == 0) {
    227227                scrbuf->col = scrbuf->cols - 1;
    228228                scrbuf->row--;
    229                
     229
    230230                chargrid_putchar(scrbuf, ' ', false);
    231231                return 2;
    232232        }
    233        
     233
    234234        scrbuf->col--;
    235235        chargrid_putchar(scrbuf, ' ', false);
     
    249249                scrbuf->data[pos].flags = CHAR_FLAG_DIRTY;
    250250        }
    251        
     251
    252252        scrbuf->col = 0;
    253253        scrbuf->row = 0;
     
    284284        assert(col);
    285285        assert(row);
    286        
     286
    287287        *col = scrbuf->col;
    288288        *row = scrbuf->row;
     
    305305                charfield_t *field =
    306306                    chargrid_charfield_at(scrbuf, col, row);
    307                
     307
    308308                field->ch = 0;
    309309                field->attrs = scrbuf->attrs;
  • uspace/lib/c/generic/io/console.c

    r3061bc1 r8565a42  
    4848        if (!ctrl)
    4949                return NULL;
    50        
     50
    5151        ctrl->input_sess = vfs_fsession(ifile, INTERFACE_CONSOLE);
    5252        if (!ctrl->input_sess) {
     
    5454                return NULL;
    5555        }
    56        
     56
    5757        ctrl->output_sess = vfs_fsession(ofile, INTERFACE_CONSOLE);
    5858        if (!ctrl->output_sess) {
     
    6060                return NULL;
    6161        }
    62        
     62
    6363        ctrl->input = ifile;
    6464        ctrl->output = ofile;
    6565        ctrl->input_aid = 0;
    66        
     66
    6767        return ctrl;
    6868}
     
    9595        errno_t rc = async_req_0_2(exch, CONSOLE_GET_SIZE, cols, rows);
    9696        async_exchange_end(exch);
    97        
     97
    9898        return rc;
    9999}
     
    134134        errno_t rc = async_req_0_1(exch, CONSOLE_GET_COLOR_CAP, ccap);
    135135        async_exchange_end(exch);
    136        
     136
    137137        return rc;
    138138}
     
    143143        errno_t rc = async_req_0_2(exch, CONSOLE_GET_POS, col, row);
    144144        async_exchange_end(exch);
    145        
     145
    146146        return rc;
    147147}
     
    183183        if (ctrl->input_aid == 0) {
    184184                ipc_call_t result;
    185                
     185
    186186                async_exch_t *exch = async_exchange_begin(ctrl->input_sess);
    187187                aid_t aid = async_send_0(exch, CONSOLE_GET_EVENT, &result);
    188188                async_exchange_end(exch);
    189                
     189
    190190                errno_t rc;
    191191                async_wait_for(aid, &rc);
    192                
     192
    193193                if (rc != EOK) {
    194194                        errno = rc;
    195195                        return false;
    196196                }
    197                
     197
    198198                rc = console_ev_decode(&result, event);
    199199                if (rc != EOK) {
     
    204204                errno_t retval;
    205205                async_wait_for(ctrl->input_aid, &retval);
    206                
     206
    207207                ctrl->input_aid = 0;
    208                
     208
    209209                if (retval != EOK) {
    210210                        errno = retval;
    211211                        return false;
    212212                }
    213                
     213
    214214                errno_t rc = console_ev_decode(&ctrl->input_call, event);
    215215                if (rc != EOK) {
     
    218218                }
    219219        }
    220        
     220
    221221        return true;
    222222}
     
    227227        struct timeval t0;
    228228        gettimeofday(&t0, NULL);
    229        
     229
    230230        if (ctrl->input_aid == 0) {
    231231                async_exch_t *exch = async_exchange_begin(ctrl->input_sess);
     
    234234                async_exchange_end(exch);
    235235        }
    236        
     236
    237237        errno_t retval;
    238238        errno_t rc = async_wait_timeout(ctrl->input_aid, &retval, *timeout);
     
    242242                return false;
    243243        }
    244        
     244
    245245        ctrl->input_aid = 0;
    246        
     246
    247247        if (retval != EOK) {
    248248                errno = retval;
    249249                return false;
    250250        }
    251        
     251
    252252        rc = console_ev_decode(&ctrl->input_call, event);
    253253        if (rc != EOK) {
     
    255255                return false;
    256256        }
    257        
     257
    258258        /* Update timeout */
    259259        struct timeval t1;
    260260        gettimeofday(&t1, NULL);
    261261        *timeout -= tv_sub_diff(&t1, &t0);
    262        
     262
    263263        return true;
    264264}
  • uspace/lib/c/generic/io/input.c

    r3061bc1 r8565a42  
    6161        errno_t rc = async_create_callback_port(exch, INTERFACE_INPUT_CB, 0, 0,
    6262            input_cb_conn, input, &port);
    63        
     63
    6464        async_exchange_end(exch);
    6565
     
    8888        errno_t rc = async_req_0_0(exch, INPUT_ACTIVATE);
    8989        async_exchange_end(exch);
    90        
     90
    9191        return rc;
    9292}
  • uspace/lib/c/generic/io/io.c

    r3061bc1 r8565a42  
    119119                list_append(&stdin->link, &files);
    120120        }
    121        
     121
    122122        int outfd = inbox_get("stdout");
    123123        if (outfd >= 0) {
     
    133133                list_append(&stdout->link, &files);
    134134        }
    135        
     135
    136136        int errfd = inbox_get("stderr");
    137137        if (errfd >= 0) {
     
    165165                return false;
    166166        }
    167        
     167
    168168        if ((*mp == 'b') || (*mp == 't'))
    169169                mp++;
    170        
     170
    171171        bool plus;
    172172        if (*mp == '+') {
     
    175175        } else
    176176                plus = false;
    177        
     177
    178178        if (*mp != 0) {
    179179                errno = EINVAL;
     
    183183        *create = false;
    184184        *truncate = false;
    185        
     185
    186186        /* Parse first character of fmode and determine mode for vfs_open(). */
    187187        switch (fmode[0]) {
     
    209209                return false;
    210210        }
    211        
     211
    212212        return true;
    213213}
     
    241241{
    242242        /* FIXME: Use more complex rules for setting buffering options. */
    243        
     243
    244244        switch (stream->fd) {
    245245        case 1:
     
    259259{
    260260        assert(stream->buf == NULL);
    261        
     261
    262262        stream->buf = malloc(stream->buf_size);
    263263        if (stream->buf == NULL) {
     
    265265                return EOF;
    266266        }
    267        
     267
    268268        stream->buf_head = stream->buf;
    269269        stream->buf_tail = stream->buf;
     
    285285        if (!parse_mode(fmode, &mode, &create, &truncate))
    286286                return NULL;
    287        
     287
    288288        /* Open file. */
    289289        FILE *stream = malloc(sizeof(FILE));
     
    311311                return NULL;
    312312        }
    313        
     313
    314314        if (truncate) {
    315315                rc = vfs_resize(file, 0);
     
    331331        _setvbuf(stream);
    332332        stream->ungetc_chars = 0;
    333        
     333
    334334        list_append(&stream->link, &files);
    335        
     335
    336336        return stream;
    337337}
     
    345345                return NULL;
    346346        }
    347        
     347
    348348        stream->fd = fd;
    349349        stream->pos = 0;
     
    355355        _setvbuf(stream);
    356356        stream->ungetc_chars = 0;
    357        
     357
    358358        list_append(&stream->link, &files);
    359        
     359
    360360        return stream;
    361361}
     
    365365{
    366366        errno_t rc = 0;
    367        
     367
    368368        fflush(stream);
    369        
     369
    370370        if (stream->sess != NULL)
    371371                async_hangup(stream->sess);
    372        
     372
    373373        if (stream->fd >= 0)
    374374                rc = vfs_put(stream->fd);
    375        
     375
    376376        list_remove(&stream->link);
    377        
     377
    378378        if (rc != EOK) {
    379379                errno = rc;
    380380                return EOF;
    381381        }
    382        
     382
    383383        return 0;
    384384}
     
    387387{
    388388        int rc = _fclose_nofree(stream);
    389        
     389
    390390        if ((stream != &stdin_null)
    391391            && (stream != &stdout_kio)
    392392            && (stream != &stderr_kio))
    393393                free(stream);
    394        
     394
    395395        return rc;
    396396}
     
    399399{
    400400        FILE *nstr;
    401        
     401
    402402        if (path == NULL) {
    403403                /* Changing mode is not supported */
    404404                return NULL;
    405405        }
    406        
     406
    407407        (void) _fclose_nofree(stream);
    408408        nstr = fopen(path, mode);
     
    411411                return NULL;
    412412        }
    413        
     413
    414414        list_remove(&nstr->link);
    415415        *stream = *nstr;
    416416        list_append(&stream->link, &files);
    417        
     417
    418418        free(nstr);
    419        
     419
    420420        return stream;
    421421}
     
    659659                        return 0; /* Errno set by _fallocbuf(). */
    660660        }
    661        
     661
    662662        data = (uint8_t *) buf;
    663663        bytes_left = size * nmemb;
    664664        total_written = 0;
    665665        need_flush = false;
    666        
     666
    667667        while ((!stream->error) && (bytes_left > 0)) {
    668668                buf_free = stream->buf_size - (stream->buf_head - stream->buf);
     
    671671                else
    672672                        now = bytes_left;
    673                
     673
    674674                for (i = 0; i < now; i++) {
    675675                        b = data[i];
    676676                        stream->buf_head[i] = b;
    677                        
     677
    678678                        if ((b == '\n') && (stream->btype == _IOLBF))
    679679                                need_flush = true;
    680680                }
    681                
     681
    682682                data += now;
    683683                stream->buf_head += now;
     
    686686                total_written += now;
    687687                stream->buf_state = _bs_write;
    688                
     688
    689689                if (buf_free == 0) {
    690690                        /* Only need to drain buffer. */
     
    697697        if (need_flush)
    698698                fflush(stream);
    699        
     699
    700700        return (total_written / size);
    701701}
     
    705705        char buf[STR_BOUNDS(1)];
    706706        size_t sz = 0;
    707        
     707
    708708        if (chr_encode(c, buf, &sz, STR_BOUNDS(1)) == EOK) {
    709709                size_t wr = fwrite(buf, 1, sz, stream);
    710                
     710
    711711                if (wr < sz)
    712712                        return EOF;
    713                
     713
    714714                return (int) c;
    715715        }
    716        
     716
    717717        return EOF;
    718718}
     
    739739{
    740740        char c;
    741        
     741
    742742        /* This could be made faster by only flushing when needed. */
    743743        if (stdout)
     
    745745        if (stderr)
    746746                fflush(stderr);
    747        
     747
    748748        if (fread(&c, sizeof(char), 1, stream) < sizeof(char))
    749749                return EOF;
    750        
     750
    751751        return (int) c;
    752752}
     
    841841        if (stream->error)
    842842                return EOF;
    843        
     843
    844844        _fflushbuf(stream);
    845845        if (stream->error) {
     
    876876        if (stream->error)
    877877                return EOF;
    878        
     878
    879879        _fflushbuf(stream);
    880880        if (stream->error) {
     
    882882                return EOF;
    883883        }
    884        
     884
    885885        if (stream->kio) {
    886886                kio_update();
    887887                return 0;
    888888        }
    889        
     889
    890890        if ((stream->fd >= 0) && (stream->need_sync)) {
    891891                errno_t rc;
     
    904904                return 0;
    905905        }
    906        
     906
    907907        return 0;
    908908}
     
    930930                return EOF;
    931931        }
    932        
     932
    933933        return stream->fd;
    934934}
     
    939939                if (stream->sess == NULL)
    940940                        stream->sess = vfs_fd_session(stream->fd, iface);
    941                
     941
    942942                return stream->sess;
    943943        }
    944        
     944
    945945        return NULL;
    946946}
     
    952952                return EOK;
    953953        }
    954        
     954
    955955        return ENOENT;
    956956}
  • uspace/lib/c/generic/io/kio.c

    r3061bc1 r8565a42  
    4646{
    4747        errno_t rc = (errno_t) __SYSCALL3(SYS_KIO, KIO_WRITE, (sysarg_t) buf, size);
    48        
     48
    4949        if (rc == EOK)
    5050                *nwritten = size;
     
    7373        va_list args;
    7474        va_start(args, fmt);
    75        
     75
    7676        int ret = kio_vprintf(fmt, args);
    77        
     77
    7878        va_end(args);
    79        
     79
    8080        return ret;
    8181}
     
    8484{
    8585        size_t wr;
    86        
     86
    8787        wr = 0;
    8888        (void) kio_write(str, size, &wr);
     
    9595        size_t chars = 0;
    9696        size_t wr;
    97        
     97
    9898        while (offset < size) {
    9999                char buf[STR_BOUNDS(1)];
    100100                size_t sz = 0;
    101                
     101
    102102                if (chr_encode(str[chars], buf, &sz, STR_BOUNDS(1)) == EOK)
    103103                        kio_write(buf, sz, &wr);
    104                
     104
    105105                chars++;
    106106                offset += sizeof(wchar_t);
    107107        }
    108        
     108
    109109        return chars;
    110110}
     
    125125                NULL
    126126        };
    127        
     127
    128128        return printf_core(fmt, &ps, ap);
    129129}
  • uspace/lib/c/generic/io/output.c

    r3061bc1 r8565a42  
    4545        errno_t ret = async_req_0_0(exch, OUTPUT_YIELD);
    4646        async_exchange_end(exch);
    47        
     47
    4848        return ret;
    4949}
     
    5454        errno_t ret = async_req_0_0(exch, OUTPUT_CLAIM);
    5555        async_exchange_end(exch);
    56        
     56
    5757        return ret;
    5858}
     
    6363        errno_t ret = async_req_0_2(exch, OUTPUT_GET_DIMENSIONS, maxx, maxy);
    6464        async_exchange_end(exch);
    65        
     65
    6666        return ret;
    6767}
     
    7070{
    7171        async_exch_t *exch = async_exchange_begin(sess);
    72        
     72
    7373        sysarg_t rv;
    7474        errno_t ret = async_req_0_1(exch, OUTPUT_GET_CAPS, &rv);
    75        
     75
    7676        async_exchange_end(exch);
    77        
     77
    7878        if (ret == EOK)
    7979                *ccaps = (console_caps_t) rv;
    80        
     80
    8181        return ret;
    8282}
     
    8686{
    8787        async_exch_t *exch = async_exchange_begin(sess);
    88        
     88
    8989        ipc_call_t answer;
    9090        aid_t req = async_send_0(exch, OUTPUT_FRONTBUF_CREATE, &answer);
    9191        errno_t rc = async_share_out_start(exch, frontbuf, AS_AREA_READ
    9292            | AS_AREA_WRITE | AS_AREA_CACHEABLE);
    93        
     93
    9494        async_exchange_end(exch);
    95        
     95
    9696        errno_t ret;
    9797        async_wait_for(req, &ret);
    98        
     98
    9999        if ((rc != EOK) || (ret != EOK))
    100100                return 0;
    101        
     101
    102102        return (frontbuf_handle_t) IPC_GET_ARG1(answer);
    103103}
     
    108108        errno_t ret = async_req_1_0(exch, OUTPUT_SET_STYLE, style);
    109109        async_exchange_end(exch);
    110        
     110
    111111        return ret;
    112112}
     
    117117        errno_t ret = async_req_1_0(exch, OUTPUT_CURSOR_UPDATE, frontbuf);
    118118        async_exchange_end(exch);
    119        
     119
    120120        return ret;
    121121}
     
    126126        errno_t ret = async_req_1_0(exch, OUTPUT_UPDATE, frontbuf);
    127127        async_exchange_end(exch);
    128        
     128
    129129        return ret;
    130130}
     
    137137            cols, rows);
    138138        async_exchange_end(exch);
    139        
     139
    140140        return ret;
    141141}
  • uspace/lib/c/generic/io/printf.c

    r3061bc1 r8565a42  
    4848        va_list args;
    4949        va_start(args, fmt);
    50        
     50
    5151        int ret = vfprintf(stream, fmt, args);
    52        
     52
    5353        va_end(args);
    54        
     54
    5555        return ret;
    5656}
     
    6767        va_list args;
    6868        va_start(args, fmt);
    69        
     69
    7070        int ret = vprintf(fmt, args);
    71        
     71
    7272        va_end(args);
    73        
     73
    7474        return ret;
    7575}
  • uspace/lib/c/generic/io/printf_core.c

    r3061bc1 r8565a42  
    211211        if (str == NULL)
    212212                return printf_putnchars(nullstr, str_size(nullstr), ps);
    213        
     213
    214214        return ps->str_write((void *) str, str_size(str), ps->data);
    215215}
     
    227227        if (!ascii_check(ch))
    228228                return ps->str_write((void *) &invalch, 1, ps->data);
    229        
     229
    230230        return ps->str_write(&ch, 1, ps->data);
    231231}
     
    243243        if (!chr_check(ch))
    244244                return ps->str_write((void *) &invalch, 1, ps->data);
    245        
     245
    246246        return ps->wstr_write(&ch, sizeof(wchar_t), ps->data);
    247247}
     
    269269                }
    270270        }
    271        
     271
    272272        if (printf_putchar(ch, ps) > 0)
    273273                counter++;
    274        
     274
    275275        while (--width > 0) {
    276276                /*
     
    281281                        counter++;
    282282        }
    283        
     283
    284284        return (int) (counter);
    285285}
     
    307307                }
    308308        }
    309        
     309
    310310        if (printf_putwchar(ch, ps) > 0)
    311311                counter++;
    312        
     312
    313313        while (--width > 0) {
    314314                /*
     
    319319                        counter++;
    320320        }
    321        
     321
    322322        return (int) (counter);
    323323}
     
    337337        if (str == NULL)
    338338                return printf_putstr(nullstr, ps);
    339        
     339
    340340        size_t strw = str_length(str);
    341341
     
    343343        if ((precision == 0) || (precision > strw))
    344344                precision = strw;
    345        
     345
    346346        /* Left padding */
    347347        size_t counter = 0;
     
    353353                }
    354354        }
    355        
     355
    356356        /* Part of @a str fitting into the alloted space. */
    357357        int retval;
     
    386386        if (str == NULL)
    387387                return printf_putstr(nullstr, ps);
    388        
     388
    389389        size_t strw = wstr_length(str);
    390390
     
    392392        if ((precision == 0) || (precision > strw))
    393393                precision = strw;
    394        
     394
    395395        /* Left padding */
    396396        size_t counter = 0;
     
    402402                }
    403403        }
    404        
     404
    405405        /* Part of @a wstr fitting into the alloted space. */
    406406        int retval;
     
    408408        if ((retval = printf_wputnchars(str, size, ps)) < 0)
    409409                return -counter;
    410        
     410
    411411        counter += retval;
    412        
     412
    413413        /* Right padding */
    414414        while (width-- > 0) {
     
    440440                precision = 0;
    441441        }
    442        
     442
    443443        const char *digits;
    444444        if (flags & __PRINTF_FLAG_BIGCHARS)
     
    446446        else
    447447                digits = digits_small;
    448        
     448
    449449        char data[PRINT_NUMBER_BUFFER_SIZE];
    450450        char *ptr = &data[PRINT_NUMBER_BUFFER_SIZE - 1];
    451        
     451
    452452        /* Size of number with all prefixes and signs */
    453453        int size = 0;
    454        
     454
    455455        /* Put zero at end of string */
    456456        *ptr-- = 0;
    457        
     457
    458458        if (num == 0) {
    459459                *ptr-- = '0';
     
    465465                } while (num /= base);
    466466        }
    467        
     467
    468468        /* Size of plain number */
    469469        int number_size = size;
    470        
     470
    471471        /*
    472472         * Collect the sum of all prefixes/signs/etc. to calculate padding and
     
    487487                }
    488488        }
    489        
     489
    490490        char sgn = 0;
    491491        if (flags & __PRINTF_FLAG_SIGNED) {
     
    501501                }
    502502        }
    503        
     503
    504504        if (flags & __PRINTF_FLAG_LEFTALIGNED)
    505505                flags &= ~__PRINTF_FLAG_ZEROPADDED;
    506        
     506
    507507        /*
    508508         * If the number is left-aligned or precision is specified then
     
    513513                        precision = width - size + number_size;
    514514        }
    515        
     515
    516516        /* Print leading spaces */
    517517        if (number_size > precision) {
     
    519519                precision = number_size;
    520520        }
    521        
     521
    522522        width -= precision + size - number_size;
    523523        size_t counter = 0;
    524        
     524
    525525        if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
    526526                while (width-- > 0) {
     
    529529                }
    530530        }
    531        
     531
    532532        /* Print sign */
    533533        if (sgn) {
     
    535535                        counter++;
    536536        }
    537        
     537
    538538        /* Print prefix */
    539539        if (flags & __PRINTF_FLAG_PREFIX) {
     
    568568                }
    569569        }
    570        
     570
    571571        /* Print leading zeroes */
    572572        precision -= number_size;
     
    575575                        counter++;
    576576        }
    577        
     577
    578578        /* Print the number itself */
    579579        int retval;
    580580        if ((retval = printf_putstr(++ptr, ps)) > 0)
    581581                counter += retval;
    582        
     582
    583583        /* Print trailing spaces */
    584        
     584
    585585        while (width-- > 0) {
    586586                if (printf_putchar(' ', ps) == 1)
    587587                        counter++;
    588588        }
    589        
     589
    590590        return ((int) counter);
    591591}
     
    601601        const int str_len = 3;
    602602        const char *str;
    603        
     603
    604604        if (flags & __PRINTF_FLAG_BIGCHARS) {
    605605                str = val.is_infinity ? "INF" : "NAN";
     
    624624                if ((ret = ps->str_write(&sign, 1, ps->data)) < 0)
    625625                        return -1;
    626                
     626
    627627                counter += ret;
    628628        }
     
    630630        if ((ret = ps->str_write(str, str_len, ps->data)) < 0)
    631631                return -1;
    632        
     632
    633633        counter += ret;
    634634
     
    751751                if ((ret = ps->str_write(&sign, 1, ps->data)) < 0)
    752752                        return -1;
    753                
     753
    754754                counter += ret;
    755755        }
     
    783783
    784784        counter += ret;
    785        
     785
    786786        /* Print the decimal point and the fractional part. */
    787787        if (has_decimal_pt) {
     
    790790                if ((ret = ps->str_write(&ch, 1, ps->data)) < 0)
    791791                        return -1;
    792                
     792
    793793                counter += ret;
    794794
     
    885885                /* Let the implementation figure out the proper precision. */
    886886                val_str.len = double_to_short_str(val, buf, buf_size, &val_str.dec_exp);
    887                
     887
    888888                /* Precision needed for the last significant digit. */
    889889                precision = max(0, -val_str.dec_exp);
     
    903903        if ((ret = ps->str_write(&exp_ch, 1, ps->data)) < 0)
    904904                return -1;
    905        
     905
    906906        counter += ret;
    907907
     
    915915        /* Print the exponent. */
    916916        exp_val = abs(exp_val);
    917        
     917
    918918        char exp_str[4] = { 0 };
    919919
     
    921921        exp_str[1] = '0' + (exp_val % 100) / 10 ;
    922922        exp_str[2] = '0' + (exp_val % 10);
    923        
     923
    924924        int exp_len = (exp_str[0] == '0') ? 2 : 3;
    925925        const char *exp_str_start = &exp_str[3] - exp_len;
     
    981981                if ((ret = ps->str_write(&sign, 1, ps->data)) < 0)
    982982                        return -1;
    983                
     983
    984984                counter += ret;
    985985        }
     
    10041004                if ((ret = ps->str_write(&ch, 1, ps->data)) < 0)
    10051005                        return -1;
    1006                
     1006
    10071007                counter += ret;
    10081008
     
    11041104                /* Let the implementation figure out the proper precision. */
    11051105                val_str.len = double_to_short_str(val, buf, buf_size, &val_str.dec_exp);
    1106                
     1106
    11071107                /* Use all produced digits. */
    11081108                precision = val_str.len - 1;
     
    12231223                precision = (precision < 0) ? 6 : precision;
    12241224                return print_double_fixed(g, precision, width, flags, ps);
    1225        
     1225
    12261226        case 'E':
    12271227                flags |= __PRINTF_FLAG_BIGCHARS;
     
    12301230                precision = (precision < 0) ? 6 : precision;
    12311231                return print_double_scientific(g, precision, width, flags, ps);
    1232        
     1232
    12331233        case 'G':
    12341234                flags |= __PRINTF_FLAG_BIGCHARS;
     
    12361236        case 'g':
    12371237                return print_double_generic(g, precision, width, flags, ps);
    1238        
     1238
    12391239        default:
    12401240                assert(false);
     
    13371337        size_t nxt = 0;  /* Index of the next character from fmt */
    13381338        size_t j = 0;    /* Index to the first not printed nonformating character */
    1339        
     1339
    13401340        size_t counter = 0;   /* Number of characters printed */
    13411341        int retval;           /* Return values from nested functions */
    1342        
     1342
    13431343        while (true) {
    13441344                i = nxt;
    13451345                wchar_t uc = str_decode(fmt, &nxt, STR_NO_LIMIT);
    1346                
     1346
    13471347                if (uc == 0)
    13481348                        break;
    1349                
     1349
    13501350                /* Control character */
    13511351                if (uc == '%') {
     
    13591359                                counter += retval;
    13601360                        }
    1361                        
     1361
    13621362                        j = i;
    1363                        
     1363
    13641364                        /* Parse modifiers */
    13651365                        uint32_t flags = 0;
    13661366                        bool end = false;
    1367                        
     1367
    13681368                        do {
    13691369                                i = nxt;
     
    13901390                                };
    13911391                        } while (!end);
    1392                        
     1392
    13931393                        /* Width & '*' operator */
    13941394                        int width = 0;
     
    13971397                                        width *= 10;
    13981398                                        width += uc - '0';
    1399                                        
     1399
    14001400                                        i = nxt;
    14011401                                        uc = str_decode(fmt, &nxt, STR_NO_LIMIT);
     
    14161416                                }
    14171417                        }
    1418                        
     1418
    14191419                        /* Precision and '*' operator */
    14201420                        int precision = -1;
     
    14271427                                                precision *= 10;
    14281428                                                precision += uc - '0';
    1429                                                
     1429
    14301430                                                i = nxt;
    14311431                                                uc = str_decode(fmt, &nxt, STR_NO_LIMIT);
     
    14461446                                }
    14471447                        }
    1448                        
     1448
    14491449                        qualifier_t qualifier;
    1450                        
     1450
    14511451                        switch (uc) {
    14521452                        case 't':
     
    14951495                                qualifier = PrintfQualifierInt;
    14961496                        }
    1497                        
     1497
    14981498                        unsigned int base = 10;
    1499                        
     1499
    15001500                        switch (uc) {
    15011501                        /*
     
    15041504                        case 's':
    15051505                                precision = max(0,  precision);
    1506                                
     1506
    15071507                                if (qualifier == PrintfQualifierLong)
    15081508                                        retval = print_wstr(va_arg(ap, wchar_t *), width, precision, flags, ps);
    15091509                                else
    15101510                                        retval = print_str(va_arg(ap, char *), width, precision, flags, ps);
    1511                                
     1511
    15121512                                if (retval < 0) {
    15131513                                        counter = -counter;
    15141514                                        goto out;
    15151515                                }
    1516                                
     1516
    15171517                                counter += retval;
    15181518                                j = nxt;
     
    15231523                                else
    15241524                                        retval = print_char(va_arg(ap, unsigned int), width, flags, ps);
    1525                                
     1525
    15261526                                if (retval < 0) {
    15271527                                        counter = -counter;
    15281528                                        goto out;
    15291529                                };
    1530                                
     1530
    15311531                                counter += retval;
    15321532                                j = nxt;
    15331533                                goto next_char;
    1534                                
     1534
    15351535                        /*
    15361536                         * Floating point values
     
    15441544                                retval = print_double(va_arg(ap, double), uc, precision,
    15451545                                        width, flags, ps);
    1546                                
     1546
    15471547                                if (retval < 0) {
    15481548                                        counter = -counter;
    15491549                                        goto out;
    15501550                                }
    1551                                
     1551
    15521552                                counter += retval;
    15531553                                j = nxt;
    15541554                                goto next_char;
    1555                        
     1555
    15561556                        /*
    15571557                         * Integer values
     
    15851585                                base = 16;
    15861586                                break;
    1587                        
     1587
    15881588                        /* Percentile itself */
    15891589                        case '%':
    15901590                                j = i;
    15911591                                goto next_char;
    1592                        
     1592
    15931593                        /*
    15941594                         * Bad formatting.
     
    16011601                                goto next_char;
    16021602                        }
    1603                        
     1603
    16041604                        /* Print integers */
    16051605                        size_t size;
    16061606                        uint64_t number;
    1607                        
     1607
    16081608                        switch (qualifier) {
    16091609                        case PrintfQualifierByte:
     
    16451645                                goto out;
    16461646                        }
    1647                        
     1647
    16481648                        if ((retval = print_number(number, width, precision,
    16491649                            base, flags, ps)) < 0) {
     
    16511651                                goto out;
    16521652                        }
    1653                        
     1653
    16541654                        counter += retval;
    16551655                        j = nxt;
     
    16581658                ;
    16591659        }
    1660        
     1660
    16611661        if (i > j) {
    16621662                if ((retval = printf_putnchars(&fmt[j], i - j, ps)) < 0) {
     
    16671667                counter += retval;
    16681668        }
    1669        
     1669
    16701670out:
    16711671        return ((int) counter);
  • uspace/lib/c/generic/io/snprintf.c

    r3061bc1 r8565a42  
    5050        va_list args;
    5151        va_start(args, fmt);
    52        
     52
    5353        int ret = vsnprintf(str, size, fmt, args);
    54        
     54
    5555        va_end(args);
    56        
     56
    5757        return ret;
    5858}
  • uspace/lib/c/generic/io/vprintf.c

    r3061bc1 r8565a42  
    5252        size_t offset = 0;
    5353        size_t chars = 0;
    54        
     54
    5555        while (offset < size) {
    5656                if (fputc(str[chars], (FILE *) stream) <= 0)
    5757                        break;
    58                
     58
    5959                chars++;
    6060                offset += sizeof(wchar_t);
    6161        }
    62        
     62
    6363        return chars;
    6464}
     
    8080                stream
    8181        };
    82        
     82
    8383        /*
    8484         * Prevent other threads to execute printf_core()
    8585         */
    8686        fibril_mutex_lock(&printf_mutex);
    87        
     87
    8888        int ret = printf_core(fmt, &ps, ap);
    89        
     89
    9090        fibril_mutex_unlock(&printf_mutex);
    91        
     91
    9292        return ret;
    9393}
  • uspace/lib/c/generic/io/vsnprintf.c

    r3061bc1 r8565a42  
    6565{
    6666        size_t left = data->size - data->len;
    67        
     67
    6868        if (left == 0)
    6969                return ((int) size);
    70        
     70
    7171        if (left == 1) {
    7272                /* We have only one free byte left in buffer
     
    7777                return ((int) size);
    7878        }
    79        
     79
    8080        if (left <= size) {
    8181                /* We do not have enough space for the whole string
     
    8484                 */
    8585                size_t index = 0;
    86                
     86
    8787                while (index < size) {
    8888                        wchar_t uc = str_decode(str, &index, size);
    89                        
     89
    9090                        if (chr_encode(uc, data->dst, &data->len, data->size - 1) != EOK)
    9191                                break;
    9292                }
    93                
     93
    9494                /* Put trailing zero at end, but not count it
    9595                 * into data->len so it could be rewritten next time
    9696                 */
    9797                data->dst[data->len] = 0;
    98                
     98
    9999                return ((int) size);
    100100        }
    101        
     101
    102102        /* Buffer is big enough to print the whole string */
    103103        memcpy((void *)(data->dst + data->len), (void *) str, size);
    104104        data->len += size;
    105        
     105
    106106        /* Put trailing zero at end, but not count it
    107107         * into data->len so it could be rewritten next time
    108108         */
    109109        data->dst[data->len] = 0;
    110        
     110
    111111        return ((int) size);
    112112}
     
    132132{
    133133        size_t index = 0;
    134        
     134
    135135        while (index < (size / sizeof(wchar_t))) {
    136136                size_t left = data->size - data->len;
    137                
     137
    138138                if (left == 0)
    139139                        return ((int) size);
    140                
     140
    141141                if (left == 1) {
    142142                        /* We have only one free byte left in buffer
     
    147147                        return ((int) size);
    148148                }
    149                
     149
    150150                if (chr_encode(str[index], data->dst, &data->len, data->size - 1) != EOK)
    151151                        break;
    152                
     152
    153153                index++;
    154154        }
    155        
     155
    156156        /* Put trailing zero at end, but not count it
    157157         * into data->len so it could be rewritten next time
    158158         */
    159159        data->dst[data->len] = 0;
    160        
     160
    161161        return ((int) size);
    162162}
     
    174174                &data
    175175        };
    176        
     176
    177177        /* Print 0 at end of string - fix the case that nothing will be printed */
    178178        if (size > 0)
    179179                str[0] = 0;
    180        
     180
    181181        /* vsnprintf_write ensures that str will be terminated by zero. */
    182182        return printf_core(fmt, &ps, ap);
  • uspace/lib/c/generic/io/window.c

    r3061bc1 r8565a42  
    4646        errno_t ret = async_req_1_2(exch, WINDOW_REGISTER, flags, in, out);
    4747        async_exchange_end(exch);
    48        
     48
    4949        return ret;
    5050}
     
    9696{
    9797        async_exch_t *exch = async_exchange_begin(sess);
    98        
     98
    9999        ipc_call_t answer;
    100100        aid_t req = async_send_5(exch, WINDOW_RESIZE, x, y, width, height,
    101101            (sysarg_t) placement_flags, &answer);
    102        
     102
    103103        errno_t rc = async_share_out_start(exch, cells, AS_AREA_READ | AS_AREA_CACHEABLE);
    104        
     104
    105105        async_exchange_end(exch);
    106        
     106
    107107        errno_t ret;
    108108        async_wait_for(req, &ret);
    109        
     109
    110110        if (rc != EOK)
    111111                return rc;
    112112        else if (ret != EOK)
    113113                return ret;
    114        
     114
    115115        return EOK;
    116116}
Note: See TracChangeset for help on using the changeset viewer.