Created
May 26, 2017 21:50
-
-
Save dattaz/62254df7b8f3d6453d87218020efbca5 to your computer and use it in GitHub Desktop.
int overflow with file in emscripten
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: | |
emcc test.c -o test.js --pre-js prejs.js --post-js postjs.js -s WASM=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
},false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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