4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
42 #include <sys/types.h>
43 #include <sys/times.h>
46 builtin(int type
, int argc
, unsigned char **argv
, struct trenod
*t
)
48 short index
= initio(t
->treio
, (type
!= SYSEXEC
));
49 unsigned char *a1
= argv
[1];
79 if ((f
= pathopen(getpath(a1
), a1
)) < 0)
99 if ( tried_to_exit
++ || endjobs(JOB_STOPPED
) ){
100 flags
|= forcexit
; /* force exit */
101 exitsh(a1
? stoi(a1
) : retval
);
112 execbrk
= breakcnt
= 1;
115 if (breakcnt
> loopcnt
)
118 breakcnt
= -breakcnt
;
125 execbrk
= breakcnt
= 1;
128 if (breakcnt
> loopcnt
)
146 #ifdef RES /* Research includes login as part of the shell */
149 if (!endjobs(JOB_STOPPED
|JOB_RUNNING
))
158 failed(argv
[0], restricted
);
159 else if (!endjobs(JOB_STOPPED
|JOB_RUNNING
))
163 flags
|= forcexit
; /* bad exec will terminate shell */
178 failed(argv
[0], restricted
);
179 else if ((a1
&& *a1
) || (a1
== 0 && (a1
= homenod
.namval
)))
181 unsigned char *cdpath
;
185 if ((cdpath
= cdpnod
.namval
) == 0 ||
189 (*a1
== '.' && (*(a1
+1) == '/' || *(a1
+1) == '.' && *(a1
+2) == '/')))
190 cdpath
= (unsigned char *)nullstr
;
195 cdpath
= catpath(cdpath
,a1
);
197 while ((f
= (chdir((const char *) curstak()) < 0)) &&
203 failed(a1
, emultihop
);
225 if (cf(nullstr
, dir
) &&
227 any('/', curstak()) &&
250 places
= a1
? stoi(a1
) : 1;
252 if ((dolc
-= places
) < 0)
269 failed(argv
[0],mssgargn
);
271 exitval
= readvar(&argv
[1]);
280 cnt
= options(argc
, argv
);
282 setargs(argv
+ argc
- cnt
);
284 else if (comptr(t
)->comset
== 0)
287 * scan name chain and print
298 attrib(lookup(*argv
), N_RDONLY
);
315 if (n
->namflg
& N_FUNCTN
)
328 execexp(a1
, &argv
[2]);
333 sysulimit(argc
, argv
);
343 while ((c
= *a1
++) >= '0' && c
<= '7')
344 i
= (i
<< 3) + c
- '0';
354 for (j
= 6; j
>= 0; j
-= 3)
355 prc_buff(((i
>> j
) & 07) +'0');
363 exitval
= test(argc
, argv
);
367 exitval
= echo(argc
, argv
);
386 if (hashtype(hash_cmd(*argv
)) == NOTFOUND
)
387 failed(*argv
, notfound
);
408 exitval
= (a1
? stoi(a1
) : retval
);
415 /* return success only if all names are found */
417 exitval
|= what_is_path(*argv
);
433 extern unsigned char numbuf
[];
434 unsigned char *varnam
= argv
[2];
437 failure(argv
[0],mssgargn
);
441 n
= lookup("OPTIND");
442 optind
= stoi(n
->namval
);
445 getoptval
= getopt(argc
-2, (char **)&argv
[2], (char *)argv
[1]);
448 getoptval
= getopt(dolc
+1, (char **)dolv
, (char *)argv
[1]);
449 if(getoptval
== -1) {
453 assign(n
, (unsigned char *)nullstr
);
464 n
= lookup("OPTARG");
465 assign(n
, (unsigned char *)optarg
);
470 prs_buff(_gettext("unknown builtin\n"));