summary refs log tree commit diff
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2014-10-27 16:06:51 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2014-10-27 16:06:51 +0800
commitbc8321eabffa23293d16d6758034203a8c7bffda (patch)
tree254729e823459f7b17648b66a8c6b8dd9ec0bc4f
parent[BUILTIN] Remove getintmax in printf (diff)
downloaddash-bc8321eabffa23293d16d6758034203a8c7bffda.tar.gz
dash-bc8321eabffa23293d16d6758034203a8c7bffda.zip
[BUILTIN] Use error instead of warnx for fatal errors in printf
This patch replaces uses of warnx where we abort with error since
the effect is the same.  The exit status however changes from 1 to
2.  Non-fatal errors where we continue are unchanged.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--ChangeLog1
-rw-r--r--src/bltin/printf.c17
2 files changed, 6 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 5b9b03a..707c24d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@
 	* Add ifdefs around MEM_OUT handling in outmem.
 	* Remove unnecessary restoration of format string in printf.
 	* Remove getintmax in printf.
+	* Use error instead of warnx for fatal errors in printf.
 
 2014-10-13  Eric Blake <eblake@redhat.com>
 
diff --git a/src/bltin/printf.c b/src/bltin/printf.c
index ebc74ae..4812e40 100644
--- a/src/bltin/printf.c
+++ b/src/bltin/printf.c
@@ -132,10 +132,8 @@ int printfcmd(int argc, char *argv[])
 	argv = argptr;
 	format = *argv;
 
-	if (!format) {
-		warnx("usage: printf format [arg ...]");
-		goto err;
-	}
+	if (!format)
+		error("usage: printf format [arg ...]");
 
 	gargv = ++argv;
 
@@ -190,10 +188,8 @@ pc:
 			fmt += strspn(fmt, SKIP2);
 
 			ch = *fmt;
-			if (!ch) {
-				warnx("missing format character");
-				goto err;
-			}
+			if (!ch)
+				error("missing format character");
 			/* null terminate format string to we can use it
 			   as an argument to printf. */
 			nextch = fmt[1];
@@ -246,8 +242,7 @@ pc:
 				break;
 			}
 			default:
-				warnx("%s: invalid directive", start);
-				goto err;
+				error("%s: invalid directive", start);
 			}
 			*++fmt = nextch;
 		}
@@ -255,8 +250,6 @@ pc:
 
 out:
 	return rval;
-err:
-	return 1;
 }