[hackers] [sbase] libutil/mode: Remove unnecessary octal-to-mode conversion || Michael Forney

From: <git_AT_suckless.org>
Date: Sat, 2 Nov 2019 03:14:32 +0100 (CET)

commit c5c8c7ff86f08915524bcb4fe767744d0d0a8a83
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Fri Nov 1 19:07:10 2019 -0700
Commit: Michael Forney <mforney_AT_mforney.org>
CommitDate: Fri Nov 1 19:07:10 2019 -0700

    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.

diff --git a/libutil/mode.c b/libutil/mode.c
index 187c7a3..5ba8eb1 100644
--- a/libutil/mode.c
+++ b/libutil/mode.c
_AT_@ -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 */
Received on Sat Nov 02 2019 - 03:14:32 CET

This archive was generated by hypermail 2.3.0 : Sat Nov 02 2019 - 03:24:27 CET