aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2023-05-07 18:44:03 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2023-05-07 18:44:03 +0200
commit07f8b6feac2ff80793394b5b5acff5cd149d7fb2 (patch)
tree5a42975b744f58419aa017a3898c3d41b6bf0055
parentc6058d221a44718d086e067b08b070bdce16a7ef (diff)
downloadbusybox-w32-07f8b6feac2ff80793394b5b5acff5cd149d7fb2.tar.gz
busybox-w32-07f8b6feac2ff80793394b5b5acff5cd149d7fb2.tar.bz2
busybox-w32-07f8b6feac2ff80793394b5b5acff5cd149d7fb2.zip
readlink: code shrink
function old new delta readlink_main 111 103 -8 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/readlink.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/coreutils/readlink.c b/coreutils/readlink.c
index 0a9aa957e..e17fc3b1e 100644
--- a/coreutils/readlink.c
+++ b/coreutils/readlink.c
@@ -68,12 +68,11 @@ int readlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
68int readlink_main(int argc UNUSED_PARAM, char **argv) 68int readlink_main(int argc UNUSED_PARAM, char **argv)
69{ 69{
70 char *buf; 70 char *buf;
71 char *fname;
72 unsigned opt; 71 unsigned opt;
73 72
73 /* -n must use bit 0 (see printf below) */
74 opt = getopt32(argv, "^" "n" IF_FEATURE_READLINK_FOLLOW("fvsq") 74 opt = getopt32(argv, "^" "n" IF_FEATURE_READLINK_FOLLOW("fvsq")
75 "\0" "=1"); 75 "\0" "=1");
76 fname = argv[optind];
77 76
78 /* compat: coreutils readlink reports errors silently via exit code */ 77 /* compat: coreutils readlink reports errors silently via exit code */
79 if (!(opt & 4)) /* not -v */ 78 if (!(opt & 4)) /* not -v */
@@ -81,14 +80,14 @@ int readlink_main(int argc UNUSED_PARAM, char **argv)
81 80
82 /* NOFORK: only one alloc is allowed; must free */ 81 /* NOFORK: only one alloc is allowed; must free */
83 if (opt & 2) { /* -f */ 82 if (opt & 2) { /* -f */
84 buf = xmalloc_realpath_coreutils(fname); 83 buf = xmalloc_realpath_coreutils(argv[optind]);
85 } else { 84 } else {
86 buf = xmalloc_readlink_or_warn(fname); 85 buf = xmalloc_readlink_or_warn(argv[optind]);
87 } 86 }
88 87
89 if (!buf) 88 if (!buf)
90 return EXIT_FAILURE; 89 return EXIT_FAILURE;
91 printf((opt & 1) ? "%s" : "%s\n", buf); 90 printf("%s%s", buf, &"\n"[opt & 1]);
92 free(buf); 91 free(buf);
93 92
94 fflush_stdout_and_exit_SUCCESS(); 93 fflush_stdout_and_exit_SUCCESS();