Addressed more issues raised by splint, and corrected some type confusion between off_t and size_t / ssize_t.

This commit is contained in:
Andrew Wood
2023-09-14 22:19:49 +01:00
parent e696b737e3
commit 252213fbc2
8 changed files with 152 additions and 71 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ struct opts_s { /* structure describing run-time options */
bool bytes; /* bytes transferred flag */
bool bits; /* report transfer size in bits */
bool bufpercent; /* transfer buffer percentage flag */
unsigned int lastwritten; /* show N bytes last written */
size_t lastwritten; /* show N bytes last written */
bool force; /* force-if-not-terminal flag */
bool cursor; /* whether to use cursor positioning */
bool numeric; /* numeric output only */
+5 -5
View File
@@ -31,7 +31,7 @@ extern "C" {
#define PV_DISPLAY_OUTPUTBUF 256
#define PV_DISPLAY_FINETA 512
#define RATE_GRANULARITY 100000000.0L /* nsec between -L rate chunks */
#define RATE_GRANULARITY 100000000 /* nsec between -L rate chunks */
#define RATE_BURST_WINDOW 5 /* rate burst window (multiples of rate) */
#define REMOTE_INTERVAL 100000000 /* nsec between checks for -R */
#define BUFFER_SIZE (size_t) 409600 /* default transfer buffer size */
@@ -170,8 +170,8 @@ struct pvstate_s {
off_t initial_offset;
/*@only@*/ char *display_buffer;
long display_buffer_size;
int lastoutput_length; /* number of last-output bytes to show */
unsigned char lastoutput_buffer[PV_SIZEOF_LASTOUTPUT_BUFFER];
size_t lastoutput_length; /* number of last-output bytes to show */
char lastoutput_buffer[PV_SIZEOF_LASTOUTPUT_BUFFER];
int prev_width; /* screen width last time we were called */
int prev_length; /* length of last string we output */
char str_name[PV_SIZEOF_STR_NAME];
@@ -226,7 +226,7 @@ struct pvstate_s {
* is the offset in the buffer that we've written data up to. It
* will always be less than or equal to read_position.
*/
unsigned char *transfer_buffer; /* data transfer buffer */
/*@keep@*/ /*@null@*/ char *transfer_buffer; /* data transfer buffer */
size_t buffer_size; /* size of buffer */
size_t read_position; /* amount of data in buffer */
size_t write_position; /* buffered data written */
@@ -285,7 +285,7 @@ void pv_error(pvstate_t, char *, ...);
int pv_main_loop(pvstate_t);
void pv_display(pvstate_t, long double, off_t, off_t);
off_t pv_transfer(pvstate_t, int, bool *, bool *, off_t, long *);
ssize_t pv_transfer(pvstate_t, int, bool *, bool *, off_t, long *);
int pv_next_file(pvstate_t, unsigned int, int);
/*@out@*/ const char *pv_current_file_name(pvstate_t);
+1 -1
View File
@@ -139,7 +139,7 @@ extern void pv_state_set_format(pvstate_t state, bool progress,
bool fineta, bool rate,
bool average_rate, bool bytes,
bool bufpercent,
unsigned int lastwritten,
size_t lastwritten,
/*@null@*/ const char *name);
/*
+1 -1
View File
@@ -341,7 +341,7 @@ opts_t opts_parse(unsigned int argc, char **argv)
opts->no_splice = true;
break;
case 'A':
opts->lastwritten = pv_getnum_ui(optarg);
opts->lastwritten = (size_t) pv_getnum_ui(optarg);
numopts++;
opts->no_splice = true;
break;
+1 -1
View File
@@ -35,7 +35,7 @@ struct remote_msg {
bool average_rate; /* average rate counter flag */
bool bytes; /* bytes transferred flag */
bool bufpercent; /* transfer buffer percentage flag */
unsigned int lastwritten; /* last-written bytes count */
size_t lastwritten; /* last-written bytes count */
off_t rate_limit; /* rate limit, in bytes per second */
size_t buffer_size; /* buffer size, in bytes (0=default) */
off_t size; /* total size of data */
+38 -19
View File
@@ -33,8 +33,8 @@
*/
int pv_main_loop(pvstate_t state)
{
long written, lineswritten;
long long total_written, transferred_since_last, cansend;
long lineswritten;
off_t written, total_written, transferred_since_last, cansend;
long double target;
bool eof_in, eof_out, final_update;
struct timespec start_time, next_update, next_ratecheck, cur_time;
@@ -67,12 +67,20 @@ int pv_main_loop(pvstate_t state)
eof_in = false;
eof_out = false;
total_written = 0;
lineswritten = 0;
transferred_since_last = 0;
state->initial_offset = 0;
memset(&cur_time, 0, sizeof(cur_time));
memset(&start_time, 0, sizeof(start_time));
pv_elapsedtime_read(&cur_time);
pv_elapsedtime_copy(&start_time, &cur_time);
memset(&next_ratecheck, 0, sizeof(next_ratecheck));
memset(&next_remotecheck, 0, sizeof(next_remotecheck));
memset(&next_update, 0, sizeof(next_update));
pv_elapsedtime_copy(&next_ratecheck, &cur_time);
pv_elapsedtime_copy(&next_remotecheck, &cur_time);
pv_elapsedtime_copy(&next_update, &cur_time);
@@ -124,8 +132,8 @@ int pv_main_loop(pvstate_t state)
* read and we weren't given a target buffer size.
*/
if ((0 == fstat(fd, &sb)) && (0 == state->target_buffer_size)) {
unsigned long long sz;
sz = sb.st_blksize * 32;
size_t sz;
sz = (size_t) (sb.st_blksize * 32);
if (sz > BUFFER_SIZE_MAX)
sz = BUFFER_SIZE_MAX;
state->target_buffer_size = sz;
@@ -147,7 +155,7 @@ int pv_main_loop(pvstate_t state)
pv_elapsedtime_add_nsec(&next_remotecheck, REMOTE_INTERVAL);
}
if (state->pv_sig_abort)
if (1 == state->pv_sig_abort)
break;
if (state->rate_limit > 0) {
@@ -155,14 +163,15 @@ int pv_main_loop(pvstate_t state)
if (pv_elapsedtime_compare(&cur_time, &next_ratecheck) > 0) {
target +=
((long double) (state->rate_limit)) / (long double) (1000000000.0 /
RATE_GRANULARITY);
(long
double) (RATE_GRANULARITY));
long double burst_max = ((long double) (state->rate_limit * RATE_BURST_WINDOW));
if (target > burst_max) {
target = burst_max;
}
pv_elapsedtime_add_nsec(&next_ratecheck, RATE_GRANULARITY);
}
cansend = target;
cansend = (off_t) target;
}
/*
@@ -170,7 +179,7 @@ int pv_main_loop(pvstate_t state)
* try to write more than we're allowed to.
*/
if ((0 < state->size) && (state->stop_at_size)) {
if (((long) (state->size) < (total_written + cansend))
if ((state->size < (total_written + cansend))
|| ((0 == cansend)
&& (0 == state->rate_limit))) {
cansend = state->size - total_written;
@@ -225,7 +234,7 @@ int pv_main_loop(pvstate_t state)
if (eof_in && eof_out) {
final_update = true;
if ((state->display_visible)
|| (0 == state->delay_start)) {
|| (state->delay_start < 0.001)) {
pv_elapsedtime_copy(&next_update, &cur_time);
}
}
@@ -290,12 +299,14 @@ int pv_main_loop(pvstate_t state)
* Calculate the effective start time: the time we actually
* started, plus the total time we spent stopped.
*/
memset(&init_time, 0, sizeof(init_time));
pv_elapsedtime_add(&init_time, &start_time, &(state->pv_sig_toffset));
/*
* Now get the effective elapsed transfer time - current
* time minus effective start time.
*/
memset(&transfer_elapsed, 0, sizeof(transfer_elapsed));
pv_elapsedtime_subtract(&transfer_elapsed, &cur_time, &init_time);
elapsed_seconds = pv_elapsedtime_seconds(&transfer_elapsed);
@@ -304,7 +315,7 @@ int pv_main_loop(pvstate_t state)
transferred_since_last = -1;
/* Resize the display, if a resize signal was received. */
if (state->pv_sig_newsize) {
if (1 == state->pv_sig_newsize) {
unsigned int new_width, new_height;
state->pv_sig_newsize = 0;
@@ -332,7 +343,7 @@ int pv_main_loop(pvstate_t state)
pv_write_retry(STDERR_FILENO, "\n", 1);
}
if (state->pv_sig_abort)
if (1 == state->pv_sig_abort)
state->exit_status |= 32;
if (fd >= 0)
@@ -360,6 +371,7 @@ int pv_watchfd_loop(pvstate_t state)
int first_check;
int rc;
memset(&info, 0, sizeof(info));
info.watch_pid = state->watch_pid;
info.watch_fd = state->watch_fd;
rc = pv_watchfd_info(state, &info, 0);
@@ -385,6 +397,10 @@ int pv_watchfd_loop(pvstate_t state)
}
}
memset(&cur_time, 0, sizeof(cur_time));
memset(&next_remotecheck, 0, sizeof(next_remotecheck));
memset(&next_update, 0, sizeof(next_update));
pv_elapsedtime_read(&cur_time);
pv_elapsedtime_copy(&(info.start_time), &cur_time);
pv_elapsedtime_copy(&next_remotecheck, &cur_time);
@@ -405,7 +421,7 @@ int pv_watchfd_loop(pvstate_t state)
pv_elapsedtime_add_nsec(&next_remotecheck, REMOTE_INTERVAL);
}
if (state->pv_sig_abort)
if (1 == state->pv_sig_abort)
break;
position_now = pv_watchfd_position(&info);
@@ -465,7 +481,7 @@ int pv_watchfd_loop(pvstate_t state)
transferred_since_last = -1;
/* Resize the display, if a resize signal was received. */
if (state->pv_sig_newsize) {
if (1 == state->pv_sig_newsize) {
unsigned int new_width, new_height;
state->pv_sig_newsize = 0;
@@ -488,7 +504,7 @@ int pv_watchfd_loop(pvstate_t state)
if (!state->numeric)
pv_write_retry(STDERR_FILENO, "\n", 1);
if (state->pv_sig_abort)
if (1 == state->pv_sig_abort)
state->exit_status |= 32;
return state->exit_status;
@@ -514,7 +530,7 @@ int pv_watchpid_loop(pvstate_t state)
struct timespec next_update, cur_time;
int idx;
int prev_displayed_lines, blank_lines;
int first_pass = 1;
bool first_pass = true;
/*
* Make sure the process exists first, so we can give an error if
@@ -551,6 +567,9 @@ int pv_watchpid_loop(pvstate_t state)
* Get things ready for the main loop.
*/
memset(&cur_time, 0, sizeof(cur_time));
memset(&next_update, 0, sizeof(next_update));
pv_elapsedtime_read(&cur_time);
pv_elapsedtime_copy(&next_update, &cur_time);
pv_elapsedtime_add_nsec(&next_update, (long long) (1000000000.0 * state->interval));
@@ -561,10 +580,10 @@ int pv_watchpid_loop(pvstate_t state)
prev_displayed_lines = 0;
while (1) {
while (true) {
int rc, fd, displayed_lines;
if (state->pv_sig_abort)
if (1 == state->pv_sig_abort)
break;
pv_elapsedtime_read(&cur_time);
@@ -601,7 +620,7 @@ int pv_watchpid_loop(pvstate_t state)
pv_elapsedtime_copy(&next_update, &cur_time);
/* Resize the display, if a resize signal was received. */
if (state->pv_sig_newsize) {
if (1 == state->pv_sig_newsize) {
state->pv_sig_newsize = 0;
pv_screensize(&(state->width), &(state->height));
for (idx = 0; idx < array_length; idx++) {
@@ -627,7 +646,7 @@ int pv_watchpid_loop(pvstate_t state)
break;
}
first_pass = 0;
first_pass = false;
displayed_lines = 0;
for (fd = 0; fd < FD_SETSIZE; fd++) {
+5 -2
View File
@@ -124,9 +124,12 @@ void pv_state_free(pvstate_t state)
state->format_string = NULL;
}
/*@-keeptrans@ */
if (NULL != state->transfer_buffer)
free(state->transfer_buffer);
state->transfer_buffer = NULL;
/*@+keeptrans@ */
/* splint - explicitly freeing this structure, so free() here is OK. */
if (NULL != state->history)
free(state->history);
@@ -153,7 +156,7 @@ void pv_state_free(pvstate_t state)
/*
* Set the formatting string, given a set of old-style formatting options.
*/
void pv_state_set_format(pvstate_t state, bool progress, bool timer, bool eta, bool fineta, bool rate, bool average_rate, bool bytes, bool bufpercent, unsigned int lastwritten, /*@null@ */
void pv_state_set_format(pvstate_t state, bool progress, bool timer, bool eta, bool fineta, bool rate, bool average_rate, bool bytes, bool bufpercent, size_t lastwritten, /*@null@ */
const char *name)
{
#define PV_ADDFORMAT(x,y) if (x) { \
@@ -175,7 +178,7 @@ void pv_state_set_format(pvstate_t state, bool progress, bool timer, bool eta, b
if (lastwritten > 0) {
char buf[16]; /* flawfinder: ignore */
memset(buf, 0, sizeof(buf));
(void) pv_snprintf(buf, sizeof(buf), "%%%uA", lastwritten);
(void) pv_snprintf(buf, sizeof(buf), "%%%uA", (unsigned int) lastwritten);
PV_ADDFORMAT(lastwritten > 0, buf);
/*
* flawfinder rationale: large enough for string, zeroed
+100 -41
View File
@@ -306,14 +306,11 @@ static ssize_t pv__transfer_write_repeated(int fd, void *buf, size_t count, bool
* sets *eof_in to true. If all data in the buffer has been written at this
* point, then also sets *eof_out to true.
*/
static int pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_out, size_t allowed)
static int pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_out, off_t allowed)
{
bool do_not_skip_errors;
size_t bytes_can_read;
off_t amount_to_skip;
long amount_skipped;
long orig_offset;
long skip_offset;
off_t amount_to_skip, amount_skipped, orig_offset, skip_offset;
ssize_t nread;
#ifdef HAVE_SPLICE
size_t bytes_to_splice;
@@ -332,7 +329,7 @@ static int pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_ou
&& (fd != state->splice_failed_fd)
&& (0 == state->to_write)) {
if (state->rate_limit > 0 || allowed != 0) {
bytes_to_splice = allowed;
bytes_to_splice = (size_t) allowed;
} else {
bytes_to_splice = bytes_can_read;
}
@@ -445,7 +442,15 @@ static int pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_ou
* reached the end of this file.
*/
if (do_not_skip_errors) {
/*@-compdef@ */
pv_error(state, "%s: %s: %s", pv_current_file_name(state), _("read failed"), strerror(errno));
/*@+compdef@ */
/*
* splint says the storage pointed to by the result of
* pv_current_file_name() is not fully defined.
*
* TODO: investigate and fix the reason for this.
*/
*eof_in = true;
if (state->write_position >= state->read_position) {
*eof_out = true;
@@ -460,12 +465,15 @@ static int pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_ou
amount_skipped = -1;
if (!state->read_error_warning_shown) {
/*@-compdef@ */
pv_error(state, "%s: %s: %s", pv_current_file_name(state), _("warning: read errors detected"),
strerror(errno));
/*@+compdef@ */
/* splint - see previous pv_current_file_name() call. */
state->read_error_warning_shown = true;
}
orig_offset = lseek(fd, 0, SEEK_CUR);
orig_offset = (off_t) lseek(fd, 0, SEEK_CUR);
/*
* If the file is not seekable, we can't skip past the error, so we
@@ -473,7 +481,10 @@ static int pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_ou
* of the file.
*/
if (0 > orig_offset) {
/*@-compdef@ */
pv_error(state, "%s: %s: %s", pv_current_file_name(state), _("file is not seekable"), strerror(errno));
/*@+compdef@ */
/* splint - see previous pv_current_file_name() calls. */
*eof_in = true;
if (state->write_position >= state->read_position) {
*eof_out = true;
@@ -490,9 +501,10 @@ static int pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_ou
amount_to_skip = state->error_skip_block;
} else {
if (state->read_errors_in_a_row < 10) {
amount_to_skip = state->read_errors_in_a_row < 5 ? 1 : 2;
amount_to_skip = (off_t) (state->read_errors_in_a_row < 5 ? 1 : 2);
} else if (state->read_errors_in_a_row < 20) {
amount_to_skip = 1 << (state->read_errors_in_a_row - 10);
unsigned int shift_by = (unsigned int) (state->read_errors_in_a_row - 10);
amount_to_skip = (off_t) (1 << shift_by);
} else {
amount_to_skip = 512;
}
@@ -514,10 +526,13 @@ static int pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_ou
/*
* Trim the skip amount so we wouldn't read too much.
*/
if (amount_to_skip > bytes_can_read)
amount_to_skip = bytes_can_read;
if (amount_to_skip > (off_t) bytes_can_read)
amount_to_skip = (off_t) bytes_can_read;
skip_offset = lseek(fd, orig_offset + amount_to_skip, SEEK_SET);
/*@+longintegral@ */
/* splint complains about __off_t vs off_t */
skip_offset = (off_t) lseek(fd, (off_t) (orig_offset + amount_to_skip), SEEK_SET);
/*@-longintegral@ */
/*
* If the skip we just tried didn't work, try only skipping 1 byte
@@ -525,7 +540,10 @@ static int pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_ou
*/
if (skip_offset < 0) {
amount_to_skip = 1;
skip_offset = lseek(fd, orig_offset + amount_to_skip, SEEK_SET);
/*@+longintegral@ */
/* see above */
skip_offset = (off_t) lseek(fd, (off_t) (orig_offset + amount_to_skip), SEEK_SET);
/*@-longintegral@ */
}
if (skip_offset < 0) {
@@ -540,9 +558,12 @@ static int pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_ou
* since it just means we've reached the end anyway.
*/
if (EINVAL != errno) {
/*@-compdef@ */
pv_error(state,
"%s: %s: %s", pv_current_file_name(state), _("failed to seek past error"),
strerror(errno));
/*@+compdef@ */
/* splint - see previous pv_current_file_name() calls. */
}
} else {
amount_skipped = skip_offset - orig_offset;
@@ -553,12 +574,16 @@ static int pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_ou
* of the transfer buffer, and update the buffer position.
*/
if (amount_skipped > 0) {
memset(state->transfer_buffer + state->read_position, 0, amount_skipped);
memset(state->transfer_buffer + state->read_position, 0, (size_t) amount_skipped);
state->read_position += amount_skipped;
if (state->skip_errors < 2) {
/*@-compdef@ */
pv_error(state, "%s: %s: %ld - %ld (%ld %s)",
pv_current_file_name(state),
_("skipped past read error"), orig_offset, skip_offset, amount_skipped, _("B"));
_("skipped past read error"), (long) orig_offset, (long) skip_offset,
(long) amount_skipped, _("B"));
/*@+compdef@ */
/* splint - see previous pv_current_file_name() calls. */
}
} else {
/*
@@ -594,15 +619,29 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long
{
ssize_t nwritten;
if (NULL == state->transfer_buffer) {
pv_error(state, "%s", _("no transfer buffer allocated"));
state->exit_status |= 64;
*eof_out = true;
state->written = -1;
return 1;
}
nwritten = 0;
if (state->discard_input) {
nwritten = state->to_write;
} else {
signal(SIGALRM, SIG_IGN);
alarm(1);
} else if (state->to_write > 0) {
if (signal(SIGALRM, SIG_IGN) == SIG_ERR) {
pv_error(state, "%s: %s", _("failed to set alarm signal handler"), strerror(errno));
} else {
(void) alarm(1);
}
nwritten = pv__transfer_write_repeated(STDOUT_FILENO,
state->transfer_buffer +
state->write_position, state->to_write, state->sync_after_write);
alarm(0);
state->write_position, (size_t) (state->to_write),
state->sync_after_write);
(void) alarm(0);
}
if (0 == nwritten) {
@@ -619,12 +658,12 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long
/*
* Guillaume Marcais: use strchr to count \n
*/
unsigned char save;
char save;
char *ptr;
long lines = 0;
save = state->transfer_buffer[state->write_position + nwritten];
state->transfer_buffer[state->write_position + nwritten] = 0;
state->transfer_buffer[state->write_position + nwritten] = '\0';
ptr = (char *) (state->transfer_buffer + state->write_position - 1);
if (state->null_terminated_lines) {
@@ -653,9 +692,9 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long
*/
if (((state->components_used & PV_DISPLAY_OUTPUTBUF) != 0)
&& (nwritten > 0)) {
long new_portion_length, old_portion_length;
size_t new_portion_length, old_portion_length;
new_portion_length = nwritten;
new_portion_length = (size_t) nwritten;
if (new_portion_length > state->lastoutput_length)
new_portion_length = state->lastoutput_length;
@@ -738,13 +777,13 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long
*
* Returns NULL on complete allocation failure.
*/
static unsigned char *pv__allocate_aligned_buffer(int fd, size_t target_size)
/*@null@*//*@only@ */ static char *pv__allocate_aligned_buffer(int fd, size_t target_size)
{
unsigned char *newptr;
char *newptr;
#if defined(HAVE_FPATHCONF) && defined(HAVE_POSIX_MEMALIGN) && defined(_PC_REC_XFER_ALIGN)
long input_alignment, output_alignment, min_alignment;
size_t required_alignment;
long required_alignment;
input_alignment = fd >= 0 ? fpathconf(fd, _PC_REC_XFER_ALIGN) : -1;
output_alignment = fpathconf(STDOUT_FILENO, _PC_REC_XFER_ALIGN);
@@ -769,13 +808,22 @@ static unsigned char *pv__allocate_aligned_buffer(int fd, size_t target_size)
required_alignment = min_alignment;
}
if (0 != posix_memalign((void **) (&newptr), required_alignment, target_size)) {
newptr = (unsigned char *) malloc(target_size);
newptr = NULL;
/*@-unrecog@ */
/* splice doesn't know of posix_memalign(). */
if (0 != posix_memalign((void **) (&newptr), (size_t) required_alignment, target_size)) {
newptr = malloc(target_size);
}
/*@+unrecog@ */
#else /* ! defined(HAVE_FPATHCONF) && defined(HAVE_POSIX_MEMALIGN) && defined(_PC_REC_XFER_ALIGN) */
newptr = (unsigned char *) malloc(target_size);
newptr = malloc(target_size);
#endif /* defined(HAVE_FPATHCONF) && defined(HAVE_POSIX_MEMALIGN) && defined(_PC_REC_XFER_ALIGN) */
/* Initialise the buffer with zeroes. */
if (NULL != newptr)
memset(newptr, 0, target_size);
return newptr;
}
@@ -791,7 +839,7 @@ static unsigned char *pv__allocate_aligned_buffer(int fd, size_t target_size)
* state->exit_status is updated). In line mode, the number of lines written
* will be put into *lineswritten.
*/
off_t pv_transfer(pvstate_t state, int fd, bool *eof_in, bool *eof_out, off_t allowed, long *lineswritten)
ssize_t pv_transfer(pvstate_t state, int fd, bool *eof_in, bool *eof_out, off_t allowed, long *lineswritten)
{
bool ready_to_read, ready_to_write;
int check_read_fd, check_write_fd;
@@ -807,11 +855,18 @@ off_t pv_transfer(pvstate_t state, int fd, bool *eof_in, bool *eof_out, off_t al
*/
if (state->direct_io_changed) {
if (!(*eof_in)) {
fcntl(fd, F_SETFL, (state->direct_io ? O_DIRECT : 0) | fcntl(fd, F_GETFL));
if (0 != fcntl(fd, F_SETFL, (state->direct_io ? O_DIRECT : 0) | fcntl(fd, F_GETFL))) {
/*@-compdef@ */
debug("%s: %s: %s", pv_current_file_name(state), "fcntl", strerror(errno));
/*@+compdef@ */
/* splint - see previous pv_current_file_name() calls. */
}
}
if (!(*eof_out)) {
fcntl(STDOUT_FILENO, F_SETFL,
(state->direct_io ? O_DIRECT : 0) | fcntl(STDOUT_FILENO, F_GETFL));
if (0 != fcntl(STDOUT_FILENO, F_SETFL,
(state->direct_io ? O_DIRECT : 0) | fcntl(STDOUT_FILENO, F_GETFL))) {
debug("%s: %s: %s", "(stdout)", "fcntl", strerror(errno));
}
}
state->direct_io_changed = false;
}
@@ -849,7 +904,7 @@ off_t pv_transfer(pvstate_t state, int fd, bool *eof_in, bool *eof_out, off_t al
* and we can't realloc() an aligned buffer.
*/
if (state->buffer_size < state->target_buffer_size) {
unsigned char *newptr;
char *newptr;
newptr = pv__allocate_aligned_buffer(fd, state->target_buffer_size + 32);
if (NULL == newptr) {
/*
@@ -895,10 +950,10 @@ off_t pv_transfer(pvstate_t state, int fd, bool *eof_in, bool *eof_out, off_t al
* is >0, then this puts an upper limit on how much we're allowed to
* write.
*/
state->to_write = state->read_position - state->write_position;
state->to_write = (ssize_t) (state->read_position - state->write_position);
if ((state->rate_limit > 0) || (allowed > 0)) {
if (state->to_write > allowed) {
state->to_write = allowed;
if ((off_t) (state->to_write) > allowed) {
state->to_write = (ssize_t) allowed;
}
}
@@ -924,8 +979,11 @@ off_t pv_transfer(pvstate_t state, int fd, bool *eof_in, bool *eof_out, off_t al
/*
* Any other error is a problem and we must report back.
*/
/*@-compdef@ */
pv_error(state, "%s: %s: %d: %s", pv_current_file_name(state), _("select call failed"), n,
strerror(errno));
/*@+compdef@ */
/* splint - see previous pv_current_file_name() calls. */
state->exit_status |= 16;
@@ -953,12 +1011,12 @@ off_t pv_transfer(pvstate_t state, int fd, bool *eof_in, bool *eof_out, off_t al
/*
* Guillaume Marcais: use strrchr to find last \n
*/
unsigned char save;
char save;
char *start;
char *end;
save = state->transfer_buffer[state->write_position + state->to_write];
state->transfer_buffer[state->write_position + state->to_write] = 0;
state->transfer_buffer[state->write_position + state->to_write] = '\0';
start = (char *) (state->transfer_buffer + state->write_position);
end = strrchr(start, '\n');
@@ -979,7 +1037,8 @@ off_t pv_transfer(pvstate_t state, int fd, bool *eof_in, bool *eof_out, off_t al
&& (!state->splice_used)
#endif /* HAVE_SPLICE */
&& (state->read_position > state->write_position)
&& (state->to_write > 0)) {
&& (state->to_write > 0)
&& (NULL != lineswritten)) {
if (pv__transfer_write(state, eof_in, eof_out, lineswritten) == 0)
return 0;
}