summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2008-08-10 16:13:14 +0200
committerJim Meyering <meyering@redhat.com>2008-08-10 16:49:40 +0200
commit43f66923ccaf0f3ba6969e43762602fdaafbe912 (patch)
treed5f2f358ae376752f504c30e95945f716324b458 /src
parentcd1f4bc1ecde1e7b313c1d0d587a07965d00d8b1 (diff)
downloadcoreutils-43f66923ccaf0f3ba6969e43762602fdaafbe912.tar.xz
sort: avoid erroneous cast
* src/sort.c (OPEN_MAX): Define if not already defined. (MAX_NMERGE): Remove definition. (specify_nmerge): Don't cast MAX_NMERGE (of type size_t) to unsigned int. Instead, use OPEN_MAX as the fall-back value.
Diffstat (limited to 'src')
-rw-r--r--src/sort.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/sort.c b/src/sort.c
index 74318b900..a07ecfc91 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -76,6 +76,13 @@ struct rlimit { size_t rlim_cur; };
# endif
#endif
+#if !defined OPEN_MAX && defined NR_OPEN
+# define OPEN_MAX NR_OPEN
+#endif
+#if !defined OPEN_MAX
+# define OPEN_MAX 20
+#endif
+
#ifndef STDC_HEADERS
double strtod ();
#endif
@@ -231,9 +238,6 @@ static struct month monthtab[] =
/* Minimum sort size; the code might not work with smaller sizes. */
#define MIN_SORT_SIZE (nmerge * MIN_MERGE_BUFFER_SIZE)
-/* Maximum merge buffers we can theoretically support */
-#define MAX_NMERGE (SIZE_MAX / MIN_MERGE_BUFFER_SIZE)
-
/* The number of bytes needed for a merge or check buffer, which can
function relatively efficiently even if it holds only one line. If
a longer line is seen, this value is increased. */
@@ -1075,14 +1079,15 @@ specify_nmerge (int oi, char c, char const *s)
{
uintmax_t n;
struct rlimit rlimit;
- unsigned int max_nmerge = (unsigned int) MAX_NMERGE;
enum strtol_error e = xstrtoumax (s, NULL, 10, &n, NULL);
/* Try to find out how many file descriptors we'll be able
to open. We need at least nmerge + 3 (STDIN_FILENO,
STDOUT_FILENO and STDERR_FILENO). */
- if (getrlimit (RLIMIT_NOFILE, &rlimit) == 0)
- max_nmerge = MIN (max_nmerge, rlimit.rlim_cur - 3);
+ unsigned int max_nmerge = ((getrlimit (RLIMIT_NOFILE, &rlimit) == 0
+ ? rlimit.rlim_cur
+ : OPEN_MAX)
+ - 3);
if (e == LONGINT_OK)
{