8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libshell / common / bltins / umask.c
blob0067c89dbefa4a98c00e608368df1c097bd6470a
1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1982-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * David Korn <dgk@research.att.com> *
18 * *
19 ***********************************************************************/
20 #pragma prototyped
22 * umask [-S] [mask]
24 * David Korn
25 * AT&T Labs
26 * research!dgk
30 #include <ast.h>
31 #include <sfio.h>
32 #include <error.h>
33 #include <ctype.h>
34 #include <ls.h>
35 #include <shell.h>
36 #include "builtins.h"
37 #ifndef SH_DICT
38 # define SH_DICT "libshell"
39 #endif
41 int b_umask(int argc,char *argv[],void *extra)
43 register char *mask;
44 register int flag = 0, sflag = 0;
45 NOT_USED(extra);
46 while((argc = optget(argv,sh_optumask))) switch(argc)
48 case 'S':
49 sflag++;
50 break;
51 case ':':
52 errormsg(SH_DICT,2, "%s", opt_info.arg);
53 break;
54 case '?':
55 errormsg(SH_DICT,ERROR_usage(2), "%s",opt_info.arg);
56 break;
58 if(error_info.errors)
59 errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
60 argv += opt_info.index;
61 if(mask = *argv)
63 register int c;
64 if(isdigit(*mask))
66 while(c = *mask++)
68 if (c>='0' && c<='7')
69 flag = (flag<<3) + (c-'0');
70 else
71 errormsg(SH_DICT,ERROR_exit(1),e_number,*argv);
74 else
76 char *cp = mask;
77 flag = umask(0);
78 c = strperm(cp,&cp,~flag&0777);
79 if(*cp)
81 umask(flag);
82 errormsg(SH_DICT,ERROR_exit(1),e_format,mask);
84 flag = (~c&0777);
86 umask(flag);
88 else
90 umask(flag=umask(0));
91 if(sflag)
92 sfprintf(sfstdout,"%s\n",fmtperm(~flag&0777));
93 else
94 sfprintf(sfstdout,"%0#4o\n",flag);
96 return(0);