You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by fd...@apache.org on 2012/01/23 00:43:13 UTC

[18/50] git commit: implement couch_readfile in couchjs utils

implement couch_readfile in couchjs utils


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/bcd5039a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/bcd5039a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/bcd5039a

Branch: refs/heads/COUCHDB-1342
Commit: bcd5039afa00952635c44a9c7e0406032366755d
Parents: 74d4c91
Author: Randall Leeds <ra...@apache.org>
Authored: Sat Jan 7 19:43:52 2012 -0800
Committer: Randall Leeds <ra...@apache.org>
Committed: Sat Jan 7 19:43:52 2012 -0800

----------------------------------------------------------------------
 src/couchdb/priv/couch_js/util.c |   14 ++++++++++++--
 src/couchdb/priv/couch_js/util.h |    1 +
 2 files changed, 13 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/bcd5039a/src/couchdb/priv/couch_js/util.c
----------------------------------------------------------------------
diff --git a/src/couchdb/priv/couch_js/util.c b/src/couchdb/priv/couch_js/util.c
index f45ee38..d95151c 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;    
 }
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/bcd5039a/src/couchdb/priv/couch_js/util.h
----------------------------------------------------------------------
diff --git a/src/couchdb/priv/couch_js/util.h b/src/couchdb/priv/couch_js/util.h
index 380ff84..d58f276 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);