Mercurial > hg > octave-shane > gnulib-hg
diff lib/modechange.c @ 972:b30f9ff1e92e
(mode_create_from_ref): New function.
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Sun, 06 Jul 1997 21:28:04 +0000 |
parents | 07f8a024691b |
children | c68ed1182a64 |
line wrap: on
line diff
--- 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 @@ -236,6 +236,41 @@ return MODE_INVALID; } +/* Return a file mode change operation created from the reference REF_FILE + Don't affect special permissions, use umask, affect 'x' if any 'x', for + maximum security + + 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; + int i; + int umask_value; + + if (stat (ref_file, &ref_stats)) + return MODE_BAD_REFERENCE; + + change = talloc (struct mode_change); + + if (change == NULL) + return MODE_MEMORY_EXHAUSTED; + + umask_value = umask (0); + umask (umask_value); + + change->op = '='; + change->flags = MODE_X_IF_ANY_X; + change->affected = 0777 & ~umask_value; + 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.