From 94fd34350f47d80d97a595b1c0f286be1b85ba77 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lo=C3=AFMinier?= Date: Mon, 14 Mar 2011 13:01:47 +0530 Subject: [PATCH] Replace die() with pdie() and err() macros MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit err() saves errno for pdie() to perror() the actual strerror() issue. Signed-off-by: LoïMinier Signed-off-by: Anand Gadiyar --- scripts/signGP.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/signGP.c b/scripts/signGP.c index f3bc2af..193f27a 100644 --- a/scripts/signGP.c +++ b/scripts/signGP.c @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -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. */ -- 2.39.5