diff options
author | Randall Leeds <randall@apache.org> | 2012-01-07 19:43:52 -0800 |
---|---|---|
committer | Randall Leeds <randall@apache.org> | 2012-01-07 19:43:52 -0800 |
commit | bcd5039afa00952635c44a9c7e0406032366755d (patch) | |
tree | 74a5b83aa1b9a2413ef804bb46ee612f5de77aa1 | |
parent | 74d4c91f0dcbfbb9772f7f8b71df9628ad242f53 (diff) | |
download | couchdb-bcd5039afa00952635c44a9c7e0406032366755d.tar.gz |
implement couch_readfile in couchjs utils
-rw-r--r-- | src/couchdb/priv/couch_js/util.c | 14 | ||||
-rw-r--r-- | src/couchdb/priv/couch_js/util.h | 1 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/couchdb/priv/couch_js/util.c b/src/couchdb/priv/couch_js/util.c index f45ee38d8..d95151c8f 100644 --- a/src/couchdb/priv/couch_js/util.c +++ b/src/couchdb/priv/couch_js/util.c @@ -200,9 +200,19 @@ couch_readline(JSContext* cx, FILE* fp) } -JSObject* -couch_readfile(JSContext* cx, FILE* fp) +JSString* +couch_readfile(JSContext* cx, const char* filename) { + JSString *string; + size_t byteslen; + char *bytes; + + if((byteslen = slurp_file(filename, &bytes))) { + string = dec_string(cx, bytes, byteslen); + + free(bytes); + return string; + } return NULL; } diff --git a/src/couchdb/priv/couch_js/util.h b/src/couchdb/priv/couch_js/util.h index 380ff8462..d58f27620 100644 --- a/src/couchdb/priv/couch_js/util.h +++ b/src/couchdb/priv/couch_js/util.h @@ -25,6 +25,7 @@ typedef struct { couch_args* couch_parse_args(int argc, const char* argv[]); int couch_fgets(char* buf, int size, FILE* fp); JSString* couch_readline(JSContext* cx, FILE* fp); +JSString* couch_readfile(JSContext* cx, const char* filename); void couch_print(JSContext* cx, uintN argc, jsval* argv); void couch_error(JSContext* cx, const char* mesg, JSErrorReport* report); JSBool couch_load_funcs(JSContext* cx, JSObject* obj, JSFunctionSpec* funcs); |