annotate toys/realpath.c @ 577:2a757e592ff7

Remove strndupa() gnu-ism at Georgi's suggestion, and adjust mdev to compile with new dirtree. (No idea if it works, this command was never finished and needs a lot more work.)
author Rob Landley <rob@landley.net>
date Wed, 09 May 2012 06:39:01 -0500
parents 7d4dbde67dfb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
469
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
1 /* vi: set sw=4 ts=4:
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
2 *
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * realpath.c - Return the canonical version of a pathname
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 * Copyright 2012 Andre Renaud <andre@bluewatersys.com>
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
6 *
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
7 * Not in SUSv4.
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
8
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
9 USE_REALPATH(NEWTOY(realpath, "<1", TOYFLAG_USR|TOYFLAG_BIN))
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
10
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
11 config REALPATH
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
12 bool "realpath"
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
13 default y
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
14 help
470
7d4dbde67dfb Move realpath from loopfiles() to a for loop, so we don't get hung on read permission for file data when we just want to look at directory info.
Rob Landley <rob@landley.net>
parents: 469
diff changeset
15 usage: realpath FILE...
7d4dbde67dfb Move realpath from loopfiles() to a for loop, so we don't get hung on read permission for file data when we just want to look at directory info.
Rob Landley <rob@landley.net>
parents: 469
diff changeset
16
469
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
17 Display the canonical absolute pathname
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
18 */
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
19
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 #include "toys.h"
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
21
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 void realpath_main(void)
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
23 {
470
7d4dbde67dfb Move realpath from loopfiles() to a for loop, so we don't get hung on read permission for file data when we just want to look at directory info.
Rob Landley <rob@landley.net>
parents: 469
diff changeset
24 char **s = toys.optargs;
7d4dbde67dfb Move realpath from loopfiles() to a for loop, so we don't get hung on read permission for file data when we just want to look at directory info.
Rob Landley <rob@landley.net>
parents: 469
diff changeset
25 for (s = toys.optargs; *s; s++) {
7d4dbde67dfb Move realpath from loopfiles() to a for loop, so we don't get hung on read permission for file data when we just want to look at directory info.
Rob Landley <rob@landley.net>
parents: 469
diff changeset
26 if (!realpath(*s, toybuf)) {
7d4dbde67dfb Move realpath from loopfiles() to a for loop, so we don't get hung on read permission for file data when we just want to look at directory info.
Rob Landley <rob@landley.net>
parents: 469
diff changeset
27 perror_msg("cannot access '%s'", *s);
7d4dbde67dfb Move realpath from loopfiles() to a for loop, so we don't get hung on read permission for file data when we just want to look at directory info.
Rob Landley <rob@landley.net>
parents: 469
diff changeset
28 toys.exitval = 1;
7d4dbde67dfb Move realpath from loopfiles() to a for loop, so we don't get hung on read permission for file data when we just want to look at directory info.
Rob Landley <rob@landley.net>
parents: 469
diff changeset
29 } else xputs(toybuf);
7d4dbde67dfb Move realpath from loopfiles() to a for loop, so we don't get hung on read permission for file data when we just want to look at directory info.
Rob Landley <rob@landley.net>
parents: 469
diff changeset
30 }
469
6378ca1da18e Realpath, by Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
31 }