2019-07-04 11:58:49 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#ifdef __EMSCRIPTEN__
|
|
|
|
|
#include "emscripten.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// VERY BAD
|
2019-07-05 19:31:31 +02:00
|
|
|
int
|
|
|
|
|
wasm_file_open(const char *url) {
|
|
|
|
|
fprintf(stderr,"10:wasm_file_open[%s]\n", url);
|
2019-07-04 11:58:49 +02:00
|
|
|
|
|
|
|
|
if (strlen(url)>1 && url[0]==':') {
|
|
|
|
|
fprintf(stderr," -> same host[%s]\n", url);
|
|
|
|
|
int fidx = EM_ASM_INT({return wasm_file_open(UTF8ToString($0)); }, url );
|
2019-07-04 13:40:28 +02:00
|
|
|
|
|
|
|
|
// TODO rebuild local path in ramdisk relative to getcwd()
|
|
|
|
|
char fname[MICROPY_ALLOC_PATH_MAX];
|
|
|
|
|
|
2019-07-04 11:58:49 +02:00
|
|
|
snprintf(fname, sizeof(fname), "cache_%d", fidx);
|
|
|
|
|
return fileno( fopen(fname,"r") );
|
|
|
|
|
}
|
|
|
|
|
if ( (strlen(url)>6) && (url[4]==':' || url[5]==':') ) {
|
|
|
|
|
fprintf(stderr," -> remote host[%s]\n", url);
|
|
|
|
|
int fidx = EM_ASM_INT({return wasm_file_open(UTF8ToString($0)); }, url );
|
2019-07-04 13:40:28 +02:00
|
|
|
char fname[20];
|
2019-07-04 11:58:49 +02:00
|
|
|
snprintf(fname, sizeof(fname), "cache_%d", fidx);
|
|
|
|
|
return fileno( fopen(fname,"r") );
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|