1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1982-2011 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* David Korn <dgk@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#pragma prototyped
1N/A/*
1N/A * umask [-S] [mask]
1N/A *
1N/A * David Korn
1N/A * AT&T Labs
1N/A * research!dgk
1N/A *
1N/A */
1N/A
1N/A#include <ast.h>
1N/A#include <sfio.h>
1N/A#include <error.h>
1N/A#include <ctype.h>
1N/A#include <ls.h>
1N/A#include <shell.h>
1N/A#include "builtins.h"
1N/A#ifndef SH_DICT
1N/A# define SH_DICT "libshell"
1N/A#endif
1N/A
1N/Aint b_umask(int argc,char *argv[],void *extra)
1N/A{
1N/A register char *mask;
1N/A register int flag = 0, sflag = 0;
1N/A NOT_USED(extra);
1N/A while((argc = optget(argv,sh_optumask))) switch(argc)
1N/A {
1N/A case 'S':
1N/A sflag++;
1N/A break;
1N/A case ':':
1N/A errormsg(SH_DICT,2, "%s", opt_info.arg);
1N/A break;
1N/A case '?':
1N/A errormsg(SH_DICT,ERROR_usage(2), "%s",opt_info.arg);
1N/A break;
1N/A }
1N/A if(error_info.errors)
1N/A errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
1N/A argv += opt_info.index;
1N/A if(mask = *argv)
1N/A {
1N/A register int c;
1N/A if(isdigit(*mask))
1N/A {
1N/A while(c = *mask++)
1N/A {
1N/A if (c>='0' && c<='7')
1N/A flag = (flag<<3) + (c-'0');
1N/A else
1N/A errormsg(SH_DICT,ERROR_exit(1),e_number,*argv);
1N/A }
1N/A }
1N/A else
1N/A {
1N/A char *cp = mask;
1N/A flag = umask(0);
1N/A c = strperm(cp,&cp,~flag&0777);
1N/A if(*cp)
1N/A {
1N/A umask(flag);
1N/A errormsg(SH_DICT,ERROR_exit(1),e_format,mask);
1N/A }
1N/A flag = (~c&0777);
1N/A }
1N/A umask(flag);
1N/A }
1N/A else
1N/A {
1N/A umask(flag=umask(0));
1N/A if(sflag)
1N/A sfprintf(sfstdout,"%s\n",fmtperm(~flag&0777));
1N/A else
1N/A sfprintf(sfstdout,"%0#4o\n",flag);
1N/A }
1N/A return(0);
1N/A}
1N/A