Skip to content

Instantly share code, notes, and snippets.

@dattaz
Created May 26, 2017 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dattaz/62254df7b8f3d6453d87218020efbca5 to your computer and use it in GitHub Desktop.
Save dattaz/62254df7b8f3d6453d87218020efbca5 to your computer and use it in GitHub Desktop.
int overflow with file in emscripten
<!doctype html>
<html>
<head><meta charset="utf-8"><title>Test int overflow of file size </title></head>
<html>
<body>
See result in JS console
<br>
<script>
var worker = new Worker("test.js");
</script>
<input type="file" id="your-files">
<script>
var control = document.getElementById("your-files");
control.addEventListener("change", function(event) {
// When the control has changed, there are new files
files = control.files;
worker.postMessage(files);
},false);
</script>
</body>
</html>
all:
emcc test.c -o test.js --pre-js prejs.js --post-js postjs.js -s WASM=1
self.addEventListener('message', function(e) {
var files = e.data;
console.log(files[0].name);
console.log(files[0].size);
if (typeof(Module) === "undefined") Module = {};
Module["arguments"] = ["/work/"+files[0].name];
Module["preInit"] = function() {
FS.mkdir("/work");
FS.mount(WORKERFS, {
files: files // Array of File objects or FileList
}, '/work');
};
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
FILE * file = NULL;
file = fopen(argv[1],"rb");
fseek(file,0,SEEK_END);
long int size = ftell(file);
fclose(file);
printf("%ld\n" ,size);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment