Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E131AB2E2 for ; Sun, 22 Jan 2012 23:44:16 +0000 (UTC) Received: (qmail 21108 invoked by uid 500); 22 Jan 2012 23:44:16 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 20909 invoked by uid 500); 22 Jan 2012 23:44:16 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 20864 invoked by uid 99); 22 Jan 2012 23:44:15 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 22 Jan 2012 23:44:15 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.114] (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 22 Jan 2012 23:44:14 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 664293190CD; Sun, 22 Jan 2012 23:43:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: fdmanana@apache.org To: commits@couchdb.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [18/50] git commit: implement couch_readfile in couchjs utils Message-Id: <20120122234313.664293190CD@tyr.zones.apache.org> Date: Sun, 22 Jan 2012 23:43:13 +0000 (UTC) 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 Authored: Sat Jan 7 19:43:52 2012 -0800 Committer: Randall Leeds 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);