05ad79
From 7bf448fe38478b6e76824fa5bbd2d2d25a48f618 Mon Sep 17 00:00:00 2001
05ad79
From: Karel Zak <kzak@redhat.com>
05ad79
Date: Tue, 30 Jun 2015 12:41:13 +0200
05ad79
Subject: [PATCH 77/84] lib/strutils: make strmode() more generic
05ad79
05ad79
Upstream: http://github.com/karelzak/util-linux/commit/7015df4936ca320a86d2916533a17499ac5e4fcf
05ad79
Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=1153770
05ad79
Signed-off-by: Karel Zak <kzak@redhat.com>
05ad79
---
05ad79
 lib/strutils.c | 36 +++++++++++++++++++-----------------
05ad79
 1 file changed, 19 insertions(+), 17 deletions(-)
05ad79
05ad79
diff --git a/lib/strutils.c b/lib/strutils.c
05ad79
index c263b86..f9cdcbb 100644
05ad79
--- a/lib/strutils.c
05ad79
+++ b/lib/strutils.c
05ad79
@@ -349,37 +349,39 @@ void strtotimeval_or_err(const char *str, struct timeval *tv, const char *errmes
05ad79
  */
05ad79
 void strmode(mode_t mode, char *str)
05ad79
 {
05ad79
+	unsigned short i = 0;
05ad79
+
05ad79
 	if (S_ISDIR(mode))
05ad79
-		str[0] = 'd';
05ad79
+		str[i++] = 'd';
05ad79
 	else if (S_ISLNK(mode))
05ad79
-		str[0] = 'l';
05ad79
+		str[i++] = 'l';
05ad79
 	else if (S_ISCHR(mode))
05ad79
-		str[0] = 'c';
05ad79
+		str[i++] = 'c';
05ad79
 	else if (S_ISBLK(mode))
05ad79
-		str[0] = 'b';
05ad79
+		str[i++] = 'b';
05ad79
 	else if (S_ISSOCK(mode))
05ad79
-		str[0] = 's';
05ad79
+		str[i++] = 's';
05ad79
 	else if (S_ISFIFO(mode))
05ad79
-		str[0] = 'p';
05ad79
+		str[i++] = 'p';
05ad79
 	else if (S_ISREG(mode))
05ad79
-		str[0] = '-';
05ad79
+		str[i++] = '-';
05ad79
 
05ad79
-	str[1] = mode & S_IRUSR ? 'r' : '-';
05ad79
-	str[2] = mode & S_IWUSR ? 'w' : '-';
05ad79
-	str[3] = (mode & S_ISUID
05ad79
+	str[i++] = mode & S_IRUSR ? 'r' : '-';
05ad79
+	str[i++] = mode & S_IWUSR ? 'w' : '-';
05ad79
+	str[i++] = (mode & S_ISUID
05ad79
 		? (mode & S_IXUSR ? 's' : 'S')
05ad79
 		: (mode & S_IXUSR ? 'x' : '-'));
05ad79
-	str[4] = mode & S_IRGRP ? 'r' : '-';
05ad79
-	str[5] = mode & S_IWGRP ? 'w' : '-';
05ad79
-	str[6] = (mode & S_ISGID
05ad79
+	str[i++] = mode & S_IRGRP ? 'r' : '-';
05ad79
+	str[i++] = mode & S_IWGRP ? 'w' : '-';
05ad79
+	str[i++] = (mode & S_ISGID
05ad79
 		? (mode & S_IXGRP ? 's' : 'S')
05ad79
 		: (mode & S_IXGRP ? 'x' : '-'));
05ad79
-	str[7] = mode & S_IROTH ? 'r' : '-';
05ad79
-	str[8] = mode & S_IWOTH ? 'w' : '-';
05ad79
-	str[9] = (mode & S_ISVTX
05ad79
+	str[i++] = mode & S_IROTH ? 'r' : '-';
05ad79
+	str[i++] = mode & S_IWOTH ? 'w' : '-';
05ad79
+	str[i++] = (mode & S_ISVTX
05ad79
 		? (mode & S_IXOTH ? 't' : 'T')
05ad79
 		: (mode & S_IXOTH ? 'x' : '-'));
05ad79
-	str[10] = '\0';
05ad79
+	str[i] = '\0';
05ad79
 }
05ad79
 
05ad79
 /*
05ad79
-- 
05ad79
2.7.4
05ad79