From c5c8c7ff86f08915524bcb4fe767744d0d0a8a83 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Fri, 1 Nov 2019 19:07:10 -0700 Subject: [PATCH] libutil/mode: Remove unnecessary octal-to-mode conversion The values of the file mode macros are specified explicitly by POSIX, so we can just use the octal value directly. --- libutil/mode.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/libutil/mode.c b/libutil/mode.c index 187c7a3..5ba8eb1 100644 --- a/libutil/mode.c +++ b/libutil/mode.c @@ -26,20 +26,7 @@ parsemode(const char *str, mode_t mode, mode_t mask) if (*end == '\0') { if (octal < 0 || octal > 07777) eprintf("%s: invalid mode\n", str); - mode = 0; - if (octal & 04000) mode |= S_ISUID; - if (octal & 02000) mode |= S_ISGID; - if (octal & 01000) mode |= S_ISVTX; - if (octal & 00400) mode |= S_IRUSR; - if (octal & 00200) mode |= S_IWUSR; - if (octal & 00100) mode |= S_IXUSR; - if (octal & 00040) mode |= S_IRGRP; - if (octal & 00020) mode |= S_IWGRP; - if (octal & 00010) mode |= S_IXGRP; - if (octal & 00004) mode |= S_IROTH; - if (octal & 00002) mode |= S_IWOTH; - if (octal & 00001) mode |= S_IXOTH; - return mode; + return octal; } next: /* first, determine which bits we will be modifying */