xref: /onnv-gate/usr/src/cmd/sgs/mcs/common/message.c (revision 1618:8c9a4f31d225)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*1618Srie  * Common Development and Distribution License (the "License").
6*1618Srie  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
220Sstevel@tonic-gate  *	Copyright(c) 1988 AT&T
230Sstevel@tonic-gate  *	  All Rights Reserved
240Sstevel@tonic-gate  *
25*1618Srie  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
26*1618Srie  * Use is subject to license terms.
270Sstevel@tonic-gate  */
280Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
290Sstevel@tonic-gate #include "mcs.h"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate static const char *msg[] = {
320Sstevel@tonic-gate /* MALLOC_ERROR */
330Sstevel@tonic-gate "%s: malloc memory allocation failure.\n",
340Sstevel@tonic-gate /* USAGE_ERROR */
350Sstevel@tonic-gate "%s: multiple -n only allowed for -d option.\n",
360Sstevel@tonic-gate /* ELFVER_ERROR */
370Sstevel@tonic-gate "%s: elf_version() failed - libelf.a out of date.\n",
380Sstevel@tonic-gate /* OPEN_ERROR */
390Sstevel@tonic-gate "%s: %s: cannot open file.\n",
400Sstevel@tonic-gate /* LIBELF_ERROR */
410Sstevel@tonic-gate "%s: libelf error.\n",
420Sstevel@tonic-gate /* OPEN_TEMP_ERROR */
430Sstevel@tonic-gate "%s: %s: cannot open temporary file\n",
440Sstevel@tonic-gate /* WRITE_ERROR */
450Sstevel@tonic-gate "%s: %s: write system failure: %s: file not manipulated.\n",
460Sstevel@tonic-gate /* GETARHDR_ERROR */
470Sstevel@tonic-gate "%s: %s: malformed archive at %ld\n",
480Sstevel@tonic-gate /* FILE_TYPE_ERROR */
490Sstevel@tonic-gate "%s: %s: invalid file type\n",
500Sstevel@tonic-gate /* NOT_MANIPULATED_ERROR */
510Sstevel@tonic-gate "%s: %s: file not manipulated\n",
520Sstevel@tonic-gate /* WRN_MANIPULATED_ERROR */
530Sstevel@tonic-gate "%s: WARNING: %s: Cannot manipulate file.\n",
540Sstevel@tonic-gate /* NO_SECT_TABLE_ERROR */
550Sstevel@tonic-gate "%s: %s: no section header table.\n",
560Sstevel@tonic-gate /* READ_ERROR */
570Sstevel@tonic-gate "%s: %s: trouble reading file\n",
580Sstevel@tonic-gate /* READ_MANI_ERROR */
590Sstevel@tonic-gate "%s: %s: read system failure: %s: file not manipulated.\n",
600Sstevel@tonic-gate /* WRITE_MANI_ERROR */
610Sstevel@tonic-gate "%s: %s: write system failure: %s: file not manipulated.\n",
620Sstevel@tonic-gate /* LSEEK_MANI_ERROR */
630Sstevel@tonic-gate "%s: %s: lseek system failure: %s: file not manipulated.\n",
640Sstevel@tonic-gate /* SYM_TAB_AR_ERROR */
650Sstevel@tonic-gate "%s: WARNING: %s: symbol table deleted from archive \n",
660Sstevel@tonic-gate /* EXEC_AR_ERROR */
670Sstevel@tonic-gate "execute  `ar -ts %s` to restore symbol table.\n",
680Sstevel@tonic-gate /* READ_SYS_ERROR */
690Sstevel@tonic-gate "%s: %s: read system failure\n",
700Sstevel@tonic-gate /* OPEN_WRITE_ERROR */
710Sstevel@tonic-gate "%s: %s: can't open file for writing\n",
720Sstevel@tonic-gate /* ACT_PRINT_ERROR */
730Sstevel@tonic-gate "%s: %s: Cannot print contents of a NOBITS section (%s)\n",
740Sstevel@tonic-gate /* ACT_DELETE1_ERROR */
750Sstevel@tonic-gate "%s: %s: Warning: Cannot delete section (%s)\n\t\tfrom a segment.\n",
760Sstevel@tonic-gate /* ACT_DELETE2_ERROR */
770Sstevel@tonic-gate "%s: %s: Warning: Cannot delete section (%s)\n"
780Sstevel@tonic-gate "\t\tbecause its relocation section (%s) is in a segment\n",
790Sstevel@tonic-gate /* ACT_APPEND1_ERROR */
800Sstevel@tonic-gate "%s: %s: Cannot append to a NOBITS section (%s)\n",
810Sstevel@tonic-gate /* ACT_APPEND2_ERROR */
820Sstevel@tonic-gate "%s: %s: Warning: Cannot append to section (%s)\n\t\tin a segment\n",
830Sstevel@tonic-gate /* ACT_COMPRESS1_ERROR */
840Sstevel@tonic-gate "%s: %s: Cannot compress a NOBITS section (%s)\n",
850Sstevel@tonic-gate /* ACT_COMPRESS2_ERROR */
860Sstevel@tonic-gate "%s: %s: Warning: Cannot compress a section (%s)\n\t\tin a segment\n",
870Sstevel@tonic-gate /* ACCESS_ERROR */
880Sstevel@tonic-gate "%s: %s: access error.\n",
890Sstevel@tonic-gate /* WRITE_MANI_ERROR2 */
900Sstevel@tonic-gate "%s: /ftruncate/lseek/write system failure: %s: file may be destroyed.\n"
910Sstevel@tonic-gate };
920Sstevel@tonic-gate 
930Sstevel@tonic-gate void
940Sstevel@tonic-gate error_message(int args, ...)
950Sstevel@tonic-gate {
960Sstevel@tonic-gate 	int mes = args;
970Sstevel@tonic-gate 	char *message = gettext((char *)msg[mes]);
980Sstevel@tonic-gate 	int flag;
990Sstevel@tonic-gate 	char *sys_mes;
1000Sstevel@tonic-gate 	va_list ap;
1010Sstevel@tonic-gate 	va_start(ap, args);
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	flag = va_arg(ap, int);
1040Sstevel@tonic-gate 	sys_mes = va_arg(ap, char *);
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 	switch (mes) {
1070Sstevel@tonic-gate 	case MALLOC_ERROR:
1080Sstevel@tonic-gate 	case USAGE_ERROR:
1090Sstevel@tonic-gate 	case ELFVER_ERROR:
1100Sstevel@tonic-gate 	case EXEC_AR_ERROR:
1110Sstevel@tonic-gate 	case LIBELF_ERROR:
112*1618Srie 		/* LINTED */
1130Sstevel@tonic-gate 		(void) fprintf(stderr, message, va_arg(ap, char *));
1140Sstevel@tonic-gate 		break;
1150Sstevel@tonic-gate 	case OPEN_ERROR:
1160Sstevel@tonic-gate 	case ACCESS_ERROR:
1170Sstevel@tonic-gate 	case OPEN_TEMP_ERROR:
1180Sstevel@tonic-gate 	case FILE_TYPE_ERROR:
1190Sstevel@tonic-gate 	case NOT_MANIPULATED_ERROR:
1200Sstevel@tonic-gate 	case WRN_MANIPULATED_ERROR:
1210Sstevel@tonic-gate 	case NO_SECT_TABLE_ERROR:
1220Sstevel@tonic-gate 	case READ_ERROR:
1230Sstevel@tonic-gate 	case SYM_TAB_AR_ERROR:
1240Sstevel@tonic-gate 	case READ_SYS_ERROR:
1250Sstevel@tonic-gate 	case OPEN_WRITE_ERROR:
1260Sstevel@tonic-gate 		/* LINTED */
1270Sstevel@tonic-gate 		(void) fprintf(stderr, message, va_arg(ap, char *),
1280Sstevel@tonic-gate 					va_arg(ap, char *));
1290Sstevel@tonic-gate 		break;
1300Sstevel@tonic-gate 	case WRITE_ERROR:
1310Sstevel@tonic-gate 	case READ_MANI_ERROR:
1320Sstevel@tonic-gate 	case WRITE_MANI_ERROR:
1330Sstevel@tonic-gate 	case LSEEK_MANI_ERROR:
1340Sstevel@tonic-gate 	case ACT_PRINT_ERROR:
1350Sstevel@tonic-gate 	case ACT_DELETE1_ERROR:
1360Sstevel@tonic-gate 	case ACT_APPEND1_ERROR:
1370Sstevel@tonic-gate 	case ACT_APPEND2_ERROR:
1380Sstevel@tonic-gate 	case ACT_COMPRESS1_ERROR:
1390Sstevel@tonic-gate 	case ACT_COMPRESS2_ERROR: {
140*1618Srie 		char *a = va_arg(ap, char *);
141*1618Srie 		char *b = va_arg(ap, char *);
142*1618Srie 		char *c = va_arg(ap, char *);
143*1618Srie 		/* LINTED */
1440Sstevel@tonic-gate 		(void) fprintf(stderr, message, a, b, c);
1450Sstevel@tonic-gate 		break;
1460Sstevel@tonic-gate 	}
1470Sstevel@tonic-gate 	case ACT_DELETE2_ERROR: {
148*1618Srie 		char *a = va_arg(ap, char *);
149*1618Srie 		char *b = va_arg(ap, char *);
150*1618Srie 		char *c = va_arg(ap, char *);
151*1618Srie 		char *d = va_arg(ap, char *);
152*1618Srie 		/* LINTED */
1530Sstevel@tonic-gate 		(void) fprintf(stderr, message, a, b, c, d);
1540Sstevel@tonic-gate 		break;
1550Sstevel@tonic-gate 	}
1560Sstevel@tonic-gate 	case GETARHDR_ERROR: {
157*1618Srie 		char *a = va_arg(ap, char *);
158*1618Srie 		char *b = va_arg(ap, char *);
1590Sstevel@tonic-gate 		long c = va_arg(ap, long);
160*1618Srie 		/* LINTED */
1610Sstevel@tonic-gate 		(void) fprintf(stderr, message, a, b, c);
1620Sstevel@tonic-gate 		break;
1630Sstevel@tonic-gate 	}
1640Sstevel@tonic-gate 	default:
1650Sstevel@tonic-gate 		(void) fprintf(stderr, "internal error: error_message(%d)\n",
1660Sstevel@tonic-gate 			mes);
1670Sstevel@tonic-gate 		exit(100);
1680Sstevel@tonic-gate 	}
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate 	if (flag != PLAIN_ERROR)
1710Sstevel@tonic-gate 		(void) fprintf(stderr, "\t%s\n", sys_mes);
1720Sstevel@tonic-gate 	va_end(ap);
1730Sstevel@tonic-gate }
174