Mercurial > hg > toybox
diff lib/lib.c @ 1436:d7be3d62a5cb draft
If string_to_mode() is called on a base mode with S_ISDIR() and such set, pass those extra bits through.
author | Rob Landley <rob@landley.net> |
---|---|
date | Fri, 15 Aug 2014 10:50:39 -0500 |
parents | a0c328bc2c14 |
children | e5b52720f539 |
line wrap: on
line diff
--- a/lib/lib.c Tue Aug 12 18:05:55 2014 -0500 +++ b/lib/lib.c Fri Aug 15 10:50:39 2014 -0500 @@ -686,15 +686,16 @@ // premute mode bits based on posix mode strings. mode_t string_to_mode(char *modestr, mode_t mode) { - char *whos = "ogua", *hows = "=+-", *whats = "xwrstX", *whys = "ogu"; - char *s, *str = modestr; + char *whos = "ogua", *hows = "=+-", *whats = "xwrstX", *whys = "ogu", + *s, *str = modestr; + mode_t extrabits = mode & ~(07777); // Handle octal mode if (isdigit(*str)) { mode = strtol(str, &s, 8); if (*s || (mode & ~(07777))) goto barf; - return mode; + return mode | extrabits; } // Gaze into the bin of permission... @@ -762,7 +763,8 @@ if (!*str) break; } - return mode; + + return mode|extrabits; barf: error_exit("bad mode '%s'", modestr); }