fix misuse of FindFirstFile

This commit is contained in:
Joel Dice 2009-09-03 17:57:32 -06:00
parent 6519047342
commit e47c149fb1
2 changed files with 15 additions and 3 deletions

View File

@ -405,14 +405,21 @@ Java_java_io_File_openDir(JNIEnv* e, jclass, jstring path)
{
const char* chars = e->GetStringUTFChars(path, 0);
if (chars) {
unsigned length = strlen(chars);
RUNTIME_ARRAY(char, buffer, length + 3);
memcpy(RUNTIME_ARRAY_BODY(buffer), chars, length);
memcpy(RUNTIME_ARRAY_BODY(buffer) + length, "\\*", 3);
e->ReleaseStringUTFChars(path, chars);
Directory* d = new (malloc(sizeof(Directory))) Directory;
d->handle = FindFirstFile(chars, &(d->data));
d->handle = FindFirstFile(buffer, &(d->data));
if (d->handle == INVALID_HANDLE_VALUE) {
d->dispose();
d = 0;
}
e->ReleaseStringUTFChars(path, chars);
return reinterpret_cast<jlong>(d);
} else {
return 0;

View File

@ -678,8 +678,13 @@ class MySystem: public System {
virtual Status open(System::Directory** directory, const char* name) {
Status status = 1;
unsigned length = strlen(name);
RUNTIME_ARRAY(char, buffer, length + 3);
memcpy(RUNTIME_ARRAY_BODY(buffer), name, length);
memcpy(RUNTIME_ARRAY_BODY(buffer) + length, "\\*", 3);
Directory* d = new (allocate(this, sizeof(Directory))) Directory(this);
d->handle = FindFirstFile(name, &(d->data));
d->handle = FindFirstFile(RUNTIME_ARRAY_BODY(buffer), &(d->data));
if (d->handle == INVALID_HANDLE_VALUE) {
d->dispose();
} else {