xref: /illumos-gate/usr/src/cmd/isaexec/isaexec.c (revision e869dbacc8a10a28e55de8591266433275234c3c)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <errno.h>
30 #include <libintl.h>
31 #include <unistd.h>
32 #include <locale.h>
33 
34 /*ARGSUSED*/
35 int
36 main(int argc, char **argv, char **envp)
37 {
38 	const char *execname;
39 	const char *fname;
40 
41 #if !defined(TEXT_DOMAIN)		/* Should be defined by cc -D */
42 #define	TEXT_DOMAIN	"SYS_TEST"	/* Use this only if it wasn't */
43 #endif
44 	(void) setlocale(LC_ALL, "");
45 	(void) textdomain(TEXT_DOMAIN);
46 
47 	/*
48 	 * Get the exec name.
49 	 */
50 	if ((execname = getexecname()) == NULL) {
51 		(void) fprintf(stderr,
52 				gettext("%s: getexecname() failed\n"),
53 				argv[0]);
54 		return (1);
55 	}
56 
57 	/*
58 	 * Get the base name of the executable.
59 	 */
60 	fname = strrchr(execname, '/');
61 	fname = (fname != NULL) ? (fname+1) : execname;
62 
63 	if (isaexec(execname, argv, envp) == -1) {
64 		if (errno == ENOENT) {
65 			(void) fprintf(stderr,
66 					gettext("%s: cannot find/execute \"%s\""
67 						" in ISA subdirectories\n"),
68 					argv[0], fname);
69 			return (1);
70 		}
71 	}
72 
73 	(void) fprintf(stderr,
74 			gettext("%s: isaexec(\"%s\") failed\n"),
75 			argv[0], fname);
76 	return (1);
77 }
78