From 66331681a6a4792e4f06fb97e13a61334fe35018 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Sun, 8 Dec 2013 23:55:02 +0200 Subject: [PATCH] add DUK_OPT_NO_FILE_IO and its DUK_USE_FILE_IO counterpart, make duk_push_string_file() sensitive to it --- src/duk_api.c | 9 +++++++++ src/duk_features.h | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/duk_api.c b/src/duk_api.c index 9b3bbacf..ce77469c 100644 --- a/src/duk_api.c +++ b/src/duk_api.c @@ -2289,6 +2289,7 @@ const char *duk_push_string(duk_context *ctx, const char *str) { } } +#ifdef DUK_USE_FILE_IO /* This is a bit clunky because it is ANSI C portable. Should perhaps * relocate to another file because this is potentially platform * dependent. @@ -2333,6 +2334,14 @@ const char *duk_push_string_file(duk_context *ctx, const char *path) { DUK_ERROR(thr, DUK_ERR_TYPE_ERROR, "failed to read file"); return NULL; } +#else +const char *duk_push_string_file(duk_context *ctx, const char *path) { + duk_hthread *thr = (duk_hthread *) ctx; + DUK_ASSERT(ctx != NULL); + DUK_ERROR(thr, DUK_ERR_TYPE_ERROR, "file I/O disabled"); + return NULL; +} +#endif /* DUK_USE_FILE_IO */ void duk_push_pointer(duk_context *ctx, void *val) { duk_tval tv; diff --git a/src/duk_features.h b/src/duk_features.h index d52399ed..f92cd309 100644 --- a/src/duk_features.h +++ b/src/duk_features.h @@ -971,6 +971,17 @@ extern double duk_computed_nan; #define DUK_USE_DPRINT_COLORS #endif +/* + * File I/O support. This is now used in a few API calls to e.g. push + * a string from file contents or eval a file. For portability it must + * be possible to disable I/O altogether. + */ + +#undef DUK_USE_FILE_IO +#if !defined(DUK_OPT_NO_FILE_IO) +#define DUK_USE_FILE_IO +#endif + /* * Profile processing *