Use off_t for file sizes, size_t for buffer sizes.

This commit is contained in:
Andrew Wood
2023-09-13 23:17:53 +01:00
parent 304b87503e
commit 153285bec0
10 changed files with 47 additions and 45 deletions
+4 -3
View File
@@ -14,6 +14,7 @@
#endif
#include <stdlib.h>
#include <sys/types.h>
#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 */
+12 -12
View File
@@ -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);
+7 -6
View File
@@ -16,6 +16,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <sys/types.h>
#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.