xref: /onnv-gate/usr/src/cmd/sgs/mcs/common/message.c (revision 8223:628841638a21)
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
51618Srie  * Common Development and Distribution License (the "License").
61618Srie  * 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*8223SAli.Bahrami@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
261618Srie  * Use is subject to license terms.
270Sstevel@tonic-gate  */
280Sstevel@tonic-gate #include "mcs.h"
290Sstevel@tonic-gate 
300Sstevel@tonic-gate static const char *msg[] = {
310Sstevel@tonic-gate /* MALLOC_ERROR */
320Sstevel@tonic-gate "%s: malloc memory allocation failure.\n",
330Sstevel@tonic-gate /* USAGE_ERROR */
340Sstevel@tonic-gate "%s: multiple -n only allowed for -d option.\n",
350Sstevel@tonic-gate /* ELFVER_ERROR */
360Sstevel@tonic-gate "%s: elf_version() failed - libelf.a out of date.\n",
370Sstevel@tonic-gate /* OPEN_ERROR */
380Sstevel@tonic-gate "%s: %s: cannot open file.\n",
390Sstevel@tonic-gate /* LIBELF_ERROR */
400Sstevel@tonic-gate "%s: libelf error.\n",
410Sstevel@tonic-gate /* OPEN_TEMP_ERROR */
420Sstevel@tonic-gate "%s: %s: cannot open temporary file\n",
430Sstevel@tonic-gate /* WRITE_ERROR */
440Sstevel@tonic-gate "%s: %s: write system failure: %s: file not manipulated.\n",
450Sstevel@tonic-gate /* GETARHDR_ERROR */
460Sstevel@tonic-gate "%s: %s: malformed archive at %ld\n",
470Sstevel@tonic-gate /* FILE_TYPE_ERROR */
480Sstevel@tonic-gate "%s: %s: invalid file type\n",
490Sstevel@tonic-gate /* NOT_MANIPULATED_ERROR */
500Sstevel@tonic-gate "%s: %s: file not manipulated\n",
510Sstevel@tonic-gate /* WRN_MANIPULATED_ERROR */
520Sstevel@tonic-gate "%s: WARNING: %s: Cannot manipulate file.\n",
530Sstevel@tonic-gate /* NO_SECT_TABLE_ERROR */
540Sstevel@tonic-gate "%s: %s: no section header table.\n",
550Sstevel@tonic-gate /* READ_ERROR */
560Sstevel@tonic-gate "%s: %s: trouble reading file\n",
570Sstevel@tonic-gate /* READ_MANI_ERROR */
580Sstevel@tonic-gate "%s: %s: read system failure: %s: file not manipulated.\n",
590Sstevel@tonic-gate /* WRITE_MANI_ERROR */
600Sstevel@tonic-gate "%s: %s: write system failure: %s: file not manipulated.\n",
610Sstevel@tonic-gate /* LSEEK_MANI_ERROR */
620Sstevel@tonic-gate "%s: %s: lseek system failure: %s: file not manipulated.\n",
630Sstevel@tonic-gate /* SYM_TAB_AR_ERROR */
640Sstevel@tonic-gate "%s: WARNING: %s: symbol table deleted from archive \n",
650Sstevel@tonic-gate /* EXEC_AR_ERROR */
660Sstevel@tonic-gate "execute  `ar -ts %s` to restore symbol table.\n",
670Sstevel@tonic-gate /* READ_SYS_ERROR */
680Sstevel@tonic-gate "%s: %s: read system failure\n",
690Sstevel@tonic-gate /* OPEN_WRITE_ERROR */
700Sstevel@tonic-gate "%s: %s: can't open file for writing\n",
710Sstevel@tonic-gate /* ACT_PRINT_ERROR */
720Sstevel@tonic-gate "%s: %s: Cannot print contents of a NOBITS section (%s)\n",
730Sstevel@tonic-gate /* ACT_DELETE1_ERROR */
740Sstevel@tonic-gate "%s: %s: Warning: Cannot delete section (%s)\n\t\tfrom a segment.\n",
750Sstevel@tonic-gate /* ACT_DELETE2_ERROR */
760Sstevel@tonic-gate "%s: %s: Warning: Cannot delete section (%s)\n"
770Sstevel@tonic-gate "\t\tbecause its relocation section (%s) is in a segment\n",
780Sstevel@tonic-gate /* ACT_APPEND1_ERROR */
790Sstevel@tonic-gate "%s: %s: Cannot append to a NOBITS section (%s)\n",
800Sstevel@tonic-gate /* ACT_APPEND2_ERROR */
810Sstevel@tonic-gate "%s: %s: Warning: Cannot append to section (%s)\n\t\tin a segment\n",
820Sstevel@tonic-gate /* ACT_COMPRESS1_ERROR */
830Sstevel@tonic-gate "%s: %s: Cannot compress a NOBITS section (%s)\n",
840Sstevel@tonic-gate /* ACT_COMPRESS2_ERROR */
850Sstevel@tonic-gate "%s: %s: Warning: Cannot compress a section (%s)\n\t\tin a segment\n",
860Sstevel@tonic-gate /* ACCESS_ERROR */
870Sstevel@tonic-gate "%s: %s: access error.\n",
880Sstevel@tonic-gate /* WRITE_MANI_ERROR2 */
890Sstevel@tonic-gate "%s: /ftruncate/lseek/write system failure: %s: file may be destroyed.\n"
900Sstevel@tonic-gate };
910Sstevel@tonic-gate 
920Sstevel@tonic-gate void
error_message(int args,...)930Sstevel@tonic-gate error_message(int args, ...)
940Sstevel@tonic-gate {
950Sstevel@tonic-gate 	int mes = args;
960Sstevel@tonic-gate 	char *message = gettext((char *)msg[mes]);
970Sstevel@tonic-gate 	int flag;
980Sstevel@tonic-gate 	char *sys_mes;
990Sstevel@tonic-gate 	va_list ap;
1000Sstevel@tonic-gate 	va_start(ap, args);
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate 	flag = va_arg(ap, int);
1030Sstevel@tonic-gate 	sys_mes = va_arg(ap, char *);
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate 	switch (mes) {
1060Sstevel@tonic-gate 	case MALLOC_ERROR:
1070Sstevel@tonic-gate 	case USAGE_ERROR:
1080Sstevel@tonic-gate 	case ELFVER_ERROR:
1090Sstevel@tonic-gate 	case EXEC_AR_ERROR:
1100Sstevel@tonic-gate 	case LIBELF_ERROR:
1111618Srie 		/* LINTED */
1120Sstevel@tonic-gate 		(void) fprintf(stderr, message, va_arg(ap, char *));
1130Sstevel@tonic-gate 		break;
1140Sstevel@tonic-gate 	case OPEN_ERROR:
1150Sstevel@tonic-gate 	case ACCESS_ERROR:
1160Sstevel@tonic-gate 	case OPEN_TEMP_ERROR:
1170Sstevel@tonic-gate 	case FILE_TYPE_ERROR:
1180Sstevel@tonic-gate 	case NOT_MANIPULATED_ERROR:
1190Sstevel@tonic-gate 	case WRN_MANIPULATED_ERROR:
1200Sstevel@tonic-gate 	case NO_SECT_TABLE_ERROR:
1210Sstevel@tonic-gate 	case READ_ERROR:
1220Sstevel@tonic-gate 	case SYM_TAB_AR_ERROR:
1230Sstevel@tonic-gate 	case READ_SYS_ERROR:
1240Sstevel@tonic-gate 	case OPEN_WRITE_ERROR:
1250Sstevel@tonic-gate 		/* LINTED */
1260Sstevel@tonic-gate 		(void) fprintf(stderr, message, va_arg(ap, char *),
127*8223SAli.Bahrami@Sun.COM 		    va_arg(ap, char *));
1280Sstevel@tonic-gate 		break;
1290Sstevel@tonic-gate 	case WRITE_ERROR:
1300Sstevel@tonic-gate 	case READ_MANI_ERROR:
1310Sstevel@tonic-gate 	case WRITE_MANI_ERROR:
1320Sstevel@tonic-gate 	case LSEEK_MANI_ERROR:
1330Sstevel@tonic-gate 	case ACT_PRINT_ERROR:
1340Sstevel@tonic-gate 	case ACT_DELETE1_ERROR:
1350Sstevel@tonic-gate 	case ACT_APPEND1_ERROR:
1360Sstevel@tonic-gate 	case ACT_APPEND2_ERROR:
1370Sstevel@tonic-gate 	case ACT_COMPRESS1_ERROR:
1380Sstevel@tonic-gate 	case ACT_COMPRESS2_ERROR: {
1391618Srie 		char *a = va_arg(ap, char *);
1401618Srie 		char *b = va_arg(ap, char *);
1411618Srie 		char *c = va_arg(ap, char *);
1421618Srie 		/* LINTED */
1430Sstevel@tonic-gate 		(void) fprintf(stderr, message, a, b, c);
1440Sstevel@tonic-gate 		break;
1450Sstevel@tonic-gate 	}
1460Sstevel@tonic-gate 	case ACT_DELETE2_ERROR: {
1471618Srie 		char *a = va_arg(ap, char *);
1481618Srie 		char *b = va_arg(ap, char *);
1491618Srie 		char *c = va_arg(ap, char *);
1501618Srie 		char *d = va_arg(ap, char *);
1511618Srie 		/* LINTED */
1520Sstevel@tonic-gate 		(void) fprintf(stderr, message, a, b, c, d);
1530Sstevel@tonic-gate 		break;
1540Sstevel@tonic-gate 	}
1550Sstevel@tonic-gate 	case GETARHDR_ERROR: {
1561618Srie 		char *a = va_arg(ap, char *);
1571618Srie 		char *b = va_arg(ap, char *);
1580Sstevel@tonic-gate 		long c = va_arg(ap, long);
1591618Srie 		/* LINTED */
1600Sstevel@tonic-gate 		(void) fprintf(stderr, message, a, b, c);
1610Sstevel@tonic-gate 		break;
1620Sstevel@tonic-gate 	}
1630Sstevel@tonic-gate 	default:
1640Sstevel@tonic-gate 		(void) fprintf(stderr, "internal error: error_message(%d)\n",
165*8223SAli.Bahrami@Sun.COM 		    mes);
166*8223SAli.Bahrami@Sun.COM 		mcs_exit(100);
1670Sstevel@tonic-gate 	}
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate 	if (flag != PLAIN_ERROR)
1700Sstevel@tonic-gate 		(void) fprintf(stderr, "\t%s\n", sys_mes);
1710Sstevel@tonic-gate 	va_end(ap);
1720Sstevel@tonic-gate }
173