From 943c05a8a04dedbcf0752fd976f2db06b1ab69ed Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Sat, 29 Jul 2023 22:21:32 +0100 Subject: [PATCH] Reformatted with "indent" to a line length of 120. --- src/library/getopt.c | 6 +- src/main/debug.c | 6 +- src/main/main.c | 48 +++---- src/main/options.c | 66 +++------ src/main/remote.c | 30 ++--- src/pv/cursor.c | 52 +++----- src/pv/display.c | 312 +++++++++++++------------------------------ src/pv/file.c | 43 ++---- src/pv/loop.c | 162 +++++++--------------- src/pv/number.c | 3 +- src/pv/signal.c | 6 +- src/pv/state.c | 16 +-- src/pv/string.c | 3 +- src/pv/transfer.c | 192 +++++++------------------- src/pv/watchpid.c | 124 +++++------------ 15 files changed, 309 insertions(+), 760 deletions(-) diff --git a/src/library/getopt.c b/src/library/getopt.c index c714ed2..d090c80 100644 --- a/src/library/getopt.c +++ b/src/library/getopt.c @@ -72,8 +72,7 @@ int minigetopt(int argc, char **argv, char *optstring) if (0 == optstring[i]) { minioptopt = optchar; if (miniopterr) - fprintf(stderr, "%s: invalid option -- %c\n", - argv[0], optchar); + fprintf(stderr, "%s: invalid option -- %c\n", argv[0], optchar); return '?'; } @@ -103,8 +102,7 @@ int minigetopt(int argc, char **argv, char *optstring) nextchar = 0; minioptind++; if (minioptind >= argc) { - fprintf(stderr, "%s: option `-%c' requires an argument\n", - argv[0], optchar); + fprintf(stderr, "%s: option `-%c' requires an argument\n", argv[0], optchar); return ':'; } minioptarg = argv[minioptind++]; diff --git a/src/main/debug.c b/src/main/debug.c index 1aaa3e5..de2960b 100644 --- a/src/main/debug.c +++ b/src/main/debug.c @@ -33,8 +33,7 @@ void debugging_output_destination(const char *filename) * Output debugging information to the file specified earlier by a call to * debugging_output_destination(), if any. */ -void debugging_output(const char *function, const char *file, int line, - const char *format, ...) +void debugging_output(const char *function, const char *file, int line, const char *format, ...) { static bool tried_open = false; static FILE *debugfptr = NULL; @@ -72,8 +71,7 @@ void debugging_output(const char *function, const char *file, int line, } tbuf[sizeof(tbuf) - 1] = '\0'; /* enforce termination */ - (void) fprintf(debugfptr, "[%s] (%d) %s (%s:%d): ", tbuf, getpid(), - function, file, line); + (void) fprintf(debugfptr, "[%s] (%d) %s (%s:%d): ", tbuf, getpid(), function, file, line); va_start(ap, format); (void) vfprintf(debugfptr, format, ap); /* flawfinder: ignore */ diff --git a/src/main/main.c b/src/main/main.c index 7f51c6a..06b9dbd 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -72,8 +72,7 @@ int main(int argc, char **argv) */ state = pv_state_alloc(opts->program_name); if (NULL == state) { - fprintf(stderr, "%s: %s: %s\n", opts->program_name, - _("state allocation failed"), strerror(errno)); + fprintf(stderr, "%s: %s: %s\n", opts->program_name, _("state allocation failed"), strerror(errno)); opts_free(opts); debug("%s: %d", "exiting with status", 64); return 64; @@ -86,16 +85,14 @@ int main(int argc, char **argv) FILE *pidfptr; pidfptr = fopen(opts->pidfile, "w"); if (NULL == pidfptr) { - fprintf(stderr, "%s: %s: %s\n", opts->program_name, - opts->pidfile, strerror(errno)); + fprintf(stderr, "%s: %s: %s\n", opts->program_name, opts->pidfile, strerror(errno)); pv_state_free(state); opts_free(opts); return 1; } fprintf(pidfptr, "%d\n", getpid()); if (0 != fclose(pidfptr)) { - fprintf(stderr, "%s: %s: %s\n", opts->program_name, - opts->pidfile, strerror(errno)); + fprintf(stderr, "%s: %s: %s\n", opts->program_name, opts->pidfile, strerror(errno)); } } @@ -110,8 +107,7 @@ int main(int argc, char **argv) /* * Put our list of files into the PV internal state. */ - pv_state_inputfiles(state, opts->argc, - (const char **) (opts->argv)); + pv_state_inputfiles(state, opts->argc, (const char **) (opts->argv)); if (0 == opts->watch_pid) { /* @@ -120,8 +116,7 @@ int main(int argc, char **argv) */ if ((0 == opts->size) && (false == opts->linemode)) { opts->size = pv_calc_total_size(state); - debug("%s: %llu", "no size given - calculated", - opts->size); + debug("%s: %llu", "no size given - calculated", opts->size); } /* @@ -154,13 +149,11 @@ int main(int argc, char **argv) pv_screensize(&width, &height); if (0 == opts->width) { opts->width = width; - debug("%s: %u", "auto-detected terminal width", - width); + debug("%s: %u", "auto-detected terminal width", width); } if (0 == opts->height) { opts->height = height; - debug("%s: %u", "auto-detected terminal height", - height); + debug("%s: %u", "auto-detected terminal height", height); } } @@ -215,8 +208,7 @@ int main(int argc, char **argv) pv_state_set_format(state, opts->progress, opts->timer, opts->eta, opts->fineta, opts->rate, opts->average_rate, - opts->bytes, opts->bufpercent, - opts->lastwritten, opts->name); + opts->bytes, opts->bufpercent, opts->lastwritten, opts->name); #ifdef MAKE_STDOUT_NONBLOCKING /* @@ -225,8 +217,7 @@ int main(int argc, char **argv) * Note that this can cause problems with (broken) applications * such as dd. */ - fcntl(STDOUT_FILENO, F_SETFL, - O_NONBLOCK | fcntl(STDOUT_FILENO, F_GETFL)); + fcntl(STDOUT_FILENO, F_SETFL, O_NONBLOCK | fcntl(STDOUT_FILENO, F_GETFL)); #endif /* MAKE_STDOUT_NONBLOCKING */ /* @@ -249,8 +240,7 @@ int main(int argc, char **argv) t_saved = true; } else { fprintf(stderr, "%s: %s: %s\n", opts->program_name, - _("failed to read terminal attributes"), - strerror(errno)); + _("failed to read terminal attributes"), strerror(errno)); } } t_save = t; @@ -266,15 +256,12 @@ int main(int argc, char **argv) pv_sig_init(state); retcode = pv_watchfd_loop(state); if (t_needs_reset && pv_in_foreground()) { - (void) tcsetattr(STDERR_FILENO, TCSANOW, - &t_save); + (void) tcsetattr(STDERR_FILENO, TCSANOW, &t_save); } if (opts->pidfile != NULL) { if (0 != remove(opts->pidfile)) { fprintf(stderr, "%s: %s: %s\n", - opts->program_name, - opts->pidfile, - strerror(errno)); + opts->program_name, opts->pidfile, strerror(errno)); } } pv_sig_fini(state); @@ -282,15 +269,12 @@ int main(int argc, char **argv) pv_sig_init(state); retcode = pv_watchpid_loop(state); if (t_needs_reset && pv_in_foreground()) { - (void) tcsetattr(STDERR_FILENO, TCSANOW, - &t_save); + (void) tcsetattr(STDERR_FILENO, TCSANOW, &t_save); } if (opts->pidfile != NULL) { if (0 != remove(opts->pidfile)) { fprintf(stderr, "%s: %s: %s\n", - opts->program_name, - opts->pidfile, - strerror(errno)); + opts->program_name, opts->pidfile, strerror(errno)); } } pv_sig_fini(state); @@ -305,9 +289,7 @@ int main(int argc, char **argv) } if (opts->pidfile != NULL) { if (0 != remove(opts->pidfile)) { - fprintf(stderr, "%s: %s: %s\n", - opts->program_name, opts->pidfile, - strerror(errno)); + fprintf(stderr, "%s: %s: %s\n", opts->program_name, opts->pidfile, strerror(errno)); } } pv_sig_fini(state); diff --git a/src/main/options.c b/src/main/options.c index 9adc644..90bb42c 100644 --- a/src/main/options.c +++ b/src/main/options.c @@ -95,8 +95,7 @@ opts_t opts_parse(int argc, char **argv) }; int option_index = 0; #endif /* HAVE_GETOPT_LONG */ - char *short_options = - "hVpteIrab8TA:fnqcWD:s:l0i:w:H:N:F:L:B:CESYKR:P:d:m:" + char *short_options = "hVpteIrab8TA:fnqcWD:s:l0i:w:H:N:F:L:B:CESYKR:P:d:m:" #ifdef ENABLE_DEBUGGING "!:" #endif @@ -109,9 +108,7 @@ opts_t opts_parse(int argc, char **argv) opts = calloc(1, sizeof(*opts)); if (!opts) { - fprintf(stderr, "%s: %s: %s\n", argv[0], - _("option structure allocation failed"), - strerror(errno)); + fprintf(stderr, "%s: %s: %s\n", argv[0], _("option structure allocation failed"), strerror(errno)); return NULL; } @@ -124,8 +121,7 @@ opts_t opts_parse(int argc, char **argv) opts->argv = calloc((size_t) (argc + 1), sizeof(char *)); if (NULL == opts->argv) { fprintf(stderr, "%s: %s: %s\n", opts->program_name, - _("option structure argv allocation failed"), - strerror(errno)); + _("option structure argv allocation failed"), strerror(errno)); opts_free(opts); return NULL; } @@ -140,9 +136,7 @@ opts_t opts_parse(int argc, char **argv) do { #ifdef HAVE_GETOPT_LONG - c = getopt_long(argc, argv, - short_options, long_options, - &option_index); + c = getopt_long(argc, argv, short_options, long_options, &option_index); #else c = getopt(argc, argv, short_options); #endif @@ -165,22 +159,16 @@ opts_t opts_parse(int argc, char **argv) case 'B': case 'R': case 'm': - if (pv_getnum_check(optarg, PV_NUMTYPE_INTEGER) != - 0) { - fprintf(stderr, "%s: -%c: %s\n", - opts->program_name, c, - _("integer argument expected")); + if (pv_getnum_check(optarg, PV_NUMTYPE_INTEGER) != 0) { + fprintf(stderr, "%s: -%c: %s\n", opts->program_name, c, _("integer argument expected")); opts_free(opts); return NULL; } break; case 'i': case 'D': - if (pv_getnum_check(optarg, PV_NUMTYPE_DOUBLE) != - 0) { - fprintf(stderr, "%s: -%c: %s\n", - opts->program_name, c, - _("numeric argument expected")); + if (pv_getnum_check(optarg, PV_NUMTYPE_DOUBLE) != 0) { + fprintf(stderr, "%s: -%c: %s\n", opts->program_name, c, _("numeric argument expected")); opts_free(opts); return NULL; } @@ -189,16 +177,12 @@ opts_t opts_parse(int argc, char **argv) if (sscanf(optarg, "%u:%d", &check_pid, &check_fd) < 1) { fprintf(stderr, "%s: -%c: %s\n", - opts->program_name, c, - _ - ("process ID or pid:fd pair expected")); + opts->program_name, c, _("process ID or pid:fd pair expected")); opts_free(opts); return NULL; } if (check_pid < 1) { - fprintf(stderr, "%s: -%c: %s\n", - opts->program_name, c, - _("invalid process ID")); + fprintf(stderr, "%s: -%c: %s\n", opts->program_name, c, _("invalid process ID")); opts_free(opts); return NULL; } @@ -297,9 +281,7 @@ opts_t opts_parse(int argc, char **argv) } else { fprintf(stderr, "%s: %s %s: %s\n", opts->program_name, - _("failed to stat file"), - size_file, - strerror(errno)); + _("failed to stat file"), size_file, strerror(errno)); opts_free(opts); return NULL; } @@ -361,8 +343,7 @@ opts_t opts_parse(int argc, char **argv) opts->watch_pid = 0; opts->watch_fd = -1; /* No syntax check here, already done earlier */ - (void) sscanf(optarg, "%u:%d", &(opts->watch_pid), - &(opts->watch_fd)); + (void) sscanf(optarg, "%u:%d", &(opts->watch_pid), &(opts->watch_fd)); break; case 'm': opts->average_rate_window = pv_getnum_ui(optarg); @@ -374,13 +355,9 @@ opts_t opts_parse(int argc, char **argv) #endif /* ENABLE_DEBUGGING */ default: #ifdef HAVE_GETOPT_LONG - fprintf(stderr, - _("Try `%s --help' for more information."), - opts->program_name); + fprintf(stderr, _("Try `%s --help' for more information."), opts->program_name); #else - fprintf(stderr, - _("Try `%s -h' for more information."), - opts->program_name); + fprintf(stderr, _("Try `%s -h' for more information."), opts->program_name); #endif fprintf(stderr, "\n"); opts_free(opts); @@ -394,40 +371,35 @@ opts_t opts_parse(int argc, char **argv) || (opts->skip_errors > 0) || (opts->buffer_size > 0) || (opts->rate_limit > 0)) { fprintf(stderr, "%s: %s\n", opts->program_name, - _ - ("cannot use line mode or transfer modifier options when watching file descriptors")); + _("cannot use line mode or transfer modifier options when watching file descriptors")); opts_free(opts); return NULL; } if (opts->cursor) { fprintf(stderr, "%s: %s\n", opts->program_name, - _ - ("cannot use cursor positioning when watching file descriptors")); + _("cannot use cursor positioning when watching file descriptors")); opts_free(opts); return NULL; } if (0 != opts->remote) { fprintf(stderr, "%s: %s\n", opts->program_name, - _ - ("cannot use remote control when watching file descriptors")); + _("cannot use remote control when watching file descriptors")); opts_free(opts); return NULL; } if (optind < argc) { fprintf(stderr, "%s: %s\n", opts->program_name, - _ - ("cannot transfer files when watching file descriptors")); + _("cannot transfer files when watching file descriptors")); opts_free(opts); return NULL; } #ifndef __APPLE__ if (0 != access("/proc/self/fdinfo", X_OK)) { fprintf(stderr, "%s: -d: %s\n", opts->program_name, - _ - ("not available on systems without /proc/self/fdinfo")); + _("not available on systems without /proc/self/fdinfo")); opts_free(opts); return NULL; } diff --git a/src/main/remote.c b/src/main/remote.c index 51793ab..df90995 100644 --- a/src/main/remote.c +++ b/src/main/remote.c @@ -103,8 +103,7 @@ int pv_remote_set(opts_t opts) * Check that the remote process exists. */ if (kill((pid_t) (opts->remote), 0) != 0) { - fprintf(stderr, "%s: %u: %s\n", opts->program_name, - opts->remote, strerror(errno)); + fprintf(stderr, "%s: %u: %s\n", opts->program_name, opts->remote, strerror(errno)); return 1; } @@ -148,29 +147,25 @@ int pv_remote_set(opts_t opts) strncpy(msgbuf.name, opts->name, sizeof(msgbuf.name) - 1); } if (opts->format != NULL) { - strncpy(msgbuf.format, opts->format, - sizeof(msgbuf.format) - 1); + strncpy(msgbuf.format, opts->format, sizeof(msgbuf.format) - 1); } msgid = remote__msgget(); if (msgid < 0) { - fprintf(stderr, "%s: %s\n", opts->program_name, - strerror(errno)); + fprintf(stderr, "%s: %s\n", opts->program_name, strerror(errno)); return 1; } memset(&qbuf, 0, sizeof(qbuf)); if (msgctl(msgid, IPC_STAT, &qbuf) < 0) { - fprintf(stderr, "%s: %s\n", opts->program_name, - strerror(errno)); + fprintf(stderr, "%s: %s\n", opts->program_name, strerror(errno)); return 1; } initial_qnum = qbuf.msg_qnum; if (msgsnd(msgid, &msgbuf, sizeof(msgbuf) - sizeof(long), 0) != 0) { - fprintf(stderr, "%s: %s\n", opts->program_name, - strerror(errno)); + fprintf(stderr, "%s: %s\n", opts->program_name, strerror(errno)); return 1; } @@ -206,9 +201,7 @@ int pv_remote_set(opts_t opts) */ memset(&qbuf, 0, sizeof(qbuf)); if (msgctl(msgid, IPC_STAT, &qbuf) >= 0) { - (void) msgrcv(msgid, &msgbuf, - sizeof(msgbuf) - sizeof(long), - (long) (opts->remote), IPC_NOWAIT); + (void) msgrcv(msgid, &msgbuf, sizeof(msgbuf) - sizeof(long), (long) (opts->remote), IPC_NOWAIT); /* * If this leaves nothing on the queue, remove the * queue, in case we created one for no reason. @@ -219,8 +212,7 @@ int pv_remote_set(opts_t opts) } } - fprintf(stderr, "%s: %u: %s\n", opts->program_name, opts->remote, - _("message not received")); + fprintf(stderr, "%s: %u: %s\n", opts->program_name, opts->remote, _("message not received")); return 1; } @@ -242,9 +234,7 @@ void pv_remote_check(pvstate_t state) memset(&msgbuf, 0, sizeof(msgbuf)); - got = - msgrcv(remote__msgid, &msgbuf, sizeof(msgbuf) - sizeof(long), - getpid(), IPC_NOWAIT); + got = msgrcv(remote__msgid, &msgbuf, sizeof(msgbuf) - sizeof(long), getpid(), IPC_NOWAIT); if (got < 0) { /* * If our queue had been deleted, re-create it. @@ -265,9 +255,7 @@ void pv_remote_check(pvstate_t state) msgbuf.eta, msgbuf.fineta, msgbuf.rate, msgbuf.average_rate, msgbuf.bytes, msgbuf.bufpercent, - msgbuf.lastwritten, - '\0' == - msgbuf.name[0] ? NULL : strdup(msgbuf.name)); + msgbuf.lastwritten, '\0' == msgbuf.name[0] ? NULL : strdup(msgbuf.name)); if (msgbuf.rate_limit > 0) pv_state_rate_limit_set(state, msgbuf.rate_limit); diff --git a/src/pv/cursor.c b/src/pv/cursor.c index 43c8633..6d0e3a2 100644 --- a/src/pv/cursor.c +++ b/src/pv/cursor.c @@ -82,17 +82,14 @@ static void pv_crs_open_lockfile(pvstate_t state, int fd) ttydev = ttyname(fd); if (!ttydev) { if (!state->force) { - pv_error(state, "%s: %s", - _("failed to get terminal name"), - strerror(errno)); + pv_error(state, "%s: %s", _("failed to get terminal name"), strerror(errno)); } /* * If we don't know our terminal name, we can neither do IPC * nor make a lock file, so turn off cursor positioning. */ state->cursor = 0; - debug("%s", - "ttyname failed - cursor positioning disabled"); + debug("%s", "ttyname failed - cursor positioning disabled"); return; } @@ -104,9 +101,7 @@ static void pv_crs_open_lockfile(pvstate_t state, int fd) memset(state->crs_lock_file, 0, PV_SIZEOF_CRS_LOCK_FILE); (void) pv_snprintf(state->crs_lock_file, - PV_SIZEOF_CRS_LOCK_FILE, - "%s/pv-%s-%i.lock", tmpdir, basename(ttydev), - (int) geteuid()); + PV_SIZEOF_CRS_LOCK_FILE, "%s/pv-%s-%i.lock", tmpdir, basename(ttydev), (int) geteuid()); /* * Pawel Piatek - not everyone has O_NOFOLLOW, e.g. AIX doesn't @@ -119,9 +114,7 @@ static void pv_crs_open_lockfile(pvstate_t state, int fd) state->crs_lock_fd = open(state->crs_lock_file, openflags, 0600); if (state->crs_lock_fd < 0) { - pv_error(state, "%s: %s: %s", - state->crs_lock_file, - _("failed to open lock file"), strerror(errno)); + pv_error(state, "%s: %s: %s", state->crs_lock_file, _("failed to open lock file"), strerror(errno)); state->cursor = 0; return; } @@ -154,17 +147,14 @@ static void pv_crs_lock(pvstate_t state, int fd) lock_fd = state->crs_lock_fd; } } else { - pv_error(state, "%s: %s", - _("lock attempt failed"), - strerror(errno)); + pv_error(state, "%s: %s", _("lock attempt failed"), strerror(errno)); return; } } } if (state->crs_lock_fd >= 0) { - debug("%s: %s", state->crs_lock_file, - "terminal lockfile acquired"); + debug("%s: %s", state->crs_lock_file, "terminal lockfile acquired"); } else { debug("%s", "terminal lock acquired"); } @@ -192,8 +182,7 @@ static void pv_crs_unlock(pvstate_t state, int fd) (void) fcntl(lock_fd, F_SETLK, &lock); if (state->crs_lock_fd >= 0) { - debug("%s: %s", state->crs_lock_file, - "terminal lockfile released"); + debug("%s: %s", state->crs_lock_file, "terminal lockfile released"); } else { debug("%s", "terminal lock released"); } @@ -269,8 +258,7 @@ static int pv_crs_get_ypos(int terminalfd) debug ("read answerback message from fd %d, length %d - buf = %02X %02X %02X %02X %02X %02X", - terminalfd, got, cpr[0], cpr[1], cpr[2], cpr[3], cpr[4], - cpr[5]); + terminalfd, got, cpr[0], cpr[1], cpr[2], cpr[3], cpr[4], cpr[5]); #else /* !CURSOR_ANSWERBACK_BYTE_BY_BYTE */ /* Read answerback in one big lump - may fail on Solaris */ @@ -280,8 +268,7 @@ static int pv_crs_get_ypos(int terminalfd) } else { debug ("read answerback message from fd %d, length %d - buf = %02X %02X %02X %02X %02X %02X", - terminalfd, r, cpr[0], cpr[1], cpr[2], cpr[3], cpr[4], - cpr[5]); + terminalfd, r, cpr[0], cpr[1], cpr[2], cpr[3], cpr[4], cpr[5]); } #endif /* CURSOR_ANSWERBACK_BYTE_BY_BYTE */ @@ -366,8 +353,7 @@ static int pv_crs_ipcinit(pvstate_t state, char *ttyfile, int terminalfd) if (state->crs_pvcount > 1) { state->crs_y_start = *(state->crs_y_top); state->crs_y_lastread = state->crs_y_start; - debug("%s: %d", "not the first to attach - got top y", - state->crs_y_start); + debug("%s: %d", "not the first to attach - got top y", state->crs_y_start); } pv_crs_unlock(state, terminalfd); @@ -395,18 +381,14 @@ void pv_crs_init(pvstate_t state) ttyfile = ttyname(STDERR_FILENO); if (!ttyfile) { - debug("%s: %s", - "disabling cursor positioning because ttyname failed", - strerror(errno)); + debug("%s: %s", "disabling cursor positioning because ttyname failed", strerror(errno)); state->cursor = 0; return; } fd = open(ttyfile, O_RDWR); if (fd < 0) { - pv_error(state, "%s: %s: %s", - _("failed to open terminal"), ttyfile, - strerror(errno)); + pv_error(state, "%s: %s: %s", _("failed to open terminal"), ttyfile, strerror(errno)); state->cursor = false; return; } @@ -527,15 +509,12 @@ void pv_crs_update(pvstate_t state, const char *str) * scroll the screen (only if we're the first `pv'), and then move * our initial Y co-ordinate up. */ - if (((state->crs_y_start + state->crs_pvmax) > - (int) (state->height)) + if (((state->crs_y_start + state->crs_pvmax) > (int) (state->height)) && (!state->crs_noipc) ) { int offs; - offs = - ((state->crs_y_start + state->crs_pvmax) - - state->height); + offs = ((state->crs_y_start + state->crs_pvmax) - state->height); state->crs_y_start -= offs; if (state->crs_y_start < 1) @@ -550,8 +529,7 @@ void pv_crs_update(pvstate_t state, const char *str) pv_crs_lock(state, STDERR_FILENO); memset(pos, 0, sizeof(pos)); - (void) pv_snprintf(pos, sizeof(pos), "\033[%u;1H", - state->height); + (void) pv_snprintf(pos, sizeof(pos), "\033[%u;1H", state->height); pv_write_retry(STDERR_FILENO, pos, strlen(pos)); for (; offs > 0; offs--) { pv_write_retry(STDERR_FILENO, "\n", 1); diff --git a/src/pv/display.c b/src/pv/display.c index e73f64d..c8f03b4 100644 --- a/src/pv/display.c +++ b/src/pv/display.c @@ -64,14 +64,12 @@ bool pv_in_foreground(void) tty_process_group = tcgetpgrp(STDERR_FILENO); if (tty_process_group == -1 && errno == ENOTTY) { - debug("%s: true: %s", "pv_in_foreground", - "tty_process_group is -1, errno is ENOTTY"); + debug("%s: true: %s", "pv_in_foreground", "tty_process_group is -1, errno is ENOTTY"); return true; } if (our_process_group == tty_process_group) { - debug("%s: true: %s", "pv_in_foreground", - "our_process_group == tty_process_group"); + debug("%s: true: %s", "pv_in_foreground", "our_process_group == tty_process_group"); return true; } @@ -121,8 +119,7 @@ static long pv__calc_percentage(long long so_far, const long long total) * transfer, and how long it's taken so far in seconds, return the estimated * number of seconds until completion. */ -static long pv__calc_eta(const long long so_far, const long long total, - const long rate) +static long pv__calc_eta(const long long so_far, const long long total, const long rate) { long long amount_left; @@ -147,8 +144,7 @@ static long pv__calc_eta(const long long so_far, const long long total, * modified. Further changed after input from Thomas Rachel; changed still * further after Debian bug #706175. */ -static void pv__si_prefix(long double *value, char *prefix, - const long double ratio, int is_bytes) +static void pv__si_prefix(long double *value, char *prefix, const long double ratio, int is_bytes) { static char *pfx_000 = NULL; /* kilo, mega, etc */ static char *pfx_024 = NULL; /* kibi, mibi, etc */ @@ -231,8 +227,7 @@ static void pv__si_prefix(long double *value, char *prefix, * parameter (a %s) which will expand to the string described above. */ static void pv__sizestr(char *buffer, int bufsize, char *format, - long double amount, char *suffix_basic, - char *suffix_bytes, int is_bytes) + long double amount, char *suffix_basic, char *suffix_bytes, int is_bytes) { char sizestr_buffer[256]; char si_prefix[8]; @@ -261,8 +256,7 @@ static void pv__sizestr(char *buffer, int bufsize, char *format, /* Fix for display of "1.01e+03" instead of "1010" */ if (display_amount > 99.9) { (void) pv_snprintf(sizestr_buffer, sizeof(sizestr_buffer), - "%4ld%.2s%.16s", (long) display_amount, - si_prefix, suffix); + "%4ld%.2s%.16s", (long) display_amount, si_prefix, suffix); } else { /* * AIX blows up with %4.3Lg%.2s%.16s for some reason, so we @@ -270,11 +264,8 @@ static void pv__sizestr(char *buffer, int bufsize, char *format, */ char str_disp[64]; /* # to get 13.0GB instead of 13GB (#1477) */ - (void) pv_snprintf(str_disp, sizeof(str_disp), "%#4.3Lg", - display_amount); - (void) pv_snprintf(sizestr_buffer, sizeof(sizestr_buffer), - "%s%.2s%.16s", str_disp, si_prefix, - suffix); + (void) pv_snprintf(str_disp, sizeof(str_disp), "%#4.3Lg", display_amount); + (void) pv_snprintf(sizestr_buffer, sizeof(sizestr_buffer), "%s%.2s%.16s", str_disp, si_prefix, suffix); } (void) pv_snprintf(buffer, bufsize, format, sizestr_buffer); @@ -301,18 +292,13 @@ static void pv__format_init(pvstate_t state) state->str_average_rate[0] = 0; state->str_progress[0] = 0; state->str_eta[0] = 0; - memset(state->format, 0, - PV_FORMAT_ARRAY_MAX * sizeof(state->format[0])); + memset(state->format, 0, PV_FORMAT_ARRAY_MAX * sizeof(state->format[0])); if (state->name) { - (void) pv_snprintf(state->str_name, - PV_SIZEOF_STR_NAME, "%9.500s:", - state->name); + (void) pv_snprintf(state->str_name, PV_SIZEOF_STR_NAME, "%9.500s:", state->name); } - formatstr = - state->format_string ? state-> - format_string : state->default_format; + formatstr = state->format_string ? state->format_string : state->default_format; state->components_used = 0; @@ -338,8 +324,7 @@ static void pv__format_init(pvstate_t state) * these segments together. */ segment = 0; - for (strpos = 0; formatstr[strpos] != 0 && segment < 99; - strpos++, segment++) { + for (strpos = 0; formatstr[strpos] != 0 && segment < 99; strpos++, segment++) { if ('%' == formatstr[strpos]) { unsigned int num; strpos++; @@ -351,92 +336,73 @@ static void pv__format_init(pvstate_t state) } switch (formatstr[strpos]) { case 'p': - state->format[segment].string = - state->str_progress; + state->format[segment].string = state->str_progress; state->format[segment].length = -1; - state->components_used |= - PV_DISPLAY_PROGRESS; + state->components_used |= PV_DISPLAY_PROGRESS; break; case 't': - state->format[segment].string = - state->str_timer; + state->format[segment].string = state->str_timer; state->format[segment].length = 0; state->components_used |= PV_DISPLAY_TIMER; break; case 'e': - state->format[segment].string = - state->str_eta; + state->format[segment].string = state->str_eta; state->format[segment].length = 0; state->components_used |= PV_DISPLAY_ETA; break; case 'I': - state->format[segment].string = - state->str_fineta; + state->format[segment].string = state->str_fineta; state->format[segment].length = 0; - state->components_used |= - PV_DISPLAY_FINETA; + state->components_used |= PV_DISPLAY_FINETA; break; case 'A': - state->format[segment].string = - state->str_lastoutput; + state->format[segment].string = state->str_lastoutput; state->format[segment].length = 0; if (num > PV_SIZEOF_LASTOUTPUT_BUFFER) num = PV_SIZEOF_LASTOUTPUT_BUFFER; if (num < 1) num = 1; state->lastoutput_length = num; - state->components_used |= - PV_DISPLAY_OUTPUTBUF; + state->components_used |= PV_DISPLAY_OUTPUTBUF; break; case 'r': - state->format[segment].string = - state->str_rate; + state->format[segment].string = state->str_rate; state->format[segment].length = 0; state->components_used |= PV_DISPLAY_RATE; break; case 'a': - state->format[segment].string = - state->str_average_rate; + state->format[segment].string = state->str_average_rate; state->format[segment].length = 0; - state->components_used |= - PV_DISPLAY_AVERAGERATE; + state->components_used |= PV_DISPLAY_AVERAGERATE; break; case 'b': - state->format[segment].string = - state->str_transferred; + state->format[segment].string = state->str_transferred; state->format[segment].length = 0; state->components_used |= PV_DISPLAY_BYTES; break; case 'T': - state->format[segment].string = - state->str_bufpercent; + state->format[segment].string = state->str_bufpercent; state->format[segment].length = 0; - state->components_used |= - PV_DISPLAY_BUFPERCENT; + state->components_used |= PV_DISPLAY_BUFPERCENT; break; case 'N': - state->format[segment].string = - state->str_name; - state->format[segment].length = - strlen(state->str_name); + state->format[segment].string = state->str_name; + state->format[segment].length = strlen(state->str_name); state->components_used |= PV_DISPLAY_NAME; break; case '%': /* %% => % */ - state->format[segment].string = - &(formatstr[strpos]); + state->format[segment].string = &(formatstr[strpos]); state->format[segment].length = 1; break; case 0: /* % at end => just % */ - state->format[segment].string = - &(formatstr[--strpos]); + state->format[segment].string = &(formatstr[--strpos]); state->format[segment].length = 1; break; default: /* %z (unknown) => %z */ - state->format[segment].string = - &(formatstr[--strpos]); + state->format[segment].string = &(formatstr[--strpos]); state->format[segment].length = 2; strpos++; break; @@ -447,11 +413,9 @@ static void pv__format_init(pvstate_t state) if (NULL == searchptr) { foundlength = strlen(&(formatstr[strpos])); } else { - foundlength = - searchptr - &(formatstr[strpos]); + foundlength = searchptr - &(formatstr[strpos]); } - state->format[segment].string = - &(formatstr[strpos]); + state->format[segment].string = &(formatstr[strpos]); state->format[segment].length = foundlength; strpos += foundlength - 1; } @@ -471,9 +435,7 @@ static long bound_long(long x, long min, long max) } /* Update history and current average rate */ -static void update_history_avg_rate(pvstate_t state, long long total_bytes, - long double elapsed_sec, - long double rate) +static void update_history_avg_rate(pvstate_t state, long long total_bytes, long double elapsed_sec, long double rate) { int first = state->history_first; int last = state->history_last; @@ -509,10 +471,8 @@ static void update_history_avg_rate(pvstate_t state, long long total_bytes, if (first == last) { state->current_avg_rate = rate; } else { - long long bytes = (state->history[last].total_bytes - - state->history[first].total_bytes); - long double sec = (state->history[last].elapsed_sec - - state->history[first].elapsed_sec); + long long bytes = (state->history[last].total_bytes - state->history[first].total_bytes); + long double sec = (state->history[last].elapsed_sec - state->history[first].elapsed_sec); state->current_avg_rate = bytes / sec; } } @@ -535,9 +495,7 @@ static void update_history_avg_rate(pvstate_t state, long long total_bytes, * NULL. */ static const char *pv__format(pvstate_t state, - long double elapsed_sec, - long long bytes_since_last, - long long total_bytes) + long double elapsed_sec, long long bytes_since_last, long long total_bytes) { long double time_since_last, rate, average_rate; long eta; @@ -569,9 +527,7 @@ static const char *pv__format(pvstate_t state, rate = state->prev_rate; state->prev_trans += bytes_since_last; } else { - rate = - ((long double) bytes_since_last + - state->prev_trans) / time_since_last; + rate = ((long double) bytes_since_last + state->prev_trans) / time_since_last; state->prev_elapsed_sec = elapsed_sec; state->prev_trans = 0; } @@ -591,9 +547,7 @@ static const char *pv__format(pvstate_t state, if (elapsed_sec < 0.000001) elapsed_sec = 0.000001; average_rate = - (((long double) total_bytes) - - ((long double) state->initial_offset)) / - (long double) elapsed_sec; + (((long double) total_bytes) - ((long double) state->initial_offset)) / (long double) elapsed_sec; rate = average_rate; } @@ -610,23 +564,19 @@ static const char *pv__format(pvstate_t state, state->percentage += 2; if (state->percentage > 199) state->percentage = 0; - } else if (state->numeric - || ((state->components_used & PV_DISPLAY_PROGRESS) != - 0)) { + } else if (state->numeric || ((state->components_used & PV_DISPLAY_PROGRESS) != 0)) { /* * If we do know the total size, and we're going to show * the percentage (numeric mode or a progress bar), * calculate the percentage completion. */ - state->percentage = - pv__calc_percentage(total_bytes, state->size); + state->percentage = pv__calc_percentage(total_bytes, state->size); } /* * Reallocate output buffer if width changes. */ - if (state->display_buffer != NULL - && state->display_buffer_size < (state->width * 2)) { + if (state->display_buffer != NULL && state->display_buffer_size < (state->width * 2)) { free(state->display_buffer); state->display_buffer = NULL; state->display_buffer_size = 0; @@ -639,12 +589,9 @@ static const char *pv__format(pvstate_t state, state->display_buffer_size = (2 * state->width) + 80; if (state->name) state->display_buffer_size += strlen(state->name); - state->display_buffer = - malloc(state->display_buffer_size + 16); + state->display_buffer = malloc(state->display_buffer_size + 16); if (NULL == state->display_buffer) { - pv_error(state, "%s: %s", - _("buffer allocation failed"), - strerror(errno)); + pv_error(state, "%s: %s", _("buffer allocation failed"), strerror(errno)); state->exit_status |= 64; return NULL; } @@ -665,29 +612,21 @@ static const char *pv__format(pvstate_t state, numericprefix[0] = 0; if ((state->components_used & PV_DISPLAY_TIMER) != 0) - (void) pv_snprintf(numericprefix, - sizeof(numericprefix), "%.4Lf ", - elapsed_sec); + (void) pv_snprintf(numericprefix, sizeof(numericprefix), "%.4Lf ", elapsed_sec); if ((state->components_used & PV_DISPLAY_BYTES) != 0) { if (state->bits) { (void) pv_snprintf(state->display_buffer, state->display_buffer_size, - "%.99s%lld\n", - numericprefix, - 8 * total_bytes); + "%.99s%lld\n", numericprefix, 8 * total_bytes); } else { (void) pv_snprintf(state->display_buffer, state->display_buffer_size, - "%.99s%lld\n", - numericprefix, - total_bytes); + "%.99s%lld\n", numericprefix, total_bytes); } } else { (void) pv_snprintf(state->display_buffer, - state->display_buffer_size, - "%.99s%ld\n", numericprefix, - state->percentage); + state->display_buffer_size, "%.99s%ld\n", numericprefix, state->percentage); } return state->display_buffer; @@ -714,14 +653,11 @@ static const char *pv__format(pvstate_t state, if ((state->components_used & PV_DISPLAY_BYTES) != 0) { if (state->bits && !state->linemode) { pv__sizestr(state->str_transferred, - PV_SIZEOF_STR_TRANSFERRED, "%s", - (long double) total_bytes * 8, "", - _("b"), 1); + PV_SIZEOF_STR_TRANSFERRED, "%s", (long double) total_bytes * 8, "", _("b"), 1); } else { pv__sizestr(state->str_transferred, PV_SIZEOF_STR_TRANSFERRED, "%s", - (long double) total_bytes, "", _("B"), - state->linemode ? 0 : 1); + (long double) total_bytes, "", _("B"), state->linemode ? 0 : 1); } } @@ -732,14 +668,10 @@ static const char *pv__format(pvstate_t state, PV_SIZEOF_STR_BUFPERCENT, "{%3ld%%}", pv__calc_percentage - (state->read_position - - state->write_position, - state->buffer_size)); + (state->read_position - state->write_position, state->buffer_size)); #ifdef HAVE_SPLICE if (state->splice_used) - (void) pv_snprintf(state->str_bufpercent, - PV_SIZEOF_STR_BUFPERCENT, - "{%s}", "----"); + (void) pv_snprintf(state->str_bufpercent, PV_SIZEOF_STR_BUFPERCENT, "{%s}", "----"); #endif } @@ -763,30 +695,23 @@ static const char *pv__format(pvstate_t state, "%ld:%02ld:%02ld:%02ld", ((long) elapsed_sec) / 86400, (((long) elapsed_sec) / 3600) % - 24, - (((long) elapsed_sec) / 60) % - 60, ((long) elapsed_sec) % 60); + 24, (((long) elapsed_sec) / 60) % 60, ((long) elapsed_sec) % 60); } else { (void) pv_snprintf(state->str_timer, PV_SIZEOF_STR_TIMER, "%ld:%02ld:%02ld", ((long) elapsed_sec) / 3600, - (((long) elapsed_sec) / 60) % - 60, ((long) elapsed_sec) % 60); + (((long) elapsed_sec) / 60) % 60, ((long) elapsed_sec) % 60); } } /* Rate - set up the display string. */ if ((state->components_used & PV_DISPLAY_RATE) != 0) { if (state->bits && !state->linemode) { - pv__sizestr(state->str_rate, - PV_SIZEOF_STR_RATE, "[%s]", - 8 * rate, "", _("b/s"), 1); + pv__sizestr(state->str_rate, PV_SIZEOF_STR_RATE, "[%s]", 8 * rate, "", _("b/s"), 1); } else { pv__sizestr(state->str_rate, - PV_SIZEOF_STR_RATE, "[%s]", rate, - _("/s"), _("B/s"), - state->linemode ? 0 : 1); + PV_SIZEOF_STR_RATE, "[%s]", rate, _("/s"), _("B/s"), state->linemode ? 0 : 1); } } @@ -794,14 +719,11 @@ static const char *pv__format(pvstate_t state, if ((state->components_used & PV_DISPLAY_AVERAGERATE) != 0) { if (state->bits && !state->linemode) { pv__sizestr(state->str_average_rate, - PV_SIZEOF_STR_AVERAGE_RATE, - "[%s]", 8 * average_rate, "", _("b/s"), - 1); + PV_SIZEOF_STR_AVERAGE_RATE, "[%s]", 8 * average_rate, "", _("b/s"), 1); } else { pv__sizestr(state->str_average_rate, PV_SIZEOF_STR_AVERAGE_RATE, - "[%s]", average_rate, _("/s"), - _("B/s"), state->linemode ? 0 : 1); + "[%s]", average_rate, _("/s"), _("B/s"), state->linemode ? 0 : 1); } } @@ -821,8 +743,7 @@ static const char *pv__format(pvstate_t state, && (state->size > 0)) { eta = pv__calc_eta(total_bytes - state->initial_offset, - state->size - state->initial_offset, - state->current_avg_rate); + state->size - state->initial_offset, state->current_avg_rate); /* * Bounds check, so we don't overrun the suffix buffer. This @@ -838,15 +759,11 @@ static const char *pv__format(pvstate_t state, (void) pv_snprintf(state->str_eta, PV_SIZEOF_STR_ETA, "%.16s %ld:%02ld:%02ld:%02ld", - _("ETA"), eta / 86400, - (eta / 3600) % 24, - (eta / 60) % 60, eta % 60); + _("ETA"), eta / 86400, (eta / 3600) % 24, (eta / 60) % 60, eta % 60); } else { (void) pv_snprintf(state->str_eta, PV_SIZEOF_STR_ETA, - "%.16s %ld:%02ld:%02ld", - _("ETA"), eta / 3600, - (eta / 60) % 60, eta % 60); + "%.16s %ld:%02ld:%02ld", _("ETA"), eta / 3600, (eta / 60) % 60, eta % 60); } /* @@ -855,8 +772,7 @@ static const char *pv__format(pvstate_t state, */ if (bytes_since_last < 0) { unsigned int i; - for (i = 0; i < PV_SIZEOF_STR_ETA - && state->str_eta[i] != '\0'; i++) { + for (i = 0; i < PV_SIZEOF_STR_ETA && state->str_eta[i] != '\0'; i++) { state->str_eta[i] = ' '; } } @@ -877,8 +793,7 @@ static const char *pv__format(pvstate_t state, eta = pv__calc_eta(total_bytes - state->initial_offset, - state->size - state->initial_offset, - state->current_avg_rate); + state->size - state->initial_offset, state->current_avg_rate); /* * Bounds check, so we don't overrun the suffix buffer. This @@ -907,20 +822,15 @@ static const char *pv__format(pvstate_t state, * by time functions. */ struct tm time = *time_ptr; - (void) pv_snprintf(state->str_fineta, - PV_SIZEOF_STR_FINETA, - "%.16s ", _("ETA")); + (void) pv_snprintf(state->str_fineta, PV_SIZEOF_STR_FINETA, "%.16s ", _("ETA")); strftime(state->str_fineta + strlen(state->str_fineta), - PV_SIZEOF_STR_FINETA - 1 - - strlen(state->str_fineta), time_format, - &time); + PV_SIZEOF_STR_FINETA - 1 - strlen(state->str_fineta), time_format, &time); } if (!show_eta) { unsigned int i; - for (i = 0; i < PV_SIZEOF_STR_FINETA - && state->str_fineta[i] != '\0'; i++) { + for (i = 0; i < PV_SIZEOF_STR_FINETA && state->str_fineta[i] != '\0'; i++) { state->str_fineta[i] = ' '; } } @@ -936,11 +846,9 @@ static const char *pv__format(pvstate_t state, if (state->format[segment].length < 0) { continue; } else if (state->format[segment].length > 0) { - static_portion_size += - state->format[segment].length; + static_portion_size += state->format[segment].length; } else { - static_portion_size += - strlen(state->format[segment].string); + static_portion_size += strlen(state->format[segment].string); } } @@ -960,56 +868,39 @@ static const char *pv__format(pvstate_t state, state->percentage = 0; if (state->percentage > 100000) state->percentage = 100000; - (void) pv_snprintf(pct, sizeof(pct), "%2ld%%", - state->percentage); + (void) pv_snprintf(pct, sizeof(pct), "%2ld%%", state->percentage); - available_width = - state->width - static_portion_size - - strlen(pct) - 3; + available_width = state->width - static_portion_size - strlen(pct) - 3; if (available_width < 0) available_width = 0; - if (available_width > - (int) (PV_SIZEOF_STR_PROGRESS) - 16) - available_width = - PV_SIZEOF_STR_PROGRESS - 16; + if (available_width > (int) (PV_SIZEOF_STR_PROGRESS) - 16) + available_width = PV_SIZEOF_STR_PROGRESS - 16; - for (i = 0; - i < - (available_width * state->percentage) / 100 - - 1; i++) { + for (i = 0; i < (available_width * state->percentage) / 100 - 1; i++) { if (i < available_width) - pv_strlcat(state->str_progress, - "=", - PV_SIZEOF_STR_PROGRESS); + pv_strlcat(state->str_progress, "=", PV_SIZEOF_STR_PROGRESS); } if (i < available_width) { - pv_strlcat(state->str_progress, ">", - PV_SIZEOF_STR_PROGRESS); + pv_strlcat(state->str_progress, ">", PV_SIZEOF_STR_PROGRESS); i++; } for (; i < available_width; i++) { - pv_strlcat(state->str_progress, " ", - PV_SIZEOF_STR_PROGRESS); + pv_strlcat(state->str_progress, " ", PV_SIZEOF_STR_PROGRESS); } - pv_strlcat(state->str_progress, "] ", - PV_SIZEOF_STR_PROGRESS); - pv_strlcat(state->str_progress, pct, - PV_SIZEOF_STR_PROGRESS); + pv_strlcat(state->str_progress, "] ", PV_SIZEOF_STR_PROGRESS); + pv_strlcat(state->str_progress, pct, PV_SIZEOF_STR_PROGRESS); } else { int p = state->percentage; - available_width = - state->width - static_portion_size - 5; + available_width = state->width - static_portion_size - 5; if (available_width < 0) available_width = 0; - if (available_width > - (int) (PV_SIZEOF_STR_PROGRESS) - 16) - available_width = - PV_SIZEOF_STR_PROGRESS - 16; + if (available_width > (int) (PV_SIZEOF_STR_PROGRESS) - 16) + available_width = PV_SIZEOF_STR_PROGRESS - 16; debug("available_width: %d", available_width); @@ -1017,25 +908,19 @@ static const char *pv__format(pvstate_t state, p = 200 - p; for (i = 0; i < (available_width * p) / 100; i++) { if (i < available_width) - pv_strlcat(state->str_progress, - " ", - PV_SIZEOF_STR_PROGRESS); + pv_strlcat(state->str_progress, " ", PV_SIZEOF_STR_PROGRESS); } - pv_strlcat(state->str_progress, "<=>", - PV_SIZEOF_STR_PROGRESS); + pv_strlcat(state->str_progress, "<=>", PV_SIZEOF_STR_PROGRESS); for (; i < available_width; i++) { - pv_strlcat(state->str_progress, " ", - PV_SIZEOF_STR_PROGRESS); + pv_strlcat(state->str_progress, " ", PV_SIZEOF_STR_PROGRESS); } - pv_strlcat(state->str_progress, "]", - PV_SIZEOF_STR_PROGRESS); + pv_strlcat(state->str_progress, "]", PV_SIZEOF_STR_PROGRESS); } /* * If the progress bar won't fit, drop it. */ - if (strlen(state->str_progress) + static_portion_size > - state->width) + if (strlen(state->str_progress) + static_portion_size > state->width) state->str_progress[0] = 0; } @@ -1050,8 +935,7 @@ static const char *pv__format(pvstate_t state, if (state->format[segment].length > 0) { segment_length = state->format[segment].length; } else { - segment_length = - strlen(state->format[segment].string); + segment_length = strlen(state->format[segment].string); } /* Skip empty segments */ if (segment_length == 0) @@ -1060,19 +944,14 @@ static const char *pv__format(pvstate_t state, * Truncate segment if it would make the display string * overflow the buffer */ - if (segment_length + display_string_length > - state->display_buffer_size - 2) - segment_length = - state->display_buffer_size - - display_string_length - 2; + if (segment_length + display_string_length > state->display_buffer_size - 2) + segment_length = state->display_buffer_size - display_string_length - 2; if (segment_length < 1) break; /* Skip segment if it would make the display too wide */ - if (segment_length + display_string_length > - (int) (state->width)) + if (segment_length + display_string_length > (int) (state->width)) break; - strncat(state->display_buffer, - state->format[segment].string, segment_length); + strncat(state->display_buffer, state->format[segment].string, segment_length); display_string_length += segment_length; } @@ -1095,8 +974,7 @@ static const char *pv__format(pvstate_t state, while (--spaces_to_add >= 0) { spaces[spaces_to_add] = ' '; } - pv_strlcat(state->display_buffer, spaces, - state->display_buffer_size); + pv_strlcat(state->display_buffer, spaces, state->display_buffer_size); } state->prev_width = state->width; state->prev_length = output_length; @@ -1116,8 +994,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, long long sl, - long long tot) +void pv_display(pvstate_t state, long double esec, long long sl, long long tot) { const char *display; @@ -1148,8 +1025,7 @@ void pv_display(pvstate_t state, long double esec, long long sl, } } else { if (state->force || pv_in_foreground()) { - pv_write_retry(STDERR_FILENO, display, - strlen(display)); + pv_write_retry(STDERR_FILENO, display, strlen(display)); pv_write_retry(STDERR_FILENO, "\r", 1); state->display_visible = true; } diff --git a/src/pv/file.c b/src/pv/file.c index ebc8dcd..eb5c040 100644 --- a/src/pv/file.c +++ b/src/pv/file.c @@ -67,11 +67,9 @@ unsigned long long pv_calc_total_size(pvstate_t state) } if (rc != 0) { - pv_error(state, "%s: %s", - state->input_files[i], strerror(errno)); + pv_error(state, "%s: %s", state->input_files[i], strerror(errno)); for (j = i; j < state->input_file_count - 1; j++) { - state->input_files[j] = - state->input_files[j + 1]; + state->input_files[j] = state->input_files[j + 1]; } state->input_file_count--; i--; @@ -93,9 +91,7 @@ unsigned long long pv_calc_total_size(pvstate_t state) total += lseek(fd, 0, SEEK_END); close(fd); } else { - pv_error(state, "%s: %s", - state->input_files[i], - strerror(errno)); + pv_error(state, "%s: %s", state->input_files[i], strerror(errno)); state->exit_status |= 2; } } else if (S_ISREG(sb.st_mode)) { @@ -120,9 +116,7 @@ unsigned long long pv_calc_total_size(pvstate_t state) total = lseek(STDOUT_FILENO, 0, SEEK_END); if (lseek(STDOUT_FILENO, 0, SEEK_SET) != 0) { pv_error(state, "%s: %s: %s", "(stdout)", - _ - ("failed to seek to start of output"), - strerror(errno)); + _("failed to seek to start of output"), strerror(errno)); state->exit_status |= 2; } /* @@ -165,8 +159,7 @@ unsigned long long pv_calc_total_size(pvstate_t state) } if (fd < 0) { - pv_error(state, "%s: %s", state->input_files[i], - strerror(errno)); + pv_error(state, "%s: %s", state->input_files[i], strerror(errno)); total = 0; state->exit_status |= 2; return total; @@ -178,9 +171,7 @@ unsigned long long pv_calc_total_size(pvstate_t state) numread = read(fd, scanbuf, sizeof(scanbuf)); if (numread < 0) { - pv_error(state, "%s: %s", - state->input_files[i], - strerror(errno)); + pv_error(state, "%s: %s", state->input_files[i], strerror(errno)); state->exit_status |= 2; break; } else if (0 == numread) { @@ -216,9 +207,7 @@ int pv_next_file(pvstate_t state, int filenum, int oldfd) if (oldfd > 0) { if (close(oldfd)) { - pv_error(state, "%s: %s", - _("failed to close file"), - strerror(errno)); + pv_error(state, "%s: %s", _("failed to close file"), strerror(errno)); state->exit_status |= 8; return -1; } @@ -240,26 +229,21 @@ int pv_next_file(pvstate_t state, int filenum, int oldfd) fd = open(state->input_files[filenum], O_RDONLY); if (fd < 0) { pv_error(state, "%s: %s: %s", - _("failed to read file"), - state->input_files[filenum], - strerror(errno)); + _("failed to read file"), state->input_files[filenum], strerror(errno)); state->exit_status |= 2; return -1; } } if (fstat(fd, &isb)) { - pv_error(state, "%s: %s: %s", - _("failed to stat file"), - state->input_files[filenum], strerror(errno)); + pv_error(state, "%s: %s: %s", _("failed to stat file"), state->input_files[filenum], strerror(errno)); close(fd); state->exit_status |= 2; return -1; } if (fstat(STDOUT_FILENO, &osb)) { - pv_error(state, "%s: %s", - _("failed to stat output file"), strerror(errno)); + pv_error(state, "%s: %s", _("failed to stat output file"), strerror(errno)); close(fd); state->exit_status |= 2; return -1; @@ -281,9 +265,7 @@ int pv_next_file(pvstate_t state, int filenum, int oldfd) input_file_is_stdout = 0; if (input_file_is_stdout) { - pv_error(state, "%s: %s", - _("input file is output file"), - state->input_files[filenum]); + pv_error(state, "%s: %s", _("input file is output file"), state->input_files[filenum]); close(fd); state->exit_status |= 4; return -1; @@ -297,8 +279,7 @@ int pv_next_file(pvstate_t state, int filenum, int oldfd) /* * Set or clear O_DIRECT on the file descriptor. */ - fcntl(fd, F_SETFL, - (state->direct_io ? O_DIRECT : 0) | fcntl(fd, F_GETFL)); + fcntl(fd, F_SETFL, (state->direct_io ? O_DIRECT : 0) | fcntl(fd, F_GETFL)); /* * We don't clear direct_io_changed here, to avoid race conditions * that could cause the input and output settings to differ. diff --git a/src/pv/loop.c b/src/pv/loop.c index 7672c0b..7823601 100644 --- a/src/pv/loop.c +++ b/src/pv/loop.c @@ -94,12 +94,9 @@ int pv_main_loop(pvstate_t state) next_update.tv_usec = start_time.tv_usec; if ((state->delay_start > 0) && (state->delay_start > state->interval)) { - pv_timeval_add_usec(&next_update, - (long) (1000000.0 * - state->delay_start)); + pv_timeval_add_usec(&next_update, (long) (1000000.0 * state->delay_start)); } else { - pv_timeval_add_usec(&next_update, - (long) (1000000.0 * state->interval)); + pv_timeval_add_usec(&next_update, (long) (1000000.0 * state->interval)); } next_ratecheck.tv_sec = start_time.tv_sec; @@ -121,9 +118,7 @@ int pv_main_loop(pvstate_t state) /* * Set or clear O_DIRECT on the output. */ - fcntl(STDOUT_FILENO, F_SETFL, - (state->direct_io ? O_DIRECT : 0) | fcntl(STDOUT_FILENO, - F_GETFL)); + fcntl(STDOUT_FILENO, F_SETFL, (state->direct_io ? O_DIRECT : 0) | fcntl(STDOUT_FILENO, F_GETFL)); state->direct_io_changed = false; #endif /* O_DIRECT */ @@ -150,11 +145,9 @@ int pv_main_loop(pvstate_t state) * Check for remote messages from -R every short while */ if ((cur_time.tv_sec > next_remotecheck.tv_sec) - || (cur_time.tv_sec == next_remotecheck.tv_sec - && cur_time.tv_usec >= next_remotecheck.tv_usec)) { + || (cur_time.tv_sec == next_remotecheck.tv_sec && cur_time.tv_usec >= next_remotecheck.tv_usec)) { pv_remote_check(state); - pv_timeval_add_usec(&next_remotecheck, - REMOTE_INTERVAL); + pv_timeval_add_usec(&next_remotecheck, REMOTE_INTERVAL); } if (state->pv_sig_abort) @@ -163,22 +156,15 @@ int pv_main_loop(pvstate_t state) if (state->rate_limit > 0) { gettimeofday(&cur_time, NULL); if ((cur_time.tv_sec > next_ratecheck.tv_sec) - || (cur_time.tv_sec == next_ratecheck.tv_sec - && cur_time.tv_usec >= - next_ratecheck.tv_usec)) { + || (cur_time.tv_sec == next_ratecheck.tv_sec && cur_time.tv_usec >= next_ratecheck.tv_usec)) { target += - ((long double) (state->rate_limit)) / - (long double) (1000000 / - RATE_GRANULARITY); - long double burstMax = - ((long double) (state->rate_limit * - RATE_BURST_WINDOW)); + ((long double) (state->rate_limit)) / (long double) (1000000 / RATE_GRANULARITY); + long double burstMax = ((long double) (state->rate_limit * RATE_BURST_WINDOW)); if (target > burstMax) { target = burstMax; } - pv_timeval_add_usec(&next_ratecheck, - RATE_GRANULARITY); + pv_timeval_add_usec(&next_ratecheck, RATE_GRANULARITY); } cansend = target; } @@ -188,8 +174,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 (((long) (state->size) < (total_written + cansend)) || ((0 == cansend) && (0 == state->rate_limit))) { cansend = state->size - total_written; @@ -204,9 +189,7 @@ int pv_main_loop(pvstate_t state) && (0 >= cansend) && eof_in && eof_out) { written = 0; } else { - written = - pv_transfer(state, fd, &eof_in, &eof_out, - cansend, &lineswritten); + written = pv_transfer(state, fd, &eof_in, &eof_out, cansend, &lineswritten); } if (written < 0) { @@ -286,32 +269,25 @@ int pv_main_loop(pvstate_t state) next_update.tv_sec = start_time.tv_sec; next_update.tv_usec = start_time.tv_usec; - pv_timeval_add_usec(&next_update, - (long) (1000000.0 * - state->interval)); + pv_timeval_add_usec(&next_update, (long) (1000000.0 * state->interval)); } if ((cur_time.tv_sec < next_update.tv_sec) - || (cur_time.tv_sec == next_update.tv_sec - && cur_time.tv_usec < next_update.tv_usec)) { + || (cur_time.tv_sec == next_update.tv_sec && cur_time.tv_usec < next_update.tv_usec)) { continue; } - pv_timeval_add_usec(&next_update, - (long) (1000000.0 * state->interval)); + pv_timeval_add_usec(&next_update, (long) (1000000.0 * state->interval)); if (next_update.tv_sec < cur_time.tv_sec) { next_update.tv_sec = cur_time.tv_sec; next_update.tv_usec = cur_time.tv_usec; - } else if (next_update.tv_sec == cur_time.tv_sec - && next_update.tv_usec < cur_time.tv_usec) { + } else if (next_update.tv_sec == cur_time.tv_sec && next_update.tv_usec < cur_time.tv_usec) { next_update.tv_usec = cur_time.tv_usec; } - init_time.tv_sec = - start_time.tv_sec + state->pv_sig_toffset.tv_sec; - init_time.tv_usec = - start_time.tv_usec + state->pv_sig_toffset.tv_usec; + init_time.tv_sec = start_time.tv_sec + state->pv_sig_toffset.tv_sec; + init_time.tv_usec = start_time.tv_usec + state->pv_sig_toffset.tv_usec; if (init_time.tv_usec >= 1000000) { init_time.tv_sec++; init_time.tv_usec -= 1000000; @@ -322,8 +298,7 @@ int pv_main_loop(pvstate_t state) } elapsed = cur_time.tv_sec - init_time.tv_sec; - elapsed += - (cur_time.tv_usec - init_time.tv_usec) / 1000000.0; + elapsed += (cur_time.tv_usec - init_time.tv_usec) / 1000000.0; if (final_update) since_last = -1; @@ -404,8 +379,7 @@ int pv_watchfd_loop(pvstate_t state) next_update.tv_sec = info.start_time.tv_sec; next_update.tv_usec = info.start_time.tv_usec; - pv_timeval_add_usec(&next_update, - (long) (1000000.0 * state->interval)); + pv_timeval_add_usec(&next_update, (long) (1000000.0 * state->interval)); next_remotecheck.tv_sec = info.start_time.tv_sec; next_remotecheck.tv_usec = info.start_time.tv_usec; @@ -420,11 +394,9 @@ int pv_watchfd_loop(pvstate_t state) * Check for remote messages from -R every short while */ if ((cur_time.tv_sec > next_remotecheck.tv_sec) - || (cur_time.tv_sec == next_remotecheck.tv_sec - && cur_time.tv_usec >= next_remotecheck.tv_usec)) { + || (cur_time.tv_sec == next_remotecheck.tv_sec && cur_time.tv_usec >= next_remotecheck.tv_usec)) { pv_remote_check(state); - pv_timeval_add_usec(&next_remotecheck, - REMOTE_INTERVAL); + pv_timeval_add_usec(&next_remotecheck, REMOTE_INTERVAL); } if (state->pv_sig_abort) @@ -451,8 +423,7 @@ int pv_watchfd_loop(pvstate_t state) } if ((cur_time.tv_sec < next_update.tv_sec) - || (cur_time.tv_sec == next_update.tv_sec - && cur_time.tv_usec < next_update.tv_usec)) { + || (cur_time.tv_sec == next_update.tv_sec && cur_time.tv_usec < next_update.tv_usec)) { struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 50000; @@ -460,22 +431,17 @@ int pv_watchfd_loop(pvstate_t state) continue; } - pv_timeval_add_usec(&next_update, - (long) (1000000.0 * state->interval)); + pv_timeval_add_usec(&next_update, (long) (1000000.0 * state->interval)); if (next_update.tv_sec < cur_time.tv_sec) { next_update.tv_sec = cur_time.tv_sec; next_update.tv_usec = cur_time.tv_usec; - } else if (next_update.tv_sec == cur_time.tv_sec - && next_update.tv_usec < cur_time.tv_usec) { + } else if (next_update.tv_sec == cur_time.tv_sec && next_update.tv_usec < cur_time.tv_usec) { next_update.tv_usec = cur_time.tv_usec; } - init_time.tv_sec = - info.start_time.tv_sec + state->pv_sig_toffset.tv_sec; - init_time.tv_usec = - info.start_time.tv_usec + - state->pv_sig_toffset.tv_usec; + init_time.tv_sec = info.start_time.tv_sec + state->pv_sig_toffset.tv_sec; + init_time.tv_usec = info.start_time.tv_usec + state->pv_sig_toffset.tv_usec; if (init_time.tv_usec >= 1000000) { init_time.tv_sec++; init_time.tv_usec -= 1000000; @@ -486,8 +452,7 @@ int pv_watchfd_loop(pvstate_t state) } elapsed = cur_time.tv_sec - init_time.tv_sec; - elapsed += - (cur_time.tv_usec - init_time.tv_usec) / 1000000.0; + elapsed += (cur_time.tv_usec - init_time.tv_usec) / 1000000.0; if (ended) since_last = -1; @@ -538,8 +503,7 @@ int pv_watchpid_loop(pvstate_t state) * it's not there at the start. */ if (kill(state->watch_pid, 0) != 0) { - pv_error(state, "%s %u: %s", - _("pid"), state->watch_pid, strerror(errno)); + pv_error(state, "%s %u: %s", _("pid"), state->watch_pid, strerror(errno)); state->exit_status |= 2; return 2; } @@ -554,23 +518,15 @@ int pv_watchpid_loop(pvstate_t state) * Make sure there's a format string, and then insert %N into it if * it's not present. */ - original_format_string = - state->format_string ? state-> - format_string : state->default_format; + original_format_string = state->format_string ? state->format_string : state->default_format; if (NULL == strstr(original_format_string, "%N")) { - (void) pv_snprintf(new_format_string, - sizeof(new_format_string), "%%N %s", - original_format_string); + (void) pv_snprintf(new_format_string, sizeof(new_format_string), "%%N %s", original_format_string); } else { - (void) pv_snprintf(new_format_string, - sizeof(new_format_string), "%s", - original_format_string); + (void) pv_snprintf(new_format_string, sizeof(new_format_string), "%s", original_format_string); } new_format_string[sizeof(new_format_string) - 1] = '\0'; state_copy.format_string = NULL; - (void) pv_snprintf(state_copy.default_format, - PV_SIZEOF_DEFAULT_FORMAT, - "%.510s", new_format_string); + (void) pv_snprintf(state_copy.default_format, PV_SIZEOF_DEFAULT_FORMAT, "%.510s", new_format_string); state_copy.default_format[PV_SIZEOF_DEFAULT_FORMAT - 1] = '\0'; /* @@ -581,8 +537,7 @@ int pv_watchpid_loop(pvstate_t state) next_update.tv_sec = cur_time.tv_sec; next_update.tv_usec = cur_time.tv_usec; - pv_timeval_add_usec(&next_update, - (long) (1000000.0 * state->interval)); + pv_timeval_add_usec(&next_update, (long) (1000000.0 * state->interval)); for (idx = 0; idx < FD_SETSIZE; idx++) { fd_to_idx[idx] = -1; @@ -600,9 +555,7 @@ int pv_watchpid_loop(pvstate_t state) if (kill(state->watch_pid, 0) != 0) { if (first_pass) { - pv_error(state, "%s %u: %s", - _("pid"), state->watch_pid, - strerror(errno)); + pv_error(state, "%s %u: %s", _("pid"), state->watch_pid, strerror(errno)); state->exit_status |= 2; if (NULL != info_array) free(info_array); @@ -614,8 +567,7 @@ int pv_watchpid_loop(pvstate_t state) } if ((cur_time.tv_sec < next_update.tv_sec) - || (cur_time.tv_sec == next_update.tv_sec - && cur_time.tv_usec < next_update.tv_usec)) { + || (cur_time.tv_sec == next_update.tv_sec && cur_time.tv_usec < next_update.tv_usec)) { struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 50000; @@ -623,14 +575,12 @@ int pv_watchpid_loop(pvstate_t state) continue; } - pv_timeval_add_usec(&next_update, - (long) (1000000.0 * state->interval)); + pv_timeval_add_usec(&next_update, (long) (1000000.0 * state->interval)); if (next_update.tv_sec < cur_time.tv_sec) { next_update.tv_sec = cur_time.tv_sec; next_update.tv_usec = cur_time.tv_usec; - } else if (next_update.tv_sec == cur_time.tv_sec - && next_update.tv_usec < cur_time.tv_usec) { + } else if (next_update.tv_sec == cur_time.tv_sec && next_update.tv_usec < cur_time.tv_usec) { next_update.tv_usec = cur_time.tv_usec; } @@ -640,21 +590,16 @@ int pv_watchpid_loop(pvstate_t state) for (idx = 0; idx < array_length; idx++) { state_array[idx].width = state->width; state_array[idx].height = state->height; - pv_watchpid_setname(state, - &(info_array[idx])); + pv_watchpid_setname(state, &(info_array[idx])); state_array[idx].reparse_display = 1; } } rc = pv_watchpid_scanfds(state, &state_copy, - state->watch_pid, &array_length, - &info_array, &state_array, - fd_to_idx); + state->watch_pid, &array_length, &info_array, &state_array, fd_to_idx); if (rc != 0) { if (first_pass) { - pv_error(state, "%s %u: %s", - _("pid"), state->watch_pid, - strerror(errno)); + pv_error(state, "%s %u: %s", _("pid"), state->watch_pid, strerror(errno)); state->exit_status |= 2; if (NULL != info_array) free(info_array); @@ -689,8 +634,7 @@ int pv_watchpid_loop(pvstate_t state) if (pv_watchfd_changed(&(info_array[idx]))) { fd_to_idx[fd] = -1; info_array[idx].watch_pid = 0; - debug("%s %d: %s", "fd", fd, - "removing"); + debug("%s %d: %s", "fd", fd, "removing"); } continue; } @@ -699,8 +643,7 @@ int pv_watchpid_loop(pvstate_t state) * Displayable fd - display, or remove if changed */ - position_now = - pv_watchfd_position(&(info_array[idx])); + position_now = pv_watchfd_position(&(info_array[idx])); if (position_now < 0) { fd_to_idx[fd] = -1; @@ -709,16 +652,11 @@ int pv_watchpid_loop(pvstate_t state) continue; } - since_last = - position_now - info_array[idx].position; + since_last = position_now - info_array[idx].position; info_array[idx].position = position_now; - init_time.tv_sec = - info_array[idx].start_time.tv_sec + - state->pv_sig_toffset.tv_sec; - init_time.tv_usec = - info_array[idx].start_time.tv_usec + - state->pv_sig_toffset.tv_usec; + init_time.tv_sec = info_array[idx].start_time.tv_sec + state->pv_sig_toffset.tv_sec; + init_time.tv_usec = info_array[idx].start_time.tv_usec + state->pv_sig_toffset.tv_usec; if (init_time.tv_usec >= 1000000) { init_time.tv_sec++; init_time.tv_usec -= 1000000; @@ -729,20 +667,16 @@ int pv_watchpid_loop(pvstate_t state) } elapsed = cur_time.tv_sec - init_time.tv_sec; - elapsed += - (cur_time.tv_usec - - init_time.tv_usec) / 1000000.0; + elapsed += (cur_time.tv_usec - init_time.tv_usec) / 1000000.0; if (displayed_lines > 0) { debug("%s", "adding newline"); pv_write_retry(STDERR_FILENO, "\n", 1); } - debug("%s %d [%d]: %Lf / %Ld / %Ld", "fd", fd, idx, - elapsed, since_last, position_now); + debug("%s %d [%d]: %Lf / %Ld / %Ld", "fd", fd, idx, elapsed, since_last, position_now); - pv_display(&(state_array[idx]), elapsed, - since_last, position_now); + pv_display(&(state_array[idx]), elapsed, since_last, position_now); displayed_lines++; } diff --git a/src/pv/number.c b/src/pv/number.c index ef8070f..7b797fe 100644 --- a/src/pv/number.c +++ b/src/pv/number.c @@ -52,8 +52,7 @@ unsigned long long pv_getnum_ull(const char *str) for (; pv__isdigit(str[0]); str++) { if (decdivisor < 10000) { decimal = decimal * 10; - decimal += - (unsigned long long) (str[0] - '0'); + decimal += (unsigned long long) (str[0] - '0'); decdivisor = decdivisor * 10; } } diff --git a/src/pv/signal.c b/src/pv/signal.c index a22373c..0dc2d21 100644 --- a/src/pv/signal.c +++ b/src/pv/signal.c @@ -85,10 +85,8 @@ static void pv_sig_cont( __attribute__((unused)) gettimeofday(&tv, NULL); - pv_sig_state->pv_sig_toffset.tv_sec += - (tv.tv_sec - pv_sig_state->pv_sig_tstp_time.tv_sec); - pv_sig_state->pv_sig_toffset.tv_usec += - (tv.tv_usec - pv_sig_state->pv_sig_tstp_time.tv_usec); + pv_sig_state->pv_sig_toffset.tv_sec += (tv.tv_sec - pv_sig_state->pv_sig_tstp_time.tv_sec); + pv_sig_state->pv_sig_toffset.tv_usec += (tv.tv_usec - pv_sig_state->pv_sig_tstp_time.tv_usec); if (pv_sig_state->pv_sig_toffset.tv_usec >= 1000000) { pv_sig_state->pv_sig_toffset.tv_sec++; pv_sig_state->pv_sig_toffset.tv_usec -= 1000000; diff --git a/src/pv/state.c b/src/pv/state.c index f16f8f2..2e23aa2 100644 --- a/src/pv/state.c +++ b/src/pv/state.c @@ -24,12 +24,10 @@ static void pv_alloc_history(pvstate_t state) free(state->history); state->history = NULL; - state->history = - calloc(state->history_len, sizeof(state->history[0])); + state->history = calloc(state->history_len, sizeof(state->history[0])); if (NULL == state->history) { fprintf(stderr, "%s: %s: %s\n", state->program_name, - _("history structure allocation failed"), - strerror(errno)); + _("history structure allocation failed"), strerror(errno)); return; } @@ -114,9 +112,7 @@ void pv_state_free(pvstate_t state) 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, const char *name) + bool average_rate, bool bytes, bool bufpercent, unsigned int lastwritten, const char *name) { #define PV_ADDFORMAT(x,y) if (x) { \ if (state->default_format[0] != '\0') \ @@ -217,8 +213,7 @@ void pv_state_rate_limit_set(pvstate_t state, unsigned long long val) state->rate_limit = val; }; -void pv_state_target_buffer_size_set(pvstate_t state, - unsigned long long val) +void pv_state_target_buffer_size_set(pvstate_t state, unsigned long long val) { state->target_buffer_size = val; }; @@ -286,8 +281,7 @@ void pv_state_average_rate_window_set(pvstate_t state, int val) /* * Set the array of input files. */ -void pv_state_inputfiles(pvstate_t state, int input_file_count, - const char **input_files) +void pv_state_inputfiles(pvstate_t state, int input_file_count, const char **input_files) { state->input_file_count = input_file_count; state->input_files = input_files; diff --git a/src/pv/string.c b/src/pv/string.c index a1b7ef7..1c97693 100644 --- a/src/pv/string.c +++ b/src/pv/string.c @@ -87,8 +87,7 @@ size_t pv_strlcat(char *dst, const char *src, size_t dstsize) available = dstsize - dstlen; if (available > 1) - (void) pv_snprintf(dst + dstlen, available, "%.*s", - available - 1, src); + (void) pv_snprintf(dst + dstlen, available, "%.*s", available - 1, src); return dstlen + srclen; #endif diff --git a/src/pv/transfer.c b/src/pv/transfer.c index 142f0e3..02a9c7c 100644 --- a/src/pv/transfer.c +++ b/src/pv/transfer.c @@ -48,10 +48,7 @@ static ssize_t pv__transfer_read_repeated(int fd, void *buf, size_t count) struct timeval now; long elapsed_usec; - nread = - read(fd, buf, - count > - MAX_READ_AT_ONCE ? MAX_READ_AT_ONCE : count); + nread = read(fd, buf, count > MAX_READ_AT_ONCE ? MAX_READ_AT_ONCE : count); if (nread < 0) return nread; @@ -63,13 +60,10 @@ static ssize_t pv__transfer_read_repeated(int fd, void *buf, size_t count) return total_read; gettimeofday(&now, NULL); - elapsed_usec = - 1000000 * (now.tv_sec - start_time.tv_sec) + - (now.tv_usec - start_time.tv_usec); + elapsed_usec = 1000000 * (now.tv_sec - start_time.tv_sec) + (now.tv_usec - start_time.tv_usec); if (elapsed_usec > TRANSFER_READ_TIMEOUT) { debug("%s %d: %s (%ld %s)", "fd", fd, - "stopping read - timer expired", - elapsed_usec, "usec elapsed"); + "stopping read - timer expired", elapsed_usec, "usec elapsed"); return total_read; } @@ -83,8 +77,7 @@ static ssize_t pv__transfer_read_repeated(int fd, void *buf, size_t count) FD_SET(fd, &readfds); debug("%s %d: %s (%ld %s, %ld %s)", "fd", fd, - "trying another read after partial buffer fill", - nread, "read", count, "remaining"); + "trying another read after partial buffer fill", nread, "read", count, "remaining"); if (select(fd + 1, &readfds, NULL, NULL, &tv) < 1) break; @@ -108,8 +101,7 @@ static ssize_t pv__transfer_read_repeated(int fd, void *buf, size_t count) * We stop retrying if the time elapsed since this function was entered * reaches TRANSFER_WRITE_TIMEOUT microseconds. */ -static ssize_t pv__transfer_write_repeated(int fd, void *buf, size_t count, - bool sync_after_write) +static ssize_t pv__transfer_write_repeated(int fd, void *buf, size_t count, bool sync_after_write) { struct timeval start_time; ssize_t total_written; @@ -124,8 +116,7 @@ static ssize_t pv__transfer_write_repeated(int fd, void *buf, size_t count, long elapsed_usec; size_t asked_to_write; - asked_to_write = count > - MAX_WRITE_AT_ONCE ? MAX_WRITE_AT_ONCE : count; + asked_to_write = count > MAX_WRITE_AT_ONCE ? MAX_WRITE_AT_ONCE : count; nwritten = write(fd, buf, asked_to_write); @@ -166,13 +157,10 @@ static ssize_t pv__transfer_write_repeated(int fd, void *buf, size_t count, return total_written; gettimeofday(&now, NULL); - elapsed_usec = - 1000000 * (now.tv_sec - start_time.tv_sec) + - (now.tv_usec - start_time.tv_usec); + elapsed_usec = 1000000 * (now.tv_sec - start_time.tv_sec) + (now.tv_usec - start_time.tv_usec); if (elapsed_usec > TRANSFER_WRITE_TIMEOUT) { debug("%s %d: %s (%ld %s)", "fd", fd, - "stopping write - timer expired", - elapsed_usec, "usec elapsed"); + "stopping write - timer expired", elapsed_usec, "usec elapsed"); return total_written; } @@ -233,9 +221,7 @@ static ssize_t pv__transfer_write_repeated(int fd, void *buf, size_t count, * sets *eof_in to 1. If all data in the buffer has been written at this * point, then also sets *eof_out. */ -static int pv__transfer_read(pvstate_t state, int fd, - int *eof_in, int *eof_out, - unsigned long long allowed) +static int pv__transfer_read(pvstate_t state, int fd, int *eof_in, int *eof_out, unsigned long long allowed) { bool do_not_skip_errors; unsigned long bytes_can_read; @@ -264,13 +250,11 @@ static int pv__transfer_read(pvstate_t state, int fd, else bytes_to_splice = bytes_can_read; - nread = splice(fd, NULL, STDOUT_FILENO, NULL, - bytes_to_splice, SPLICE_F_MORE); + nread = splice(fd, NULL, STDOUT_FILENO, NULL, bytes_to_splice, SPLICE_F_MORE); state->splice_used = 1; if ((nread < 0) && (EINVAL == errno)) { - debug("%s %d: %s", "fd", fd, - "splice failed with EINVAL - disabling"); + debug("%s %d: %s", "fd", fd, "splice failed with EINVAL - disabling"); state->splice_failed_fd = fd; state->splice_used = 0; /* @@ -304,18 +288,10 @@ static int pv__transfer_read(pvstate_t state, int fd, } } if (0 == state->splice_used) { - nread = - pv__transfer_read_repeated(fd, - state->transfer_buffer + - state->read_position, - bytes_can_read); + nread = pv__transfer_read_repeated(fd, state->transfer_buffer + state->read_position, bytes_can_read); } #else - nread = - pv__transfer_read_repeated(fd, - state->transfer_buffer + - state->read_position, - bytes_can_read); + nread = pv__transfer_read_repeated(fd, state->transfer_buffer + state->read_position, bytes_can_read); #endif /* HAVE_SPLICE */ @@ -360,9 +336,7 @@ static int pv__transfer_read(pvstate_t state, int fd, */ if ((EINTR == errno) || (EAGAIN == errno)) { struct timeval tv; - debug("%s %d: %s: %s", "fd", fd, - "transient error - waiting briefly", - strerror(errno)); + debug("%s %d: %s: %s", "fd", fd, "transient error - waiting briefly", strerror(errno)); tv.tv_sec = 0; tv.tv_usec = 10000; select(0, NULL, NULL, NULL, &tv); @@ -382,9 +356,7 @@ static int pv__transfer_read(pvstate_t state, int fd, * reached the end of this file. */ if (do_not_skip_errors) { - pv_error(state, "%s: %s: %s", - state->current_file, - _("read failed"), strerror(errno)); + pv_error(state, "%s: %s: %s", state->current_file, _("read failed"), strerror(errno)); *eof_in = 1; if (state->write_position >= state->read_position) { *eof_out = 1; @@ -399,11 +371,7 @@ static int pv__transfer_read(pvstate_t state, int fd, amount_skipped = -1; if (!state->read_error_warning_shown) { - pv_error(state, "%s: %s: %s", - state->current_file, - _ - ("warning: read errors detected"), - strerror(errno)); + pv_error(state, "%s: %s: %s", state->current_file, _("warning: read errors detected"), strerror(errno)); state->read_error_warning_shown = 1; } @@ -415,9 +383,7 @@ static int pv__transfer_read(pvstate_t state, int fd, * of the file. */ if (0 > orig_offset) { - pv_error(state, "%s: %s: %s", - state->current_file, - _("file is not seekable"), strerror(errno)); + pv_error(state, "%s: %s: %s", state->current_file, _("file is not seekable"), strerror(errno)); *eof_in = 1; if (state->write_position >= state->read_position) { *eof_out = 1; @@ -460,8 +426,7 @@ static int pv__transfer_read(pvstate_t state, int fd, */ if (skip_offset < 0) { amount_to_skip = 1; - skip_offset = - lseek(fd, orig_offset + amount_to_skip, SEEK_SET); + skip_offset = lseek(fd, orig_offset + amount_to_skip, SEEK_SET); } if (skip_offset < 0) { @@ -477,11 +442,7 @@ static int pv__transfer_read(pvstate_t state, int fd, */ if (EINVAL != errno) { pv_error(state, - "%s: %s: %s", - state->current_file, - _ - ("failed to seek past error"), - strerror(errno)); + "%s: %s: %s", state->current_file, _("failed to seek past error"), strerror(errno)); } } else { amount_skipped = skip_offset - orig_offset; @@ -492,16 +453,12 @@ static int pv__transfer_read(pvstate_t state, int fd, * 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, amount_skipped); state->read_position += amount_skipped; if (state->skip_errors < 2) { pv_error(state, "%s: %s: %ld - %ld (%ld %s)", state->current_file, - _ - ("skipped past read error"), - orig_offset, - skip_offset, amount_skipped, _("B")); + _("skipped past read error"), orig_offset, skip_offset, amount_skipped, _("B")); } } else { /* @@ -530,9 +487,7 @@ static int pv__transfer_read(pvstate_t state, int fd, * On error, sets *eof_out to 1, sets state->written to -1, and updates * state->exit_status. */ -static int pv__transfer_write(pvstate_t state, - int *eof_in, int *eof_out, - long *lineswritten) +static int pv__transfer_write(pvstate_t state, int *eof_in, int *eof_out, long *lineswritten) { ssize_t nwritten; @@ -541,9 +496,7 @@ static int pv__transfer_write(pvstate_t state, nwritten = pv__transfer_write_repeated(STDOUT_FILENO, state->transfer_buffer + - state->write_position, - state->to_write, - state->sync_after_write); + state->write_position, state->to_write, state->sync_after_write); alarm(0); @@ -565,33 +518,25 @@ static int pv__transfer_write(pvstate_t state, char *ptr; long lines = 0; - save = - state->transfer_buffer[state->write_position + - nwritten]; - state->transfer_buffer[state->write_position + - nwritten] = 0; - ptr = - (char *) (state->transfer_buffer + - state->write_position - 1); + save = state->transfer_buffer[state->write_position + nwritten]; + state->transfer_buffer[state->write_position + nwritten] = 0; + ptr = (char *) (state->transfer_buffer + state->write_position - 1); if (state->null) { for (ptr++; ptr - (char *) state->transfer_buffer - - state->write_position < - (size_t) nwritten; ptr++) { + state->write_position < (size_t) nwritten; ptr++) { if (*ptr == '\0') ++lines; } } else { - while ((ptr = - strchr((char *) (ptr + 1), '\n'))) + while ((ptr = strchr((char *) (ptr + 1), '\n'))) ++lines; } *lineswritten += lines; - state->transfer_buffer[state->write_position + - nwritten] = save; + state->transfer_buffer[state->write_position + nwritten] = save; } state->write_position += nwritten; @@ -607,20 +552,16 @@ static int pv__transfer_write(pvstate_t state, new_portion_length = nwritten; if (new_portion_length > state->lastoutput_length) - new_portion_length = - state->lastoutput_length; + new_portion_length = state->lastoutput_length; - old_portion_length = - state->lastoutput_length - new_portion_length; + old_portion_length = state->lastoutput_length - new_portion_length; /* * Make room for the new portion. */ if (old_portion_length > 0) { memmove(state->lastoutput_buffer, - state->lastoutput_buffer + - new_portion_length, - old_portion_length); + state->lastoutput_buffer + new_portion_length, old_portion_length); } /* @@ -628,9 +569,7 @@ static int pv__transfer_write(pvstate_t state, */ memcpy(state->lastoutput_buffer + old_portion_length, - state->transfer_buffer + - state->write_position - new_portion_length, - new_portion_length); + state->transfer_buffer + state->write_position - new_portion_length, new_portion_length); } /* @@ -696,8 +635,7 @@ static int pv__transfer_write(pvstate_t state, * * Returns NULL on complete allocation failure. */ -static unsigned char *pv__allocate_aligned_buffer(int fd, - size_t target_size) +static unsigned char *pv__allocate_aligned_buffer(int fd, size_t target_size) { unsigned char *newptr; @@ -728,9 +666,7 @@ static unsigned char *pv__allocate_aligned_buffer(int fd, required_alignment = min_alignment; } - if (0 != - posix_memalign((void **) (&newptr), required_alignment, - target_size)) { + if (0 != posix_memalign((void **) (&newptr), required_alignment, target_size)) { newptr = (unsigned char *) malloc(target_size); } #else /* ! defined(HAVE_FPATHCONF) && defined(HAVE_POSIX_MEMALIGN) && defined(_PC_REC_XFER_ALIGN) */ @@ -752,8 +688,7 @@ static unsigned char *pv__allocate_aligned_buffer(int fd, * state->exit_status is updated). In line mode, the number of lines written * will be put into *lineswritten. */ -long pv_transfer(pvstate_t state, int fd, int *eof_in, int *eof_out, - unsigned long long allowed, long *lineswritten) +long pv_transfer(pvstate_t state, int fd, int *eof_in, int *eof_out, unsigned long long allowed, long *lineswritten) { struct timeval tv; fd_set readfds; @@ -771,14 +706,11 @@ long pv_transfer(pvstate_t state, int fd, int *eof_in, int *eof_out, */ if (state->direct_io_changed) { if (!(*eof_in)) { - fcntl(fd, F_SETFL, - (state->direct_io ? O_DIRECT : 0) | fcntl(fd, - F_GETFL)); + fcntl(fd, F_SETFL, (state->direct_io ? O_DIRECT : 0) | fcntl(fd, F_GETFL)); } if (!(*eof_out)) { fcntl(STDOUT_FILENO, F_SETFL, - (state->direct_io ? O_DIRECT : 0) | - fcntl(STDOUT_FILENO, F_GETFL)); + (state->direct_io ? O_DIRECT : 0) | fcntl(STDOUT_FILENO, F_GETFL)); } state->direct_io_changed = false; } @@ -799,14 +731,9 @@ long pv_transfer(pvstate_t state, int fd, int *eof_in, int *eof_out, * (important if using O_DIRECT). */ if (NULL == state->transfer_buffer) { - state->transfer_buffer = - pv__allocate_aligned_buffer(fd, - state->target_buffer_size + - 32); + state->transfer_buffer = pv__allocate_aligned_buffer(fd, state->target_buffer_size + 32); if (NULL == state->transfer_buffer) { - pv_error(state, "%s: %s", - _("buffer allocation failed"), - strerror(errno)); + pv_error(state, "%s: %s", _("buffer allocation failed"), strerror(errno)); state->exit_status |= 64; return -1; } @@ -822,10 +749,7 @@ long pv_transfer(pvstate_t state, int fd, int *eof_in, int *eof_out, */ if (state->buffer_size < state->target_buffer_size) { unsigned char *newptr; - newptr = - pv__allocate_aligned_buffer(fd, - state->target_buffer_size + - 32); + newptr = pv__allocate_aligned_buffer(fd, state->target_buffer_size + 32); if (NULL == newptr) { /* * Reset target if realloc failed so we don't keep @@ -834,15 +758,13 @@ long pv_transfer(pvstate_t state, int fd, int *eof_in, int *eof_out, debug("realloc: %s", strerror(errno)); state->target_buffer_size = state->buffer_size; } else { - debug("%s: %ld", "buffer resized", - state->buffer_size); + debug("%s: %ld", "buffer resized", state->buffer_size); /* * Copy the old buffer contents into the new buffer, * and free the old one. */ if (state->buffer_size > 0) - memcpy(newptr, state->transfer_buffer, - state->buffer_size); + memcpy(newptr, state->transfer_buffer, state->buffer_size); free(state->transfer_buffer); state->transfer_buffer = newptr; state->buffer_size = state->target_buffer_size; @@ -908,9 +830,7 @@ long pv_transfer(pvstate_t state, int fd, int *eof_in, int *eof_out, /* * Any other error is a problem and we must report back. */ - pv_error(state, "%s: %s: %d: %s", - state->current_file, - _("select call failed"), n, strerror(errno)); + pv_error(state, "%s: %s: %d: %s", state->current_file, _("select call failed"), n, strerror(errno)); state->exit_status |= 16; @@ -926,8 +846,7 @@ long pv_transfer(pvstate_t state, int fd, int *eof_in, int *eof_out, * NB this can update state->written because of splice(). */ if (FD_ISSET(fd, &readfds)) { - if (pv__transfer_read - (state, fd, eof_in, eof_out, allowed) == 0) + if (pv__transfer_read(state, fd, eof_in, eof_out, allowed) == 0) return 0; } @@ -943,18 +862,12 @@ long pv_transfer(pvstate_t state, int fd, int *eof_in, int *eof_out, char *start; char *end; - save = - state->transfer_buffer[state->write_position + - state->to_write]; - state->transfer_buffer[state->write_position + - state->to_write] = 0; + save = state->transfer_buffer[state->write_position + state->to_write]; + state->transfer_buffer[state->write_position + state->to_write] = 0; - start = - (char *) (state->transfer_buffer + - state->write_position); + start = (char *) (state->transfer_buffer + state->write_position); end = strrchr(start, '\n'); - state->transfer_buffer[state->write_position + - state->to_write] = save; + state->transfer_buffer[state->write_position + state->to_write] = save; if (end != NULL) { state->to_write = (end - start) + 1; @@ -972,8 +885,7 @@ long pv_transfer(pvstate_t state, int fd, int *eof_in, int *eof_out, #endif /* HAVE_SPLICE */ && (state->read_position > state->write_position) && (state->to_write > 0)) { - if (pv__transfer_write - (state, eof_in, eof_out, lineswritten) == 0) + if (pv__transfer_write(state, eof_in, eof_out, lineswritten) == 0) return 0; } #ifdef MAXIMISE_BUFFER_FILL @@ -985,9 +897,7 @@ long pv_transfer(pvstate_t state, int fd, int *eof_in, int *eof_out, if (state->write_position < state->read_position) { memmove(state->transfer_buffer, state->transfer_buffer + - state->write_position, - state->read_position - - state->write_position); + state->write_position, state->read_position - state->write_position); state->read_position -= state->write_position; state->write_position = 0; } else { diff --git a/src/pv/watchpid.c b/src/pv/watchpid.c index 188c4c5..89e2daf 100644 --- a/src/pv/watchpid.c +++ b/src/pv/watchpid.c @@ -70,9 +70,7 @@ int pv_watchfd_info(pvstate_t state, pvwatchfd_t info, int automatic) if (kill(info->watch_pid, 0) != 0) { if (!automatic) - pv_error(state, "%s %u: %s", - _("pid"), - info->watch_pid, strerror(errno)); + pv_error(state, "%s %u: %s", _("pid"), info->watch_pid, strerror(errno)); return 1; } @@ -82,14 +80,11 @@ int pv_watchfd_info(pvstate_t state, pvwatchfd_t info, int automatic) PROC_PIDFDVNODEPATHINFO_SIZE); if (size != PROC_PIDFDVNODEPATHINFO_SIZE) { pv_error(state, "%s %u: %s %d: %s", - _("pid"), - info->watch_pid, - _("fd"), info->watch_fd, strerror(errno)); + _("pid"), info->watch_pid, _("fd"), info->watch_fd, strerror(errno)); return 3; } - strlcpy(info->file_fdpath, vnodeInfo.pvip.vip_path, - PV_SIZEOF_FILE_FDPATH); + strlcpy(info->file_fdpath, vnodeInfo.pvip.vip_path, PV_SIZEOF_FILE_FDPATH); info->size = 0; @@ -97,10 +92,7 @@ int pv_watchfd_info(pvstate_t state, pvwatchfd_t info, int automatic) if (!automatic) pv_error(state, "%s %u: %s %d: %s: %s", _("pid"), - info->watch_pid, - _("fd"), - info->watch_fd, info->file_fdpath, - strerror(errno)); + info->watch_pid, _("fd"), info->watch_fd, info->file_fdpath, strerror(errno)); return 3; } @@ -109,10 +101,7 @@ int pv_watchfd_info(pvstate_t state, pvwatchfd_t info, int automatic) pv_error(state, "%s %u: %s %d: %s: %s", _("pid"), info->watch_pid, - _("fd"), - info->watch_fd, - info->file_fdpath, - _("not a regular file or block device")); + _("fd"), info->watch_fd, info->file_fdpath, _("not a regular file or block device")); return 4; } @@ -147,27 +136,18 @@ int pv_watchfd_info(pvstate_t state, pvwatchfd_t info, int automatic) if (kill(info->watch_pid, 0) != 0) { if (!automatic) - pv_error(state, "%s %u: %s", - _("pid"), - info->watch_pid, strerror(errno)); + pv_error(state, "%s %u: %s", _("pid"), info->watch_pid, strerror(errno)); return 1; } (void) pv_snprintf(info->file_fdinfo, PV_SIZEOF_FILE_FDINFO, - "/proc/%u/fdinfo/%d", info->watch_pid, - info->watch_fd); - (void) pv_snprintf(info->file_fd, PV_SIZEOF_FILE_FD, - "/proc/%u/fd/%d", info->watch_pid, - info->watch_fd); + "/proc/%u/fdinfo/%d", info->watch_pid, info->watch_fd); + (void) pv_snprintf(info->file_fd, PV_SIZEOF_FILE_FD, "/proc/%u/fd/%d", info->watch_pid, info->watch_fd); memset(info->file_fdpath, 0, PV_SIZEOF_FILE_FDPATH); - if (readlink - (info->file_fd, info->file_fdpath, - PV_SIZEOF_FILE_FDPATH - 1) < 0) { + if (readlink(info->file_fd, info->file_fdpath, PV_SIZEOF_FILE_FDPATH - 1) < 0) { if (!automatic) pv_error(state, "%s %u: %s %d: %s", - _("pid"), - info->watch_pid, - _("fd"), info->watch_fd, strerror(errno)); + _("pid"), info->watch_pid, _("fd"), info->watch_fd, strerror(errno)); return 2; } @@ -176,10 +156,7 @@ int pv_watchfd_info(pvstate_t state, pvwatchfd_t info, int automatic) if (!automatic) pv_error(state, "%s %u: %s %d: %s: %s", _("pid"), - info->watch_pid, - _("fd"), - info->watch_fd, info->file_fdpath, - strerror(errno)); + info->watch_pid, _("fd"), info->watch_fd, info->file_fdpath, strerror(errno)); return 3; } @@ -191,10 +168,7 @@ int pv_watchfd_info(pvstate_t state, pvwatchfd_t info, int automatic) pv_error(state, "%s %u: %s %d: %s: %s", _("pid"), info->watch_pid, - _("fd"), - info->watch_fd, - info->file_fdpath, - _("not a regular file or block device")); + _("fd"), info->watch_fd, info->file_fdpath, _("not a regular file or block device")); return ret; } @@ -272,13 +246,11 @@ long long pv_watchfd_position(pvwatchfd_t info) #ifdef __APPLE__ -static int pidfds(pvstate_t state, unsigned int pid, - struct proc_fdinfo **fds, int *count) +static int pidfds(pvstate_t state, unsigned int pid, struct proc_fdinfo **fds, int *count) { int size_needed = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, 0, 0); if (size_needed == -1) { - pv_error(state, "%s: unable to list pid fds: %s", _("pid"), - strerror(errno)); + pv_error(state, "%s: unable to list pid fds: %s", _("pid"), strerror(errno)); return -1; } @@ -286,8 +258,7 @@ static int pidfds(pvstate_t state, unsigned int pid, *fds = (struct proc_fdinfo *) malloc(size_needed); if (*fds == NULL) { - pv_error(state, "%s: alloc failed: %s", _("pid"), - strerror(errno)); + pv_error(state, "%s: alloc failed: %s", _("pid"), strerror(errno)); return -1; } @@ -306,8 +277,7 @@ static int pidfds(pvstate_t state, unsigned int pid, */ int pv_watchpid_scanfds(pvstate_t state, pvstate_t pristine, unsigned int watch_pid, int *array_length_ptr, - pvwatchfd_t * info_array_ptr, - pvstate_t * state_array_ptr, int *fd_to_idx) + pvwatchfd_t * info_array_ptr, pvstate_t * state_array_ptr, int *fd_to_idx) { char fd_dir[512] = { 0, }; int array_length = 0; @@ -326,8 +296,7 @@ int pv_watchpid_scanfds(pvstate_t state, pvstate_t pristine, DIR *dptr; struct dirent *d; - (void) pv_snprintf(fd_dir, sizeof(fd_dir), "/proc/%u/fd", - watch_pid); + (void) pv_snprintf(fd_dir, sizeof(fd_dir), "/proc/%u/fd", watch_pid); dptr = opendir(fd_dir); if (NULL == dptr) @@ -389,14 +358,9 @@ int pv_watchpid_scanfds(pvstate_t state, pvstate_t pristine, use_idx = array_length - 1; if (NULL == info_array) { - new_info_array = - malloc(array_length * - sizeof(*info_array)); + new_info_array = malloc(array_length * sizeof(*info_array)); } else { - new_info_array = - realloc(info_array, - array_length * - sizeof(*info_array)); + new_info_array = realloc(info_array, array_length * sizeof(*info_array)); } if (NULL == new_info_array) return 2; @@ -405,14 +369,9 @@ int pv_watchpid_scanfds(pvstate_t state, pvstate_t pristine, info_array[use_idx].watch_pid = 0; if (NULL == state_array) { - new_state_array = - malloc(array_length * - sizeof(*state_array)); + new_state_array = malloc(array_length * sizeof(*state_array)); } else { - new_state_array = - realloc(state_array, - array_length * - sizeof(*state_array)); + new_state_array = realloc(state_array, array_length * sizeof(*state_array)); } if (NULL == new_state_array) return 2; @@ -421,10 +380,8 @@ int pv_watchpid_scanfds(pvstate_t state, pvstate_t pristine, *array_length_ptr = array_length; - for (check_idx = 0; check_idx < array_length; - check_idx++) { - state_array[check_idx].name = - info_array[check_idx].display_name; + for (check_idx = 0; check_idx < array_length; check_idx++) { + state_array[check_idx].name = info_array[check_idx].display_name; state_array[check_idx].reparse_display = 1; } } @@ -434,10 +391,8 @@ int pv_watchpid_scanfds(pvstate_t state, pvstate_t pristine, /* * Initialise the details of this new entry. */ - memcpy(&(state_array[use_idx]), pristine, - sizeof(*pristine)); - memset(&(info_array[use_idx]), 0, - sizeof(info_array[use_idx])); + memcpy(&(state_array[use_idx]), pristine, sizeof(*pristine)); + memset(&(info_array[use_idx]), 0, sizeof(info_array[use_idx])); info_array[use_idx].watch_pid = watch_pid; info_array[use_idx].watch_fd = fd; @@ -453,9 +408,7 @@ int pv_watchpid_scanfds(pvstate_t state, pvstate_t pristine, */ if ((rc != 0) && (rc != 4)) { info_array[use_idx].watch_pid = 0; - debug("%s %d: %s: %d", "fd", fd, - "lookup failed - marking slot for re-use", - use_idx); + debug("%s %d: %s: %d", "fd", fd, "lookup failed - marking slot for re-use", use_idx); continue; } @@ -466,18 +419,14 @@ int pv_watchpid_scanfds(pvstate_t state, pvstate_t pristine, * show it. */ if (rc != 0) { - debug("%s %d: %s", "fd", fd, - "marking as not displayable"); + debug("%s %d: %s", "fd", fd, "marking as not displayable"); info_array[use_idx].watch_fd = -1; } state_array[use_idx].size = info_array[use_idx].size; if (state_array[use_idx].size < 1) { char *fmt; - while (NULL != - (fmt = - strstr(state_array[use_idx].default_format, - "%e"))) { + while (NULL != (fmt = strstr(state_array[use_idx].default_format, "%e"))) { debug("%s", "zero size - removing ETA"); /* strlen-1 here to include trailing NUL */ memmove(fmt, fmt + 2, strlen(fmt) - 1); @@ -485,8 +434,7 @@ int pv_watchpid_scanfds(pvstate_t state, pvstate_t pristine, } } - state_array[use_idx].name = - info_array[use_idx].display_name; + state_array[use_idx].name = info_array[use_idx].display_name; pv_watchpid_setname(state, &(info_array[use_idx])); @@ -532,8 +480,7 @@ void pv_watchpid_setname(pvstate_t state, pvwatchfd_t info) path_length = strlen(info->file_fdpath); cwd_length = strlen(state->cwd); if (cwd_length > 0 && path_length > cwd_length) { - if (0 == - strncmp(info->file_fdpath, state->cwd, cwd_length)) { + if (0 == strncmp(info->file_fdpath, state->cwd, cwd_length)) { file_fdpath += cwd_length + 1; path_length -= cwd_length + 1; } @@ -542,9 +489,7 @@ void pv_watchpid_setname(pvstate_t state, pvwatchfd_t info) max_display_length = (state->width / 2) - 6; if (max_display_length >= path_length) { (void) pv_snprintf(info->display_name, - PV_SIZEOF_DISPLAY_NAME, - "%4d:%.498s", info->watch_fd, - file_fdpath); + PV_SIZEOF_DISPLAY_NAME, "%4d:%.498s", info->watch_fd, file_fdpath); } else { int prefix_length, suffix_length; @@ -555,13 +500,10 @@ void pv_watchpid_setname(pvstate_t state, pvwatchfd_t info) PV_SIZEOF_DISPLAY_NAME, "%4d:%.*s...%.*s", info->watch_fd, prefix_length, - file_fdpath, suffix_length, - file_fdpath + path_length - - suffix_length); + file_fdpath, suffix_length, file_fdpath + path_length - suffix_length); } - debug("%s: %d: [%s]", "set name for fd", info->watch_fd, - info->display_name); + debug("%s: %d: [%s]", "set name for fd", info->watch_fd, info->display_name); } /* EOF */