X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fmodechange.c;h=b1af8e5fc867882f5d98f400a770fdfc5128a2e6;hb=12cc8b970806cca3260e499c74d2f001df705a60;hp=5a009271e43a385f3d953730f0dc0a0b1e1492e6;hpb=40399360923cb817164dc755c67eb5460958150e;p=gnulib.git diff --git a/lib/modechange.c b/lib/modechange.c index 5a009271e..b1af8e5fc 100644 --- a/lib/modechange.c +++ b/lib/modechange.c @@ -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 @@ -12,8 +12,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Written by David MacKenzie */ @@ -24,30 +24,30 @@ changing the mode of many files, this probably results in a performance gain. */ -#ifdef HAVE_CONFIG_H -#include +#if HAVE_CONFIG_H +# include #endif #include #include #include "modechange.h" -#ifdef STDC_HEADERS -#include +#if STDC_HEADERS +# include #else char *malloc (); #endif #ifndef NULL -#define NULL 0 +# define NULL 0 #endif -#ifdef STAT_MACROS_BROKEN -#undef S_ISDIR -#endif /* STAT_MACROS_BROKEN. */ +#if STAT_MACROS_BROKEN +# undef S_ISDIR +#endif #if !defined(S_ISDIR) && defined(S_IFDIR) -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #endif /* Return newly allocated memory to hold one element of type TYPE. */ @@ -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.