ELOG("mkdir(%s) failed: %s\n", path, strerror(errno));
return false;
}
- char *copy = strdup(path);
+ char *copy = sstrdup(path);
/* strip trailing slashes, if any */
while (copy[strlen(copy)-1] == '/')
copy[strlen(copy)-1] = '\0';
/* TODO: percent of other windows are not correctly fixed at the moment */
FILE *f;
if ((f = fopen(filename, "r")) == NULL) {
- LOG("Cannot open file\n");
+ LOG("Cannot open file \"%s\"\n", filename);
+ return;
+ }
+ struct stat stbuf;
+ if (fstat(fileno(f), &stbuf) != 0) {
+ LOG("Cannot fstat() the file\n");
+ fclose(f);
+ return;
+ }
+ char *buf = smalloc(stbuf.st_size);
+ int n = fread(buf, 1, stbuf.st_size, f);
+ if (n != stbuf.st_size) {
+ LOG("File \"%s\" could not be read entirely, not loading.\n", filename);
+ fclose(f);
return;
}
- char *buf = malloc(65535); /* TODO */
- int n = fread(buf, 1, 65535, f);
LOG("read %d bytes\n", n);
yajl_gen g;
yajl_handle hand;