X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fmodechange.c;h=057803124f573d0e753bf980ef334fa9711217f2;hb=0bb0c42bbc23b604ec21f3f9e30363eb17fdc484;hp=97f2e63ba7709a05ba051b7ce9b8e6be2d18d504;hpb=68fa88b900c9096c51a309411fbc3b2089b42621;p=gnulib.git diff --git a/lib/modechange.c b/lib/modechange.c index 97f2e63ba..057803124 100644 --- a/lib/modechange.c +++ b/lib/modechange.c @@ -1,5 +1,5 @@ /* modechange.c -- file mode manipulation - Copyright (C) 1989, 1990, 1997 Free Software Foundation, Inc. + Copyright (C) 1989, 1990, 1997, 1998, 1999 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 @@ -55,7 +55,22 @@ char *malloc (); #define isodigit(c) ((c) >= '0' && (c) <= '7') -static int oatoi (); +/* Return a positive integer containing the value of the ASCII + octal number S. If S is not an octal number, return -1. */ + +static int +oatoi (const char *s) +{ + register int i; + + if (*s == 0) + return -1; + for (i = 0; isodigit (*s); ++s) + i = i * 8 + *s - '0'; + if (*s) + return -1; + return i; +} /* Return a linked list of file mode change operations created from MODE_STRING, an ASCII string that contains either an octal number @@ -71,9 +86,7 @@ static int oatoi (); return MODE_MEMORY_EXHAUSTED if there is insufficient memory. */ struct mode_change * -mode_compile (mode_string, masked_ops) - const char *mode_string; - unsigned masked_ops; +mode_compile (const char *mode_string, unsigned int masked_ops) { struct mode_change *head; /* First element of the linked list. */ struct mode_change *change; /* An element of the linked list. */ @@ -158,7 +171,7 @@ mode_compile (mode_string, masked_ops) change->next = talloc (struct mode_change); if (change->next == NULL) { - mode_free (change); + mode_free (head); return MODE_MEMORY_EXHAUSTED; } change = change->next; @@ -236,20 +249,14 @@ invalid: 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 */ +/* 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; +mode_create_from_ref (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; @@ -259,12 +266,9 @@ mode_create_from_ref (ref_file) 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->flags = 0; + change->affected = 07777; change->value = ref_stats.st_mode; change->next = NULL; @@ -277,9 +281,7 @@ mode_create_from_ref (ref_file) The returned value has the S_IFMT bits cleared. */ unsigned short -mode_adjust (oldmode, changes) - unsigned oldmode; - const struct mode_change *changes; +mode_adjust (unsigned int oldmode, const struct mode_change *changes) { unsigned short newmode; /* The adjusted mode and one operand. */ unsigned short value; /* The other operand. */ @@ -344,8 +346,7 @@ mode_adjust (oldmode, changes) CHANGES. */ void -mode_free (changes) - register struct mode_change *changes; +mode_free (register struct mode_change *changes) { register struct mode_change *next; @@ -356,21 +357,3 @@ mode_free (changes) changes = next; } } - -/* Return a positive integer containing the value of the ASCII - octal number S. If S is not an octal number, return -1. */ - -static int -oatoi (s) - char *s; -{ - register int i; - - if (*s == 0) - return -1; - for (i = 0; isodigit (*s); ++s) - i = i * 8 + *s - '0'; - if (*s) - return -1; - return i; -}