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