xref: /titanic_41/usr/src/cmd/sgs/mcs/common/message.c (revision 505d05c73a6e56769f263d4803b22eddd168ee24)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *	Copyright(c) 1988 AT&T
24  *	  All Rights Reserved
25  *
26  *
27  *	Copyright(c) 1995 by Sun Microsystems, Inc.
28  *	All Rights Reserved
29  */
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 #include "mcs.h"
32 
33 static const char *msg[] = {
34 /* MALLOC_ERROR */
35 "%s: malloc memory allocation failure.\n",
36 /* USAGE_ERROR */
37 "%s: multiple -n only allowed for -d option.\n",
38 /* ELFVER_ERROR */
39 "%s: elf_version() failed - libelf.a out of date.\n",
40 /* OPEN_ERROR */
41 "%s: %s: cannot open file.\n",
42 /* LIBELF_ERROR */
43 "%s: libelf error.\n",
44 /* OPEN_TEMP_ERROR */
45 "%s: %s: cannot open temporary file\n",
46 /* WRITE_ERROR */
47 "%s: %s: write system failure: %s: file not manipulated.\n",
48 /* GETARHDR_ERROR */
49 "%s: %s: malformed archive at %ld\n",
50 /* FILE_TYPE_ERROR */
51 "%s: %s: invalid file type\n",
52 /* NOT_MANIPULATED_ERROR */
53 "%s: %s: file not manipulated\n",
54 /* WRN_MANIPULATED_ERROR */
55 "%s: WARNING: %s: Cannot manipulate file.\n",
56 /* NO_SECT_TABLE_ERROR */
57 "%s: %s: no section header table.\n",
58 /* READ_ERROR */
59 "%s: %s: trouble reading file\n",
60 /* READ_MANI_ERROR */
61 "%s: %s: read system failure: %s: file not manipulated.\n",
62 /* WRITE_MANI_ERROR */
63 "%s: %s: write system failure: %s: file not manipulated.\n",
64 /* LSEEK_MANI_ERROR */
65 "%s: %s: lseek system failure: %s: file not manipulated.\n",
66 /* SYM_TAB_AR_ERROR */
67 "%s: WARNING: %s: symbol table deleted from archive \n",
68 /* EXEC_AR_ERROR */
69 "execute  `ar -ts %s` to restore symbol table.\n",
70 /* READ_SYS_ERROR */
71 "%s: %s: read system failure\n",
72 /* OPEN_WRITE_ERROR */
73 "%s: %s: can't open file for writing\n",
74 /* ACT_PRINT_ERROR */
75 "%s: %s: Cannot print contents of a NOBITS section (%s)\n",
76 /* ACT_DELETE1_ERROR */
77 "%s: %s: Warning: Cannot delete section (%s)\n\t\tfrom a segment.\n",
78 /* ACT_DELETE2_ERROR */
79 "%s: %s: Warning: Cannot delete section (%s)\n"
80 "\t\tbecause its relocation section (%s) is in a segment\n",
81 /* ACT_APPEND1_ERROR */
82 "%s: %s: Cannot append to a NOBITS section (%s)\n",
83 /* ACT_APPEND2_ERROR */
84 "%s: %s: Warning: Cannot append to section (%s)\n\t\tin a segment\n",
85 /* ACT_COMPRESS1_ERROR */
86 "%s: %s: Cannot compress a NOBITS section (%s)\n",
87 /* ACT_COMPRESS2_ERROR */
88 "%s: %s: Warning: Cannot compress a section (%s)\n\t\tin a segment\n",
89 /* ACCESS_ERROR */
90 "%s: %s: access error.\n",
91 /* WRITE_MANI_ERROR2 */
92 "%s: /ftruncate/lseek/write system failure: %s: file may be destroyed.\n"
93 };
94 
95 void
96 error_message(int args, ...)
97 {
98 	int mes = args;
99 	char *message = gettext((char *)msg[mes]);
100 	int flag;
101 	char *sys_mes;
102 	va_list ap;
103 	va_start(ap, args);
104 
105 	flag = va_arg(ap, int);
106 	sys_mes = va_arg(ap, char *);
107 
108 	switch (mes) {
109 	case MALLOC_ERROR:
110 	case USAGE_ERROR:
111 	case ELFVER_ERROR:
112 	case EXEC_AR_ERROR:
113 	case LIBELF_ERROR:
114 		(void) fprintf(stderr, message, va_arg(ap, char *));
115 		break;
116 	case OPEN_ERROR:
117 	case ACCESS_ERROR:
118 	case OPEN_TEMP_ERROR:
119 	case FILE_TYPE_ERROR:
120 	case NOT_MANIPULATED_ERROR:
121 	case WRN_MANIPULATED_ERROR:
122 	case NO_SECT_TABLE_ERROR:
123 	case READ_ERROR:
124 	case SYM_TAB_AR_ERROR:
125 	case READ_SYS_ERROR:
126 	case OPEN_WRITE_ERROR:
127 		/* LINTED */
128 		(void) fprintf(stderr, message, va_arg(ap, char *),
129 					va_arg(ap, char *));
130 		break;
131 	case WRITE_ERROR:
132 	case READ_MANI_ERROR:
133 	case WRITE_MANI_ERROR:
134 	case LSEEK_MANI_ERROR:
135 	case ACT_PRINT_ERROR:
136 	case ACT_DELETE1_ERROR:
137 	case ACT_APPEND1_ERROR:
138 	case ACT_APPEND2_ERROR:
139 	case ACT_COMPRESS1_ERROR:
140 	case ACT_COMPRESS2_ERROR: {
141 		char * a = va_arg(ap, char *);
142 		char * b = va_arg(ap, char *);
143 		char * c = va_arg(ap, char *);
144 		(void) fprintf(stderr, message, a, b, c);
145 		break;
146 	}
147 	case ACT_DELETE2_ERROR: {
148 		char * a = va_arg(ap, char *);
149 		char * b = va_arg(ap, char *);
150 		char * c = va_arg(ap, char *);
151 		char * d = va_arg(ap, char *);
152 		(void) fprintf(stderr, message, a, b, c, d);
153 		break;
154 	}
155 	case GETARHDR_ERROR: {
156 		char * a = va_arg(ap, char *);
157 		char * b = va_arg(ap, char *);
158 		long c = va_arg(ap, long);
159 		(void) fprintf(stderr, message, a, b, c);
160 		break;
161 	}
162 	default:
163 		(void) fprintf(stderr, "internal error: error_message(%d)\n",
164 			mes);
165 		exit(100);
166 	}
167 
168 	if (flag != PLAIN_ERROR)
169 		(void) fprintf(stderr, "\t%s\n", sys_mes);
170 	va_end(ap);
171 }
172