]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/jsmn/example/maptest.c
modified: data/test.map
[16.git] / src / lib / jsmn / example / maptest.c
index 9c5b11d74b92b9f689009734ff2fa933a72859e4..7c305bffe770e00ca94102b78440697f7ece1520 100644 (file)
@@ -34,28 +34,28 @@ static int jsoneq(const char *json, jsmntok_t *tok, const char *s) {
 int main() {
        int i;
        int r;
+       size_t z;
        //char json_s[8192];
        jsmn_parser p;
        jsmntok_t t[2048]; /* We expect no more than 128 tokens */
        FILE *fh = fopen("../../../../data/test.map", "r");
-
-       char *json_string = malloc(filesize(fh)+1);
+       char *json_string = malloc(filesize(fh));
        //memset(json_string, 0, sizeof(*json_string));
 
        if(fh != NULL)
        {
-               fread(json_string, 1, filesize(fh), fh);
-               json_string+1="\0";
+               z = fread(json_string, 1, filesize(fh), fh);
+               fclose(fh); fh = NULL;
+               printf("[[%d]]\n", z);
+               json_string[z] = '\0';
                // we can now close the file
                //printf("]%s[\n", json_s);
                //json_string=json_s;
                //printf("[[%s]]\n", json_string);
 
        jsmn_init(&p);
+       r = jsmn_parse(&p, json_string, z, t, sizeof(t)/sizeof(t[0]));
        printf("[\n%s\n]", json_string);
-       r = jsmn_parse(&p, json_string, filesize(fh), t, sizeof(t)/sizeof(t[0]));
-               fclose(fh); fh = NULL;
-       //printf("[\n%s\n]", json_string);
        if (r < 0) {
                printf("Failed to parse JSON: %d\n", r);
                return 1;