* lib/listfile.h (list_file): Make the relname parameter const. * lib/listfile.c (list_file): Make the relname parameter const. Remove the unused local variable inode_field_width. Update nlink_width with the greatest width of the st_nlink field, and print the field using the maximum width (as we do for other fields). --- lib/listfile.c | 27 ++++++++++++++++++++++++--- lib/listfile.h | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/lib/listfile.c b/lib/listfile.c index 4b7d4b2..c6c8609 100644 --- a/lib/listfile.c +++ b/lib/listfile.c @@ -111,7 +111,7 @@ static bool print_num(FILE *stream, unsigned long num, int *width) void list_file (const char *name, int dir_fd, - char *relname, + const char *relname, const struct stat *statp, time_t current_time, int output_block_size, @@ -126,7 +126,6 @@ list_file (const char *name, bool output_good = true; int chars_out; int failed_at = 000; - int inode_field_width; #if HAVE_ST_DM_MODE /* Cray DMF: look at the file's migrated, not real, status */ @@ -179,13 +178,35 @@ list_file (const char *name, output_good = false; failed_at = 250; } + } + if (output_good) + { /* modebuf includes the space between the mode and the number of links, as the POSIX "optional alternate access method flag". */ - if (fprintf (stream, "%s%3lu ", modebuf, (unsigned long) statp->st_nlink) < 0) + if (fputs (modebuf, stream) < 0) + { + output_good = false; + failed_at = 275; + } + } + if (output_good) + { + /* This format used to end in a space, but the output of "ls" + has only one space between the link count and the owner name, + so we removed the trailing space. Happily this also makes it + easier to update nlink_width. */ + chars_out = fprintf (stream, "%*lu", + nlink_width, (unsigned long) statp->st_nlink); + if (chars_out < 0) { output_good = false; failed_at = 300; } + else + { + if (chars_out > nlink_width) + nlink_width = chars_out; + } } if (output_good) diff --git a/lib/listfile.h b/lib/listfile.h index 9ee71a2..2e15165 100644 --- a/lib/listfile.h +++ b/lib/listfile.h @@ -19,5 +19,5 @@ #if !defined LISTFILE_H # define LISTFILE_H -void list_file (const char *name, int dir_fd, char *relname, const struct stat *statp, time_t current_time, int output_block_size, int literal_control_chars, FILE *stream); +void list_file (const char *name, int dir_fd, const char *relname, const struct stat *statp, time_t current_time, int output_block_size, int literal_control_chars, FILE *stream); #endif -- 2.1.4