]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/strutils: make strmode() more generic
authorKarel Zak <kzak@redhat.com>
Tue, 30 Jun 2015 10:41:13 +0000 (12:41 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 30 Jun 2015 10:41:13 +0000 (12:41 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/strutils.c

index ebfc5110b92458d2f07e5ecd543349d69ffd9e1e..b033f7592b4638ef5be91fb152a909ecf912d65b 100644 (file)
@@ -424,37 +424,39 @@ void strtotimeval_or_err(const char *str, struct timeval *tv, const char *errmes
  */
 void strmode(mode_t mode, char *str)
 {
+       unsigned short i = 0;
+
        if (S_ISDIR(mode))
-               str[0] = 'd';
+               str[i++] = 'd';
        else if (S_ISLNK(mode))
-               str[0] = 'l';
+               str[i++] = 'l';
        else if (S_ISCHR(mode))
-               str[0] = 'c';
+               str[i++] = 'c';
        else if (S_ISBLK(mode))
-               str[0] = 'b';
+               str[i++] = 'b';
        else if (S_ISSOCK(mode))
-               str[0] = 's';
+               str[i++] = 's';
        else if (S_ISFIFO(mode))
-               str[0] = 'p';
+               str[i++] = 'p';
        else if (S_ISREG(mode))
-               str[0] = '-';
+               str[i++] = '-';
 
-       str[1] = mode & S_IRUSR ? 'r' : '-';
-       str[2] = mode & S_IWUSR ? 'w' : '-';
-       str[3] = (mode & S_ISUID
+       str[i++] = mode & S_IRUSR ? 'r' : '-';
+       str[i++] = mode & S_IWUSR ? 'w' : '-';
+       str[i++] = (mode & S_ISUID
                ? (mode & S_IXUSR ? 's' : 'S')
                : (mode & S_IXUSR ? 'x' : '-'));
-       str[4] = mode & S_IRGRP ? 'r' : '-';
-       str[5] = mode & S_IWGRP ? 'w' : '-';
-       str[6] = (mode & S_ISGID
+       str[i++] = mode & S_IRGRP ? 'r' : '-';
+       str[i++] = mode & S_IWGRP ? 'w' : '-';
+       str[i++] = (mode & S_ISGID
                ? (mode & S_IXGRP ? 's' : 'S')
                : (mode & S_IXGRP ? 'x' : '-'));
-       str[7] = mode & S_IROTH ? 'r' : '-';
-       str[8] = mode & S_IWOTH ? 'w' : '-';
-       str[9] = (mode & S_ISVTX
+       str[i++] = mode & S_IROTH ? 'r' : '-';
+       str[i++] = mode & S_IWOTH ? 'w' : '-';
+       str[i++] = (mode & S_ISVTX
                ? (mode & S_IXOTH ? 't' : 'T')
                : (mode & S_IXOTH ? 'x' : '-'));
-       str[10] = '\0';
+       str[i] = '\0';
 }
 
 /*