Skip to content

Commit

Permalink
test/libcjson: add diag output on open failure
Browse files Browse the repository at this point in the history
  • Loading branch information
garlick committed Oct 5, 2016
1 parent 55ec91a commit f1d06e6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/common/libcjson/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "cJSON.h"
#include <errno.h>
#include <string.h>

#include "src/common/libutil/xzmalloc.h"
#include "src/common/libtap/tap.h"

#include "cJSON.h"

/* Parse text to JSON, then render back to text, and print! */
int doit(char *text)
{
Expand Down Expand Up @@ -56,11 +59,14 @@ int dofile(char *filename)
char path[PATH_MAX+1];
snprintf (path, sizeof (path), "%s/%s", SRCDIR, filename);
f=fopen(path,"rb");
if (f == NULL)
if (f == NULL) {
diag ("%s: %s", path, strerror (errno));
return 0;
}
fseek(f,0,SEEK_END);len=ftell(f);fseek(f,0,SEEK_SET);
data=(char*)xzmalloc(len+1);
if (fread(data,1,len,f) != len) {
diag ("%s: fread %d failed", path, len);
fclose (f);
return 0;
}
Expand Down

0 comments on commit f1d06e6

Please sign in to comment.