From 0038f9d39a306c3c7860756f03102de217dc5cd9 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 10 Apr 2018 21:52:58 +0100 Subject: ls, stat: don't try to read symlinks Currently the WIN32 emulation of readlink(2) fails with ENOSYS. This causes ugly error messages in ls and stat. Don't even try calling readlink(2) and skip any code that uses the name it doesn't return. --- coreutils/ls.c | 2 ++ coreutils/stat.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/coreutils/ls.c b/coreutils/ls.c index 4cc9517b1..b0c543d28 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -492,9 +492,11 @@ static NOINLINE unsigned display_single(const struct dnode *dn) /* Do readlink early, so that if it fails, error message * does not appear *inside* the "ls -l" line */ lpath = NULL; +#if !ENABLE_PLATFORM_MINGW32 if (opt & OPT_l) if (S_ISLNK(dn->dn_mode)) lpath = xmalloc_readlink_or_warn(dn->fullname); +#endif if (opt & OPT_i) /* show inode# */ column += printf("%7"LL_FMT"u ", (long long) dn->dn_ino); diff --git a/coreutils/stat.c b/coreutils/stat.c index 2944cdfcb..43fad2324 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c @@ -317,6 +317,7 @@ static void FAST_FUNC print_stat(char *pformat, const char m, printfs(pformat, filename); } else if (m == 'N') { strcatc(pformat, 's'); +#if !ENABLE_PLATFORM_MINGW32 if (S_ISLNK(statbuf->st_mode)) { char *linkname = xmalloc_readlink_or_warn(filename); if (linkname == NULL) @@ -326,6 +327,9 @@ static void FAST_FUNC print_stat(char *pformat, const char m, } else { printf(pformat, filename); } +#else + printf(pformat, filename); +#endif } else if (m == 'd') { strcat(pformat, "llu"); printf(pformat, (unsigned long long) statbuf->st_dev); @@ -708,6 +712,7 @@ static bool do_stat(const char *filename, const char *format) gw_ent = getgrgid(statbuf.st_gid); pw_ent = getpwuid(statbuf.st_uid); +#if !ENABLE_PLATFORM_MINGW32 if (S_ISLNK(statbuf.st_mode)) linkname = xmalloc_readlink_or_warn(filename); if (linkname) { @@ -716,6 +721,9 @@ static bool do_stat(const char *filename, const char *format) } 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