17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
539e7390aSna * Common Development and Distribution License (the "License").
639e7390aSna * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate
227c478bd9Sstevel@tonic-gate /*
2339e7390aSna * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24965005c8Schin * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
27965005c8Schin /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28965005c8Schin /* All Rights Reserved */
29965005c8Schin
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate *
327c478bd9Sstevel@tonic-gate * UNIX shell
337c478bd9Sstevel@tonic-gate *
347c478bd9Sstevel@tonic-gate */
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gate #include "defs.h"
387c478bd9Sstevel@tonic-gate #include <errno.h>
397c478bd9Sstevel@tonic-gate #include "sym.h"
407c478bd9Sstevel@tonic-gate #include "hash.h"
417c478bd9Sstevel@tonic-gate #include <sys/types.h>
427c478bd9Sstevel@tonic-gate #include <sys/times.h>
437c478bd9Sstevel@tonic-gate
44965005c8Schin void
builtin(int type,int argc,unsigned char ** argv,struct trenod * t)45965005c8Schin builtin(int type, int argc, unsigned char **argv, struct trenod *t)
467c478bd9Sstevel@tonic-gate {
477c478bd9Sstevel@tonic-gate short index = initio(t->treio, (type != SYSEXEC));
487c478bd9Sstevel@tonic-gate unsigned char *a1 = argv[1];
497c478bd9Sstevel@tonic-gate
50*2a8bcb4eSToomas Soome switch (type)
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate case SYSSUSP:
547c478bd9Sstevel@tonic-gate syssusp(argc,argv);
557c478bd9Sstevel@tonic-gate break;
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate case SYSSTOP:
587c478bd9Sstevel@tonic-gate sysstop(argc,argv);
597c478bd9Sstevel@tonic-gate break;
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate case SYSKILL:
627c478bd9Sstevel@tonic-gate syskill(argc,argv);
637c478bd9Sstevel@tonic-gate break;
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate case SYSFGBG:
667c478bd9Sstevel@tonic-gate sysfgbg(argc,argv);
677c478bd9Sstevel@tonic-gate break;
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate case SYSJOBS:
707c478bd9Sstevel@tonic-gate sysjobs(argc,argv);
717c478bd9Sstevel@tonic-gate break;
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate case SYSDOT:
747c478bd9Sstevel@tonic-gate if (a1)
757c478bd9Sstevel@tonic-gate {
76965005c8Schin int f;
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate if ((f = pathopen(getpath(a1), a1)) < 0)
797c478bd9Sstevel@tonic-gate failed(a1, notfound);
807c478bd9Sstevel@tonic-gate else
817c478bd9Sstevel@tonic-gate execexp(0, f);
827c478bd9Sstevel@tonic-gate }
837c478bd9Sstevel@tonic-gate break;
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate case SYSTIMES:
867c478bd9Sstevel@tonic-gate {
877c478bd9Sstevel@tonic-gate struct tms tms;
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate times(&tms);
907c478bd9Sstevel@tonic-gate prt(tms.tms_cutime);
917c478bd9Sstevel@tonic-gate prc_buff(SPACE);
927c478bd9Sstevel@tonic-gate prt(tms.tms_cstime);
937c478bd9Sstevel@tonic-gate prc_buff(NL);
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate break;
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate case SYSEXIT:
987c478bd9Sstevel@tonic-gate if ( tried_to_exit++ || endjobs(JOB_STOPPED) ){
997c478bd9Sstevel@tonic-gate flags |= forcexit; /* force exit */
1007c478bd9Sstevel@tonic-gate exitsh(a1 ? stoi(a1) : retval);
1017c478bd9Sstevel@tonic-gate }
1027c478bd9Sstevel@tonic-gate break;
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate case SYSNULL:
1057c478bd9Sstevel@tonic-gate t->treio = 0;
1067c478bd9Sstevel@tonic-gate break;
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate case SYSCONT:
1097c478bd9Sstevel@tonic-gate if (loopcnt)
1107c478bd9Sstevel@tonic-gate {
1117c478bd9Sstevel@tonic-gate execbrk = breakcnt = 1;
1127c478bd9Sstevel@tonic-gate if (a1)
1137c478bd9Sstevel@tonic-gate breakcnt = stoi(a1);
1147c478bd9Sstevel@tonic-gate if (breakcnt > loopcnt)
1157c478bd9Sstevel@tonic-gate breakcnt = loopcnt;
1167c478bd9Sstevel@tonic-gate else
1177c478bd9Sstevel@tonic-gate breakcnt = -breakcnt;
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate break;
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate case SYSBREAK:
1227c478bd9Sstevel@tonic-gate if (loopcnt)
1237c478bd9Sstevel@tonic-gate {
1247c478bd9Sstevel@tonic-gate execbrk = breakcnt = 1;
1257c478bd9Sstevel@tonic-gate if (a1)
1267c478bd9Sstevel@tonic-gate breakcnt = stoi(a1);
1277c478bd9Sstevel@tonic-gate if (breakcnt > loopcnt)
1287c478bd9Sstevel@tonic-gate breakcnt = loopcnt;
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate break;
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate case SYSTRAP:
1337c478bd9Sstevel@tonic-gate systrap(argc,argv);
1347c478bd9Sstevel@tonic-gate break;
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate case SYSEXEC:
1377c478bd9Sstevel@tonic-gate argv++;
1387c478bd9Sstevel@tonic-gate ioset = 0;
1397c478bd9Sstevel@tonic-gate if (a1 == 0) {
1407c478bd9Sstevel@tonic-gate setmode(0);
1417c478bd9Sstevel@tonic-gate break;
1427c478bd9Sstevel@tonic-gate }
1437c478bd9Sstevel@tonic-gate /* FALLTHROUGH */
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate #ifdef RES /* Research includes login as part of the shell */
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate case SYSLOGIN:
1487c478bd9Sstevel@tonic-gate if (!endjobs(JOB_STOPPED|JOB_RUNNING))
1497c478bd9Sstevel@tonic-gate break;
1507c478bd9Sstevel@tonic-gate oldsigs();
1517c478bd9Sstevel@tonic-gate execa(argv, -1);
1527c478bd9Sstevel@tonic-gate done(0);
1537c478bd9Sstevel@tonic-gate #else
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate case SYSNEWGRP:
1567c478bd9Sstevel@tonic-gate if (flags & rshflg)
1577c478bd9Sstevel@tonic-gate failed(argv[0], restricted);
1587c478bd9Sstevel@tonic-gate else if (!endjobs(JOB_STOPPED|JOB_RUNNING))
1597c478bd9Sstevel@tonic-gate break;
1607c478bd9Sstevel@tonic-gate else
1617c478bd9Sstevel@tonic-gate {
1627c478bd9Sstevel@tonic-gate flags |= forcexit; /* bad exec will terminate shell */
1637c478bd9Sstevel@tonic-gate oldsigs();
1647c478bd9Sstevel@tonic-gate rmtemp(0);
1657c478bd9Sstevel@tonic-gate rmfunctmp();
1667c478bd9Sstevel@tonic-gate #ifdef ACCT
1677c478bd9Sstevel@tonic-gate doacct();
1687c478bd9Sstevel@tonic-gate #endif
1697c478bd9Sstevel@tonic-gate execa(argv, -1);
1707c478bd9Sstevel@tonic-gate done(0);
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate #endif
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate case SYSCD:
1767c478bd9Sstevel@tonic-gate if (flags & rshflg)
1777c478bd9Sstevel@tonic-gate failed(argv[0], restricted);
1787c478bd9Sstevel@tonic-gate else if ((a1 && *a1) || (a1 == 0 && (a1 = homenod.namval)))
1797c478bd9Sstevel@tonic-gate {
1807c478bd9Sstevel@tonic-gate unsigned char *cdpath;
1817c478bd9Sstevel@tonic-gate unsigned char *dir;
1827c478bd9Sstevel@tonic-gate int f;
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate if ((cdpath = cdpnod.namval) == 0 ||
1857c478bd9Sstevel@tonic-gate *a1 == '/' ||
1867c478bd9Sstevel@tonic-gate cf(a1, ".") == 0 ||
1877c478bd9Sstevel@tonic-gate cf(a1, "..") == 0 ||
1887c478bd9Sstevel@tonic-gate (*a1 == '.' && (*(a1+1) == '/' || *(a1+1) == '.' && *(a1+2) == '/')))
1897c478bd9Sstevel@tonic-gate cdpath = (unsigned char *)nullstr;
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate do
1927c478bd9Sstevel@tonic-gate {
1937c478bd9Sstevel@tonic-gate dir = cdpath;
1947c478bd9Sstevel@tonic-gate cdpath = catpath(cdpath,a1);
1957c478bd9Sstevel@tonic-gate }
1967c478bd9Sstevel@tonic-gate while ((f = (chdir((const char *) curstak()) < 0)) &&
1977c478bd9Sstevel@tonic-gate cdpath);
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate if (f) {
2007c478bd9Sstevel@tonic-gate switch(errno) {
2017c478bd9Sstevel@tonic-gate case EMULTIHOP:
2027c478bd9Sstevel@tonic-gate failed(a1, emultihop);
2037c478bd9Sstevel@tonic-gate break;
2047c478bd9Sstevel@tonic-gate case ENOTDIR:
2057c478bd9Sstevel@tonic-gate failed(a1, enotdir);
2067c478bd9Sstevel@tonic-gate break;
2077c478bd9Sstevel@tonic-gate case ENOENT:
2087c478bd9Sstevel@tonic-gate failed(a1, enoent);
2097c478bd9Sstevel@tonic-gate break;
2107c478bd9Sstevel@tonic-gate case EACCES:
2117c478bd9Sstevel@tonic-gate failed(a1, eacces);
2127c478bd9Sstevel@tonic-gate break;
2137c478bd9Sstevel@tonic-gate case ENOLINK:
2147c478bd9Sstevel@tonic-gate failed(a1, enolink);
2157c478bd9Sstevel@tonic-gate break;
216*2a8bcb4eSToomas Soome default:
2177c478bd9Sstevel@tonic-gate failed(a1, baddir);
2187c478bd9Sstevel@tonic-gate break;
2197c478bd9Sstevel@tonic-gate }
2207c478bd9Sstevel@tonic-gate }
221*2a8bcb4eSToomas Soome else
2227c478bd9Sstevel@tonic-gate {
2237c478bd9Sstevel@tonic-gate cwd(curstak());
2247c478bd9Sstevel@tonic-gate if (cf(nullstr, dir) &&
2257c478bd9Sstevel@tonic-gate *dir != ':' &&
2267c478bd9Sstevel@tonic-gate any('/', curstak()) &&
2277c478bd9Sstevel@tonic-gate flags & prompt)
2287c478bd9Sstevel@tonic-gate {
2297c478bd9Sstevel@tonic-gate prs_buff(cwdget());
2307c478bd9Sstevel@tonic-gate prc_buff(NL);
2317c478bd9Sstevel@tonic-gate }
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate zapcd();
2347c478bd9Sstevel@tonic-gate }
235*2a8bcb4eSToomas Soome else
2367c478bd9Sstevel@tonic-gate {
2377c478bd9Sstevel@tonic-gate if (a1)
2387c478bd9Sstevel@tonic-gate error(nulldir);
2397c478bd9Sstevel@tonic-gate else
2407c478bd9Sstevel@tonic-gate error(nohome);
2417c478bd9Sstevel@tonic-gate }
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate break;
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate case SYSSHFT:
2467c478bd9Sstevel@tonic-gate {
2477c478bd9Sstevel@tonic-gate int places;
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate places = a1 ? stoi(a1) : 1;
2507c478bd9Sstevel@tonic-gate
2517c478bd9Sstevel@tonic-gate if ((dolc -= places) < 0)
2527c478bd9Sstevel@tonic-gate {
2537c478bd9Sstevel@tonic-gate dolc = 0;
2547c478bd9Sstevel@tonic-gate error(badshift);
2557c478bd9Sstevel@tonic-gate }
2567c478bd9Sstevel@tonic-gate else
2577c478bd9Sstevel@tonic-gate dolv += places;
258*2a8bcb4eSToomas Soome }
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate break;
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate case SYSWAIT:
2637c478bd9Sstevel@tonic-gate syswait(argc,argv);
2647c478bd9Sstevel@tonic-gate break;
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate case SYSREAD:
2677c478bd9Sstevel@tonic-gate if(argc < 2)
2687c478bd9Sstevel@tonic-gate failed(argv[0],mssgargn);
2697c478bd9Sstevel@tonic-gate rwait = 1;
2707c478bd9Sstevel@tonic-gate exitval = readvar(&argv[1]);
2717c478bd9Sstevel@tonic-gate rwait = 0;
2727c478bd9Sstevel@tonic-gate break;
2737c478bd9Sstevel@tonic-gate
2747c478bd9Sstevel@tonic-gate case SYSSET:
2757c478bd9Sstevel@tonic-gate if (a1)
2767c478bd9Sstevel@tonic-gate {
2777c478bd9Sstevel@tonic-gate int cnt;
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate cnt = options(argc, argv);
2807c478bd9Sstevel@tonic-gate if (cnt > 1)
2817c478bd9Sstevel@tonic-gate setargs(argv + argc - cnt);
2827c478bd9Sstevel@tonic-gate }
2837c478bd9Sstevel@tonic-gate else if (comptr(t)->comset == 0)
2847c478bd9Sstevel@tonic-gate {
2857c478bd9Sstevel@tonic-gate /*
2867c478bd9Sstevel@tonic-gate * scan name chain and print
2877c478bd9Sstevel@tonic-gate */
2887c478bd9Sstevel@tonic-gate namscan(printnam);
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate break;
2917c478bd9Sstevel@tonic-gate
2927c478bd9Sstevel@tonic-gate case SYSRDONLY:
2937c478bd9Sstevel@tonic-gate exitval = 0;
2947c478bd9Sstevel@tonic-gate if (a1)
2957c478bd9Sstevel@tonic-gate {
2967c478bd9Sstevel@tonic-gate while (*++argv)
2977c478bd9Sstevel@tonic-gate attrib(lookup(*argv), N_RDONLY);
2987c478bd9Sstevel@tonic-gate }
2997c478bd9Sstevel@tonic-gate else
3007c478bd9Sstevel@tonic-gate namscan(printro);
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gate break;
3037c478bd9Sstevel@tonic-gate
3047c478bd9Sstevel@tonic-gate case SYSXPORT:
3057c478bd9Sstevel@tonic-gate {
3067c478bd9Sstevel@tonic-gate struct namnod *n;
3077c478bd9Sstevel@tonic-gate
3087c478bd9Sstevel@tonic-gate exitval = 0;
3097c478bd9Sstevel@tonic-gate if (a1)
3107c478bd9Sstevel@tonic-gate {
3117c478bd9Sstevel@tonic-gate while (*++argv)
3127c478bd9Sstevel@tonic-gate {
3137c478bd9Sstevel@tonic-gate n = lookup(*argv);
3147c478bd9Sstevel@tonic-gate if (n->namflg & N_FUNCTN)
3157c478bd9Sstevel@tonic-gate error(badexport);
3167c478bd9Sstevel@tonic-gate else
3177c478bd9Sstevel@tonic-gate attrib(n, N_EXPORT);
3187c478bd9Sstevel@tonic-gate }
3197c478bd9Sstevel@tonic-gate }
3207c478bd9Sstevel@tonic-gate else
3217c478bd9Sstevel@tonic-gate namscan(printexp);
3227c478bd9Sstevel@tonic-gate }
3237c478bd9Sstevel@tonic-gate break;
3247c478bd9Sstevel@tonic-gate
3257c478bd9Sstevel@tonic-gate case SYSEVAL:
3267c478bd9Sstevel@tonic-gate if (a1)
3277c478bd9Sstevel@tonic-gate execexp(a1, &argv[2]);
3287c478bd9Sstevel@tonic-gate break;
3297c478bd9Sstevel@tonic-gate
330*2a8bcb4eSToomas Soome #ifndef RES
3317c478bd9Sstevel@tonic-gate case SYSULIMIT:
3327c478bd9Sstevel@tonic-gate sysulimit(argc, argv);
3337c478bd9Sstevel@tonic-gate break;
334*2a8bcb4eSToomas Soome
3357c478bd9Sstevel@tonic-gate case SYSUMASK:
3367c478bd9Sstevel@tonic-gate if (a1)
337*2a8bcb4eSToomas Soome {
3387c478bd9Sstevel@tonic-gate int c;
3397c478bd9Sstevel@tonic-gate mode_t i;
3407c478bd9Sstevel@tonic-gate
3417c478bd9Sstevel@tonic-gate i = 0;
3427c478bd9Sstevel@tonic-gate while ((c = *a1++) >= '0' && c <= '7')
3437c478bd9Sstevel@tonic-gate i = (i << 3) + c - '0';
3447c478bd9Sstevel@tonic-gate umask(i);
3457c478bd9Sstevel@tonic-gate }
3467c478bd9Sstevel@tonic-gate else
3477c478bd9Sstevel@tonic-gate {
3487c478bd9Sstevel@tonic-gate mode_t i;
3497c478bd9Sstevel@tonic-gate int j;
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gate umask(i = umask(0));
3527c478bd9Sstevel@tonic-gate prc_buff('0');
3537c478bd9Sstevel@tonic-gate for (j = 6; j >= 0; j -= 3)
3547c478bd9Sstevel@tonic-gate prc_buff(((i >> j) & 07) +'0');
3557c478bd9Sstevel@tonic-gate prc_buff(NL);
3567c478bd9Sstevel@tonic-gate }
3577c478bd9Sstevel@tonic-gate break;
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate #endif
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate case SYSTST:
3627c478bd9Sstevel@tonic-gate exitval = test(argc, argv);
3637c478bd9Sstevel@tonic-gate break;
3647c478bd9Sstevel@tonic-gate
3657c478bd9Sstevel@tonic-gate case SYSECHO:
3667c478bd9Sstevel@tonic-gate exitval = echo(argc, argv);
3677c478bd9Sstevel@tonic-gate break;
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate case SYSHASH:
3707c478bd9Sstevel@tonic-gate exitval = 0;
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate if (a1)
3737c478bd9Sstevel@tonic-gate {
3747c478bd9Sstevel@tonic-gate if (a1[0] == '-')
3757c478bd9Sstevel@tonic-gate {
3767c478bd9Sstevel@tonic-gate if (a1[1] == 'r')
3777c478bd9Sstevel@tonic-gate zaphash();
3787c478bd9Sstevel@tonic-gate else
3797c478bd9Sstevel@tonic-gate error(badopt);
3807c478bd9Sstevel@tonic-gate }
3817c478bd9Sstevel@tonic-gate else
3827c478bd9Sstevel@tonic-gate {
3837c478bd9Sstevel@tonic-gate while (*++argv)
3847c478bd9Sstevel@tonic-gate {
3857c478bd9Sstevel@tonic-gate if (hashtype(hash_cmd(*argv)) == NOTFOUND)
3867c478bd9Sstevel@tonic-gate failed(*argv, notfound);
3877c478bd9Sstevel@tonic-gate }
3887c478bd9Sstevel@tonic-gate }
3897c478bd9Sstevel@tonic-gate }
3907c478bd9Sstevel@tonic-gate else
3917c478bd9Sstevel@tonic-gate hashpr();
3927c478bd9Sstevel@tonic-gate
3937c478bd9Sstevel@tonic-gate break;
3947c478bd9Sstevel@tonic-gate
3957c478bd9Sstevel@tonic-gate case SYSPWD:
3967c478bd9Sstevel@tonic-gate {
3977c478bd9Sstevel@tonic-gate exitval = 0;
3987c478bd9Sstevel@tonic-gate cwdprint();
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate break;
4017c478bd9Sstevel@tonic-gate
4027c478bd9Sstevel@tonic-gate case SYSRETURN:
4037c478bd9Sstevel@tonic-gate if (funcnt == 0)
4047c478bd9Sstevel@tonic-gate error(badreturn);
4057c478bd9Sstevel@tonic-gate
4067c478bd9Sstevel@tonic-gate execbrk = 1;
4077c478bd9Sstevel@tonic-gate exitval = (a1 ? stoi(a1) : retval);
4087c478bd9Sstevel@tonic-gate break;
409*2a8bcb4eSToomas Soome
4107c478bd9Sstevel@tonic-gate case SYSTYPE:
4117c478bd9Sstevel@tonic-gate exitval = 0;
4127c478bd9Sstevel@tonic-gate if (a1)
4137c478bd9Sstevel@tonic-gate {
4147c478bd9Sstevel@tonic-gate /* return success only if all names are found */
4157c478bd9Sstevel@tonic-gate while (*++argv)
4167c478bd9Sstevel@tonic-gate exitval |= what_is_path(*argv);
4177c478bd9Sstevel@tonic-gate }
4187c478bd9Sstevel@tonic-gate break;
4197c478bd9Sstevel@tonic-gate
4207c478bd9Sstevel@tonic-gate case SYSUNS:
4217c478bd9Sstevel@tonic-gate exitval = 0;
4227c478bd9Sstevel@tonic-gate if (a1)
4237c478bd9Sstevel@tonic-gate {
4247c478bd9Sstevel@tonic-gate while (*++argv)
4257c478bd9Sstevel@tonic-gate unset_name(*argv);
4267c478bd9Sstevel@tonic-gate }
4277c478bd9Sstevel@tonic-gate break;
4287c478bd9Sstevel@tonic-gate
4297c478bd9Sstevel@tonic-gate case SYSGETOPT: {
4307c478bd9Sstevel@tonic-gate int getoptval;
4317c478bd9Sstevel@tonic-gate struct namnod *n;
4327c478bd9Sstevel@tonic-gate extern unsigned char numbuf[];
4337c478bd9Sstevel@tonic-gate unsigned char *varnam = argv[2];
4347c478bd9Sstevel@tonic-gate unsigned char c[2];
4357c478bd9Sstevel@tonic-gate if(argc < 3) {
4367c478bd9Sstevel@tonic-gate failure(argv[0],mssgargn);
4377c478bd9Sstevel@tonic-gate break;
4387c478bd9Sstevel@tonic-gate }
4397c478bd9Sstevel@tonic-gate exitval = 0;
4407c478bd9Sstevel@tonic-gate n = lookup("OPTIND");
4417c478bd9Sstevel@tonic-gate optind = stoi(n->namval);
4427c478bd9Sstevel@tonic-gate if(argc > 3) {
4437c478bd9Sstevel@tonic-gate argv[2] = dolv[0];
4447c478bd9Sstevel@tonic-gate getoptval = getopt(argc-2, (char **)&argv[2], (char *)argv[1]);
4457c478bd9Sstevel@tonic-gate }
4467c478bd9Sstevel@tonic-gate else
4477c478bd9Sstevel@tonic-gate getoptval = getopt(dolc+1, (char **)dolv, (char *)argv[1]);
4487c478bd9Sstevel@tonic-gate if(getoptval == -1) {
4497c478bd9Sstevel@tonic-gate itos(optind);
4507c478bd9Sstevel@tonic-gate assign(n, numbuf);
4517c478bd9Sstevel@tonic-gate n = lookup(varnam);
452965005c8Schin assign(n, (unsigned char *)nullstr);
4537c478bd9Sstevel@tonic-gate exitval = 1;
4547c478bd9Sstevel@tonic-gate break;
4557c478bd9Sstevel@tonic-gate }
4567c478bd9Sstevel@tonic-gate argv[2] = varnam;
4577c478bd9Sstevel@tonic-gate itos(optind);
4587c478bd9Sstevel@tonic-gate assign(n, numbuf);
4597c478bd9Sstevel@tonic-gate c[0] = getoptval;
4607c478bd9Sstevel@tonic-gate c[1] = 0;
4617c478bd9Sstevel@tonic-gate n = lookup(varnam);
4627c478bd9Sstevel@tonic-gate assign(n, c);
4637c478bd9Sstevel@tonic-gate n = lookup("OPTARG");
464965005c8Schin assign(n, (unsigned char *)optarg);
4657c478bd9Sstevel@tonic-gate }
4667c478bd9Sstevel@tonic-gate break;
4677c478bd9Sstevel@tonic-gate
4687c478bd9Sstevel@tonic-gate default:
46939e7390aSna prs_buff(_gettext("unknown builtin\n"));
4707c478bd9Sstevel@tonic-gate }
4717c478bd9Sstevel@tonic-gate
4727c478bd9Sstevel@tonic-gate
4737c478bd9Sstevel@tonic-gate flushb();
4747c478bd9Sstevel@tonic-gate restore(index);
4757c478bd9Sstevel@tonic-gate chktrap();
4767c478bd9Sstevel@tonic-gate }
477