summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-03-06 12:00:50 +0000
committerRon Yorston <rmy@pobox.com>2019-03-06 12:00:50 +0000
commit585d17d262efabce4a9a87f33f531ef9ab7c0e36 (patch)
treee9b5d4bffaf1d8962d3c3d5e4529d7b87f831c7c
parent5c5197df8668ba58ec7799ccc418d124a6c6a49e (diff)
downloadbusybox-w32-585d17d262efabce4a9a87f33f531ef9ab7c0e36.tar.gz
busybox-w32-585d17d262efabce4a9a87f33f531ef9ab7c0e36.tar.bz2
busybox-w32-585d17d262efabce4a9a87f33f531ef9ab7c0e36.zip
win32: canonicalize path in chdir(2)
Provide an implementation of chdir(2) which canonicalizes the path to resolve symlinks. Otherwise changing to a symlinked directory confuses 'ls -l' because it thinks '.' is a link rather than a directory. OTOH, using 'cd' in the shell to change to a symlinked directory now results in a mismatch between the shell's idea of where we are and what's displayed in the prompt. But upstream BusyBox does that too so it must be OK.
-rw-r--r--include/mingw.h2
-rw-r--r--win32/mingw.c13
2 files changed, 15 insertions, 0 deletions
diff --git a/include/mingw.h b/include/mingw.h
index b5324e49b..9bc5eb018 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -271,9 +271,11 @@ mode_t mingw_umask(mode_t mode);
271IMPL(fchmod,int,0,int fildes UNUSED_PARAM, mode_t mode UNUSED_PARAM); 271IMPL(fchmod,int,0,int fildes UNUSED_PARAM, mode_t mode UNUSED_PARAM);
272NOIMPL(fchown,int fd UNUSED_PARAM, uid_t uid UNUSED_PARAM, gid_t gid UNUSED_PARAM); 272NOIMPL(fchown,int fd UNUSED_PARAM, uid_t uid UNUSED_PARAM, gid_t gid UNUSED_PARAM);
273int mingw_mkdir(const char *path, int mode); 273int mingw_mkdir(const char *path, int mode);
274int mingw_chdir(const char *path);
274int mingw_chmod(const char *path, int mode); 275int mingw_chmod(const char *path, int mode);
275 276
276#define mkdir mingw_mkdir 277#define mkdir mingw_mkdir
278#define chdir mingw_chdir
277#define chmod mingw_chmod 279#define chmod mingw_chmod
278 280
279#if ENABLE_LFS && !defined(__MINGW64_VERSION_MAJOR) 281#if ENABLE_LFS && !defined(__MINGW64_VERSION_MAJOR)
diff --git a/win32/mingw.c b/win32/mingw.c
index c42dbed97..b1a8b9711 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -1159,6 +1159,19 @@ int mingw_mkdir(const char *path, int mode UNUSED_PARAM)
1159 return ret; 1159 return ret;
1160} 1160}
1161 1161
1162#undef chdir
1163int mingw_chdir(const char *dirname)
1164{
1165 int ret = -1;
1166 char *realdir = xmalloc_realpath(dirname);
1167
1168 if (realdir) {
1169 ret = chdir(realdir);
1170 free(realdir);
1171 }
1172 return ret;
1173}
1174
1162#undef chmod 1175#undef chmod
1163int mingw_chmod(const char *path, int mode) 1176int mingw_chmod(const char *path, int mode)
1164{ 1177{