1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-11-03 04:17:20 -05:00

Update: Code style

This commit is contained in:
Philipp Schafft 2022-03-07 10:51:58 +00:00
parent 265f4eb61e
commit a6db913245

View File

@ -518,29 +518,22 @@ static void __vsnprintf(char *str, size_t size, const char *format, va_list ap)
const char * arg; const char * arg;
char buf[80]; char buf[80];
for (; *format && size; format++) for (; *format && size; format++) {
{ if ( !in_block ) {
if ( !in_block )
{
if ( *format == '%' ) { if ( *format == '%' ) {
in_block = 1; in_block = 1;
block_size = 0; block_size = 0;
block_len = 0; block_len = 0;
block_space = 0; block_space = 0;
block_alt = 0; block_alt = 0;
} } else {
else
{
*(str++) = *format; *(str++) = *format;
size--; size--;
} }
} } else {
else
{
// TODO: %l*[sdupi] as well as %.4080s and "%.*s // TODO: %l*[sdupi] as well as %.4080s and "%.*s
arg = NULL; arg = NULL;
switch (*format) switch (*format) {
{
case 'l': case 'l':
block_size++; block_size++;
break; break;
@ -575,37 +568,40 @@ static void __vsnprintf(char *str, size_t size, const char *format, va_list ap)
case 'p': case 'p':
snprintf(buf, sizeof(buf), "%p", (void*)va_arg(ap, void *)); snprintf(buf, sizeof(buf), "%p", (void*)va_arg(ap, void *));
arg = buf; arg = buf;
/* fall through */
case 'd': case 'd':
case 'i': case 'i':
case 'u': case 'u':
if (!arg) if (!arg) {
{ switch (block_size) {
switch (block_size)
{
case 0: case 0:
if (*format == 'u') if (*format == 'u') {
snprintf(buf, sizeof(buf), "%u", (unsigned int)va_arg(ap, unsigned int)); snprintf(buf, sizeof(buf), "%u", (unsigned int)va_arg(ap, unsigned int));
else } else {
snprintf(buf, sizeof(buf), "%i", (int)va_arg(ap, int)); snprintf(buf, sizeof(buf), "%i", (int)va_arg(ap, int));
}
break; break;
case 1: case 1:
if (*format == 'u') if (*format == 'u') {
snprintf(buf, sizeof(buf), "%lu", (unsigned long int)va_arg(ap, unsigned long int)); snprintf(buf, sizeof(buf), "%lu", (unsigned long int)va_arg(ap, unsigned long int));
else } else {
snprintf(buf, sizeof(buf), "%li", (long int)va_arg(ap, long int)); snprintf(buf, sizeof(buf), "%li", (long int)va_arg(ap, long int));
}
break; break;
case 2: case 2:
if (*format == 'u') if (*format == 'u') {
snprintf(buf, sizeof(buf), "%llu", (unsigned long long int)va_arg(ap, unsigned long long int)); snprintf(buf, sizeof(buf), "%llu", (unsigned long long int)va_arg(ap, unsigned long long int));
else } else {
snprintf(buf, sizeof(buf), "%lli", (long long int)va_arg(ap, long long int)); snprintf(buf, sizeof(buf), "%lli", (long long int)va_arg(ap, long long int));
}
break; break;
case 'z': case 'z':
/* We do not use 'z' type of snprintf() here as it is not safe to use on a few outdated platforms. */ /* We do not use 'z' type of snprintf() here as it is not safe to use on a few outdated platforms. */
if (*format == 'u') if (*format == 'u') {
snprintf(buf, sizeof(buf), "%llu", (unsigned long long int)va_arg(ap, size_t)); snprintf(buf, sizeof(buf), "%llu", (unsigned long long int)va_arg(ap, size_t));
else } else {
snprintf(buf, sizeof(buf), "%lli", (long long int)va_arg(ap, ssize_t)); snprintf(buf, sizeof(buf), "%lli", (long long int)va_arg(ap, ssize_t));
}
break; break;
default: default:
snprintf(buf, sizeof(buf), "<<<invalid>>>"); snprintf(buf, sizeof(buf), "<<<invalid>>>");
@ -613,14 +609,14 @@ static void __vsnprintf(char *str, size_t size, const char *format, va_list ap)
} }
arg = buf; arg = buf;
} }
/* fall through */
case 's': case 's':
case 'H': case 'H':
// TODO. // TODO.
if (!arg) if (!arg)
arg = va_arg(ap, const char *); arg = va_arg(ap, const char *);
if (*format != 'H') { if (*format != 'H')
block_alt = 0; block_alt = 0;
}
if (!arg && !block_alt) if (!arg && !block_alt)
arg = "(null)"; arg = "(null)";
if (!block_len) { if (!block_len) {
@ -629,23 +625,19 @@ static void __vsnprintf(char *str, size_t size, const char *format, va_list ap)
// the if() is the outer structure so the inner for() // the if() is the outer structure so the inner for()
// is branch optimized. // is branch optimized.
if (*format == 'H' && !arg) if (*format == 'H' && !arg) {
{
if (size && block_len) { if (size && block_len) {
*(str++) = '-'; *(str++) = '-';
size--; size--;
block_len--; block_len--;
} }
} } else if (*format == 'H') {
else if (*format == 'H')
{
if (block_alt && size && block_len) { if (block_alt && size && block_len) {
*(str++) = '"'; *(str++) = '"';
size--; size--;
block_len--; block_len--;
} }
for (; *arg && block_len && size; arg++, size--, block_len--) for (; *arg && block_len && size; arg++, size--, block_len--) {
{
if (!__vsnprintf__is_print(*arg, block_space)) { if (!__vsnprintf__is_print(*arg, block_space)) {
if (size < 4 || block_len < 4) { if (size < 4 || block_len < 4) {
/* Use old system if we do not have space for new one */ /* Use old system if we do not have space for new one */
@ -668,9 +660,7 @@ static void __vsnprintf(char *str, size_t size, const char *format, va_list ap)
size--; size--;
block_len--; block_len--;
} }
} } else {
else
{
for (; *arg && block_len && size; arg++, size--, block_len--) for (; *arg && block_len && size; arg++, size--, block_len--)
*(str++) = *arg; *(str++) = *arg;
} }