validate JSON before loading

This commit also introduces slurp() which reads a file in its entirety. Using
this function instead of doing IO in the functions in load_layout.c again and
again makes the code cleaner (fixing at least two memory leaks) and avoids
re-reading the same file 3 times.

related to #2755
This commit is contained in:
Michael Stapelberg
2017-09-13 17:14:51 +02:00
parent 72c972a36c
commit c45c002bad
6 changed files with 131 additions and 83 deletions

View File

@ -164,3 +164,11 @@ void kill_nagbar(pid_t *nagbar_pid, bool wait_for_it);
* if the number could be parsed.
*/
bool parse_long(const char *str, long *out, int base);
/**
* Slurp reads path in its entirety into buf, returning the length of the file
* or -1 if the file could not be read. buf is set to a buffer of appropriate
* size, or NULL if -1 is returned.
*
*/
ssize_t slurp(const char *path, char **buf);