summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c20
-rw-r--r--win32/win32.h3
2 files changed, 23 insertions, 0 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 13c45005df..c5ca269732 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -3433,6 +3433,26 @@ rb_w32_rmdir(const char *path)
return ret;
}
+#undef unlink
+int
+rb_w32_unlink(const char *path)
+{
+ DWORD attr;
+ int ret;
+ RUBY_CRITICAL({
+ attr = GetFileAttributes(path);
+ if (attr != (DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
+ attr &= ~FILE_ATTRIBUTE_READONLY;
+ SetFileAttributes(path, attr);
+ }
+ ret = unlink(path);
+ if (ret < 0 && attr != (DWORD)-1) {
+ SetFileAttributes(path, attr);
+ }
+ });
+ return ret;
+}
+
#if !defined(__BORLANDC__) && !defined(_WIN32_WCE)
int
rb_w32_isatty(int fd)
diff --git a/win32/win32.h b/win32/win32.h
index c73b91bda5..6e0b1fe851 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -128,6 +128,8 @@ extern "C++" {
#define mkdir(p, m) rb_w32_mkdir(p, m)
#undef rmdir
#define rmdir(p) rb_w32_rmdir(p)
+#undef unlink
+#define unlink(p) rb_w32_unlink(p)
#ifdef __MINGW32__
struct timezone {
@@ -191,6 +193,7 @@ extern int rb_w32_isatty(int);
#endif
extern int rb_w32_mkdir(const char *, int);
extern int rb_w32_rmdir(const char *);
+extern int rb_w32_unlink(const char*);
#ifdef __BORLANDC__
extern FILE *rb_w32_fopen(const char *, const char *);