[ostree-init] Quiet a gcc warning



commit 985171a19e18318b983689eb2c3fcf4ae4db723b
Author: Colin Walters <walters verbum org>
Date:   Mon Jan 16 12:59:28 2012 -0500

    Quiet a gcc warning

 src/ostree-init.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/src/ostree-init.c b/src/ostree-init.c
index fd2570a..1288089 100644
--- a/src/ostree-init.c
+++ b/src/ostree-init.c
@@ -106,8 +106,9 @@ static char *
 get_file_contents (const char *path, size_t *len)
 {
   FILE *f = NULL;
+  int did_save_errno = 0;
   char *ret = NULL;
-  int saved_errno;
+  int saved_errno = 0;
   char *buf = NULL;
   size_t bytes_read;
   size_t buf_size;
@@ -116,6 +117,7 @@ get_file_contents (const char *path, size_t *len)
   f = fopen (path, "r");
   if (!f)
     {
+      did_save_errno = 1;
       saved_errno = errno;
       goto out;
     }
@@ -137,6 +139,7 @@ get_file_contents (const char *path, size_t *len)
     }
   if (bytes_read < 0)
     {
+      did_save_errno = 1;
       saved_errno = errno;
       goto out;
     }
@@ -148,7 +151,8 @@ get_file_contents (const char *path, size_t *len)
   if (f)
     fclose (f);
   free (buf);
-  errno = saved_errno;
+  if (did_save_errno)
+    errno = saved_errno;
   return ret;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]