- an array of lines, in reverse order. */
size_t used; /* Number of bytes used for input data. */
size_t nlines; /* Number of lines in the line array. */
- size_t alloc; /* Number of bytes allocated. */
+ idx_t alloc; /* Number of bytes allocated. */
size_t left; /* Number of bytes left from previous reads. */
size_t line_bytes; /* Number of bytes to reserve for each line. */
bool eof; /* An EOF has been read. */
static char const **temp_dirs;
/* Number of temporary directory names used. */
-static size_t temp_dir_count;
+static idx_t temp_dir_count;
/* Number of allocated slots in temp_dirs. */
-static size_t temp_dir_alloc;
+static idx_t temp_dir_alloc;
/* Flag to reverse the order of all comparisons. */
static bool reverse;
create_temp_file (int *pfd, bool survive_fd_exhaustion)
{
static char const slashbase[] = "/sortXXXXXX";
- static size_t temp_dir_index;
+ static idx_t temp_dir_index;
int fd;
int saved_errno;
char const *temp_dir = temp_dirs[temp_dir_index];
add_temp_dir (char const *dir)
{
if (temp_dir_count == temp_dir_alloc)
- temp_dirs = X2NREALLOC (temp_dirs, &temp_dir_alloc);
+ temp_dirs = xpalloc (temp_dirs, &temp_dir_alloc, 1, -1, sizeof *temp_dirs);
temp_dirs[temp_dir_count++] = dir;
}
/* The current input line is too long to fit in the buffer.
Increase the buffer size and try again, keeping it properly
aligned. */
- size_t line_alloc = buf->alloc / sizeof (struct line);
- buf->buf = x2nrealloc (buf->buf, &line_alloc, sizeof (struct line));
+ idx_t line_alloc = buf->alloc / sizeof (struct line);
+ buf->buf = xpalloc (buf->buf, &line_alloc, 1, -1, sizeof (struct line));
buf->alloc = line_alloc * sizeof (struct line);
}
}
#include "xalloc.h"
#include "verify.h"
-/* This is simply a shorthand for the common case in which
- the third argument to x2nrealloc would be 'sizeof *(P)'.
- Ensure that sizeof *(P) is *not* 1. In that case, it'd be
- better to use X2REALLOC, although not strictly necessary. */
-#define X2NREALLOC(P, PN) verify_expr (sizeof *(P) != 1, \
- x2nrealloc (P, PN, sizeof *(P)))
-
/* Using x2realloc (when appropriate) usually makes your code more
readable than using x2nrealloc, but it also makes it so your
code will malfunction if sizeof *(P) ever becomes 2 or greater.