diff --git a/src/include/options.h b/src/include/options.h index 64bee3c..b477a7e 100644 --- a/src/include/options.h +++ b/src/include/options.h @@ -14,6 +14,7 @@ #endif #include +#include #ifdef __cplusplus extern "C" { @@ -42,13 +43,13 @@ struct opts_s { /* structure describing run-time options */ bool linemode; /* count lines instead of bytes */ bool null_terminated_lines; /* lines are null-terminated */ bool no_display; /* do nothing other than pipe data */ - size_t rate_limit; /* rate limit, in bytes per second */ + off_t rate_limit; /* rate limit, in bytes per second */ size_t buffer_size; /* buffer size, in bytes (0=default) */ unsigned int remote; /* PID of pv to update settings of */ - size_t size; /* total size of data */ + off_t size; /* total size of data */ bool no_splice; /* flag set if never to use splice */ unsigned int skip_errors; /* skip read errors counter */ - size_t error_skip_block; /* skip block size, 0 for adaptive */ + off_t error_skip_block; /* skip block size, 0 for adaptive */ bool stop_at_size; /* set if we stop at "size" bytes */ bool sync_after_write; /* set if we sync after every write */ bool direct_io; /* set if O_DIRECT is to be used */ diff --git a/src/include/pv-internal.h b/src/include/pv-internal.h index 3bf141f..51ec1d7 100644 --- a/src/include/pv-internal.h +++ b/src/include/pv-internal.h @@ -36,8 +36,8 @@ extern "C" { #define REMOTE_INTERVAL 100000000 /* nsec between checks for -R */ #define BUFFER_SIZE 409600 /* default transfer buffer size */ #define BUFFER_SIZE_MAX 524288 /* max auto transfer buffer size */ -#define MAX_READ_AT_ONCE (size_t) 524288 /* max to read() in one go */ -#define MAX_WRITE_AT_ONCE (size_t) 524288 /* max to write() in one go */ +#define MAX_READ_AT_ONCE (off_t) 524288 /* max to read() in one go */ +#define MAX_WRITE_AT_ONCE (off_t) 524288 /* max to write() in one go */ #define TRANSFER_READ_TIMEOUT 0.09L /* seconds to time reads out at */ #define TRANSFER_WRITE_TIMEOUT 0.9L /* seconds to time writes out at */ @@ -45,7 +45,7 @@ extern "C" { typedef struct pvhistory { - size_t total_bytes; + off_t total_bytes; long double elapsed_sec; } pvhistory_t; @@ -102,16 +102,16 @@ struct pvstate_s { bool null_terminated_lines; /* lines are null-terminated */ bool no_display; /* do nothing other than pipe data */ unsigned int skip_errors; /* skip read errors counter */ - size_t error_skip_block; /* skip block size, 0 for adaptive */ + off_t error_skip_block; /* skip block size, 0 for adaptive */ bool stop_at_size; /* set if we stop at "size" bytes */ bool sync_after_write; /* set if we sync after every write */ bool direct_io; /* set if O_DIRECT is to be used */ bool direct_io_changed; /* set when direct_io is changed */ bool no_splice; /* never use splice() */ bool discard_input; /* write nothing to stdout */ - size_t rate_limit; /* rate limit, in bytes per second */ + off_t rate_limit; /* rate limit, in bytes per second */ size_t target_buffer_size; /* buffer size (0=default) */ - size_t size; /* total size of data */ + off_t size; /* total size of data */ double interval; /* interval between updates */ double delay_start; /* delay before first display */ unsigned int watch_pid; /* process to watch fds of */ @@ -167,7 +167,7 @@ struct pvstate_s { int history_last; long double current_avg_rate; /* current average rate over last history intervals */ - size_t initial_offset; + off_t initial_offset; /*@only@*/ char *display_buffer; long display_buffer_size; int lastoutput_length; /* number of last-output bytes to show */ @@ -245,7 +245,7 @@ struct pvstate_s { * This way, we're treating each input file separately. */ int last_read_skip_fd; - size_t read_errors_in_a_row; + off_t read_errors_in_a_row; int read_error_warning_shown; #ifdef HAVE_SPLICE /* @@ -275,8 +275,8 @@ struct pvwatchfd_s { char display_name[PV_SIZEOF_DISPLAY_NAME]; /* name to show on progress bar */ struct stat sb_fd; /* stat of fd symlink */ struct stat sb_fd_link; /* lstat of fd symlink */ - size_t size; /* size of whole file, 0 if unknown */ - ssize_t position; /* position last seen at */ + off_t size; /* size of whole file, 0 if unknown */ + off_t position; /* position last seen at */ struct timespec start_time; /* time we started watching the fd */ }; typedef struct pvwatchfd_s *pvwatchfd_t; @@ -284,8 +284,8 @@ typedef struct pvwatchfd_s *pvwatchfd_t; void pv_error(pvstate_t, char *, ...); int pv_main_loop(pvstate_t); -void pv_display(pvstate_t, long double, ssize_t, ssize_t); -ssize_t pv_transfer(pvstate_t, int, bool *, bool *, size_t, long *); +void pv_display(pvstate_t, long double, off_t, off_t); +off_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); diff --git a/src/include/pv.h b/src/include/pv.h index 5450444..281320b 100644 --- a/src/include/pv.h +++ b/src/include/pv.h @@ -16,6 +16,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -51,9 +52,9 @@ extern double pv_getnum_d(const char *); extern unsigned int pv_getnum_ui(const char *); /* - * Return the given string converted to a size_t. + * Return the given string converted to an off_t. */ -extern size_t pv_getnum_size(const char *); +extern off_t pv_getnum_size(const char *); /* * Return zero if the given string is a number of the given type. NB an @@ -154,15 +155,15 @@ extern void pv_state_bits_set(pvstate_t, bool); extern void pv_state_null_terminated_lines_set(pvstate_t, bool); extern void pv_state_no_display_set(pvstate_t, bool); extern void pv_state_skip_errors_set(pvstate_t, unsigned int); -extern void pv_state_error_skip_block_set(pvstate_t, size_t); +extern void pv_state_error_skip_block_set(pvstate_t, off_t); extern void pv_state_stop_at_size_set(pvstate_t, bool); extern void pv_state_sync_after_write_set(pvstate_t, bool); extern void pv_state_direct_io_set(pvstate_t, bool); -extern void pv_state_rate_limit_set(pvstate_t, size_t); +extern void pv_state_rate_limit_set(pvstate_t, off_t); extern void pv_state_target_buffer_size_set(pvstate_t, size_t); extern void pv_state_no_splice_set(pvstate_t, bool); extern void pv_state_discard_input_set(pvstate_t, bool); -extern void pv_state_size_set(pvstate_t, size_t); +extern void pv_state_size_set(pvstate_t, off_t); extern void pv_state_interval_set(pvstate_t, double); extern void pv_state_width_set(pvstate_t, unsigned int, bool); extern void pv_state_height_set(pvstate_t, unsigned int, bool); @@ -187,7 +188,7 @@ extern void pv_screensize(unsigned int *width, unsigned int *height); /* * Calculate the total size of all input files. */ -extern size_t pv_calc_total_size(pvstate_t); +extern off_t pv_calc_total_size(pvstate_t); /* * Set up signal handlers ready for running the main loop. diff --git a/src/main/options.c b/src/main/options.c index 27d77bd..fd84628 100644 --- a/src/main/options.c +++ b/src/main/options.c @@ -376,7 +376,7 @@ opts_t opts_parse(unsigned int argc, char **argv) memset(&sb, 0, sizeof(sb)); rc = stat(size_file, &sb); if (0 == rc) { - opts->size = (size_t) (sb.st_size); + opts->size = (off_t) (sb.st_size); } else { /*@-mustfreefresh@ *//* see above */ fprintf(stderr, "%s: %s %s: %s\n", @@ -420,7 +420,7 @@ opts_t opts_parse(unsigned int argc, char **argv) opts->rate_limit = pv_getnum_size(optarg); break; case 'B': - opts->buffer_size = pv_getnum_size(optarg); + opts->buffer_size = (size_t) pv_getnum_size(optarg); opts->no_splice = true; break; case 'C': diff --git a/src/main/remote.c b/src/main/remote.c index 8cde960..9b6e108 100644 --- a/src/main/remote.c +++ b/src/main/remote.c @@ -36,9 +36,9 @@ struct remote_msg { bool bytes; /* bytes transferred flag */ bool bufpercent; /* transfer buffer percentage flag */ unsigned int lastwritten; /* last-written bytes count */ - size_t rate_limit; /* rate limit, in bytes per second */ + off_t rate_limit; /* rate limit, in bytes per second */ size_t buffer_size; /* buffer size, in bytes (0=default) */ - size_t size; /* total size of data */ + off_t size; /* total size of data */ double interval; /* interval between updates */ unsigned int width; /* screen width */ unsigned int height; /* screen height */ diff --git a/src/pv/display.c b/src/pv/display.c index f9685a5..c9f85e3 100644 --- a/src/pv/display.c +++ b/src/pv/display.c @@ -1107,7 +1107,7 @@ static const char *pv__format(pvstate_t state, * * In line mode, "sl" and "tot" are in lines, not bytes. */ -void pv_display(pvstate_t state, long double esec, ssize_t sl, ssize_t tot) +void pv_display(pvstate_t state, long double esec, off_t sl, off_t tot) { const char *display; diff --git a/src/pv/file.c b/src/pv/file.c index bfdbdc6..b976532 100644 --- a/src/pv/file.c +++ b/src/pv/file.c @@ -33,9 +33,9 @@ * * Returns the total size, or 0 if it is unknown. */ -static size_t pv_calc_total_bytes(pvstate_t state) +static off_t pv_calc_total_bytes(pvstate_t state) { - size_t total; + off_t total; struct stat sb; unsigned int file_idx; @@ -108,7 +108,7 @@ static size_t pv_calc_total_bytes(pvstate_t state) off_t end_position; end_position = lseek(fd, 0, SEEK_END); if (end_position > 0) { - total += (size_t) end_position; + total += end_position; } (void) close(fd); } else { @@ -141,7 +141,7 @@ static size_t pv_calc_total_bytes(pvstate_t state) end_position = lseek(STDOUT_FILENO, 0, SEEK_END); total = 0; if (end_position > 0) { - total = (size_t) end_position; + total = end_position; } if (lseek(STDOUT_FILENO, 0, SEEK_SET) != 0) { pv_error(state, "%s: %s: %s", "(stdout)", @@ -174,9 +174,9 @@ static size_t pv_calc_total_bytes(pvstate_t state) * * Returns the total size, or 0 if it is unknown. */ -static size_t pv_calc_total_lines(pvstate_t state) +static off_t pv_calc_total_lines(pvstate_t state) { - size_t total; + off_t total; struct stat sb; unsigned int file_idx; @@ -263,7 +263,7 @@ static size_t pv_calc_total_lines(pvstate_t state) * * Returns the total size, or 0 if it is unknown. */ -size_t pv_calc_total_size(pvstate_t state) +off_t pv_calc_total_size(pvstate_t state) { if (state->linemode) { return pv_calc_total_lines(state); diff --git a/src/pv/number.c b/src/pv/number.c index e613545..c6cebfc 100644 --- a/src/pv/number.c +++ b/src/pv/number.c @@ -24,12 +24,12 @@ static bool pv__isdigit(char c) /* - * Return the numeric value of "str", as a size_t. + * Return the numeric value of "str", as an off_t. */ -size_t pv_getnum_size(const char *str) +off_t pv_getnum_size(const char *str) { - size_t n = 0; - size_t decimal = 0; + off_t n = 0; + off_t decimal = 0; unsigned int decdivisor = 1; unsigned int shift = 0; @@ -41,7 +41,7 @@ size_t pv_getnum_size(const char *str) for (; pv__isdigit(str[0]); str++) { n = n * 10; - n += (size_t) (str[0] - '0'); + n += (off_t) (str[0] - '0'); } /* @@ -52,7 +52,7 @@ size_t pv_getnum_size(const char *str) for (; pv__isdigit(str[0]); str++) { if (decdivisor < 10000) { decimal = decimal * 10; - decimal += (size_t) (str[0] - '0'); + decimal += (off_t) (str[0] - '0'); decdivisor = decdivisor * 10; } } @@ -99,8 +99,8 @@ size_t pv_getnum_size(const char *str) if (shiftby > 30) shiftby = 30; - n = (size_t) (n << shiftby); - decimal = (size_t) (decimal << shiftby); + n = (off_t) (n << shiftby); + decimal = (off_t) (decimal << shiftby); shift -= shiftby; } diff --git a/src/pv/state.c b/src/pv/state.c index 40b8436..1b52b7c 100644 --- a/src/pv/state.c +++ b/src/pv/state.c @@ -246,7 +246,7 @@ void pv_state_skip_errors_set(pvstate_t state, unsigned int val) state->skip_errors = val; } -void pv_state_error_skip_block_set(pvstate_t state, size_t val) +void pv_state_error_skip_block_set(pvstate_t state, off_t val) { state->error_skip_block = val; } @@ -272,7 +272,7 @@ void pv_state_discard_input_set(pvstate_t state, bool val) state->discard_input = val; } -void pv_state_rate_limit_set(pvstate_t state, size_t val) +void pv_state_rate_limit_set(pvstate_t state, off_t val) { state->rate_limit = val; } @@ -287,7 +287,7 @@ void pv_state_no_splice_set(pvstate_t state, bool val) state->no_splice = val; } -void pv_state_size_set(pvstate_t state, size_t val) +void pv_state_size_set(pvstate_t state, off_t val) { state->size = val; } diff --git a/src/pv/transfer.c b/src/pv/transfer.c index 3c7dad3..0c650ef 100644 --- a/src/pv/transfer.c +++ b/src/pv/transfer.c @@ -784,7 +784,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. */ -ssize_t pv_transfer(pvstate_t state, int fd, bool *eof_in, bool *eof_out, size_t allowed, long *lineswritten) +off_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;