1162{
1163 int rc;
1165 char * str, * end;
1167
1169
1170 rc = 0;
1171 goto err_oor;
1172 }
1173
1174 str = buf;
1175 end = buf + size;
1176
1177
1178 if (end < buf) {
1179 end = ((void *)-1);
1180 size = (
xwsz_t)(end - buf);
1181 }
1182
1183 while (*fmt) {
1184 const char * oldfmt = fmt;
1186 fmt += read;
1187 switch (spec.
type) {
1189 int copy = read;
1190 if (str < end) {
1191 if (copy > end - str) {
1192 copy = end - str;
1193 }
1194 memcpy(str, oldfmt, (
xwsz_t)copy);
1195 }
1196 str += read;
1197 break;
1198 }
1199
1202 break;
1203
1206 break;
1207
1209 char c;
1210
1213 if (str < end) {
1214 *str = ' ';
1215 }
1216 ++str;
1217 }
1218 }
1219 c = (char)va_arg(args, int);
1220 if (str < end) {
1221 *str = c;
1222 }
1223 ++str;
1225 if (str < end) {
1226 *str = ' ';
1227 }
1228 ++str;
1229 }
1230 break;
1231 }
1232
1235 spec);
1236 break;
1237
1240 va_arg(args, void *), spec);
1241 while (isalnum((int)(*fmt))) {
1242 fmt++;
1243 }
1244 break;
1245
1247 if (str < end) {
1248 *str = '%';
1249 }
1250 ++str;
1251 break;
1252
1254 if (str < end) {
1255 *str = '%';
1256 }
1257 ++str;
1258 break;
1259
1260#if defined(XWLIBCFG_SPF_FLOAT) && (1U == XWLIBCFG_SPF_FLOAT)
1265 break;
1266
1267# if defined(XWLIBCFG_SPF_LONG_DOUBLE) && (1U == XWLIBCFG_SPF_LONG_DOUBLE)
1272 break;
1273# endif
1274#endif
1275
1276 default:
1277 switch (spec.
type) {
1279 num = (
xwu64_t)va_arg(args,
long long);
1280 break;
1282 num = (
xwu64_t)va_arg(args,
unsigned long);
1283 break;
1285 num = (
xwu64_t)va_arg(args,
long);
1286 break;
1290 } else {
1292 }
1293 break;
1295 num = (
xwu64_t)va_arg(args, ptrdiff_t);
1296 break;
1298 num = (
xwu64_t)va_arg(args, intmax_t);
1299 break;
1301 num = (
xwu64_t)va_arg(args, uintmax_t);
1302 break;
1304 num = (
xwu64_t)va_arg(args,
int);
1305 break;
1307 num = (
xwu64_t)va_arg(args,
int);
1308 break;
1310 num = (
xwu64_t)va_arg(args,
int);
1311 break;
1313 num = (
xwu64_t)va_arg(args,
int);
1314 break;
1316 num = (
xwu64_t)va_arg(args,
int);
1317 break;
1318 default:
1319 num = (
xwu64_t)va_arg(args,
unsigned int);
1320 }
1322 }
1323 }
1324
1325 if (size > 0) {
1326 if (str < end) {
1327 *str = '\0';
1328 } else {
1329 end[-1] = '\0';
1330 }
1331 }
1332 rc = str - buf;
1333err_oor:
1334 return rc;
1335}
static int xwvsnpf_format_decode(const char *fmt, struct xwvsnpf_format_spec *spec)
static char * xwvsnpf_format_string(char *buf, char *end, const char *s, struct xwvsnpf_format_spec spec)
static char * xwvsnpf_format_pointer(const char *fmt, char *buf, char *end, void *ptr, struct xwvsnpf_format_spec spec)
@ XWVSNPF_FT_PERCENT_CHAR
@ XWVSNPF_FT_LONG_DOUBLE_GENERAL
@ XWVSNPF_FT_LONG_DOUBLE_SCI
@ XWVSNPF_FT_FLOAT_GENERAL
static char * xwvsnpf_format_long_double(char *buf, char *end, long double num, struct xwvsnpf_format_spec spec)
static char * xwvsnpf_format_number(char *buf, char *end, xwu64_t num, struct xwvsnpf_format_spec spec)
static char * xwvsnpf_format_float(char *buf, char *end, double num, struct xwvsnpf_format_spec spec)