From e9897e542d2e7cdabd881d1b3002d387c0a51faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Thu, 9 Dec 2021 23:44:51 +0100 Subject: [PATCH] libzfs: diff: print_what() can return the symbol => get_what() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Brian Behlendorf Reviewed-by: Rich Ercolani Signed-off-by: Ahelenia ZiemiaƄska Closes #12829 --- lib/libzfs/libzfs_diff.c | 55 +++++++++++++--------------------------- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/lib/libzfs/libzfs_diff.c b/lib/libzfs/libzfs_diff.c index 57a7c15565..77b9da6aad 100644 --- a/lib/libzfs/libzfs_diff.c +++ b/lib/libzfs/libzfs_diff.c @@ -129,48 +129,35 @@ stream_bytes(FILE *fp, const char *string) } } -static void -print_what(FILE *fp, mode_t what) +static char +get_what(mode_t what) { - char symbol; - switch (what & S_IFMT) { case S_IFBLK: - symbol = 'B'; - break; + return ('B'); case S_IFCHR: - symbol = 'C'; - break; + return ('C'); case S_IFDIR: - symbol = '/'; - break; + return ('/'); #ifdef S_IFDOOR case S_IFDOOR: - symbol = '>'; - break; + return ('>'); #endif case S_IFIFO: - symbol = '|'; - break; + return ('|'); case S_IFLNK: - symbol = '@'; - break; + return ('@'); #ifdef S_IFPORT case S_IFPORT: - symbol = 'P'; - break; + return ('P'); #endif case S_IFSOCK: - symbol = '='; - break; + return ('='); case S_IFREG: - symbol = 'F'; - break; + return ('F'); default: - symbol = '?'; - break; + return ('?'); } - (void) fprintf(fp, "%c", symbol); } static void @@ -194,10 +181,8 @@ print_rename(FILE *fp, differ_info_t *di, const char *old, const char *new, (longlong_t)isb->zs_ctime[0], (longlong_t)isb->zs_ctime[1]); (void) fprintf(fp, "%c\t", ZDIFF_RENAMED); - if (di->classify) { - print_what(fp, isb->zs_mode); - (void) fprintf(fp, "\t"); - } + if (di->classify) + (void) fprintf(fp, "%c\t", get_what(isb->zs_mode)); print_cmn(fp, di, old); if (di->scripted) (void) fprintf(fp, "\t"); @@ -216,10 +201,8 @@ print_link_change(FILE *fp, differ_info_t *di, int delta, const char *file, (longlong_t)isb->zs_ctime[0], (longlong_t)isb->zs_ctime[1]); (void) fprintf(fp, "%c\t", ZDIFF_MODIFIED); - if (di->classify) { - print_what(fp, isb->zs_mode); - (void) fprintf(fp, "\t"); - } + if (di->classify) + (void) fprintf(fp, "%c\t", get_what(isb->zs_mode)); print_cmn(fp, di, file); (void) fprintf(fp, "\t(%+d)", delta); (void) fprintf(fp, "\n"); @@ -234,10 +217,8 @@ print_file(FILE *fp, differ_info_t *di, char type, const char *file, (longlong_t)isb->zs_ctime[0], (longlong_t)isb->zs_ctime[1]); (void) fprintf(fp, "%c\t", type); - if (di->classify) { - print_what(fp, isb->zs_mode); - (void) fprintf(fp, "\t"); - } + if (di->classify) + (void) fprintf(fp, "%c\t", get_what(isb->zs_mode)); print_cmn(fp, di, file); (void) fprintf(fp, "\n"); }