summaryrefslogtreecommitdiff
path: root/src/envstore.c
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2009-12-09 14:15:50 +0100
committerDaniel Friesel <derf@derf.homelinux.org>2009-12-09 14:15:50 +0100
commitc82490f8f4f69092457a15598de0e358dc4c0caa (patch)
treed4a0c4a6c50ea855f4bee5afe28689dde746e077 /src/envstore.c
parent5786caaf73de8e65debef450a7c6ee3f284313e4 (diff)
Fix the output of empty values (like envstore save foo '')
Diffstat (limited to 'src/envstore.c')
-rw-r--r--src/envstore.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/envstore.c b/src/envstore.c
index bf01aa9..43e6d56 100644
--- a/src/envstore.c
+++ b/src/envstore.c
@@ -98,12 +98,19 @@ static inline void print_escaped(char *name, char *content) {
static void command_disp(char *file, int command) {
char vname[PARAM_LENGTH];
char vcontent[VALUE_LENGTH];
+ int read_items;
FILE *fp = store_open(file);
if (fp == NULL)
exit(EXIT_SUCCESS);
- while (fscanf(fp, SCAN_FORMAT, vname, vcontent) != EOF) {
+ while ((read_items = fscanf(fp, SCAN_FORMAT, vname, vcontent)) != EOF) {
+
+ if (read_items == 0)
+ errx(EXIT_FAILURE, "Unable to read items, store file '%s' corrupt?", file);
+ else if (read_items == 1)
+ vcontent[0] = '\0';
+
if (command == CMD_LIST)
printf("%-15s = %s\n", vname, vcontent);
else