Created
December 7, 2011 01:55
-
-
Save shirosaki/1441067 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/file.c b/file.c | |
index e566ce3..24b25b8 100644 | |
--- a/file.c | |
+++ b/file.c | |
@@ -5060,7 +5060,38 @@ static int | |
file_load_ok(const char *path) | |
{ | |
int ret = 1; | |
- int fd = open(path, O_RDONLY); | |
+ int fd; | |
+#ifdef _WIN32 | |
+ static int use_attribute = -1; | |
+ if (use_attribute == -1) { | |
+ if (getenv("RUBY_USE_ATTRIBUTE") == NULL) { | |
+ use_attribute = 0; | |
+ } | |
+ else { | |
+ use_attribute = 1; | |
+ } | |
+ } | |
+ if (use_attribute) { | |
+ DWORD attr = GetFileAttributes(path); | |
+ if (attr == INVALID_FILE_ATTRIBUTES || | |
+ attr & FILE_ATTRIBUTE_DIRECTORY) { | |
+ ret = 0; | |
+ } | |
+ else { | |
+ HANDLE h = CreateFile(path, GENERIC_READ, | |
+ FILE_SHARE_READ | FILE_SHARE_WRITE, | |
+ NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | |
+ if (h != INVALID_HANDLE_VALUE) { | |
+ CloseHandle(h); | |
+ } | |
+ else { | |
+ ret = 0; | |
+ } | |
+ } | |
+ return ret; | |
+ } | |
+#endif | |
+ fd = open(path, O_RDONLY); | |
if (fd == -1) return 0; | |
rb_update_max_fd(fd); | |
#if !defined DOSISH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Benchmark on Windows XP
fenix enabled