From c82490f8f4f69092457a15598de0e358dc4c0caa Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 9 Dec 2009 14:15:50 +0100 Subject: Fix the output of empty values (like envstore save foo '') --- src/envstore.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') 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 -- cgit v1.2.3