Rev 1604 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1604 | Rev 1605 | ||
---|---|---|---|
Line 51... | Line 51... | ||
51 | int vsnprintf_write(const char *str, size_t count, struct vsnprintf_data *data) |
51 | int vsnprintf_write(const char *str, size_t count, struct vsnprintf_data *data) |
52 | { |
52 | { |
53 | size_t i; |
53 | size_t i; |
54 | i = data->size - data->len; |
54 | i = data->size - data->len; |
55 | 55 | ||
56 | if ((count == 0) || (i == 0)) { |
56 | if (i == 0) { |
57 | return 0; |
57 | return count; |
58 | } |
58 | } |
59 | 59 | ||
60 | if (i == 1) { |
60 | if (i == 1) { |
61 | /* We have only one free byte left in buffer => write there trailing zero */ |
61 | /* We have only one free byte left in buffer => write there trailing zero */ |
62 | data->string[data->size - 1] = 0; |
62 | data->string[data->size - 1] = 0; |
63 | data->len = data->size; |
63 | data->len = data->size; |
64 | return 1; |
64 | return count; |
65 | } |
65 | } |
66 | 66 | ||
67 | if (i <= count) { |
67 | if (i <= count) { |
68 | /* We have not enought space for whole string with the trailing zero => print only a part of string */ |
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); |
69 | memcpy((void *)(data->string + data->len), (void *)str, i - 1); |
70 | data->string[data->size - 1] = 0; |
70 | data->string[data->size - 1] = 0; |
71 | data->len = data->size; |
71 | data->len = data->size; |
72 | return i; |
72 | return count; |
73 | } |
73 | } |
74 | 74 | ||
75 | /* Buffer is big enought to print whole string */ |
75 | /* Buffer is big enought to print whole string */ |
76 | memcpy((void *)(data->string + data->len), (void *)str, count); |
76 | memcpy((void *)(data->string + data->len), (void *)str, count); |
77 | data->len += count; |
77 | data->len += count; |