Remove overly specific edge-case error messages, where just the filename and the system error would suffice; replace all the different types of memory allocation error with "memory allocation failure", since the action for the end-user is the same in all cases; and use the error messages "memory allocation failure", "interrupted by a signal", "error closing file", "input file is also the output", and "write error" since these are all used by either coreutils and grep, in similar contexts, so their translations can be copied.
This commit is contained in:
+1
-1
@@ -701,7 +701,7 @@ int main(int argc, char **argv)
|
||||
* mitigated by the fact that each string is only translated
|
||||
* once.
|
||||
*/
|
||||
pv_perror("%s", _("state allocation failed"));
|
||||
pv_perror("%s", _("memory allocation failure"));
|
||||
opts_free(opts);
|
||||
debug("%s: %d", "exiting with status", PV_ERROREXIT_MEMORY);
|
||||
pv_set_error_prefix(NULL);
|
||||
|
||||
+10
-21
@@ -534,10 +534,8 @@ static bool opts_use_size_of_file(opts_t opts, const char *size_file)
|
||||
stat_rc = stat(size_file, &sb);
|
||||
|
||||
if (0 != stat_rc) {
|
||||
/*@-mustfreefresh@ *//* see above */
|
||||
pv_perror("%s: %s", size_file, _("failed to stat file"));
|
||||
pv_perror("%s", size_file);
|
||||
return false;
|
||||
/*@+mustfreefresh@ */
|
||||
}
|
||||
|
||||
/* This was a regular file - use its size and return. */
|
||||
@@ -577,10 +575,9 @@ static bool opts_use_size_of_file(opts_t opts, const char *size_file)
|
||||
#else /* HAVE_NFTW */
|
||||
/* This was a directory - report an error. */
|
||||
if (S_ISDIR((mode_t) (sb.st_mode))) {
|
||||
/*@-mustfreefresh@ *//* see above */
|
||||
pv_error("%s: %s", size_file, _("is a directory"));
|
||||
errno = EISDIR;
|
||||
pv_perror("%s", size_file);
|
||||
return false;
|
||||
/*@+mustfreefresh@ */
|
||||
}
|
||||
#endif /* !HAVE_NFTW */
|
||||
|
||||
@@ -606,10 +603,8 @@ static bool opts_use_size_of_file(opts_t opts, const char *size_file)
|
||||
if (pv_snprintf
|
||||
(sysfs_filename, sizeof(sysfs_filename), "/sys/dev/block/%u:%u/size", major(sb.st_rdev),
|
||||
minor(sb.st_rdev)) < 0) {
|
||||
/*@-mustfreefresh@ *//* see above */
|
||||
pv_perror("%s: %s", size_file, _("failed to generate sysfs filename"));
|
||||
pv_perror("%s", size_file);
|
||||
return false;
|
||||
/*@+mustfreefresh@ */
|
||||
}
|
||||
|
||||
sysfs_fptr = fopen(sysfs_filename, "r"); /* flawfinder: ignore */
|
||||
@@ -627,11 +622,9 @@ static bool opts_use_size_of_file(opts_t opts, const char *size_file)
|
||||
}
|
||||
/* Read not successful - report the error and return. */
|
||||
/* NB fclose() comes after the error report, to retain errno. */
|
||||
/*@-mustfreefresh@ *//* see above */
|
||||
pv_perror("%s: %s", size_file, _("failed to read sysfs size file"));
|
||||
pv_perror("%s: %s", size_file, sysfs_filename);
|
||||
(void) fclose(sysfs_fptr);
|
||||
return false;
|
||||
/*@+mustfreefresh@ */
|
||||
}
|
||||
#endif /* CAN_BUILD_SYSFS_FILENAME */
|
||||
|
||||
@@ -646,21 +639,17 @@ static bool opts_use_size_of_file(opts_t opts, const char *size_file)
|
||||
*/
|
||||
|
||||
if (device_fd < 0) {
|
||||
/*@-mustfreefresh@ *//* see above */
|
||||
pv_perror("%s: %s", size_file, _("failed to open block device"));
|
||||
pv_perror("%s", size_file);
|
||||
return false;
|
||||
/*@+mustfreefresh@ */
|
||||
}
|
||||
|
||||
device_size = (off_t) lseek(device_fd, 0, SEEK_END);
|
||||
|
||||
if (device_size < 0) {
|
||||
/*@-mustfreefresh@ *//* see above */
|
||||
pv_perror("%s: %s", size_file, _("failed to determine size of block device"));
|
||||
pv_perror("%s", size_file);
|
||||
/* NB close() after reporting error, to preserve errno. */
|
||||
(void) close(device_fd);
|
||||
return false;
|
||||
/*@+mustfreefresh@ */
|
||||
}
|
||||
|
||||
(void) close(device_fd);
|
||||
@@ -762,9 +751,9 @@ opts_t opts_parse(unsigned int argc, char **argv)
|
||||
char *leafptr;
|
||||
|
||||
opts = calloc(1, sizeof(*opts));
|
||||
if (!opts) {
|
||||
if (NULL == opts) {
|
||||
/*@-mustfreefresh@ *//* see above */
|
||||
pv_perror("%s", _("option structure allocation failed"));
|
||||
pv_perror("%s", _("memory allocation failure"));
|
||||
return NULL;
|
||||
/*@+mustfreefresh@ */
|
||||
}
|
||||
@@ -784,7 +773,7 @@ opts_t opts_parse(unsigned int argc, char **argv)
|
||||
opts->argv = calloc((size_t) (argc + 1), sizeof(char *));
|
||||
if (NULL == opts->argv) {
|
||||
/*@-mustfreefresh@ *//* see above */
|
||||
pv_perror("%s", _("option structure argv allocation failed"));
|
||||
pv_perror("%s", _("memory allocation failure"));
|
||||
free(opts); /* can't call opts_free as argv is not set */
|
||||
return NULL;
|
||||
/*@+mustfreefresh@ */
|
||||
|
||||
+11
-5
@@ -70,7 +70,13 @@ static void pv_crs_open_lockfile(pvcursorstate_t cursor, readonly_pvcontrol_t co
|
||||
ttydev = pv_strdup(ttyname(fd));
|
||||
if (NULL == ttydev) {
|
||||
if (!control->force) {
|
||||
pv_error("%s", _("failed to get terminal name"));
|
||||
/*
|
||||
* Error not translated as this should never be
|
||||
* reached, since ttyname() will have been called
|
||||
* earlier, and if it failed, cursor positioning
|
||||
* would have been turned off.
|
||||
*/
|
||||
pv_perror("%s", "ttyname");
|
||||
}
|
||||
/*
|
||||
* If the terminal name is unknown, then neither IPC nor a
|
||||
@@ -159,7 +165,7 @@ static void pv_crs_lock(pvcursorstate_t cursor, readonly_pvcontrol_t control, in
|
||||
lock_fd = cursor->lock_fd;
|
||||
}
|
||||
} else {
|
||||
pv_perror("%s", _("lock attempt failed"));
|
||||
pv_perror("%s", NULL == cursor->lock_file ? "(tty)" : cursor->lock_file);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -434,7 +440,7 @@ void pv_crs_init(pvcursorstate_t cursor, readonly_pvcontrol_t control, pvtransie
|
||||
*/
|
||||
|
||||
if (terminalfd < 0) {
|
||||
pv_perror("%s: %s", ttyfile, _("failed to open terminal"));
|
||||
pv_perror("%s", ttyfile);
|
||||
cursor->disable = true;
|
||||
return;
|
||||
}
|
||||
@@ -781,9 +787,9 @@ void pv_report_signal_interrupt(int signum)
|
||||
/*@+unrecog @ */
|
||||
#endif
|
||||
if (NULL != signal_name) {
|
||||
pv_error("%s: %s", _("exiting due to signal"), signal_name);
|
||||
pv_error("%s: %s", _("interrupted by a signal"), signal_name);
|
||||
} else {
|
||||
pv_error("%s", _("exiting due to signal"));
|
||||
pv_error("%s", _("interrupted by a signal"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1079,7 +1079,7 @@ static bool pv_format(pvprogramstatus_t status, readonly_pvcontrol_t control, re
|
||||
|
||||
new_buffer = malloc(new_size + 16);
|
||||
if (NULL == new_buffer) {
|
||||
pv_perror("%s", _("buffer allocation failed"));
|
||||
pv_perror("%s", _("memory allocation failure"));
|
||||
status->exit_status |= PV_ERROREXIT_MEMORY;
|
||||
display->display_buffer = NULL;
|
||||
return false;
|
||||
|
||||
+7
-8
@@ -212,9 +212,8 @@ static off_t pv_calc_total_bytes(pvstate_t state)
|
||||
total = end_position;
|
||||
}
|
||||
if (lseek(state->control.output_fd, 0, SEEK_SET) != 0) {
|
||||
pv_perror("%s: %s",
|
||||
NULL == state->control.output_name ? "(null)" : state->control.output_name,
|
||||
_("failed to seek to start of output"));
|
||||
pv_perror("%s",
|
||||
NULL == state->control.output_name ? "(null)" : state->control.output_name);
|
||||
state->status.exit_status |= PV_ERROREXIT_ACCESS;
|
||||
}
|
||||
/*
|
||||
@@ -369,7 +368,7 @@ int pv_next_file(pvstate_t state, unsigned int filenum, int oldfd)
|
||||
|
||||
if (oldfd >= 0) {
|
||||
if (0 != close(oldfd)) {
|
||||
pv_perror("%s", _("failed to close file"));
|
||||
pv_perror("%s: %s", pv_current_file_name(state), _("error closing file"));
|
||||
state->status.exit_status |= PV_ERROREXIT_TRANSITION;
|
||||
return -1;
|
||||
}
|
||||
@@ -401,21 +400,21 @@ int pv_next_file(pvstate_t state, unsigned int filenum, int oldfd)
|
||||
* open symlinks would be counterintuitive.
|
||||
*/
|
||||
if (fd < 0) {
|
||||
pv_perror("%s: %s", next_filename, _("failed to read file"));
|
||||
pv_perror("%s", next_filename);
|
||||
state->status.exit_status |= PV_ERROREXIT_ACCESS;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 != fstat(fd, &isb)) {
|
||||
pv_perror("%s: %s", NULL == next_filename ? "-" : next_filename, _("failed to stat file"));
|
||||
pv_perror("%s", NULL == next_filename ? "-" : next_filename);
|
||||
(void) close(fd);
|
||||
state->status.exit_status |= PV_ERROREXIT_ACCESS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 != fstat(state->control.output_fd, &osb)) {
|
||||
pv_perror("%s", _("failed to stat output file"));
|
||||
pv_perror("%s", NULL == state->control.output_name ? "(null)" : state->control.output_name);
|
||||
(void) close(fd);
|
||||
state->status.exit_status |= PV_ERROREXIT_ACCESS;
|
||||
return -1;
|
||||
@@ -436,7 +435,7 @@ int pv_next_file(pvstate_t state, unsigned int filenum, int oldfd)
|
||||
input_file_is_output = false;
|
||||
|
||||
if (input_file_is_output) {
|
||||
pv_error("%s: %s", _("input file is output file"), NULL == next_filename ? "-" : next_filename);
|
||||
pv_error("%s: %s", _("input file is also the output"), NULL == next_filename ? "-" : next_filename);
|
||||
(void) close(fd);
|
||||
state->status.exit_status |= PV_ERROREXIT_OUROBOROS;
|
||||
return -1;
|
||||
|
||||
+4
-4
@@ -42,7 +42,7 @@ static void pv_alloc_calc_history(pvtransfercalc_t calc)
|
||||
* unavoidable memory leak warnings, but they are mitigated
|
||||
* by the fact that each string is only translated once.
|
||||
*/
|
||||
pv_perror("%s", _("history structure allocation failed"));
|
||||
pv_perror("%s", _("memory allocation failure"));
|
||||
/*@+mustfreefresh@ */
|
||||
return;
|
||||
}
|
||||
@@ -891,7 +891,7 @@ void pv_state_inputfiles(pvstate_t state, unsigned int input_file_count, const c
|
||||
new_array = calloc((size_t) (input_file_count + 1), sizeof(char *));
|
||||
if (NULL == new_array) {
|
||||
/*@-mustfreefresh@ *//* see similar _() issue above */
|
||||
pv_perror("%s", _("file list allocation failed"));
|
||||
pv_perror("%s", _("memory allocation failure"));
|
||||
/*@+mustfreefresh@ */
|
||||
return;
|
||||
}
|
||||
@@ -903,7 +903,7 @@ void pv_state_inputfiles(pvstate_t state, unsigned int input_file_count, const c
|
||||
new_string = pv_strdup(input_files[file_idx]);
|
||||
if (NULL == new_string) {
|
||||
/*@-mustfreefresh@ *//* see similar _() issue above */
|
||||
pv_perror("%s", _("file list allocation failed"));
|
||||
pv_perror("%s", _("memory allocation failure"));
|
||||
/*@+mustfreefresh@ */
|
||||
return;
|
||||
}
|
||||
@@ -939,7 +939,7 @@ void pv_state_watchfds(pvstate_t state, unsigned int watchfd_count, const pid_t
|
||||
new_array = malloc((1 + watchfd_count) * sizeof(*new_array));
|
||||
if (NULL == new_array) {
|
||||
/*@-mustfreefresh@ *//* see similar _() issue above */
|
||||
pv_perror("%s", _("buffer allocation failed"));
|
||||
pv_perror("%s", _("memory allocation failure"));
|
||||
/*@+mustfreefresh@ */
|
||||
return;
|
||||
}
|
||||
|
||||
+24
-11
@@ -739,7 +739,7 @@ static bool pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_o
|
||||
* the end of the file was reached.
|
||||
*/
|
||||
if (do_not_skip_errors) {
|
||||
pv_perror("%s: %s", pv_current_file_name(state), _("read failed"));
|
||||
pv_perror("%s", pv_current_file_name(state));
|
||||
*eof_in = true;
|
||||
if (state->transfer.write_position >= state->transfer.read_position) {
|
||||
*eof_out = true;
|
||||
@@ -765,8 +765,8 @@ static bool pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_o
|
||||
* report the error and behave as if the end of input had been
|
||||
* reached.
|
||||
*/
|
||||
if (0 > orig_offset) {
|
||||
pv_perror("%s: %s", pv_current_file_name(state), _("file is not seekable"));
|
||||
if (orig_offset < 0) {
|
||||
pv_perror("%s", pv_current_file_name(state));
|
||||
*eof_in = true;
|
||||
if (state->transfer.write_position >= state->transfer.read_position) {
|
||||
*eof_out = true;
|
||||
@@ -843,7 +843,7 @@ static bool pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_o
|
||||
* file was reached.
|
||||
*/
|
||||
if (EINVAL != errno) {
|
||||
pv_perror("%s: %s", pv_current_file_name(state), _("failed to seek past error"));
|
||||
pv_perror("%s", pv_current_file_name(state));
|
||||
}
|
||||
} else {
|
||||
amount_skipped = skip_offset - orig_offset;
|
||||
@@ -906,7 +906,12 @@ static bool pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, lon
|
||||
size_t write_check_position, write_end_position;
|
||||
|
||||
if (NULL == state->transfer.transfer_buffer) {
|
||||
pv_error("%s", _("no transfer buffer allocated"));
|
||||
/*
|
||||
* Report it as a generic allocation error, since this
|
||||
* condition should never be reached due to checks made on
|
||||
* the path to this function.
|
||||
*/
|
||||
pv_error("%s", _("memory allocation failure"));
|
||||
state->status.exit_status |= PV_ERROREXIT_MEMORY;
|
||||
*eof_out = true;
|
||||
state->transfer.written = -1;
|
||||
@@ -994,7 +999,12 @@ static bool pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, lon
|
||||
(long) (new_timer.it_value.tv_usec));
|
||||
|
||||
if (0 != setitimer(ITIMER_REAL, &new_timer, NULL)) {
|
||||
pv_perror("%s", _("failed to set interval timer"));
|
||||
/*
|
||||
* Record failure only as debugging information,
|
||||
* since if this call failed, it's not actionable by
|
||||
* the user and would only clutter the display.
|
||||
*/
|
||||
debug("%s: %s", "setitimer (set) failed", strerror(errno));
|
||||
}
|
||||
|
||||
#else /* ! HAVE_SETITIMER */
|
||||
@@ -1020,7 +1030,8 @@ static bool pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, lon
|
||||
new_timer.it_value.tv_sec = 0;
|
||||
new_timer.it_value.tv_usec = 0;
|
||||
if (0 != setitimer(ITIMER_REAL, &new_timer, NULL)) {
|
||||
pv_perror("%s", _("failed to clear interval timer"));
|
||||
/* Debug output only, as above. */
|
||||
debug("%s: %s", "setitimer (clear) failed", strerror(errno));
|
||||
}
|
||||
|
||||
/*@+unrecog@ */
|
||||
@@ -1067,7 +1078,7 @@ static bool pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, lon
|
||||
state->transfer.line_positions =
|
||||
calloc((size_t) (state->transfer.line_positions_capacity), sizeof(off_t));
|
||||
if (NULL == state->transfer.line_positions) {
|
||||
pv_perror("%s", _("line position buffer allocation failed"));
|
||||
pv_perror("%s", _("memory allocation failure"));
|
||||
}
|
||||
/*@+mustfreeonly@ */
|
||||
/*
|
||||
@@ -1256,7 +1267,9 @@ static bool pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, lon
|
||||
* adjust the exit status, and mark the output as EOF.
|
||||
*/
|
||||
|
||||
pv_error("%s: %s", _("write failed"), strerror(write_errno));
|
||||
errno = write_errno;
|
||||
pv_perror("%s: %s", NULL == state->control.output_name ? "(null)" : state->control.output_name,
|
||||
_("write error"));
|
||||
state->status.exit_status |= PV_ERROREXIT_TRANSFER;
|
||||
*eof_out = true;
|
||||
state->transfer.written = -1;
|
||||
@@ -1392,7 +1405,7 @@ ssize_t pv_transfer(pvstate_t state, int fd, bool *eof_in, bool *eof_out, off_t
|
||||
state->transfer.transfer_buffer =
|
||||
pv__allocate_aligned_buffer(state->control.output_fd, fd, state->control.target_buffer_size + 32);
|
||||
if (NULL == state->transfer.transfer_buffer) {
|
||||
pv_perror("%s", _("buffer allocation failed"));
|
||||
pv_perror("%s", _("memory allocation failure"));
|
||||
state->status.exit_status |= PV_ERROREXIT_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
@@ -1492,7 +1505,7 @@ ssize_t pv_transfer(pvstate_t state, int fd, bool *eof_in, bool *eof_out, off_t
|
||||
/*
|
||||
* Any other error is reported and causes an early return.
|
||||
*/
|
||||
pv_perror("%s: %s", pv_current_file_name(state), _("select call failed"));
|
||||
pv_perror("%s", pv_current_file_name(state));
|
||||
|
||||
state->status.exit_status |= PV_ERROREXIT_TRANSFER;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user