]> pilppa.com Git - uci.git/commitdiff
fix compilation on later glibc/gcc versions with stricter checks
authorFelix Fietkau <nbd@openwrt.org>
Mon, 23 Feb 2009 14:57:12 +0000 (15:57 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Mon, 23 Feb 2009 14:57:12 +0000 (15:57 +0100)
file.c
history.c
libuci.c

diff --git a/file.c b/file.c
index 1abe8ff4987d6159affc60c7f847ccb7f84d365c..a58e3924048dd0c96d2bc588d1420824b4fb94a5 100644 (file)
--- a/file.c
+++ b/file.c
@@ -454,7 +454,8 @@ void uci_file_commit(struct uci_context *ctx, struct uci_package **package, bool
        }
 
        rewind(f);
-       ftruncate(fileno(f), 0);
+       if (ftruncate(fileno(f), 0) < 0)
+               UCI_THROW(ctx, UCI_ERR_IO);
 
        uci_export(ctx, f, p, false);
        UCI_TRAP_RESTORE(ctx);
index a31dbfaf1cb23d5ed196e4f6cbc66daf0a4ea042..e3e19de4e60dc0ce4a0e238df30b275796038ff9 100644 (file)
--- a/history.c
+++ b/history.c
@@ -250,7 +250,10 @@ static int uci_load_history(struct uci_context *ctx, struct uci_package *p, bool
        changes = uci_load_history_file(ctx, p, filename, &f, flush);
        if (flush && f && (changes > 0)) {
                rewind(f);
-               ftruncate(fileno(f), 0);
+               if (ftruncate(fileno(f), 0) < 0) {
+                       uci_close_stream(f);
+                       UCI_THROW(ctx, UCI_ERR_IO);
+               }
        }
        if (filename)
                free(filename);
@@ -308,7 +311,8 @@ static void uci_filter_history(struct uci_context *ctx, const char *name, const
 
        /* rebuild the history file */
        rewind(f);
-       ftruncate(fileno(f), 0);
+       if (ftruncate(fileno(f), 0) < 0)
+               UCI_THROW(ctx, UCI_ERR_IO);
        uci_foreach_element_safe(&list, tmp, e) {
                fprintf(f, "%s\n", e->name);
                uci_free_element(e);
index bc68462fad19036288ba609a01fb20f580cc6810..947b029e970299fa99acabeb3f07ee6d9cc5ee6e 100644 (file)
--- a/libuci.c
+++ b/libuci.c
@@ -167,13 +167,15 @@ uci_get_errorstr(struct uci_context *ctx, char **dest, const char *prefix)
        default:
                break;
        }
-       if (dest)
-               asprintf(dest, format,
+       if (dest) {
+               err = asprintf(dest, format,
                        (prefix ? prefix : ""), (prefix ? ": " : ""),
                        (ctx->func ? ctx->func : ""), (ctx->func ? ": " : ""),
                        uci_errstr[err],
                        error_info);
-       else {
+               if (err < 0)
+                       *dest = NULL;
+       } else {
                strcat(error_info, "\n");
                fprintf(stderr, format,
                        (prefix ? prefix : ""), (prefix ? ": " : ""),