示例#1
0
文件: vm.c 项目: joegen/sjs
DUK_EXTERNAL int sjs_vm_eval_file(const sjs_vm_t* vm,
                                  const char* filename,
                                  FILE* foutput,
                                  FILE* ferror,
                                  bool use_strict) {
    int r;
    char* data;
    char path[8192];

    r = sjs__path_normalize(filename, path, sizeof(path));
    if (r < 0) {
        if (ferror) {
            fprintf(ferror, "sjs: cannot open file '%s': [Errno %d] %s\n", filename, -r, strerror(-r));
            fflush(ferror);
        }
        return r;
    }
    r = sjs__file_read(path, &data);
    if (r < 0) {
        if (ferror) {
            fprintf(ferror, "sjs: cannot open file '%s': [Errno %d] %s\n", filename, -r, strerror(-r));
            fflush(ferror);
        }
        return r;
    } else if (r == 0) {
        /* also return in case of a 0 sized file */
        free(data);
        return r;
    } else {
        r = sjs_vm_eval_code(vm, path, data, r, foutput, ferror, use_strict);
        free(data);
        return r;
    }
}
示例#2
0
文件: vm.c 项目: cjihrig/sjs
DUK_EXTERNAL int sjs_path_normalize(const char* path, char* normalized_path, size_t normalized_path_len) {
    return sjs__path_normalize(path, normalized_path, normalized_path_len);
}