(re_match_2_internal): Declare buf_ch unsigned int.
[gnulib.git] / lib / modechange.c
index 9006077..b1af8e5 100644 (file)
@@ -1,5 +1,5 @@
 /* modechange.c -- file mode manipulation
-   Copyright (C) 1989, 1990 Free Software Foundation, Inc.
+   Copyright (C) 1989, 1990, 1997 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -44,7 +44,7 @@ char *malloc ();
 
 #if STAT_MACROS_BROKEN
 # undef S_ISDIR
-#endif /* STAT_MACROS_BROKEN.  */
+#endif
 
 #if !defined(S_ISDIR) && defined(S_IFDIR)
 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
@@ -236,6 +236,33 @@ invalid:
   return MODE_INVALID;
 }
 
+/* Return a file mode change operation that sets permissions to match those
+   of REF_FILE.  Return MODE_BAD_REFERENCE if REF_FILE can't be accessed.  */
+
+struct mode_change *
+mode_create_from_ref (ref_file)
+     const char *ref_file;
+{
+  struct mode_change *change;  /* the only change element */
+  struct stat ref_stats;
+
+  if (stat (ref_file, &ref_stats))
+    return MODE_BAD_REFERENCE;
+
+  change = talloc (struct mode_change);
+
+  if (change == NULL)
+    return MODE_MEMORY_EXHAUSTED;
+
+  change->op = '=';
+  change->flags = 0;
+  change->affected = 07777;
+  change->value = ref_stats.st_mode;
+  change->next = NULL;
+
+  return change;
+}
+
 /* Return file mode OLDMODE, adjusted as indicated by the list of change
    operations CHANGES.  If OLDMODE is a directory, the type `X'
    change affects it even if no execute bits were set in OLDMODE.