Replace die() with pdie() and err() macros
authorLoïMinier <loic.minier@linaro.org>
Mon, 14 Mar 2011 07:31:47 +0000 (13:01 +0530)
committerAnand Gadiyar <gadiyar@ti.com>
Mon, 14 Mar 2011 08:22:28 +0000 (13:52 +0530)
err() saves errno for pdie() to perror() the actual strerror() issue.

Signed-off-by: LoïMinier <loic.minier@linaro.org>
Signed-off-by: Anand Gadiyar <gadiyar@ti.com>
scripts/signGP.c

index f3bc2af..193f27a 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 #include <stdio.h>
+#include <errno.h>
 #include <stdlib.h>
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -236,7 +237,11 @@ static struct ch_chsettings_nochram config_header
 #endif
 
 
-#define die(...) do { fprintf(stderr, __VA_ARGS__); exit(1); } while (0);
+#define err(...) do { int save_errno = errno; \
+                      fprintf(stderr, __VA_ARGS__); \
+                      errno = save_errno; \
+                    } while (0);
+#define pdie(func, ...) do { perror(func); exit(1); } while (0);
 
 int main(int argc, char *argv[])
 {
@@ -268,7 +273,8 @@ int main(int argc, char *argv[])
        /* Open the input file. */
        ifile = fopen(ifname, "rb");
        if (ifile == NULL) {
-               die("Cannot open %s\n", ifname);
+               err("Cannot open %s\n", ifname);
+               pdie("fopen");
        }
 
        /* Get file length. */
@@ -279,7 +285,8 @@ int main(int argc, char *argv[])
        ofile = fopen(ofname, "wb");
        if (ofile == NULL) {
                fclose(ifile);
-               die("Cannot open %s\n", ofname);
+               err("Cannot open %s\n", ofname);
+               pdie("fopen");
        }
 
        /* Pad 1 sector of zeroes. */