|
@ -20,6 +20,7 @@ static int exit_code = 0; |
|
|
static Handle<String> |
|
|
static Handle<String> |
|
|
ReadFile (const string& name) |
|
|
ReadFile (const string& name) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
FILE* file = fopen(name.c_str(), "rb"); |
|
|
FILE* file = fopen(name.c_str(), "rb"); |
|
|
if (file == NULL) return Handle<String>(); |
|
|
if (file == NULL) return Handle<String>(); |
|
|
|
|
|
|
|
@ -27,16 +28,27 @@ ReadFile (const string& name) |
|
|
int size = ftell(file); |
|
|
int size = ftell(file); |
|
|
rewind(file); |
|
|
rewind(file); |
|
|
|
|
|
|
|
|
char* chars = new char[size + 1]; |
|
|
char chars[size+1]; |
|
|
chars[size] = '\0'; |
|
|
chars[size] = '\0'; |
|
|
for (int i = 0; i < size;) { |
|
|
for (int i = 0; i < size;) { |
|
|
int read = fread(&chars[i], 1, size - i, file); |
|
|
int read = fread(&chars[i], 1, size - i, file); |
|
|
|
|
|
if(read <= 0) { |
|
|
|
|
|
perror("read()"); |
|
|
|
|
|
} |
|
|
i += read; |
|
|
i += read; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint16_t expanded_base[size+1]; |
|
|
|
|
|
expanded_base[size] = '\0'; |
|
|
|
|
|
for(int i = 0; i < size; i++) |
|
|
|
|
|
expanded_base[i] = chars[i]; |
|
|
|
|
|
|
|
|
fclose(file); |
|
|
fclose(file); |
|
|
Handle<String> result = String::New(chars, size); |
|
|
|
|
|
delete[] chars; |
|
|
HandleScope scope; |
|
|
return result; |
|
|
Local<String> result = String::New(expanded_base, size); |
|
|
|
|
|
|
|
|
|
|
|
return scope.Close(result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static Handle<Value> |
|
|
static Handle<Value> |
|
@ -61,7 +73,6 @@ BlockingFileRead (const Arguments& args) |
|
|
HandleScope scope; |
|
|
HandleScope scope; |
|
|
|
|
|
|
|
|
String::Utf8Value filename(args[0]); |
|
|
String::Utf8Value filename(args[0]); |
|
|
|
|
|
|
|
|
Handle<String> output = ReadFile (*filename); |
|
|
Handle<String> output = ReadFile (*filename); |
|
|
return scope.Close(output); |
|
|
return scope.Close(output); |
|
|
} |
|
|
} |
|
|