Mercurial > hg > freeDiameter
comparison extensions/dict_json/json-schema-to-c.cc @ 1358:cf411b1dcbbb
Improve compatibility with old systems.
Use c_str() to get C strings for printing.
author | Thomas Klausner <tk@giga.or.at> |
---|---|
date | Wed, 29 May 2019 16:36:32 +0200 |
parents | 70b6067f4552 |
children |
comparison
equal
deleted
inserted
replaced
1357:925470fbe59d | 1358:cf411b1dcbbb |
---|---|
35 #include <libgen.h> | 35 #include <libgen.h> |
36 #include <stdio.h> | 36 #include <stdio.h> |
37 #include <stdlib.h> | 37 #include <stdlib.h> |
38 #include <string.h> | 38 #include <string.h> |
39 #include <sys/stat.h> | 39 #include <sys/stat.h> |
40 #include <unistd.h> | |
40 | 41 |
41 #include <json/SchemaValidator.h> | 42 #include <json/SchemaValidator.h> |
42 | 43 |
43 [[noreturn]] | 44 [[noreturn]] |
44 void usage(char *prg, int exit_status) { | 45 void usage(char *prg, int exit_status) { |
89 fclose (fp); | 90 fclose (fp); |
90 return NULL; | 91 return NULL; |
91 } | 92 } |
92 off_t n = stat_buf.st_size; | 93 off_t n = stat_buf.st_size; |
93 if (max_size > 0 && n > max_size) { | 94 if (max_size > 0 && n > max_size) { |
94 fprintf (stderr, "%s file [%s] is larger than %" PRIi64 " bytes\n", desc, filename, (int64_t)max_size); | 95 fprintf (stderr, "%s file [%s] is larger than %lld bytes\n", desc, filename, (long long)max_size); |
95 fclose (fp); | 96 fclose (fp); |
96 return NULL; | 97 return NULL; |
97 } | 98 } |
98 char *buf; | 99 char *buf; |
99 if ((buf = (char *) malloc ((size_t)n+1)) == NULL) { | 100 if ((buf = (char *) malloc ((size_t)n+1)) == NULL) { |
100 fprintf (stderr, "error allocating %" PRIi64 " bytes for read of %s file [%s]\n", (int64_t)n, desc, filename); | 101 fprintf (stderr, "error allocating %lld bytes for read of %s file [%s]\n", (long long)n, desc, filename); |
101 fclose (fp); | 102 fclose (fp); |
102 return NULL; | 103 return NULL; |
103 } | 104 } |
104 if (fread (buf, 1, (size_t)n, fp) < (size_t) n) { | 105 if (fread (buf, 1, (size_t)n, fp) < (size_t) n) { |
105 fprintf (stderr, "error reading %s file [%s]: %d, %s\n", desc, filename, errno, strerror(errno)); | 106 fprintf (stderr, "error reading %s file [%s]: %d, %s\n", desc, filename, errno, strerror(errno)); |
178 | 179 |
179 Json::Reader reader; | 180 Json::Reader reader; |
180 | 181 |
181 Json::Value json; | 182 Json::Value json; |
182 if (!reader.parse(str, json)) { | 183 if (!reader.parse(str, json)) { |
183 fprintf(stderr, "%s: parse error: %s\n", input, reader.getFormattedErrorMessages()); | 184 fprintf(stderr, "%s: parse error: %s\n", input, reader.getFormattedErrorMessages().c_str()); |
184 exit(1); | 185 exit(1); |
185 } | 186 } |
186 | 187 |
187 if (validate) { | 188 if (validate) { |
188 std::string error_message; | 189 std::string error_message; |