1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/win32/file.c
usa ab649ef3c4 * win32/file.c (INVALID_FILE_ATTRIBUTES): commit miss of r35384.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35385 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-04-18 05:50:45 +00:00

29 lines
590 B
C

#include "ruby/ruby.h"
#include <winbase.h>
#ifndef INVALID_FILE_ATTRIBUTES
# define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
#endif
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;
}