changeset 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 6bc78fa4c31f
children 1d79c0c23f69
files lib/lib.c
diffstat 1 files changed, 6 insertions(+), 4 deletions(-) [+]
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);
 }