Skip to content

Commit

Permalink
npdm: Invert top-level conditional within ndpm_save()
Browse files Browse the repository at this point in the history
Allows for denesting of the code.
  • Loading branch information
lioncash committed Aug 12, 2018
1 parent ff6c8eb commit ab6fe34
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions npdm.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,19 +662,22 @@ void npdm_print(npdm_t *npdm, hactool_ctx_t *tool_ctx) {

void npdm_save(npdm_t *npdm, hactool_ctx_t *tool_ctx) {
filepath_t *json_path = &tool_ctx->settings.npdm_json_path;
if (json_path->valid == VALIDITY_VALID) {
FILE *f_json = os_fopen(json_path->os_path, OS_MODE_WRITE);
if (f_json == NULL) {
fprintf(stderr, "Failed to open %s!\n", json_path->char_path);
return;
}
const char *json = npdm_get_json(npdm);
if (fwrite(json, 1, strlen(json), f_json) != strlen(json)) {
fprintf(stderr, "Failed to write JSON file!\n");
exit(EXIT_FAILURE);
}
fclose(f_json);
if (json_path->valid != VALIDITY_VALID) {
return;
}

FILE *f_json = os_fopen(json_path->os_path, OS_MODE_WRITE);
if (f_json == NULL) {
fprintf(stderr, "Failed to open %s!\n", json_path->char_path);
return;
}

const char *json = npdm_get_json(npdm);
if (fwrite(json, 1, strlen(json), f_json) != strlen(json)) {
fprintf(stderr, "Failed to write JSON file!\n");
exit(EXIT_FAILURE);
}
fclose(f_json);
}

void cJSON_AddU8ToObject(cJSON *obj, char *name, uint8_t val) {
Expand Down

0 comments on commit ab6fe34

Please sign in to comment.