firmware-utils: zyimage: fix compiler warnings/errors
authorPetr Štetiar <ynezz@true.cz>
Sat, 20 Jul 2019 11:45:45 +0000 (13:45 +0200)
committerPetr Štetiar <ynezz@true.cz>
Tue, 23 Jul 2019 20:07:22 +0000 (22:07 +0200)
zyimage.c:10: error: "_POSIX_SOURCE" redefined [-Werror]
zyimage.c:11: error: "_POSIX_C_SOURCE" redefined [-Werror]
zyimage.c:132:5: error: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Werror=unused-result]

Signed-off-by: Petr Štetiar <ynezz@true.cz>
tools/firmware-utils/src/zyimage.c

index 6aacf2ff1bd94fa55258f30a6d4aa9e93312b072..4bf6241ab759abdb5f94a647e0e4506bfa0715ea 100644 (file)
@@ -7,8 +7,14 @@
  *
  */
 
+#ifndef _POSIX_SOURCE
 #define _POSIX_SOURCE
+#endif
+
+#ifndef _POSIX_C_SOURCE
 #define _POSIX_C_SOURCE 199309L /* getopt */
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
@@ -128,8 +134,15 @@ int main(int argc, char *argv[]) {
   f = fopen(argv[optind], "r+");
   if (f != NULL)
   {
+    size_t r;
+
     fseek(f, sizeof(sign)*-1, SEEK_END);
-    fread(&oldsign, sizeof(oldsign), 1, f);
+    r = fread(&oldsign, sizeof(oldsign), 1, f);
+    if (r != 1)
+    {
+      printf("Failed to read oldsign\n");
+      exit(0);
+    }
 
     if (strncmp(oldsign.magic,"ZNBG", sizeof(oldsign.magic)) == 0 )
     {