[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Findutils-patches] [PATCH 5/8] lib: Update the width of the st_nlink fi
From: |
James Youngman |
Subject: |
[Findutils-patches] [PATCH 5/8] lib: Update the width of the st_nlink field and fix some compiler warnings. |
Date: |
Sat, 2 Jan 2016 23:54:55 +0000 |
* 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
- [Findutils-patches] (no subject), James Youngman, 2016/01/02
- [Findutils-patches] [PATCH 1/8] maint: Remove --I../intl from AM_CPPFLAGS; the directory is gone., James Youngman, 2016/01/02
- [Findutils-patches] [PATCH 4/8] xargs: Avoid unused-macro warnings., James Youngman, 2016/01/02
- [Findutils-patches] [PATCH 5/8] lib: Update the width of the st_nlink field and fix some compiler warnings.,
James Youngman <=
- [Findutils-patches] [PATCH 3/8] find: Fix a number of compiler warnings (mostly const-correctness)., James Youngman, 2016/01/02
- [Findutils-patches] [PATCH 2/8] maint: Don't define the gettext-related macro N_ where it is not needed., James Youngman, 2016/01/02
- [Findutils-patches] [PATCH 6/8] locate: Fix compiler warnings., James Youngman, 2016/01/02
- [Findutils-patches] [PATCH 8/8] configure: Add option --enable-compiler-warnings-are-errors, limit --enable-compiler-warnings., James Youngman, 2016/01/02
- [Findutils-patches] [PATCH 7/8] find: fix some compiler warnings., James Youngman, 2016/01/02