Write wide string to given buffer. * * Write at most data->size plain characters including trailing zero. * According to C99, snprintf() has to return number of characters that * would have been written if enough space had been available. Hence * the return value is not the number of actually printed characters * but size of the input string. * * @param str Source wide string to print. *
| 133 | * |
| 134 | */ |
| 135 | static int vsnprintf_wstr_write(const char32_t *str, size_t size, vsnprintf_data_t *data) |
| 136 | { |
| 137 | size_t index = 0; |
| 138 | |
| 139 | while (index < (size / sizeof(char32_t))) { |
| 140 | size_t left = data->size - data->len; |
| 141 | |
| 142 | if (left == 0) |
| 143 | return ((int) size); |
| 144 | |
| 145 | if (left == 1) { |
| 146 | /* |
| 147 | * We have only one free byte left in buffer |
| 148 | * -> store trailing zero |
| 149 | */ |
| 150 | data->dst[data->size - 1] = 0; |
| 151 | data->len = data->size; |
| 152 | return ((int) size); |
| 153 | } |
| 154 | |
| 155 | if (chr_encode(str[index], data->dst, &data->len, data->size - 1) != EOK) |
| 156 | break; |
| 157 | |
| 158 | index++; |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | * Put trailing zero at end, but not count it |
| 163 | * into data->len so it could be rewritten next time |
| 164 | */ |
| 165 | data->dst[data->len] = 0; |
| 166 | |
| 167 | return ((int) size); |
| 168 | } |
| 169 | |
| 170 | int vsnprintf(char *str, size_t size, const char *fmt, va_list ap) |
| 171 | { |
nothing calls this directly
no test coverage detected