diff options
author | Ron Yorston <rmy@pobox.com> | 2021-01-26 14:12:04 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-01-26 14:50:34 +0000 |
commit | 7e1c2cb3b2c917f799d406e186fa84dcac19e992 (patch) | |
tree | 3f18abd6f4f4a4504073b6ec8ab0d24f3d68449d | |
parent | 48684e182f2e6195af191be00ccf08788d91db7a (diff) | |
download | busybox-w32-7e1c2cb3b2c917f799d406e186fa84dcac19e992.tar.gz busybox-w32-7e1c2cb3b2c917f799d406e186fa84dcac19e992.tar.bz2 busybox-w32-7e1c2cb3b2c917f799d406e186fa84dcac19e992.zip |
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.
-rw-r--r-- | coreutils/stat.c | 9 |
1 files 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, | |||
314 | struct passwd *pw_ent; | 314 | struct passwd *pw_ent; |
315 | struct group *gw_ent; | 315 | struct group *gw_ent; |
316 | 316 | ||
317 | #if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_READLINK2 | ||
317 | if (m == 'n') { | 318 | if (m == 'n') { |
318 | printfs(pformat, filename); | 319 | printfs(pformat, filename); |
319 | } else if (m == 'N') { | 320 | } else if (m == 'N') { |
320 | strcatc(pformat, 's'); | 321 | strcatc(pformat, 's'); |
321 | #if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_READLINK2 | ||
322 | if (S_ISLNK(statbuf->st_mode)) { | 322 | if (S_ISLNK(statbuf->st_mode)) { |
323 | char *linkname = xmalloc_readlink_or_warn(filename); | 323 | char *linkname = xmalloc_readlink_or_warn(filename); |
324 | if (linkname == NULL) | 324 | if (linkname == NULL) |
@@ -329,7 +329,8 @@ static void FAST_FUNC print_stat(char *pformat, const char m, | |||
329 | printf(pformat, filename); | 329 | printf(pformat, filename); |
330 | } | 330 | } |
331 | #else | 331 | #else |
332 | printf(pformat, filename); | 332 | if (m == 'n' || m == 'N') { |
333 | printfs(pformat, filename); | ||
333 | #endif | 334 | #endif |
334 | } else if (m == 'd') { | 335 | } else if (m == 'd') { |
335 | strcat(pformat, "llu"); | 336 | strcat(pformat, "llu"); |
@@ -717,15 +718,13 @@ static bool do_stat(const char *filename, const char *format) | |||
717 | #if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_READLINK2 | 718 | #if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_READLINK2 |
718 | if (S_ISLNK(statbuf.st_mode)) | 719 | if (S_ISLNK(statbuf.st_mode)) |
719 | linkname = xmalloc_readlink_or_warn(filename); | 720 | linkname = xmalloc_readlink_or_warn(filename); |
721 | #endif | ||
720 | if (linkname) { | 722 | if (linkname) { |
721 | printf(" File: '%s' -> '%s'\n", filename, linkname); | 723 | printf(" File: '%s' -> '%s'\n", filename, linkname); |
722 | free(linkname); | 724 | free(linkname); |
723 | } else { | 725 | } else { |
724 | printf(" File: '%s'\n", filename); | 726 | printf(" File: '%s'\n", filename); |
725 | } | 727 | } |
726 | #else | ||
727 | printf(" File: '%s'\n", filename); | ||
728 | #endif | ||
729 | 728 | ||
730 | printf(" Size: %-10llu\tBlocks: %-10llu IO Block: %-6lu %s\n" | 729 | printf(" Size: %-10llu\tBlocks: %-10llu IO Block: %-6lu %s\n" |
731 | "Device: %llxh/%llud\tInode: %-10llu Links: %-5lu", | 730 | "Device: %llxh/%llud\tInode: %-10llu Links: %-5lu", |