aboutsummaryrefslogtreecommitdiff
path: root/win32/mingw.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-02-12 14:07:55 +0000
committerRon Yorston <rmy@pobox.com>2021-02-12 14:07:55 +0000
commit1b61a02b5139a47e2e3ac8be5afca325d7b3cea7 (patch)
treef9fc7925ed82444ac2ac64fccee4ac7ef9cbd925 /win32/mingw.c
parente86a3ddd8b60eb0720874f5b9679446d12a1ac41 (diff)
downloadbusybox-w32-1b61a02b5139a47e2e3ac8be5afca325d7b3cea7.tar.gz
busybox-w32-1b61a02b5139a47e2e3ac8be5afca325d7b3cea7.tar.bz2
busybox-w32-1b61a02b5139a47e2e3ac8be5afca325d7b3cea7.zip
win32: allow symlinks to directories to be unlinked
Windows distinguishes between symlinks to directories and files. A symlink to a directory must be deleted by calling rmdir(2) rather than unlink(2).
Diffstat (limited to 'win32/mingw.c')
-rw-r--r--win32/mingw.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index 15529ed58..41dba9857 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -1316,9 +1316,21 @@ int fcntl(int fd, int cmd, ...)
1316#undef unlink 1316#undef unlink
1317int mingw_unlink(const char *pathname) 1317int mingw_unlink(const char *pathname)
1318{ 1318{
1319 int ret;
1320 struct stat st;
1321
1319 /* read-only files cannot be removed */ 1322 /* read-only files cannot be removed */
1320 chmod(pathname, 0666); 1323 chmod(pathname, 0666);
1321 return unlink(pathname); 1324
1325 ret = unlink(pathname);
1326 if (ret == -1 && errno == EACCES) {
1327 /* a symlink to a directory needs to be removed by calling rmdir */
1328 if (lstat(pathname, &st) == 0 && S_ISLNK(st.st_mode)) {
1329 return rmdir(pathname);
1330 }
1331 errno = EACCES;
1332 }
1333 return ret;
1322} 1334}
1323 1335
1324#undef strftime 1336#undef strftime