xref: /titanic_44/usr/src/cmd/sgs/mcs/common/message.c (revision 587032cf0967234b39ccb50adca936a367841063)
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(c) 1988 AT&T
23  *	  All Rights Reserved
24  *
25  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 #include "mcs.h"
30 
31 static const char *msg[] = {
32 /* MALLOC_ERROR */
33 "%s: malloc memory allocation failure.\n",
34 /* USAGE_ERROR */
35 "%s: multiple -n only allowed for -d option.\n",
36 /* ELFVER_ERROR */
37 "%s: elf_version() failed - libelf.a out of date.\n",
38 /* OPEN_ERROR */
39 "%s: %s: cannot open file.\n",
40 /* LIBELF_ERROR */
41 "%s: libelf error.\n",
42 /* OPEN_TEMP_ERROR */
43 "%s: %s: cannot open temporary file\n",
44 /* WRITE_ERROR */
45 "%s: %s: write system failure: %s: file not manipulated.\n",
46 /* GETARHDR_ERROR */
47 "%s: %s: malformed archive at %ld\n",
48 /* FILE_TYPE_ERROR */
49 "%s: %s: invalid file type\n",
50 /* NOT_MANIPULATED_ERROR */
51 "%s: %s: file not manipulated\n",
52 /* WRN_MANIPULATED_ERROR */
53 "%s: WARNING: %s: Cannot manipulate file.\n",
54 /* NO_SECT_TABLE_ERROR */
55 "%s: %s: no section header table.\n",
56 /* READ_ERROR */
57 "%s: %s: trouble reading file\n",
58 /* READ_MANI_ERROR */
59 "%s: %s: read system failure: %s: file not manipulated.\n",
60 /* WRITE_MANI_ERROR */
61 "%s: %s: write system failure: %s: file not manipulated.\n",
62 /* LSEEK_MANI_ERROR */
63 "%s: %s: lseek system failure: %s: file not manipulated.\n",
64 /* SYM_TAB_AR_ERROR */
65 "%s: WARNING: %s: symbol table deleted from archive \n",
66 /* EXEC_AR_ERROR */
67 "execute  `ar -ts %s` to restore symbol table.\n",
68 /* READ_SYS_ERROR */
69 "%s: %s: read system failure\n",
70 /* OPEN_WRITE_ERROR */
71 "%s: %s: can't open file for writing\n",
72 /* ACT_PRINT_ERROR */
73 "%s: %s: Cannot print contents of a NOBITS section (%s)\n",
74 /* ACT_DELETE1_ERROR */
75 "%s: %s: Warning: Cannot delete section (%s)\n\t\tfrom a segment.\n",
76 /* ACT_DELETE2_ERROR */
77 "%s: %s: Warning: Cannot delete section (%s)\n"
78 "\t\tbecause its relocation section (%s) is in a segment\n",
79 /* ACT_APPEND1_ERROR */
80 "%s: %s: Cannot append to a NOBITS section (%s)\n",
81 /* ACT_APPEND2_ERROR */
82 "%s: %s: Warning: Cannot append to section (%s)\n\t\tin a segment\n",
83 /* ACT_COMPRESS1_ERROR */
84 "%s: %s: Cannot compress a NOBITS section (%s)\n",
85 /* ACT_COMPRESS2_ERROR */
86 "%s: %s: Warning: Cannot compress a section (%s)\n\t\tin a segment\n",
87 /* ACCESS_ERROR */
88 "%s: %s: access error.\n",
89 /* WRITE_MANI_ERROR2 */
90 "%s: /ftruncate/lseek/write system failure: %s: file may be destroyed.\n"
91 };
92 
93 void
94 error_message(int args, ...)
95 {
96 	int mes = args;
97 	char *message = gettext((char *)msg[mes]);
98 	int flag;
99 	char *sys_mes;
100 	va_list ap;
101 	va_start(ap, args);
102 
103 	flag = va_arg(ap, int);
104 	sys_mes = va_arg(ap, char *);
105 
106 	switch (mes) {
107 	case MALLOC_ERROR:
108 	case USAGE_ERROR:
109 	case ELFVER_ERROR:
110 	case EXEC_AR_ERROR:
111 	case LIBELF_ERROR:
112 		/* LINTED */
113 		(void) fprintf(stderr, message, va_arg(ap, char *));
114 		break;
115 	case OPEN_ERROR:
116 	case ACCESS_ERROR:
117 	case OPEN_TEMP_ERROR:
118 	case FILE_TYPE_ERROR:
119 	case NOT_MANIPULATED_ERROR:
120 	case WRN_MANIPULATED_ERROR:
121 	case NO_SECT_TABLE_ERROR:
122 	case READ_ERROR:
123 	case SYM_TAB_AR_ERROR:
124 	case READ_SYS_ERROR:
125 	case OPEN_WRITE_ERROR:
126 		/* LINTED */
127 		(void) fprintf(stderr, message, va_arg(ap, char *),
128 					va_arg(ap, char *));
129 		break;
130 	case WRITE_ERROR:
131 	case READ_MANI_ERROR:
132 	case WRITE_MANI_ERROR:
133 	case LSEEK_MANI_ERROR:
134 	case ACT_PRINT_ERROR:
135 	case ACT_DELETE1_ERROR:
136 	case ACT_APPEND1_ERROR:
137 	case ACT_APPEND2_ERROR:
138 	case ACT_COMPRESS1_ERROR:
139 	case ACT_COMPRESS2_ERROR: {
140 		char *a = va_arg(ap, char *);
141 		char *b = va_arg(ap, char *);
142 		char *c = va_arg(ap, char *);
143 		/* LINTED */
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 		/* LINTED */
153 		(void) fprintf(stderr, message, a, b, c, d);
154 		break;
155 	}
156 	case GETARHDR_ERROR: {
157 		char *a = va_arg(ap, char *);
158 		char *b = va_arg(ap, char *);
159 		long c = va_arg(ap, long);
160 		/* LINTED */
161 		(void) fprintf(stderr, message, a, b, c);
162 		break;
163 	}
164 	default:
165 		(void) fprintf(stderr, "internal error: error_message(%d)\n",
166 			mes);
167 		exit(100);
168 	}
169 
170 	if (flag != PLAIN_ERROR)
171 		(void) fprintf(stderr, "\t%s\n", sys_mes);
172 	va_end(ap);
173 }
174