Skip to content

Instantly share code, notes, and snippets.

@DeltaF1
Created November 6, 2021 19:18
Show Gist options
  • Save DeltaF1/712cd4fb32bb6d71218b28d87b9960b2 to your computer and use it in GitHub Desktop.
Save DeltaF1/712cd4fb32bb6d71218b28d87b9960b2 to your computer and use it in GitHub Desktop.
Patch to fix incomplete file writing in uxn file device
Uint16
file_write(void *src, Uint16 len, Uint8 flags)
{
+ /* If we're not already writing then re-open the file */
if(state != FILE_WRITE) {
reset();
if((f = fopen(current_filename, (flags & 0x01) ? "ab" : "wb")) != NULL)
state = FILE_WRITE;
}
- if(state == FILE_WRITE)
- return fwrite(src, 1, len, f);
+
+ size_t bytes_written;
+ if(state == FILE_WRITE) {
+ bytes_written = fwrite(src, 1, len, f);
+ fflush(f);
+ return bytes_written;
+ }
+
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment