From 4504df71178fe7a0eb8e7c37fa548b7c853a800f Mon Sep 17 00:00:00 2001 From: Michael Clark Date: Tue, 13 Mar 2007 08:26:20 +0000 Subject: =?UTF-8?q?=20=20*=20printbuf.c=20-=20C.=20Watford=20(christopher?= =?UTF-8?q?=20dot=20watford=20at=20gmail=20dot=20com)=20=20=20=20=20Added?= =?UTF-8?q?=20a=20Win32/Win64=20compliant=20implementation=20of=20vasprint?= =?UTF-8?q?f=20=20=20*=20debug.c=20-=20C.=20Watford=20(christopher=20dot?= =?UTF-8?q?=20watford=20at=20gmail=20dot=20com)=20=20=20=20=20Removed=20us?= =?UTF-8?q?age=20of=20vsyslog=20on=20Win32/Win64=20systems,=20needs=20to?= =?UTF-8?q?=20be=20handled=20=20=20=20=20by=20a=20configure=20script=20=20?= =?UTF-8?q?=20*=20json=5Fobject.c=20-=20C.=20Watford=20(christopher=20dot?= =?UTF-8?q?=20watford=20at=20gmail=20dot=20com)=20=20=20=20=20Added=20scop?= =?UTF-8?q?e=20operator=20to=20wrap=20usage=20of=20json=5Fobject=5Fobject?= =?UTF-8?q?=5Fforeach,=20this=20=20=20=20=20needs=20to=20be=20rethought=20?= =?UTF-8?q?to=20be=20more=20ANSI=20C=20friendly=20=20=20*=20json=5Fobject.?= =?UTF-8?q?h=20-=20C.=20Watford=20(christopher=20dot=20watford=20at=20gmai?= =?UTF-8?q?l=20dot=20com)=20=20=20=20=20Added=20Microsoft=20C=20friendly?= =?UTF-8?q?=20version=20of=20json=5Fobject=5Fobject=5Fforeach=20=20=20*=20?= =?UTF-8?q?json=5Ftokener.c=20-=20C.=20Watford=20(christopher=20dot=20watf?= =?UTF-8?q?ord=20at=20gmail=20dot=20com)=20=20=20=20=20Added=20a=20Win32/W?= =?UTF-8?q?in64=20compliant=20implementation=20of=20strndup=20=20=20*=20js?= =?UTF-8?q?on=5Futil.c=20-=20C.=20Watford=20(christopher=20dot=20watford?= =?UTF-8?q?=20at=20gmail=20dot=20com)=20=20=20=20=20Added=20cast=20and=20m?= =?UTF-8?q?ask=20to=20suffice=20size=5Ft=20v.=20unsigned=20int=20conversio?= =?UTF-8?q?n=20=20=20=20=20correctness=20=20=20*=20json=5Ftokener.c=20-=20?= =?UTF-8?q?sign=20reversal=20issue=20on=20error=20info=20for=20nested=20ob?= =?UTF-8?q?ject=20parse=20=20=20=20=20spotted=20by=20Johan=20Bj=EF=BF=BDrk?= =?UTF-8?q?lund=20(johbjo09=20at=20kth.se)=20=20=20*=20json=5Fobject.c=20-?= =?UTF-8?q?=20escape=20"=20in=20json=5Fescape=5Fstr=20=20=20*=20Change=20t?= =?UTF-8?q?o=20automake=20and=20libtool=20to=20build=20shared=20and=20stat?= =?UTF-8?q?ic=20library=20=20=20=20=20Michael=20Clark=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@4 327403b1-1117-474d-bef2-5cb71233fd97 --- json_util.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) (limited to 'json_util.c') diff --git a/json_util.c b/json_util.c index 483644e..07abd89 100644 --- a/json_util.c +++ b/json_util.c @@ -1,11 +1,50 @@ +/* + * $Id: json_util.c,v 1.2 2005/06/14 22:41:51 mclark Exp $ + * + * Copyright Metaparadigm Pte. Ltd. 2004. + * Michael Clark + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public (LGPL) + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details: http://www.gnu.org/ + * + */ + +#include "config.h" + #include #include +#include #include #include -#include + +#if HAVE_SYS_TYPES_H #include +#endif /* HAVE_SYS_TYPES_H */ + +#if HAVE_SYS_STAT_H #include +#endif /* HAVE_SYS_STAT_H */ + +#if HAVE_FCNTL_H #include +#endif /* HAVE_FCNTL_H */ + +#if HAVE_UNISTD_H +# include +#endif /* HAVE_UNISTD_H */ + +#ifdef WIN32 +# define WIN32_LEAN_AND_MEAN +# include +# include +#endif /* defined(WIN32) */ #include "bits.h" #include "debug.h" @@ -14,7 +53,6 @@ #include "json_tokener.h" #include "json_util.h" - struct json_object* json_object_from_file(char *filename) { struct printbuf *pb; @@ -49,7 +87,8 @@ struct json_object* json_object_from_file(char *filename) int json_object_to_file(char *filename, struct json_object *obj) { char *json_str; - int fd, ret, wpos, wsize; + int fd, ret; + unsigned int wpos, wsize; if(!obj) { mc_error("json_object_to_file: object is null\n"); @@ -61,8 +100,11 @@ int json_object_to_file(char *filename, struct json_object *obj) filename, strerror(errno)); return -1; } - if(!(json_str = json_object_to_json_string(obj))) return -1; - wsize = strlen(json_str); + + if(!(json_str = json_object_to_json_string(obj))) { return -1; } + + + wsize = (unsigned int)(strlen(json_str) & UINT_MAX); /* CAW: probably unnecessary, but the most 64bit safe */ wpos = 0; while(wpos < wsize) { if((ret = write(fd, json_str + wpos, wsize-wpos)) < 0) { @@ -71,7 +113,9 @@ int json_object_to_file(char *filename, struct json_object *obj) filename, strerror(errno)); return -1; } - wpos += ret; + + /* because of the above check for ret < 0, we can safely cast and add */ + wpos += (unsigned int)ret; } close(fd); -- cgit v1.2.1