Changeset 4ddeace in mainline for generic/src/printf/vsnprintf.c


Ignore:
Timestamp:
2006-06-06T11:45:42Z (19 years ago)
Author:
Josef Cejka <malyzelenyhnus@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
99f3249
Parents:
3247f0a
Message:

Fixed printf return value.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • generic/src/printf/vsnprintf.c

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