diff --git a/parson.c b/parson.c index e6c2cc6..1397bb4 100644 --- a/parson.c +++ b/parson.c @@ -33,6 +33,7 @@ #include #include #include +#include #define STARTING_CAPACITY 15 #define ARRAY_MAX_CAPACITY 122880 /* 15*(2^13) */ @@ -1381,6 +1382,9 @@ JSON_Status json_serialize_to_file(const JSON_Value *value, const char *filename if (fputs(serialized_string, fp) == EOF) { return_code = JSONFailure; } + if(fsync(fileno(fp)) < 0){ + return_code = JSONFailure; + } if (fclose(fp) == EOF) { return_code = JSONFailure; } @@ -1441,6 +1445,9 @@ JSON_Status json_serialize_to_file_pretty(const JSON_Value *value, const char *f if (fputs(serialized_string, fp) == EOF) { return_code = JSONFailure; } + if(fsync(fileno(fp)) < 0){ + return_code = JSONFailure; + } if (fclose(fp) == EOF) { return_code = JSONFailure; }