diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-10-16 05:16:50 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-10-16 05:16:50 +0200 |
commit | 4c77ad75b11caa824a82eb8a88e91d71c51cdd43 (patch) | |
tree | ced5adb21a97c0e5647090f3e12282b0e64322be | |
parent | ecccbac37b733a57099c73bc806ac5de64643a35 (diff) | |
download | busybox-w32-4c77ad75b11caa824a82eb8a88e91d71c51cdd43.tar.gz busybox-w32-4c77ad75b11caa824a82eb8a88e91d71c51cdd43.tar.bz2 busybox-w32-4c77ad75b11caa824a82eb8a88e91d71c51cdd43.zip |
pwd: implement -LP if DESKTOP
function old new delta
pwd_main 41 244 +203
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/pwd.c | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/coreutils/pwd.c b/coreutils/pwd.c index 739b835b5..9455975e7 100644 --- a/coreutils/pwd.c +++ b/coreutils/pwd.c | |||
@@ -20,13 +20,63 @@ | |||
20 | 20 | ||
21 | /* This is a NOFORK applet. Be very careful! */ | 21 | /* This is a NOFORK applet. Be very careful! */ |
22 | 22 | ||
23 | static int logical_getcwd(void) | ||
24 | { | ||
25 | struct stat st1; | ||
26 | struct stat st2; | ||
27 | char *wd; | ||
28 | char *p; | ||
29 | |||
30 | wd = getenv("PWD"); | ||
31 | if (!wd || wd[0] != '/') | ||
32 | return 0; | ||
33 | |||
34 | p = wd; | ||
35 | while (*p) { | ||
36 | /* doing strstr(p, "/.") by hand is smaller and faster... */ | ||
37 | if (*p++ != '/') | ||
38 | continue; | ||
39 | if (*p != '.') | ||
40 | continue; | ||
41 | /* we found "/.", skip to next char */ | ||
42 | p++; | ||
43 | if (*p == '.') | ||
44 | p++; /* we found "/.." */ | ||
45 | if (*p == '\0' || *p == '/') | ||
46 | return 0; /* "/./" or "/../" component: bad */ | ||
47 | } | ||
48 | |||
49 | if (stat(wd, &st1) != 0) | ||
50 | return 0; | ||
51 | if (stat(".", &st2) != 0) | ||
52 | return 0; | ||
53 | if (st1.st_ino != st2.st_ino) | ||
54 | return 0; | ||
55 | if (st1.st_dev != st2.st_dev) | ||
56 | return 0; | ||
57 | |||
58 | puts(wd); | ||
59 | return 1; | ||
60 | } | ||
61 | |||
23 | int pwd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 62 | int pwd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
24 | int pwd_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | 63 | int pwd_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
25 | { | 64 | { |
26 | char *buf; | 65 | char *buf; |
27 | 66 | ||
67 | if (ENABLE_DESKTOP) { | ||
68 | /* TODO: assume -L if $POSIXLY_CORRECT? (coreutils does that) | ||
69 | * Rationale: | ||
70 | * POSIX requires a default of -L, but most scripts expect -P | ||
71 | */ | ||
72 | unsigned opt = getopt32(argv, "LP"); | ||
73 | if ((opt & 1) && logical_getcwd()) | ||
74 | return fflush_all(); | ||
75 | } | ||
76 | |||
28 | buf = xrealloc_getcwd_or_warn(NULL); | 77 | buf = xrealloc_getcwd_or_warn(NULL); |
29 | if (buf != NULL) { | 78 | |
79 | if (buf) { | ||
30 | puts(buf); | 80 | puts(buf); |
31 | free(buf); | 81 | free(buf); |
32 | return fflush_all(); | 82 | return fflush_all(); |