[pacman-dev] [PATCH 2/3] pacman/util.c: use switch when there are fall through statements

Sami Kerola kerolasa at iki.fi
Mon Sep 2 16:30:47 EDT 2013


An 'if' clause with empty statement is allowed, but unusual construct.
When 'if' is used this way the statement should at least have orphan
semicolon ';'.  For empty statements 'switch' feels like a native way
express what is meant.

Signed-off-by: Sami Kerola <kerolasa at iki.fi>
---
 src/pacman/util.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/src/pacman/util.c b/src/pacman/util.c
index 9eb0042..6035963 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -190,16 +190,13 @@ int rmrf(const char *path)
 	if(!unlink(path)) {
 		return 0;
 	} else {
-		if(errno == ENOENT) {
+		switch(errno) {
+		case ENOENT:
 			return 0;
-		} else if(errno == EPERM) {
-			/* fallthrough */
-		} else if(errno == EISDIR) {
-			/* fallthrough */
-		} else if(errno == ENOTDIR) {
-			return 1;
-		} else {
-			/* not a directory */
+		case EPERM:
+		case EISDIR:
+			break;
+		default:
 			return 1;
 		}
 
-- 
1.8.4



More information about the pacman-dev mailing list