Changeset f1249e1 in mainline for libc/generic/io/vsnprintf.c


Ignore:
Timestamp:
2006-06-06T16:45:43Z (19 years ago)
Author:
Josef Cejka <malyzelenyhnus@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f4b961f
Parents:
0d11fc1c
Message:

Printf return value fix ported from kernel to uspace.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libc/generic/io/vsnprintf.c

    r0d11fc1c rf1249e1  
    5353int vsnprintf_write(const char *str, size_t count, struct vsnprintf_data *data)
    5454{
    55         size_t i,j;
     55        size_t i;
    5656        i = data->size - data->len;
    57         j = count;
    5857
    59         if (i > 0) {
    60                 if (i <= j) {
    61                         if (i == 1) {
    62                                 /* We have only one free byte left in buffer => write there trailing zero */
    63                                 data->string[data->size - 1] = 0;
    64                                 data->len = data->size;
    65                         } else {
    66                                 /* We have not enought space for whole string with the trailing zero => print only a part of string */
    67                                 memcpy((void *)(data->string + data->len), (void *)str, i - 1);
    68                                 data->string[data->size - 1] = 0;
    69                                 data->len = data->size;
    70                         }
    71                 } else {
    72                         /* Buffer is big enought to print whole string */
    73                         memcpy((void *)(data->string + data->len), (void *)str, j);
    74                         data->len += j;
    75                         /* Put trailing zero at end, but not count it into data->len so it could be rewritten next time */
    76                         data->string[data->len] = 0;
    77                 }
     58        if (i == 0) {
     59                return count;
    7860        }
    7961       
     62        if (i == 1) {
     63                /* We have only one free byte left in buffer => write there trailing zero */
     64                data->string[data->size - 1] = 0;
     65                data->len = data->size;
     66                return count;
     67        }
     68       
     69        if (i <= count) {
     70                /* We have not enought space for whole string with the trailing zero => print only a part of string */
     71                        memcpy((void *)(data->string + data->len), (void *)str, i - 1);
     72                        data->string[data->size - 1] = 0;
     73                        data->len = data->size;
     74                        return count;
     75        }
     76       
     77        /* Buffer is big enought to print whole string */
     78        memcpy((void *)(data->string + data->len), (void *)str, count);
     79        data->len += count;
     80        /* Put trailing zero at end, but not count it into data->len so it could be rewritten next time */
     81        data->string[data->len] = 0;
     82
    8083        return count;   
    8184}
Note: See TracChangeset for help on using the changeset viewer.