Specify how many inputs may be merged at once. This may be set on the command-line with the --batch-size option. */
| 1437 | This may be set on the command-line with the |
| 1438 | --batch-size option. */ |
| 1439 | static void |
| 1440 | specify_nmerge (int oi, char c, char const *s) |
| 1441 | { |
| 1442 | uintmax_t n; |
| 1443 | struct rlimit rlimit; |
| 1444 | enum strtol_error e = xstrtoumax (s, NULL, 10, &n, ""); |
| 1445 | |
| 1446 | /* Try to find out how many file descriptors we'll be able |
| 1447 | to open. We need at least nmerge + 3 (STDIN_FILENO, |
| 1448 | STDOUT_FILENO and STDERR_FILENO). */ |
| 1449 | unsigned int max_nmerge = ((getrlimit (RLIMIT_NOFILE, &rlimit) == 0 |
| 1450 | ? rlimit.rlim_cur |
| 1451 | : OPEN_MAX) |
| 1452 | - 3); |
| 1453 | |
| 1454 | if (e == LONGINT_OK) |
| 1455 | { |
| 1456 | nmerge = n; |
| 1457 | if (nmerge != n) |
| 1458 | e = LONGINT_OVERFLOW; |
| 1459 | else |
| 1460 | { |
| 1461 | if (nmerge < 2) |
| 1462 | { |
| 1463 | error (0, 0, _("invalid --%s argument %s"), |
| 1464 | long_options[oi].name, quote (s)); |
| 1465 | error (SORT_FAILURE, 0, |
| 1466 | _("minimum --%s argument is %s"), |
| 1467 | long_options[oi].name, quote ("2")); |
| 1468 | } |
| 1469 | else if (max_nmerge < nmerge) |
| 1470 | { |
| 1471 | e = LONGINT_OVERFLOW; |
| 1472 | } |
| 1473 | else |
| 1474 | return; |
| 1475 | } |
| 1476 | } |
| 1477 | |
| 1478 | if (e == LONGINT_OVERFLOW) |
| 1479 | { |
| 1480 | error (0, 0, _("--%s argument %s too large"), |
| 1481 | long_options[oi].name, quote (s)); |
| 1482 | error (SORT_FAILURE, 0, |
| 1483 | _("maximum --%s argument with current rlimit is %u"), |
| 1484 | long_options[oi].name, max_nmerge); |
| 1485 | } |
| 1486 | else |
| 1487 | xstrtol_fatal (e, oi, c, long_options, s); |
| 1488 | } |
| 1489 | |
| 1490 | /* Specify the amount of main memory to use when sorting. */ |
| 1491 | static void |