annotate toys/readlink.c @ 587:82ffae226c40

Convert another realpath use to xrealpath().
author Rob Landley <rob@landley.net>
date Fri, 01 Jun 2012 17:59:11 -0500
parents 163498bf547b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
1 /* vi: set sw=4 ts=4:
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
2 *
129
0dfead29c893 Add readlink. Why doesn't mercurial show newly added files in "hg diff"?
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * readlink.c - Return string representation of a symbolic link.
194
30a6db5a95c2 Add comments about SUSv3 specs (or lack thereof).
Rob Landley <rob@landley.net>
parents: 186
diff changeset
4 *
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
5 * Copyright 2007 Rob Landley <rob@landley.net>
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
6 *
194
30a6db5a95c2 Add comments about SUSv3 specs (or lack thereof).
Rob Landley <rob@landley.net>
parents: 186
diff changeset
7 * Not in SUSv3.
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
8
234
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
9 USE_READLINK(NEWTOY(readlink, "<1f", TOYFLAG_BIN))
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
10
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
11 config READLINK
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
12 bool "readlink"
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
13 default n
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
14 help
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
15 usage: readlink
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
16
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
17 Show what a symbolic link points to.
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
18
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
19 config READLINK_F
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
20 bool "readlink -f"
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
21 default n
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
22 depends on READLINK
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
23 help
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
24 usage: readlink [-f]
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
25
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
26 -f Show full cannonical path, with no symlinks in it. Returns
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
27 nonzero if nothing could currently exist at this location.
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 223
diff changeset
28 */
129
0dfead29c893 Add readlink. Why doesn't mercurial show newly added files in "hg diff"?
Rob Landley <rob@landley.net>
parents:
diff changeset
29
0dfead29c893 Add readlink. Why doesn't mercurial show newly added files in "hg diff"?
Rob Landley <rob@landley.net>
parents:
diff changeset
30 #include "toys.h"
0dfead29c893 Add readlink. Why doesn't mercurial show newly added files in "hg diff"?
Rob Landley <rob@landley.net>
parents:
diff changeset
31
186
25447caf1b4b Change command main() functions to return void, and exit(toys.exitval) from
Rob Landley <rob@landley.net>
parents: 129
diff changeset
32 void readlink_main(void)
129
0dfead29c893 Add readlink. Why doesn't mercurial show newly added files in "hg diff"?
Rob Landley <rob@landley.net>
parents:
diff changeset
33 {
223
52a0c06b2dad Teach readlink to actually do -f.
Rob Landley <rob@landley.net>
parents: 194
diff changeset
34 char *s;
52a0c06b2dad Teach readlink to actually do -f.
Rob Landley <rob@landley.net>
parents: 194
diff changeset
35
52a0c06b2dad Teach readlink to actually do -f.
Rob Landley <rob@landley.net>
parents: 194
diff changeset
36 // Calculating full cannonical path?
52a0c06b2dad Teach readlink to actually do -f.
Rob Landley <rob@landley.net>
parents: 194
diff changeset
37
587
82ffae226c40 Convert another realpath use to xrealpath().
Rob Landley <rob@landley.net>
parents: 234
diff changeset
38 if (CFG_READLINK_F && toys.optflags) s = xrealpath(*toys.optargs);
223
52a0c06b2dad Teach readlink to actually do -f.
Rob Landley <rob@landley.net>
parents: 194
diff changeset
39 else s = xreadlink(*toys.optargs);
129
0dfead29c893 Add readlink. Why doesn't mercurial show newly added files in "hg diff"?
Rob Landley <rob@landley.net>
parents:
diff changeset
40
0dfead29c893 Add readlink. Why doesn't mercurial show newly added files in "hg diff"?
Rob Landley <rob@landley.net>
parents:
diff changeset
41 if (s) {
0dfead29c893 Add readlink. Why doesn't mercurial show newly added files in "hg diff"?
Rob Landley <rob@landley.net>
parents:
diff changeset
42 xputs(s);
0dfead29c893 Add readlink. Why doesn't mercurial show newly added files in "hg diff"?
Rob Landley <rob@landley.net>
parents:
diff changeset
43 if (CFG_TOYBOX_FREE) free(s);
186
25447caf1b4b Change command main() functions to return void, and exit(toys.exitval) from
Rob Landley <rob@landley.net>
parents: 129
diff changeset
44 } else toys.exitval = 1;
129
0dfead29c893 Add readlink. Why doesn't mercurial show newly added files in "hg diff"?
Rob Landley <rob@landley.net>
parents:
diff changeset
45 }