Changeset 615 in kBuild for trunk/src/gmake/kmkbuiltin/setmode.c
- Timestamp:
- Nov 26, 2006 6:33:40 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/kmkbuiltin/setmode.c
r370 r615 1 /* $NetBSD: setmode.c,v 1.30 2003/08/07 16:42:56 agc Exp $ */ 2 1 3 /* 2 4 * Copyright (c) 1989, 1993, 1994 … … 14 16 * notice, this list of conditions and the following disclaimer in the 15 17 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of 19 * California, Berkeley and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors 18 * 3. Neither the name of the University nor the names of its contributors 21 19 * may be used to endorse or promote products derived from this software 22 20 * without specific prior written permission. … … 35 33 */ 36 34 35 #include <sys/cdefs.h> 37 36 #if defined(LIBC_SCCS) && !defined(lint) 37 #if 0 38 38 static char sccsid[] = "@(#)setmode.c 8.2 (Berkeley) 3/25/94"; 39 #include <sys/cdefs.h> 40 //__FBSDID("$FreeBSD: src/lib/libc/gen/setmode.c,v 1.9 2003/02/23 00:24:03 mikeh Exp $"); 39 #else 40 __RCSID("$NetBSD: setmode.c,v 1.30 2003/08/07 16:42:56 agc Exp $"); 41 #endif 41 42 #endif /* LIBC_SCCS and not lint */ 42 43 43 //#include "namespace.h"44 #include "namespace.h" 44 45 #include <sys/types.h> 45 46 #include <sys/stat.h> 46 47 48 #include <assert.h> 47 49 #include <ctype.h> 50 #include <errno.h> 48 51 #include <signal.h> 49 #include <stddef.h>50 52 #include <stdlib.h> 51 #ifndef _MSC_VER52 53 #include <unistd.h> 53 #else54 #include "mscfakes.h"55 #endif56 54 57 55 #ifdef SETMODE_DEBUG 58 56 #include <stdio.h> 59 57 #endif 60 //#include "un-namespace.h" 58 59 #ifdef __weak_alias 60 __weak_alias(getmode,_getmode) 61 __weak_alias(setmode,_setmode) 62 #endif 61 63 62 64 #define SET_LEN 6 /* initial # of bitcmd struct to malloc */ … … 75 77 #define CMD2_UBITS 0x10 76 78 77 static BITCMD *addcmd(BITCMD *, int, int, int, u_int); 78 static void compress_mode(BITCMD *); 79 #ifdef SETMODE_DEBUG 80 static void dumpmode(BITCMD *); 81 #endif 82 83 #ifndef S_ISTXT 84 #ifdef S_ISVTX 85 #define S_ISTXT S_ISVTX 86 #else 87 #define S_ISTXT 0 88 #endif 89 #endif /* !S_ISTXT */ 79 static BITCMD *addcmd __P((BITCMD *, int, int, int, u_int)); 80 static void compress_mode __P((BITCMD *)); 81 #ifdef SETMODE_DEBUG 82 static void dumpmode __P((BITCMD *)); 83 #endif 90 84 91 85 /* … … 102 96 const BITCMD *set; 103 97 mode_t clrval, newmode, value; 98 99 _DIAGASSERT(bbox != NULL); 104 100 105 101 set = (const BITCMD *)bbox; … … 165 161 } 166 162 167 #define ADDCMD(a, b, c, d) \163 #define ADDCMD(a, b, c, d) do { \ 168 164 if (set >= endset) { \ 169 165 BITCMD *newset; \ 170 166 setlen += SET_LEN_INCR; \ 171 167 newset = realloc(saveset, sizeof(BITCMD) * setlen); \ 172 if (!newset) { \ 173 if (saveset) \ 174 free(saveset); \ 175 saveset = NULL; \ 168 if (newset == NULL) { \ 169 free(saveset); \ 176 170 return (NULL); \ 177 171 } \ … … 180 174 endset = newset + (setlen - 2); \ 181 175 } \ 182 set = addcmd(set, (a), (b), (c), (d)) 176 set = addcmd(set, (a), (b), (c), (d)); \ 177 } while (/*CONSTCOND*/0) 183 178 184 179 #define STANDARD_BITS (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO) … … 191 186 char op, *ep; 192 187 BITCMD *set, *saveset, *endset; 193 #ifndef _MSC_VER 194 sigset_t sigset, sigoset; 195 #endif 188 sigset_t signset, sigoset; 196 189 mode_t mask; 197 int equalopdone =0, permXbits, setlen;198 long perml;190 int equalopdone = 0; /* pacify gcc */ 191 int permXbits, setlen; 199 192 200 193 if (!*p) … … 207 200 * as best we can. 208 201 */ 209 #ifndef _MSC_VER 210 sigfillset(&sigset); 211 (void)sigprocmask(SIG_BLOCK, &sigset, &sigoset); 212 #endif 202 sigfillset(&signset); 203 (void)sigprocmask(SIG_BLOCK, &signset, &sigoset); 213 204 (void)umask(mask = umask(0)); 214 205 mask = ~mask; 215 #ifndef _MSC_VER 216 (void)sigprocmask(SIG_SETMASK, &sigoset, NULL); 217 #endif 206 (void)sigprocmask(SIG_SETMASK, &sigoset, NULL); 218 207 219 208 setlen = SET_LEN + 2; 220 209 221 210 if ((set = malloc((u_int)(sizeof(BITCMD) * setlen))) == NULL) 222 211 return (NULL); … … 229 218 */ 230 219 if (isdigit((unsigned char)*p)) { 231 perm l =strtol(p, &ep, 8);232 if (*ep || perm l < 0 || perml& ~(STANDARD_BITS|S_ISTXT)) {220 perm = (mode_t)strtol(p, &ep, 8); 221 if (*ep || perm & ~(STANDARD_BITS|S_ISTXT)) { 233 222 free(saveset); 234 223 return (NULL); 235 224 } 236 perm = (mode_t)perml;237 225 ADDCMD('=', (STANDARD_BITS|S_ISTXT), perm, mask); 238 226 set->cmd = 0; … … 279 267 break; 280 268 case 's': 281 /* If only "other" bits ignore set-id. */ 282 if (!who || who & ~S_IRWXO) 269 /* 270 * If specific bits where requested and 271 * only "other" bits ignore set-id. 272 */ 273 if (who == 0 || (who & ~S_IRWXO)) 283 274 perm |= S_ISUID|S_ISGID; 284 275 break; 285 276 case 't': 286 /* If only "other" bits ignore sticky. */ 287 if (!who || who & ~S_IRWXO) { 277 /* 278 * If specific bits where requested and 279 * only "other" bits ignore set-id. 280 */ 281 if (who == 0 || (who & ~S_IRWXO)) { 288 282 who |= S_ISTXT; 289 283 perm |= S_ISTXT; … … 365 359 u_int mask; 366 360 { 361 362 _DIAGASSERT(set != NULL); 363 367 364 switch (op) { 368 365 case '=': … … 393 390 set->bits = mask; 394 391 } 395 392 396 393 if (oparg == '+') 397 394 set->cmd2 |= CMD2_SET; … … 410 407 BITCMD *set; 411 408 { 409 410 _DIAGASSERT(set != NULL); 411 412 412 for (; set->cmd; ++set) 413 413 (void)printf("cmd: '%c' bits %04o%s%s%s%s%s%s\n", … … 424 424 * Given an array of bitcmd structures, compress by compacting consecutive 425 425 * '+', '-' and 'X' commands into at most 3 commands, one of each. The 'u', 426 * 'g' and 'o' commands continue to be separate. They could probably be 426 * 'g' and 'o' commands continue to be separate. They could probably be 427 427 * compacted, but it's not worth the effort. 428 428 */ … … 433 433 BITCMD *nset; 434 434 int setbits, clrbits, Xbits, op; 435 436 _DIAGASSERT(set != NULL); 435 437 436 438 for (nset = set;;) {
Note:
See TracChangeset
for help on using the changeset viewer.