summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2016-11-29 10:58:34 +0100
committerErich Eckner <git@eckner.net>2017-02-16 13:23:49 +0100
commit33b35e255d1d045e28c4cd8c54c37808d0ed3ace (patch)
tree45b401efc8494611a659d62e465d027c8513ae46
parent698617e7eb710a3da51ff4edaf44274109544e4a (diff)
downloadcoreutils-33b35e255d1d045e28c4cd8c54c37808d0ed3ace.tar.xz
sort: split off even more source lines useful for uniq
-rw-r--r--src/sort-uniq-keyfuncs.c28
-rw-r--r--src/sort.c28
2 files changed, 28 insertions, 28 deletions
diff --git a/src/sort-uniq-keyfuncs.c b/src/sort-uniq-keyfuncs.c
index d661aefe3..31bf03e19 100644
--- a/src/sort-uniq-keyfuncs.c
+++ b/src/sort-uniq-keyfuncs.c
@@ -174,6 +174,34 @@ sort_die (char const *message, char const *file)
quotef (file ? file : _("standard output")));
}
+/* Initialize BUF. Reserve LINE_BYTES bytes for each line; LINE_BYTES
+ must be at least sizeof (struct line). Allocate ALLOC bytes
+ initially. */
+
+static void
+initbuf (struct buffer *buf, size_t line_bytes, size_t alloc)
+{
+ /* Ensure that the line array is properly aligned. If the desired
+ size cannot be allocated, repeatedly halve it until allocation
+ succeeds. The smaller allocation may hurt overall performance,
+ but that's better than failing. */
+ while (true)
+ {
+ alloc += sizeof (struct line) - alloc % sizeof (struct line);
+ buf->buf = malloc (alloc);
+ if (buf->buf)
+ break;
+ alloc /= 2;
+ if (alloc <= line_bytes + 1)
+ xalloc_die ();
+ }
+
+ buf->line_bytes = line_bytes;
+ buf->alloc = alloc;
+ buf->used = buf->left = buf->nlines = 0;
+ buf->eof = false;
+}
+
/* Return one past the limit of the line array. */
static inline struct line *
diff --git a/src/sort.c b/src/sort.c
index e2a3c7e3e..b7a6f7aec 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -1382,34 +1382,6 @@ sort_buffer_size (FILE *const *fps, size_t nfps,
return size;
}
-/* Initialize BUF. Reserve LINE_BYTES bytes for each line; LINE_BYTES
- must be at least sizeof (struct line). Allocate ALLOC bytes
- initially. */
-
-static void
-initbuf (struct buffer *buf, size_t line_bytes, size_t alloc)
-{
- /* Ensure that the line array is properly aligned. If the desired
- size cannot be allocated, repeatedly halve it until allocation
- succeeds. The smaller allocation may hurt overall performance,
- but that's better than failing. */
- while (true)
- {
- alloc += sizeof (struct line) - alloc % sizeof (struct line);
- buf->buf = malloc (alloc);
- if (buf->buf)
- break;
- alloc /= 2;
- if (alloc <= line_bytes + 1)
- xalloc_die ();
- }
-
- buf->line_bytes = line_bytes;
- buf->alloc = alloc;
- buf->used = buf->left = buf->nlines = 0;
- buf->eof = false;
-}
-
/* Initialize the randomly chosen MD5 state. */
static void