Changeset a35b458 in mainline for uspace/lib/c/generic/io/io.c


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

File:
1 edited

Legend:

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

    r3061bc1 ra35b458  
    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}
Note: See TracChangeset for help on using the changeset viewer.