Bläddra i källkod

libdpkg: Refactor error output into a function variable in subproc_check()

This deduplicates two sets of identical strings.
Guillem Jover 15 år sedan
förälder
incheckning
e61824e3e7
1 ändrade filer med 11 tillägg och 14 borttagningar
  1. 11 14
      lib/dpkg/subproc.c

+ 11 - 14
lib/dpkg/subproc.c

@@ -100,34 +100,31 @@ subproc_fork(void)
 int
 subproc_check(int status, const char *desc, int flags)
 {
+	void (*out)(const char *fmt, ...) DPKG_ATTR_PRINTF(1);
 	int n;
 
+	if (flags & PROCWARN)
+		out = warning;
+	else
+		out = ohshit;
+
 	if (WIFEXITED(status)) {
 		n = WEXITSTATUS(status);
 		if (!n)
 			return 0;
 		if (flags & PROCNOERR)
 			return n;
-		if (flags & PROCWARN)
-			warning(_("subprocess %s returned error exit status %d"),
-			        desc, n);
-		else
-			ohshit(_("subprocess %s returned error exit status %d"),
-			       desc, n);
+
+		out(_("subprocess %s returned error exit status %d"), desc, n);
 	} else if (WIFSIGNALED(status)) {
 		n = WTERMSIG(status);
 		if (!n)
 			return 0;
 		if ((flags & PROCPIPE) && n == SIGPIPE)
 			return 0;
-		if (flags & PROCWARN)
-			warning(_("subprocess %s killed by signal (%s)%s"),
-			        desc, strsignal(n),
-			        WCOREDUMP(status) ? _(", core dumped") : "");
-		else
-			ohshit(_("subprocess %s killed by signal (%s)%s"),
-			       desc, strsignal(n),
-			       WCOREDUMP(status) ? _(", core dumped") : "");
+
+		out(_("subprocess %s killed by signal (%s)%s"), desc,
+		    strsignal(n), WCOREDUMP(status) ? _(", core dumped") : "");
 	} else {
 		ohshit(_("subprocess %s failed with wait status code %d"),
 		       desc, status);