printf() wrapper that is not sensitive to LC_NUMERIC settings. * * This function has the same contract as standard printf(), except that * formatting of floating-point numbers will use decimal point, whatever the * current locale is set. * * @param fmt formatting string * @param ... arguments * @return the number of characters (excluding terminating nul) written in * output buffer. */
| 1398 | * output buffer. |
| 1399 | */ |
| 1400 | int CPLprintf(CPL_FORMAT_STRING(const char *fmt), ...) |
| 1401 | { |
| 1402 | va_list wrk_args, args; |
| 1403 | |
| 1404 | va_start(args, fmt); |
| 1405 | |
| 1406 | #ifdef va_copy |
| 1407 | va_copy(wrk_args, args); |
| 1408 | #else |
| 1409 | wrk_args = args; |
| 1410 | #endif |
| 1411 | |
| 1412 | char szBuffer[4096] = {}; |
| 1413 | // Quiet coverity by staring off nul terminated. |
| 1414 | int ret = CPLvsnprintf(szBuffer, sizeof(szBuffer), fmt, wrk_args); |
| 1415 | |
| 1416 | #ifdef va_copy |
| 1417 | va_end(wrk_args); |
| 1418 | #endif |
| 1419 | |
| 1420 | if (ret < int(sizeof(szBuffer)) - 1) |
| 1421 | ret = printf("%s", szBuffer); /*ok*/ |
| 1422 | else |
| 1423 | { |
| 1424 | #ifdef va_copy |
| 1425 | va_copy(wrk_args, args); |
| 1426 | #else |
| 1427 | wrk_args = args; |
| 1428 | #endif |
| 1429 | |
| 1430 | ret = vfprintf(stdout, fmt, wrk_args); |
| 1431 | |
| 1432 | #ifdef va_copy |
| 1433 | va_end(wrk_args); |
| 1434 | #endif |
| 1435 | } |
| 1436 | |
| 1437 | va_end(args); |
| 1438 | |
| 1439 | return ret; |
| 1440 | } |
| 1441 | |
| 1442 | /************************************************************************/ |
| 1443 | /* CPLsscanf() */ |
no test coverage detected