From 11e80db556dfece23e313a327bb95cb4efbef869 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Fri, 19 Oct 2012 08:03:36 +0800 Subject: fix compile warnings under ubuntu These aren't reported by default in Fedora Rawhide gcc Reported-by: Nicolas Dechesne Signed-off-by: Andy Green --- libarmep/configuration.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/libarmep/configuration.c b/libarmep/configuration.c index 67752ca..829ba09 100644 --- a/libarmep/configuration.c +++ b/libarmep/configuration.c @@ -134,6 +134,7 @@ int configure(struct aep_context *aep_context, struct aep *aep, const char *dev_ char temp_config[1024]; char linebuf[1024]; int no_copy = 0; + int ret = 0; if (wch) { strncpy(temp_config, config_filepath, sizeof temp_config - 2); @@ -177,7 +178,10 @@ int configure(struct aep_context *aep_context, struct aep *aep, const char *dev_ entry_parser = parser; if (!no_copy && wfd > 0) - write(wfd, &c, 1); + if (write(wfd, &c, 1) < 1) { + fprintf(stderr, "Unable to write config file\n"); + goto bail; + } switch (parser) { case ACPP_FIRST: @@ -290,7 +294,10 @@ int configure(struct aep_context *aep_context, struct aep *aep, const char *dev_ if (aep->aep_context->verbose) fprintf(stderr, "Updating config " "with \"%s\"\n", linebuf); - write(wfd, linebuf, strlen(linebuf)); + if (write(wfd, linebuf, strlen(linebuf)) < 0) { + fprintf(stderr, "Unable to write config file\n"); + goto bail; + } } ch++; @@ -361,20 +368,24 @@ int configure(struct aep_context *aep_context, struct aep *aep, const char *dev_ } c = buf[pos++]; - write(wfd, &c, 1); + if (write(wfd, &c, 1) < 0) { + fprintf(stderr, "Unable to write config file\n"); + goto bail; + } } - - close(wfd); } - +bail: close(fd); if (wfd > 0) { - unlink(config_filepath); - rename(temp_config, config_filepath); + close(wfd); + if (!ret) { + unlink(config_filepath); + rename(temp_config, config_filepath); + } } - return 0; + return ret; } -- cgit v1.2.3