From 7e1c2cb3b2c917f799d406e186fa84dcac19e992 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 26 Jan 2021 14:12:04 +0000 Subject: stat: improve conditional compilation If FEATURE_READLINK2 isn't enabled: - in print_stat() combine the code for 'n' and 'N' format; - in do_stat() let the compiler figure out that it doesn't need to emit code to print the symbolic link. --- coreutils/stat.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/coreutils/stat.c b/coreutils/stat.c index 0a3f251f3..1267df450 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c @@ -314,11 +314,11 @@ static void FAST_FUNC print_stat(char *pformat, const char m, struct passwd *pw_ent; struct group *gw_ent; +#if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_READLINK2 if (m == 'n') { printfs(pformat, filename); } else if (m == 'N') { strcatc(pformat, 's'); -#if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_READLINK2 if (S_ISLNK(statbuf->st_mode)) { char *linkname = xmalloc_readlink_or_warn(filename); if (linkname == NULL) @@ -329,7 +329,8 @@ static void FAST_FUNC print_stat(char *pformat, const char m, printf(pformat, filename); } #else - printf(pformat, filename); + if (m == 'n' || m == 'N') { + printfs(pformat, filename); #endif } else if (m == 'd') { strcat(pformat, "llu"); @@ -717,15 +718,13 @@ static bool do_stat(const char *filename, const char *format) #if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_READLINK2 if (S_ISLNK(statbuf.st_mode)) linkname = xmalloc_readlink_or_warn(filename); +#endif if (linkname) { printf(" File: '%s' -> '%s'\n", filename, linkname); free(linkname); } else { printf(" File: '%s'\n", filename); } -#else - printf(" File: '%s'\n", filename); -#endif printf(" Size: %-10llu\tBlocks: %-10llu IO Block: %-6lu %s\n" "Device: %llxh/%llud\tInode: %-10llu Links: %-5lu", -- cgit v1.2.3-55-g6feb