1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00
cde/src/cmd/ksh93/bltins/umask.c
Martijn Dekker 441dcc0483 Upgrade licence to EPL 2.0
EPL 1.0 says, in section 7: "The Program (including Contributions)
may always be distributed subject to the version of the Agreement
under which it was received. In addition, after a new version of
the Agreement is published, Contributor may elect to distribute the
Program (including its Contributions) under the new version."

The Eclipse Foundation also encourage everyone to upgrade:
https://www.eclipse.org/legal/epl-2.0/faq.php#h.60mjudroo8e5
https://www.eclipse.org/legal/epl-2.0/faq.php#h.tci84nlsqpgw

Unfortunately the new Secondary License option is not available to
us as we're not the original copyright holders and don't have the
legal power to add one. So, no GPL compatibility. Sorry.
2022-07-28 05:46:08 +02:00

100 lines
2.5 KiB
C

/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1982-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
* A copy of the License is available at *
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html *
* (with md5 checksum 84283fa8859daf213bdda5a9f8d1be1d) *
* *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
/*
* umask [-S] [mask]
*
* David Korn
* AT&T Labs
* research!dgk
*
*/
#include "shopt.h"
#include <ast.h>
#include <sfio.h>
#include <error.h>
#include <ctype.h>
#include <ls.h>
#include <shell.h>
#include "builtins.h"
#ifndef SH_DICT
# define SH_DICT "libshell"
#endif
int b_umask(int argc,char *argv[],Shbltin_t *context)
{
register char *mask;
register int flag = 0, sflag = 0;
NOT_USED(context);
while((argc = optget(argv,sh_optumask))) switch(argc)
{
case 'S':
sflag++;
break;
case ':':
errormsg(SH_DICT,2, "%s", opt_info.arg);
break;
case '?':
errormsg(SH_DICT,ERROR_usage(2), "%s",opt_info.arg);
UNREACHABLE();
}
if(error_info.errors)
{
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
UNREACHABLE();
}
argv += opt_info.index;
if(mask = *argv)
{
register int c;
if(isdigit(*mask))
{
while(c = *mask++)
{
if (c>='0' && c<='7')
flag = (flag<<3) + (c-'0');
else
{
errormsg(SH_DICT,ERROR_exit(1),e_number,*argv);
UNREACHABLE();
}
}
}
else
{
char *cp = mask;
flag = umask(0);
c = strperm(cp,&cp,~flag&0777);
if(*cp)
{
umask(flag);
errormsg(SH_DICT,ERROR_exit(1),e_format,mask);
UNREACHABLE();
}
flag = (~c&0777);
}
umask(flag);
}
else
{
umask(flag=umask(0));
if(sflag)
sfprintf(sfstdout,"%s\n",fmtperm(~flag&0777));
else
sfprintf(sfstdout,"%0#4o\n",flag);
}
return(0);
}