return json_object_to_file_ext(filename, obj, JSON_C_TO_STRING_PLAIN);
}
+ int json_parse_double(const char *buf, double *retval)
+ {
+ return (sscanf(buf, "%lf", retval)==1 ? 0 : 1);
+ }
+
+/*
+ * Not all implementations of sscanf actually work properly.
+ * Check whether the one we're currently using does, and if
+ * it's broken, enable the workaround code.
+ */
+static void sscanf_is_broken_test()
+{
+ int64_t num64;
+
+ (void)sscanf(" -01234567890123456789012345", "%" SCNd64, &num64);
+ int ret_errno = errno;
+ int is_int64_min = (num64 == INT64_MIN);
+
+ (void)sscanf(" 01234567890123456789012345", "%" SCNd64, &num64);
+ int ret_errno2 = errno;
+ int is_int64_max = (num64 == INT64_MAX);
+
+ if (ret_errno != ERANGE || !is_int64_min ||
+ ret_errno2 != ERANGE || !is_int64_max)
+ {
+ MC_DEBUG("sscanf_is_broken_test failed, enabling workaround code\n");
+ sscanf_is_broken = 1;
+ }
+}
+
int json_parse_int64(const char *buf, int64_t *retval)
{
int64_t num64;