diff --git a/builtins/cd.def b/builtins/cd.def index b87c5d9..5e4e78e 100644 --- a/builtins/cd.def +++ b/builtins/cd.def @@ -28,6 +28,8 @@ $PRODUCES cd.c # include #endif +# include + #include "../bashtypes.h" #include "posixdir.h" #include "posixstat.h" @@ -461,13 +463,14 @@ cd_builtin (list) $BUILTIN pwd $FUNCTION pwd_builtin -$SHORT_DOC pwd [-LP] +$SHORT_DOC pwd [-LPW] Print the name of the current working directory. Options: -L print the value of $PWD if it names the current working directory -P print the physical directory, without any symbolic links + -W print the Win32 value of the physical directory By default, `pwd' behaves as if `-L' were specified. @@ -485,13 +488,13 @@ int pwd_builtin (list) WORD_LIST *list; { - char *directory; + char *directory, *buffer, *wbuffer; int opt, pflag; verbatim_pwd = no_symbolic_links; pflag = 0; reset_internal_getopt (); - while ((opt = internal_getopt (list, "LP")) != -1) + while ((opt = internal_getopt (list, "LPW")) != -1) { switch (opt) { @@ -501,6 +504,9 @@ pwd_builtin (list) case 'L': verbatim_pwd = 0; break; + case 'W': + verbatim_pwd = 2; + break; CASE_HELPOPT; default: builtin_usage (); @@ -509,6 +515,19 @@ pwd_builtin (list) } list = loptend; + if (verbatim_pwd == 2) { + buffer = xmalloc (PATH_MAX); + wbuffer = xmalloc (PATH_MAX); + directory = getcwd (buffer, PATH_MAX); + cygwin_conv_path (CCP_POSIX_TO_WIN_A|CCP_ABSOLUTE, buffer, wbuffer, PATH_MAX+1); + { + char *c = wbuffer; + while (c = strchr (c, '\\')) + *c = '/'; + } + free (buffer); + directory = wbuffer; + } else { #define tcwd the_current_working_directory directory = tcwd ? (verbatim_pwd ? sh_physpath (tcwd, 0) : tcwd) @@ -525,6 +544,7 @@ pwd_builtin (list) } #undef tcwd + } if (directory) {