зеркало из https://github.com/github/ruby.git
* win32/win32.c (open_dir_handle, rb_w32_opendir, move_to_next_entry,
rb_w32_readdir, check_valid_dir): change backend API from A to W. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
ef9206bbea
Коммит
41e770944e
|
@ -1,3 +1,8 @@
|
||||||
|
Mon Feb 2 10:57:27 2009 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
|
* win32/win32.c (open_dir_handle, rb_w32_opendir, move_to_next_entry,
|
||||||
|
rb_w32_readdir, check_valid_dir): change backend API from A to W.
|
||||||
|
|
||||||
Mon Feb 2 10:48:38 2009 Tanaka Akira <akr@fsij.org>
|
Mon Feb 2 10:48:38 2009 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* ext/socket/basicsocket.c (bsock_setsockopt): accept Socket::Option
|
* ext/socket/basicsocket.c (bsock_setsockopt): accept Socket::Option
|
||||||
|
|
|
@ -33,9 +33,6 @@
|
||||||
#endif
|
#endif
|
||||||
#include "ruby/win32.h"
|
#include "ruby/win32.h"
|
||||||
#include "win32/dir.h"
|
#include "win32/dir.h"
|
||||||
#ifndef index
|
|
||||||
#define index(x, y) strchr((x), (y))
|
|
||||||
#endif
|
|
||||||
#define isdirsep(x) ((x) == '/' || (x) == '\\')
|
#define isdirsep(x) ((x) == '/' || (x) == '\\')
|
||||||
|
|
||||||
#undef stat
|
#undef stat
|
||||||
|
@ -1434,31 +1431,40 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
|
||||||
#define DIRENT_PER_CHAR (CHAR_BIT / 2)
|
#define DIRENT_PER_CHAR (CHAR_BIT / 2)
|
||||||
|
|
||||||
static HANDLE
|
static HANDLE
|
||||||
open_dir_handle(const char *filename, WIN32_FIND_DATA *fd)
|
open_dir_handle(const char *filename, WIN32_FIND_DATAW *fd)
|
||||||
{
|
{
|
||||||
HANDLE fh;
|
HANDLE fh;
|
||||||
static const char wildcard[] = "/*";
|
static const WCHAR wildcard[] = L"\\*";
|
||||||
long len = strlen(filename);
|
UINT cp = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
|
||||||
char *scanname = malloc(len + sizeof(wildcard));
|
WCHAR *scanname;
|
||||||
|
WCHAR *p;
|
||||||
|
int len;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Create the search pattern
|
// Create the search pattern
|
||||||
//
|
//
|
||||||
if (!scanname) {
|
len = MultiByteToWideChar(cp, 0, filename, -1, NULL, 0);
|
||||||
|
if (len <= 0) {
|
||||||
|
errno = map_errno(GetLastError());
|
||||||
|
return INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
scanname = ALLOCA_N(WCHAR, len + sizeof(wildcard) / sizeof(WCHAR));
|
||||||
|
len = MultiByteToWideChar(cp, 0, filename, -1, scanname, len + 2);
|
||||||
|
if (len <= 0) {
|
||||||
|
errno = map_errno(GetLastError());
|
||||||
return INVALID_HANDLE_VALUE;
|
return INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
memcpy(scanname, filename, len + 1);
|
|
||||||
|
|
||||||
if (index("/\\:", *CharPrev(scanname, scanname + len)) == NULL)
|
p = CharPrevW(scanname, scanname + len);
|
||||||
memcpy(scanname + len, wildcard, sizeof(wildcard));
|
if (*p == L'/' || *p == L'\\' || *p == L':')
|
||||||
|
lstrcatW(scanname, wildcard + 1);
|
||||||
else
|
else
|
||||||
memcpy(scanname + len, wildcard + 1, sizeof(wildcard) - 1);
|
lstrcatW(scanname, wildcard);
|
||||||
|
|
||||||
//
|
//
|
||||||
// do the FindFirstFile call
|
// do the FindFirstFile call
|
||||||
//
|
//
|
||||||
fh = FindFirstFile(scanname, fd);
|
fh = FindFirstFileW(scanname, fd);
|
||||||
free(scanname);
|
|
||||||
if (fh == INVALID_HANDLE_VALUE) {
|
if (fh == INVALID_HANDLE_VALUE) {
|
||||||
errno = map_errno(GetLastError());
|
errno = map_errno(GetLastError());
|
||||||
}
|
}
|
||||||
|
@ -1471,9 +1477,10 @@ rb_w32_opendir(const char *filename)
|
||||||
DIR *p;
|
DIR *p;
|
||||||
long len;
|
long len;
|
||||||
long idx;
|
long idx;
|
||||||
char *tmp;
|
WCHAR *tmpW;
|
||||||
|
char *tmp;
|
||||||
struct stati64 sbuf;
|
struct stati64 sbuf;
|
||||||
WIN32_FIND_DATA fd;
|
WIN32_FIND_DATAW fd;
|
||||||
HANDLE fh;
|
HANDLE fh;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -1509,14 +1516,14 @@ rb_w32_opendir(const char *filename)
|
||||||
// of the previous string found.
|
// of the previous string found.
|
||||||
//
|
//
|
||||||
do {
|
do {
|
||||||
len = strlen(fd.cFileName) + 1;
|
len = lstrlenW(fd.cFileName) + 1;
|
||||||
|
|
||||||
//
|
//
|
||||||
// bump the string table size by enough for the
|
// bump the string table size by enough for the
|
||||||
// new name and it's null terminator
|
// new name and it's null terminator
|
||||||
//
|
//
|
||||||
tmp = realloc(p->start, idx + len);
|
tmpW = realloc(p->start, (idx + len) * sizeof(WCHAR));
|
||||||
if (!tmp) {
|
if (!tmpW) {
|
||||||
error:
|
error:
|
||||||
rb_w32_closedir(p);
|
rb_w32_closedir(p);
|
||||||
FindClose(fh);
|
FindClose(fh);
|
||||||
|
@ -1524,8 +1531,8 @@ rb_w32_opendir(const char *filename)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
p->start = tmp;
|
p->start = tmpW;
|
||||||
strlcpy(&p->start[idx], fd.cFileName, len);
|
memcpy(&p->start[idx], fd.cFileName, len * sizeof(WCHAR));
|
||||||
|
|
||||||
if (p->nfiles % DIRENT_PER_CHAR == 0) {
|
if (p->nfiles % DIRENT_PER_CHAR == 0) {
|
||||||
tmp = realloc(p->bits, p->nfiles / DIRENT_PER_CHAR + 1);
|
tmp = realloc(p->bits, p->nfiles / DIRENT_PER_CHAR + 1);
|
||||||
|
@ -1541,7 +1548,7 @@ rb_w32_opendir(const char *filename)
|
||||||
|
|
||||||
p->nfiles++;
|
p->nfiles++;
|
||||||
idx += len;
|
idx += len;
|
||||||
} while (FindNextFile(fh, &fd));
|
} while (FindNextFileW(fh, &fd));
|
||||||
FindClose(fh);
|
FindClose(fh);
|
||||||
p->size = idx;
|
p->size = idx;
|
||||||
p->curr = p->start;
|
p->curr = p->start;
|
||||||
|
@ -1557,7 +1564,7 @@ move_to_next_entry(DIR *dirp)
|
||||||
{
|
{
|
||||||
if (dirp->curr) {
|
if (dirp->curr) {
|
||||||
dirp->loc++;
|
dirp->loc++;
|
||||||
dirp->curr += strlen(dirp->curr) + 1;
|
dirp->curr += lstrlenW(dirp->curr) + 1;
|
||||||
if (dirp->curr >= (dirp->start + dirp->size)) {
|
if (dirp->curr >= (dirp->start + dirp->size)) {
|
||||||
dirp->curr = NULL;
|
dirp->curr = NULL;
|
||||||
}
|
}
|
||||||
|
@ -1572,17 +1579,20 @@ move_to_next_entry(DIR *dirp)
|
||||||
struct direct *
|
struct direct *
|
||||||
rb_w32_readdir(DIR *dirp)
|
rb_w32_readdir(DIR *dirp)
|
||||||
{
|
{
|
||||||
static int dummy = 0;
|
static int dummy = 0;
|
||||||
|
UINT cp = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
|
||||||
|
|
||||||
if (dirp->curr) {
|
if (dirp->curr) {
|
||||||
|
|
||||||
//
|
//
|
||||||
// first set up the structure to return
|
// first set up the structure to return
|
||||||
//
|
//
|
||||||
dirp->dirstr.d_namlen = strlen(dirp->curr);
|
dirp->dirstr.d_namlen =
|
||||||
|
WideCharToMultiByte(cp, 0, dirp->curr, -1, NULL, 0, NULL, NULL) - 1;
|
||||||
if (!(dirp->dirstr.d_name = malloc(dirp->dirstr.d_namlen + 1)))
|
if (!(dirp->dirstr.d_name = malloc(dirp->dirstr.d_namlen + 1)))
|
||||||
return NULL;
|
return NULL;
|
||||||
strlcpy(dirp->dirstr.d_name, dirp->curr, dirp->dirstr.d_namlen + 1);
|
WideCharToMultiByte(cp, 0, dirp->curr, -1, dirp->dirstr.d_name,
|
||||||
|
dirp->dirstr.d_namlen + 1, NULL, NULL);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Fake inode
|
// Fake inode
|
||||||
|
@ -3531,7 +3541,7 @@ fileattr_to_unixmode(DWORD attr, const char *path)
|
||||||
static int
|
static int
|
||||||
check_valid_dir(const char *path)
|
check_valid_dir(const char *path)
|
||||||
{
|
{
|
||||||
WIN32_FIND_DATA fd;
|
WIN32_FIND_DATAW fd;
|
||||||
HANDLE fh = open_dir_handle(path, &fd);
|
HANDLE fh = open_dir_handle(path, &fd);
|
||||||
if (fh == INVALID_HANDLE_VALUE)
|
if (fh == INVALID_HANDLE_VALUE)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче