From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH 6/7] whereis: canonicalize files before printing
Date: Sat, 16 Mar 2013 23:40:18 +0000 [thread overview]
Message-ID: <1363477219-29245-7-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1363477219-29245-1-git-send-email-kerolasa@iki.fi>
The whereis gives promise to find files so it seems to be more correct
print symlink destinations than locations of symlinks.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/Makemodule.am | 1 +
misc-utils/whereis.c | 20 +++++++++++++-------
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/misc-utils/Makemodule.am b/misc-utils/Makemodule.am
index b77c30a..a615047 100644
--- a/misc-utils/Makemodule.am
+++ b/misc-utils/Makemodule.am
@@ -44,6 +44,7 @@ namei_SOURCES = misc-utils/namei.c lib/strutils.c
usrbin_exec_PROGRAMS += whereis
dist_man_MANS += misc-utils/whereis.1
whereis_SOURCES = misc-utils/whereis.c
+whereis_LDADD = $(LDADD) libcommon.la
if BUILD_LSLOCKS
usrbin_exec_PROGRAMS += lslocks
diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c
index 3fad843..5136eff 100644
--- a/misc-utils/whereis.c
+++ b/misc-utils/whereis.c
@@ -55,6 +55,7 @@
#include "nls.h"
#include "c.h"
#include "closestream.h"
+#include "canonicalize.h"
#define BIN_BIT (1 << 1)
#define MAN_BIT (1 << 2)
@@ -204,21 +205,26 @@ static void findin(char *dir, char *cp, int *nr_found, char **wait)
{
DIR *dirp;
struct dirent *dp;
+ char *full_path, *rl;
dirp = opendir(dir);
if (dirp == NULL)
return;
while ((dp = readdir(dirp)) != NULL)
if (itsit(cp, dp->d_name)) {
+ xasprintf(&full_path, "%s/%s", dir, dp->d_name);
+ rl = canonicalize_path(full_path);
+ free(full_path);
if (*(nr_found) == 0)
- xasprintf(wait, "%s/%s", dir, dp->d_name);
- else if (*(nr_found) == 1 && *wait != NULL)
- printf("%s: %s %s/%s", cp, *wait, dir,
- dp->d_name);
- else if (*(nr_found) == 1)
- printf("%s: %s/%s", cp, dir, dp->d_name);
+ wait = &rl;
+ else if (*(nr_found) == 1 && *wait != NULL) {
+ printf("%s: %s %s", cp, *wait, rl);
+ free(*wait);
+ } else if (*(nr_found) == 1)
+ printf("%s: %s", cp, rl);
else
- printf(" %s/%s", dir, dp->d_name);
+ printf(" %s", rl);
+ free(rl);
(*nr_found)++;
}
closedir(dirp);
--
1.8.2
next prev parent reply other threads:[~2013-03-16 23:40 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-16 23:40 [PATCH 0/7] pull: whereis changes Sami Kerola
2013-03-16 23:40 ` [PATCH 1/7] whereis: rewrite most of the command Sami Kerola
2013-03-16 23:40 ` [PATCH 2/7] whereis: add search scope listing option Sami Kerola
2013-03-16 23:40 ` [PATCH 3/7] whereis: align with howto-usage-function.txt Sami Kerola
2013-03-16 23:40 ` [PATCH 4/7] whereis: support MANPATH environment variable Sami Kerola
2013-03-16 23:40 ` [PATCH 5/7] docs: generic whereis.1 clean up Sami Kerola
2013-03-16 23:40 ` Sami Kerola [this message]
2013-03-20 12:56 ` [PATCH 6/7] whereis: canonicalize files before printing Karel Zak
2013-03-20 14:03 ` Sami Kerola
2013-03-16 23:40 ` [PATCH 7/7] whereis: remove duplicates from search results Sami Kerola
2013-03-20 12:59 ` Karel Zak
2013-03-17 9:23 ` [PATCH 0/7] pull: whereis changes Sami Kerola
2013-03-20 13:02 ` Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1363477219-29245-7-git-send-email-kerolasa@iki.fi \
--to=kerolasa@iki.fi \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox