dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/0077-lib-strutils-make-strmode-more-generic.patch

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