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