readlink: code shrink

function                                             old     new   delta
readlink_main                                        111     103      -8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
master
Denys Vlasenko 2023-05-07 18:44:03 +02:00
parent c6058d221a
commit 07f8b6feac
1 changed files with 4 additions and 5 deletions

View File

@ -68,12 +68,11 @@ int readlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int readlink_main(int argc UNUSED_PARAM, char **argv)
{
char *buf;
char *fname;
unsigned opt;
/* -n must use bit 0 (see printf below) */
opt = getopt32(argv, "^" "n" IF_FEATURE_READLINK_FOLLOW("fvsq")
"\0" "=1");
fname = argv[optind];
/* compat: coreutils readlink reports errors silently via exit code */
if (!(opt & 4)) /* not -v */
@ -81,14 +80,14 @@ int readlink_main(int argc UNUSED_PARAM, char **argv)
/* NOFORK: only one alloc is allowed; must free */
if (opt & 2) { /* -f */
buf = xmalloc_realpath_coreutils(fname);
buf = xmalloc_realpath_coreutils(argv[optind]);
} else {
buf = xmalloc_readlink_or_warn(fname);
buf = xmalloc_readlink_or_warn(argv[optind]);
}
if (!buf)
return EXIT_FAILURE;
printf((opt & 1) ? "%s" : "%s\n", buf);
printf("%s%s", buf, &"\n"[opt & 1]);
free(buf);
fflush_stdout_and_exit_SUCCESS();