MCPcopy Create free account
hub / github.com/coreutils/coreutils / max_out

Function max_out

src/csplit.c:1249–1279  ·  view source on GitHub ↗

Return the maximum number of bytes that can be generated by applying FORMAT to an int value. If the format is invalid, diagnose the problem and exit. */

Source from the content-addressed store, hash-verified

1247 applying FORMAT to an int value. If the format is
1248 invalid, diagnose the problem and exit. */
1249static idx_t
1250max_out (char *format)
1251{
1252 bool percent = false;
1253
1254 for (char *f = format; *f; f++)
1255 if (*f == '%' && *++f != '%')
1256 {
1257 if (percent)
1258 error (EXIT_FAILURE, 0,
1259 _("too many %% conversion specifications in suffix"));
1260 percent = true;
1261 int flags;
1262 f += get_format_flags (f, &flags);
1263 while (c_isdigit (*f))
1264 f++;
1265 if (*f == '.')
1266 while (c_isdigit (*++f))
1267 continue;
1268 check_format_conv_type (f, flags);
1269 }
1270
1271 if (! percent)
1272 error (EXIT_FAILURE, 0,
1273 _("missing %% conversion specification in suffix"));
1274
1275 int maxlen = snprintf (NULL, 0, format, INT_MAX);
1276 if (! (0 <= maxlen && maxlen <= IDX_MAX))
1277 xalloc_die ();
1278 return maxlen;
1279}
1280
1281int
1282main (int argc, char **argv)

Callers 1

mainFunction · 0.85

Calls 3

get_format_flagsFunction · 0.85
check_format_conv_typeFunction · 0.85
xalloc_dieFunction · 0.85

Tested by

no test coverage detected