aboutsummaryrefslogtreecommitdiffstats
path: root/win32/file.c
diff options
context:
space:
mode:
authorshirosaki <shirosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-28 15:51:25 +0000
committershirosaki <shirosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-28 15:51:25 +0000
commit4b1e9f0c476879242ce3dab2e430deb28651d54c (patch)
tree8ea557e42c983d1335b64bc9eae972bf4283ac1d /win32/file.c
parent3486a98a71d3d2d09258cbd0ab13dc715f750f25 (diff)
downloadruby-4b1e9f0c476879242ce3dab2e430deb28651d54c.tar.gz
* Makefile.in (PLATFORM_DIR): add a variable for `win32` directory.
* Makefile.in (clean-platform): add new target. It cleans `win32` directory. * common.mk (clean): add a dependency for `win32` directory. * common.mk (distclean): ditto. * common.mk (distclean-platform): add new target. It cleans `win32` directory. * common.mk ($(PLATFORM_D)): add new target to make `win32` directory. * common.mk (win32/win32.$(OBJEXT)): move win32.o into `win32` directory. * common.mk (win32/file.$(OBJEXT)): add new target for win32/file.c. * configure.in: move win32.o into `win32` directory and add win32/file.o to MISSING. * file.c (file_load_ok, rb_file_load_ok): replace static file_load_ok() with public rb_file_load_ok(). It's to link Windows implementation in win32/file.c. * file.c (rb_find_file_ext_safe): ditto. * file.c (rb_find_file_safe): ditto. * win32/file.c (rb_file_load_ok): new file. Add Windows specific optimized implementation of rb_file_load_ok(). We created a separated file to avoid too many #ifdef macro which is unreadable. * win32/Makefile.sub (PLATFORM_DIR): add a variable for `win32` directory. * win32/Makefile.sub (MISSING): move win32.obj into `win32` directory and add win32/file.obj to MISSING. * win32/Makefile.sub (MAKEDIRS): replace MINIRUBY with BASERUBY. It's because miniruby doesn't exist when making `win32` directory. * win32/Makefile.sub (clean-platform): add new target to clean `win32` directory. * win32/Makefile.sub ({$(srcdir)}.c{}.obj): make it not match win32/file.c to build properly. * win32/Makefile.sub (win32/win32.$(OBJEXT)): move win32.obj into `win32` directory. Patch created with Luis Lavena. [ruby-core:42480] [Feature #5999] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32/file.c')
-rw-r--r--win32/file.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/win32/file.c b/win32/file.c
new file mode 100644
index 0000000000..cd89da24f5
--- /dev/null
+++ b/win32/file.c
@@ -0,0 +1,25 @@
+#include "ruby/ruby.h"
+#include <winbase.h>
+
+int
+rb_file_load_ok(const char *path)
+{
+ int ret = 1;
+ 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;
+}