xref: /titanic_41/usr/src/cmd/sgs/mcs/common/message.c (revision d1477c77ba111543ba7e032687032e617c63fb08)
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
55aefb655Srie  * Common Development and Distribution License (the "License").
65aefb655Srie  * 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  *	Copyright(c) 1988 AT&T
237c478bd9Sstevel@tonic-gate  *	  All Rights Reserved
247c478bd9Sstevel@tonic-gate  *
25*d1477c77SAli Bahrami  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
265aefb655Srie  * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate #include "mcs.h"
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate static const char *msg[] = {
317c478bd9Sstevel@tonic-gate /* MALLOC_ERROR */
327c478bd9Sstevel@tonic-gate "%s: malloc memory allocation failure.\n",
337c478bd9Sstevel@tonic-gate /* USAGE_ERROR */
347c478bd9Sstevel@tonic-gate "%s: multiple -n only allowed for -d option.\n",
357c478bd9Sstevel@tonic-gate /* ELFVER_ERROR */
367c478bd9Sstevel@tonic-gate "%s: elf_version() failed - libelf.a out of date.\n",
377c478bd9Sstevel@tonic-gate /* OPEN_ERROR */
387c478bd9Sstevel@tonic-gate "%s: %s: cannot open file.\n",
397c478bd9Sstevel@tonic-gate /* LIBELF_ERROR */
407c478bd9Sstevel@tonic-gate "%s: libelf error.\n",
417c478bd9Sstevel@tonic-gate /* OPEN_TEMP_ERROR */
427c478bd9Sstevel@tonic-gate "%s: %s: cannot open temporary file\n",
437c478bd9Sstevel@tonic-gate /* WRITE_ERROR */
447c478bd9Sstevel@tonic-gate "%s: %s: write system failure: %s: file not manipulated.\n",
457c478bd9Sstevel@tonic-gate /* GETARHDR_ERROR */
467c478bd9Sstevel@tonic-gate "%s: %s: malformed archive at %ld\n",
477c478bd9Sstevel@tonic-gate /* FILE_TYPE_ERROR */
487c478bd9Sstevel@tonic-gate "%s: %s: invalid file type\n",
497c478bd9Sstevel@tonic-gate /* NOT_MANIPULATED_ERROR */
507c478bd9Sstevel@tonic-gate "%s: %s: file not manipulated\n",
517c478bd9Sstevel@tonic-gate /* WRN_MANIPULATED_ERROR */
527c478bd9Sstevel@tonic-gate "%s: WARNING: %s: Cannot manipulate file.\n",
537c478bd9Sstevel@tonic-gate /* NO_SECT_TABLE_ERROR */
547c478bd9Sstevel@tonic-gate "%s: %s: no section header table.\n",
557c478bd9Sstevel@tonic-gate /* READ_ERROR */
567c478bd9Sstevel@tonic-gate "%s: %s: trouble reading file\n",
577c478bd9Sstevel@tonic-gate /* READ_MANI_ERROR */
587c478bd9Sstevel@tonic-gate "%s: %s: read system failure: %s: file not manipulated.\n",
597c478bd9Sstevel@tonic-gate /* WRITE_MANI_ERROR */
607c478bd9Sstevel@tonic-gate "%s: %s: write system failure: %s: file not manipulated.\n",
617c478bd9Sstevel@tonic-gate /* LSEEK_MANI_ERROR */
627c478bd9Sstevel@tonic-gate "%s: %s: lseek system failure: %s: file not manipulated.\n",
637c478bd9Sstevel@tonic-gate /* SYM_TAB_AR_ERROR */
647c478bd9Sstevel@tonic-gate "%s: WARNING: %s: symbol table deleted from archive \n",
657c478bd9Sstevel@tonic-gate /* EXEC_AR_ERROR */
667c478bd9Sstevel@tonic-gate "execute  `ar -ts %s` to restore symbol table.\n",
677c478bd9Sstevel@tonic-gate /* READ_SYS_ERROR */
687c478bd9Sstevel@tonic-gate "%s: %s: read system failure\n",
697c478bd9Sstevel@tonic-gate /* OPEN_WRITE_ERROR */
707c478bd9Sstevel@tonic-gate "%s: %s: can't open file for writing\n",
717c478bd9Sstevel@tonic-gate /* ACT_PRINT_ERROR */
727c478bd9Sstevel@tonic-gate "%s: %s: Cannot print contents of a NOBITS section (%s)\n",
737c478bd9Sstevel@tonic-gate /* ACT_DELETE1_ERROR */
747c478bd9Sstevel@tonic-gate "%s: %s: Warning: Cannot delete section (%s)\n\t\tfrom a segment.\n",
757c478bd9Sstevel@tonic-gate /* ACT_DELETE2_ERROR */
767c478bd9Sstevel@tonic-gate "%s: %s: Warning: Cannot delete section (%s)\n"
777c478bd9Sstevel@tonic-gate "\t\tbecause its relocation section (%s) is in a segment\n",
787c478bd9Sstevel@tonic-gate /* ACT_APPEND1_ERROR */
797c478bd9Sstevel@tonic-gate "%s: %s: Cannot append to a NOBITS section (%s)\n",
807c478bd9Sstevel@tonic-gate /* ACT_APPEND2_ERROR */
817c478bd9Sstevel@tonic-gate "%s: %s: Warning: Cannot append to section (%s)\n\t\tin a segment\n",
827c478bd9Sstevel@tonic-gate /* ACT_COMPRESS1_ERROR */
837c478bd9Sstevel@tonic-gate "%s: %s: Cannot compress a NOBITS section (%s)\n",
847c478bd9Sstevel@tonic-gate /* ACT_COMPRESS2_ERROR */
857c478bd9Sstevel@tonic-gate "%s: %s: Warning: Cannot compress a section (%s)\n\t\tin a segment\n",
867c478bd9Sstevel@tonic-gate /* ACCESS_ERROR */
877c478bd9Sstevel@tonic-gate "%s: %s: access error.\n",
887c478bd9Sstevel@tonic-gate /* WRITE_MANI_ERROR2 */
897c478bd9Sstevel@tonic-gate "%s: /ftruncate/lseek/write system failure: %s: file may be destroyed.\n"
907c478bd9Sstevel@tonic-gate };
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate void
error_message(int args,...)937c478bd9Sstevel@tonic-gate error_message(int args, ...)
947c478bd9Sstevel@tonic-gate {
957c478bd9Sstevel@tonic-gate 	int mes = args;
967c478bd9Sstevel@tonic-gate 	char *message = gettext((char *)msg[mes]);
977c478bd9Sstevel@tonic-gate 	int flag;
987c478bd9Sstevel@tonic-gate 	char *sys_mes;
997c478bd9Sstevel@tonic-gate 	va_list ap;
1007c478bd9Sstevel@tonic-gate 	va_start(ap, args);
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	flag = va_arg(ap, int);
1037c478bd9Sstevel@tonic-gate 	sys_mes = va_arg(ap, char *);
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate 	switch (mes) {
1067c478bd9Sstevel@tonic-gate 	case MALLOC_ERROR:
1077c478bd9Sstevel@tonic-gate 	case USAGE_ERROR:
1087c478bd9Sstevel@tonic-gate 	case ELFVER_ERROR:
1097c478bd9Sstevel@tonic-gate 	case EXEC_AR_ERROR:
1107c478bd9Sstevel@tonic-gate 	case LIBELF_ERROR:
1115aefb655Srie 		/* LINTED */
1127c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, message, va_arg(ap, char *));
1137c478bd9Sstevel@tonic-gate 		break;
1147c478bd9Sstevel@tonic-gate 	case OPEN_ERROR:
1157c478bd9Sstevel@tonic-gate 	case ACCESS_ERROR:
1167c478bd9Sstevel@tonic-gate 	case OPEN_TEMP_ERROR:
1177c478bd9Sstevel@tonic-gate 	case FILE_TYPE_ERROR:
1187c478bd9Sstevel@tonic-gate 	case NOT_MANIPULATED_ERROR:
1197c478bd9Sstevel@tonic-gate 	case WRN_MANIPULATED_ERROR:
1207c478bd9Sstevel@tonic-gate 	case NO_SECT_TABLE_ERROR:
1217c478bd9Sstevel@tonic-gate 	case READ_ERROR:
1227c478bd9Sstevel@tonic-gate 	case SYM_TAB_AR_ERROR:
1237c478bd9Sstevel@tonic-gate 	case READ_SYS_ERROR:
1247c478bd9Sstevel@tonic-gate 	case OPEN_WRITE_ERROR:
1257c478bd9Sstevel@tonic-gate 		/* LINTED */
1267c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, message, va_arg(ap, char *),
1277c478bd9Sstevel@tonic-gate 		    va_arg(ap, char *));
1287c478bd9Sstevel@tonic-gate 		break;
1297c478bd9Sstevel@tonic-gate 	case WRITE_ERROR:
1307c478bd9Sstevel@tonic-gate 	case READ_MANI_ERROR:
1317c478bd9Sstevel@tonic-gate 	case WRITE_MANI_ERROR:
1327c478bd9Sstevel@tonic-gate 	case LSEEK_MANI_ERROR:
1337c478bd9Sstevel@tonic-gate 	case ACT_PRINT_ERROR:
1347c478bd9Sstevel@tonic-gate 	case ACT_DELETE1_ERROR:
1357c478bd9Sstevel@tonic-gate 	case ACT_APPEND1_ERROR:
1367c478bd9Sstevel@tonic-gate 	case ACT_APPEND2_ERROR:
1377c478bd9Sstevel@tonic-gate 	case ACT_COMPRESS1_ERROR:
1387c478bd9Sstevel@tonic-gate 	case ACT_COMPRESS2_ERROR: {
1397c478bd9Sstevel@tonic-gate 		char *a = va_arg(ap, char *);
1407c478bd9Sstevel@tonic-gate 		char *b = va_arg(ap, char *);
1417c478bd9Sstevel@tonic-gate 		char *c = va_arg(ap, char *);
1425aefb655Srie 		/* LINTED */
1437c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, message, a, b, c);
1447c478bd9Sstevel@tonic-gate 		break;
1457c478bd9Sstevel@tonic-gate 	}
1467c478bd9Sstevel@tonic-gate 	case ACT_DELETE2_ERROR: {
1477c478bd9Sstevel@tonic-gate 		char *a = va_arg(ap, char *);
1487c478bd9Sstevel@tonic-gate 		char *b = va_arg(ap, char *);
1497c478bd9Sstevel@tonic-gate 		char *c = va_arg(ap, char *);
1507c478bd9Sstevel@tonic-gate 		char *d = va_arg(ap, char *);
1515aefb655Srie 		/* LINTED */
1527c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, message, a, b, c, d);
1537c478bd9Sstevel@tonic-gate 		break;
1547c478bd9Sstevel@tonic-gate 	}
1557c478bd9Sstevel@tonic-gate 	case GETARHDR_ERROR: {
1567c478bd9Sstevel@tonic-gate 		char *a = va_arg(ap, char *);
1577c478bd9Sstevel@tonic-gate 		char *b = va_arg(ap, char *);
1587c478bd9Sstevel@tonic-gate 		long c = va_arg(ap, long);
1595aefb655Srie 		/* LINTED */
1607c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, message, a, b, c);
1617c478bd9Sstevel@tonic-gate 		break;
1627c478bd9Sstevel@tonic-gate 	}
1637c478bd9Sstevel@tonic-gate 	default:
1647c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "internal error: error_message(%d)\n",
1657c478bd9Sstevel@tonic-gate 		    mes);
166*d1477c77SAli Bahrami 		mcs_exit(100);
1677c478bd9Sstevel@tonic-gate 	}
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate 	if (flag != PLAIN_ERROR)
1707c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "\t%s\n", sys_mes);
1717c478bd9Sstevel@tonic-gate 	va_end(ap);
1727c478bd9Sstevel@tonic-gate }
173