Skip to content

Commit 746414c

Browse files
author
Mirko Pasqualetti
committed
Moved test_json in directory examples
1 parent df18b36 commit 746414c

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

examples/test_json

21.8 KB
Binary file not shown.

tests/test_json.c renamed to examples/test_json.c

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
/* vim: set et ts=4
2+
*
3+
* Copyright (C) 2015 Mirko Pasqualetti All rights reserved.
4+
* https://github.com/udp/json-parser
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions
8+
* are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright
11+
* notice, this list of conditions and the following disclaimer.
12+
*
13+
* 2. Redistributions in binary form must reproduce the above copyright
14+
* notice, this list of conditions and the following disclaimer in the
15+
* documentation and/or other materials provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27+
* SUCH DAMAGE.
28+
*/
29+
130
#include <stdio.h>
231
#include <stdlib.h>
332
#include <sys/stat.h>
@@ -84,7 +113,7 @@ static void process_value(json_value* value, int depth)
84113
}
85114
}
86115

87-
void main(int argc, char** argv)
116+
int main(int argc, char** argv)
88117
{
89118
char* filename;
90119
FILE *fp;
@@ -96,33 +125,33 @@ void main(int argc, char** argv)
96125

97126
if (argc != 2) {
98127
fprintf(stderr, "%s <file_json>\n", argv[0]);
99-
exit(1);
128+
return 1;
100129
}
101130
filename = argv[1];
102131

103132
if ( stat(filename, &filestatus) != 0) {
104133
fprintf(stderr, "File %s not found\n", filename);
105-
exit(1);
134+
return 1;
106135
}
107136
file_size = filestatus.st_size;
108137
file_contents = (char*)malloc(filestatus.st_size);
109138
if ( file_contents == NULL) {
110139
fprintf(stderr, "Memory error: unable to allocate %d bytes\n", file_size);
111-
exit(1);
140+
return 1;
112141
}
113142

114143
fp = fopen(filename, "rt");
115144
if (fp == NULL) {
116145
fprintf(stderr, "Unable to open %s\n", filename);
117146
fclose(fp);
118147
free(file_contents);
119-
exit(1);
148+
return 1;
120149
}
121150
if ( fread(file_contents, file_size, 1, fp) != 1 ) {
122151
fprintf(stderr, "Unable t read content of %s\n", filename);
123152
fclose(fp);
124153
free(file_contents);
125-
exit(1);
154+
return 1;
126155
}
127156
fclose(fp);
128157

@@ -144,5 +173,5 @@ void main(int argc, char** argv)
144173

145174
json_value_free(value);
146175
free(file_contents);
147-
exit(0);
176+
return 0;
148177
}

0 commit comments

Comments
 (0)