You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implemented new functions to allow for reading and writing of binary files, also fixed a protential issue with arrays not being known as arrays when created natively
* Writes the given number array to the file specified by the filename. Each number in your number array
205
+
* will be treated as a single 8 bit character all other bits of the number are ignored. For example if you have a number with the value 0xffff. Only 0xff will be used
206
+
* If the file does not exist it creates it, if it does exist it overwrites it
207
+
*
208
+
* @works_without_class
209
+
* function file_put_binary_contents(string filename, number[] data) : void
throwSystemException(std::dynamic_pointer_cast<ExceptionObject>(Object::create(interpreter->getClassSystem()->getClassByName("IOException"))), "Failed to open the file: " + absolute_filename_path, interpreter->getStackTraceLog());
348
+
349
+
try
350
+
{
351
+
fseek(fp, 0, SEEK_END);
352
+
int size = ftell(fp);
353
+
fseek(fp, 0, SEEK_SET);
354
+
355
+
unsignedchar buf[size];
356
+
if (!fread(buf, size, 1, fp))
357
+
throwSystemException(std::dynamic_pointer_cast<ExceptionObject>(Object::create(interpreter->getClassSystem()->getClassByName("IOException"))), "Failed to read the file: " + absolute_filename_path + " but it opened succesfully", interpreter->getStackTraceLog());
358
+
359
+
// Ok let's create a number array to store these file contents in
throwSystemException(std::dynamic_pointer_cast<ExceptionObject>(Object::create(interpreter->getClassSystem()->getClassByName("IOException"))), "Failed to open the file: " + absolute_filename_path, interpreter->getStackTraceLog());
throwSystemException(std::dynamic_pointer_cast<ExceptionObject>(Object::create(interpreter->getClassSystem()->getClassByName("IOException"))), "Failed to write the file: " + absolute_filename_path + " but it opened succesfully", interpreter->getStackTraceLog());
421
+
422
+
fclose(fp);
423
+
}
424
+
catch (...)
425
+
{
426
+
fclose(fp);
427
+
throw;
428
+
}
429
+
}
430
+
337
431
voidFileModule_File::File_chmod(Interpreter *interpreter, std::vector<Value> values, Value *return_value, std::shared_ptr<Object> object, Scope *caller_scope)
0 commit comments