Fixed pwmd_get_fds() when doing an ASYNC_CMD_OPEN2 when the file was
[libpwmd.git] / assuan / mkerrors
blob79ac23b65af4933e11415fb9b3291d7f8eee3389
1 #!/bin/sh
2 # mkerrors - Extract error strings from assuan.h
3 # and create C source for assuan_strerror
4 # Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc.
6 # This file is part of Assuan.
8 # Assuan is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU Lesser General Public License as
10 # published by the Free Software Foundation; either version 2.1 of
11 # the License, or (at your option) any later version.
13 # Assuan is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this program; if not, see <http://www.gnu.org/licenses/>.
20 cat <<EOF
21 /* Generated automatically by mkerrors */
22 /* Do not edit! See mkerrors for copyright notice. */
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
28 #include <stdio.h>
29 #include <assert.h>
30 #include <errno.h>
32 #undef _ASSUAN_IN_LIBASSUAN /* undef to get all error codes. */
33 #include "assuan.h"
34 #include "assuan-defs.h"
36 /* If true the modern gpg-error style error codes are used in the
37 API. */
38 static unsigned int err_source;
40 /* Enable gpg-error style error codes. ERRSOURCE is one of gpg-error
41 sources. Note, that this function is not thread-safe and should be
42 used right at startup. Switching back to the old style mode is not
43 supported. */
44 void
45 assuan_set_assuan_err_source (int errsource)
47 errsource &= 0xff;
48 err_source = errsource? errsource : 31 /*GPG_ERR_SOURCE_ANY*/;
52 /* Helper to map old style Assuan error codes to gpg-error codes.
53 This is used internally to keep an compatible ABI. */
54 assuan_error_t
55 _assuan_error (int oldcode)
57 unsigned int n;
59 if (!err_source)
61 if (oldcode == -1)
62 return -1;
63 else
64 return (oldcode & 0x00ffffff); /* Make sure that the gpg-error
65 source part is cleared. */
68 switch (oldcode)
70 case ASSUAN_General_Error: n = 257; break;
71 case ASSUAN_Accept_Failed: n = 258; break;
72 case ASSUAN_Connect_Failed: n = 259; break;
73 case ASSUAN_Invalid_Response: n = 260; break;
74 case ASSUAN_Invalid_Value: n = 261; break;
75 case ASSUAN_Line_Not_Terminated: n = 262; break;
76 case ASSUAN_Line_Too_Long: n = 263; break;
77 case ASSUAN_Nested_Commands: n = 264; break;
78 case ASSUAN_No_Data_Callback: n = 265; break;
79 case ASSUAN_No_Inquire_Callback: n = 266; break;
80 case ASSUAN_Not_A_Server: n = 267; break;
81 case ASSUAN_Not_Implemented: n = 69; break;
82 case ASSUAN_Parameter_Conflict: n = 280; break;
83 case ASSUAN_Problem_Starting_Server: n = 269; break;
84 case ASSUAN_Server_Fault: n = 80; break;
85 case ASSUAN_Syntax_Error: n = 276; break;
86 case ASSUAN_Too_Much_Data: n = 273; break;
87 case ASSUAN_Unexpected_Command: n = 274; break;
88 case ASSUAN_Unknown_Command: n = 275; break;
89 case ASSUAN_Canceled: n = 277; break;
90 case ASSUAN_No_Secret_Key: n = 17; break;
91 case ASSUAN_Not_Confirmed: n = 114; break;
93 case ASSUAN_Read_Error:
94 switch (errno)
96 case 0: n = 16381; /*GPG_ERR_MISSING_ERRNO*/ break;
97 case EAGAIN:
98 n = (6 | (1 << 15));
99 break;
100 default: n = 270; /*GPG_ERR_ASS_READ_ERROR*/ break;
102 break;
104 case ASSUAN_Write_Error:
105 switch (errno)
107 case 0: n = 16381; /*GPG_ERR_MISSING_ERRNO*/ break;
108 case EAGAIN:
109 n = (6 | (1 << 15));
110 break;
111 default: n = 271; /*GPG_ERR_ASS_WRITE_ERROR*/ break;
113 break;
115 case ASSUAN_Out_Of_Core:
116 switch (errno)
118 case 0: /* Should not happen but a user might have provided
119 an incomplete implemented malloc function. Give
120 him a chance to correct this fault but make sure
121 an error is indeed returned. */
122 n = 16381; /*GPG_ERR_MISSING_ERRNO*/
123 break;
124 case ENOMEM:
125 n = (86 | (1 << 15));
126 break;
127 default:
128 n = 16382; /*GPG_ERR_UNKNOWN_ERRNO*/
129 break;
131 break;
133 case -1: n = 16383 /*GPG_ERR_EOF*/; break;
135 default:
136 n = 257;
137 break;
140 return ((err_source << 24) | (n & 0x00ffffff));
145 /* A small helper function to treat EAGAIN transparently to the
146 caller. */
148 _assuan_error_is_eagain (assuan_error_t err)
150 if ((!err_source && err == ASSUAN_Read_Error && errno == EAGAIN)
151 || (err_source && (err & ((1 << 24) - 1)) == (6 | (1 << 15))))
153 /* Avoid spinning by sleeping for one tenth of a second. */
154 _assuan_usleep (100000);
155 return 1;
157 else
158 return 0;
163 * assuan_strerror:
164 * @err: Error code
166 * This function returns a textual representaion of the given
167 * errorcode. If this is an unknown value, a string with the value
168 * is returned (Beware: it is hold in a static buffer).
170 * Return value: String with the error description.
172 const char *
173 assuan_strerror (assuan_error_t err)
175 const char *s;
176 static char buf[50];
178 switch (err)
182 awk '
183 /ASSUAN_No_Error/ { okay=1 }
184 !okay {next}
185 /^#define[ ]+ASSUAN_[A-Za-z_]*/ { print_code($2) }
186 /ASSUAN_USER_ERROR_LAST/ { exit 0 }
189 function print_code( s )
191 printf " case %s: s=\"", s ;
192 gsub(/_/, " ", s );
193 printf "%s\"; break;\n", tolower(substr(s,8));
197 cat <<EOF
198 case -1: s = "EOF (-1)"; break;
199 default:
201 unsigned int source, code, n;
203 source = ((err >> 24) & 0xff);
204 code = (err & 0x00ffffff);
205 if (source)
207 /* Assume this is an libgpg-error and try to map the codes
208 back. */
209 switch (code)
211 case 257: n = ASSUAN_General_Error ; break;
212 case 258: n = ASSUAN_Accept_Failed ; break;
213 case 259: n = ASSUAN_Connect_Failed ; break;
214 case 260: n = ASSUAN_Invalid_Response ; break;
215 case 261: n = ASSUAN_Invalid_Value ; break;
216 case 262: n = ASSUAN_Line_Not_Terminated ; break;
217 case 263: n = ASSUAN_Line_Too_Long ; break;
218 case 264: n = ASSUAN_Nested_Commands ; break;
219 case 265: n = ASSUAN_No_Data_Callback ; break;
220 case 266: n = ASSUAN_No_Inquire_Callback ; break;
221 case 267: n = ASSUAN_Not_A_Server ; break;
222 case 69: n = ASSUAN_Not_Implemented ; break;
223 case 280: n = ASSUAN_Parameter_Conflict ; break;
224 case 269: n = ASSUAN_Problem_Starting_Server; break;
225 case 270: n = ASSUAN_Read_Error ; break;
226 case 271: n = ASSUAN_Write_Error ; break;
227 case 80: n = ASSUAN_Server_Fault ; break;
228 case 276: n = ASSUAN_Syntax_Error ; break;
229 case 273: n = ASSUAN_Too_Much_Data ; break;
230 case 274: n = ASSUAN_Unexpected_Command ; break;
231 case 275: n = ASSUAN_Unknown_Command ; break;
232 case 277: n = ASSUAN_Canceled ; break;
233 case 114: n = ASSUAN_Not_Confirmed ; break;
234 case ((1<<15)|86): n = ASSUAN_Out_Of_Core ; break;
235 default: n = 0; break;
237 if (n)
238 s = assuan_strerror (n);
239 else
241 sprintf (buf, "ec=%u.%u", source, code );
242 s=buf;
245 else
247 sprintf (buf, "ec=%d", err );
248 s=buf;
251 break;
254 return s;