|
Packit |
fc043f |
/* mkw32errmap.c - Generate mapping sources for Windows.
|
|
Packit |
fc043f |
Copyright (C) 2010 g10 Code GmbH
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
This file is part of libgpg-error.
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
libgpg-error is free software; you can redistribute it and/or
|
|
Packit |
fc043f |
modify it under the terms of the GNU Lesser General Public License
|
|
Packit |
fc043f |
as published by the Free Software Foundation; either version 2.1 of
|
|
Packit |
fc043f |
the License, or (at your option) any later version.
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
libgpg-error is distributed in the hope that it will be useful, but
|
|
Packit |
fc043f |
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
fc043f |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
fc043f |
Lesser General Public License for more details.
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
fc043f |
License along with this program; if not, see <https://www.gnu.org/licenses/>.
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#ifdef RESOLVE_MACROS
|
|
Packit |
fc043f |
# include <winerror.h>
|
|
Packit |
fc043f |
#endif
|
|
Packit |
fc043f |
#include <stdio.h>
|
|
Packit |
fc043f |
#include <stdlib.h>
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
static const char header_gpg_extra_errno_h[] =
|
|
Packit |
fc043f |
"/* errno.h - WindowsCE errno.h substitute\n"
|
|
Packit |
fc043f |
" Copyright (C) 2010 g10 Code GmbH\n"
|
|
Packit |
fc043f |
"\n"
|
|
Packit |
fc043f |
" This file is free software; as a special exception the author gives\n"
|
|
Packit |
fc043f |
" unlimited permission to copy and/or distribute it, with or without\n"
|
|
Packit |
fc043f |
" modifications, as long as this notice is preserved.\n"
|
|
Packit |
fc043f |
"\n"
|
|
Packit |
fc043f |
" This file is distributed in the hope that it will be useful, but\n"
|
|
Packit |
fc043f |
" WITHOUT ANY WARRANTY, to the extent permitted by law; without even\n"
|
|
Packit |
fc043f |
" the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR\n"
|
|
Packit |
fc043f |
" PURPOSE.\n"
|
|
Packit |
fc043f |
"\n"
|
|
Packit |
fc043f |
" +++ Do not edit! File has been generated by mkw32errmap.c +++\n"
|
|
Packit |
fc043f |
"\n"
|
|
Packit |
fc043f |
" This file is intended to be used with ming32ce-gcc to implement an\n"
|
|
Packit |
fc043f |
" errno substitute under WindowsCE. It must be included via gcc's\n"
|
|
Packit |
fc043f |
" -idirafter option. The gpg-error-config script emits the\n"
|
|
Packit |
fc043f |
" appropriate option snippet. The actual implementation of the errno\n"
|
|
Packit |
fc043f |
" related functions are part of libgpg-error. A separate header file\n"
|
|
Packit |
fc043f |
" is required because errno.h is often included before gpg-error.h.\n"
|
|
Packit |
fc043f |
" */\n"
|
|
Packit |
fc043f |
"\n"
|
|
Packit |
fc043f |
"#ifndef _GPG_ERROR_EXTRA_ERRNO_H\n"
|
|
Packit |
fc043f |
"#define _GPG_ERROR_EXTRA_ERRNO_H\n"
|
|
Packit |
fc043f |
"\n"
|
|
Packit |
fc043f |
"/* Due to peculiarities in W32 we can't implement ERRNO as an\n"
|
|
Packit |
fc043f |
" writable lvalue. This also allows us to easily find places\n"
|
|
Packit |
fc043f |
" where ERRNO is being written to. See also gpg_err_set_errno. */\n"
|
|
Packit |
fc043f |
"int _gpg_w32ce_get_errno (void);\n"
|
|
Packit |
fc043f |
"#define errno (_gpg_w32ce_get_errno ())\n"
|
|
Packit |
fc043f |
"\n";
|
|
Packit |
fc043f |
static const char footer_gpg_extra_errno_h[] =
|
|
Packit |
fc043f |
"\n"
|
|
Packit |
fc043f |
"#endif /*_GPG_ERROR_EXTRA_ERRNO_H*/\n";
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
/* The table below is used in two modes. First we run the host
|
|
Packit |
fc043f |
preprocessor over it to generate a new include file. This include
|
|
Packit |
fc043f |
file has the same content but the Windows error macros are
|
|
Packit |
fc043f |
resolved. This is so that we don't need to include winerror.h into
|
|
Packit |
fc043f |
the generated errno.h. The mkw32errmap_marker variable is only
|
|
Packit |
fc043f |
here to have something to grep for after preprocessing. */
|
|
Packit |
fc043f |
static int mkw32errmap_marker;
|
|
Packit |
fc043f |
struct table_s
|
|
Packit |
fc043f |
{
|
|
Packit |
fc043f |
int *dummy;
|
|
Packit |
fc043f |
const char *name;
|
|
Packit |
fc043f |
int w32code;
|
|
Packit |
fc043f |
int w32code2;
|
|
Packit |
fc043f |
};
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
struct table_s table[] =
|
|
Packit |
fc043f |
{
|
|
Packit |
fc043f |
#ifdef RESOLVE_MACROS
|
|
Packit |
fc043f |
#define X(a,b,c) \
|
|
Packit |
fc043f |
{&mkw32errmap_marker, (a), (b), (c)}
|
|
Packit |
fc043f |
X( "EPERM", ERROR_CANNOT_MAKE , 0 ),
|
|
Packit |
fc043f |
X( "ENOENT", ERROR_FILE_NOT_FOUND , ERROR_PATH_NOT_FOUND ),
|
|
Packit |
fc043f |
X( "EINTR", ERROR_INVALID_AT_INTERRUPT_TIME , 0 ),
|
|
Packit |
fc043f |
X( "EIO", ERROR_IO_DEVICE , 0 ),
|
|
Packit |
fc043f |
X( "ENXIO", ERROR_FILE_INVALID , 0 ),
|
|
Packit |
fc043f |
X( "EBADF", ERROR_INVALID_HANDLE , 0 ),
|
|
Packit |
fc043f |
X( "EAGAIN", ERROR_MORE_DATA , WSAEWOULDBLOCK ),
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
X( "ENOMEM", ERROR_NOT_ENOUGH_MEMORY , 0 ),
|
|
Packit |
fc043f |
X( "EACCES", ERROR_ACCESS_DENIED , 0 ),
|
|
Packit |
fc043f |
X( "EFAULT", ERROR_PROCESS_ABORTED , 0 ),
|
|
Packit |
fc043f |
X( "EBUSY", ERROR_BUSY , 0 ),
|
|
Packit |
fc043f |
X( "EEXIST", ERROR_FILE_EXISTS , WSAEADDRINUSE ),
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
X( "EXDEV", ERROR_NOT_SAME_DEVICE , 0 ),
|
|
Packit |
fc043f |
X( "ENODEV", ERROR_BAD_DEVICE , ERROR_DEV_NOT_EXIST ),
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
X( "ENOTDIR",ERROR_DIRECTORY , 0 ),
|
|
Packit |
fc043f |
X( "EINVAL", ERROR_INVALID_PARAMETER , 0 ),
|
|
Packit |
fc043f |
X( "ENFILE", ERROR_NO_MORE_FILES , 0 ),
|
|
Packit |
fc043f |
X( "EMFILE", ERROR_TOO_MANY_OPEN_FILES , 0 ),
|
|
Packit |
fc043f |
X( "ENOSPC", ERROR_DISK_FULL , 0 ),
|
|
Packit |
fc043f |
X( "EROFS", ERROR_WRITE_PROTECT , 0 ),
|
|
Packit |
fc043f |
X( "EPIPE", ERROR_BROKEN_PIPE , 0 ),
|
|
Packit |
fc043f |
X( "ERANGE", ERROR_ARITHMETIC_OVERFLOW , 0 ),
|
|
Packit |
fc043f |
X( "EDEADLOCK",ERROR_POSSIBLE_DEADLOCK , 0 ),
|
|
Packit |
fc043f |
X( "ENAMETOOLONG", ERROR_FILENAME_EXCED_RANGE, 0 ),
|
|
Packit |
fc043f |
X( "ENOLCK", ERROR_SHARING_BUFFER_EXCEEDED , 0 ),
|
|
Packit |
fc043f |
X( "ENOSYS", ERROR_NOT_SUPPORTED , 0 ),
|
|
Packit |
fc043f |
X( "ENOTEMPTY",ERROR_DIR_NOT_EMPTY , 0 ),
|
|
Packit |
fc043f |
X( "ESPIPE", ERROR_SEEK_ON_DEVICE , 0 ),
|
|
Packit |
fc043f |
#if 0 /* FIXME: Find appropriate mappings. */
|
|
Packit |
fc043f |
X( "EILSEQ", ),
|
|
Packit |
fc043f |
X( "EDOM", ),
|
|
Packit |
fc043f |
X( "EMLINK", ),
|
|
Packit |
fc043f |
X( "ESRCH", ), /* No such process */
|
|
Packit |
fc043f |
X( "E2BIG", ), /* Arg list too long */
|
|
Packit |
fc043f |
X( "ENOEXEC", ), /* Exec format error */
|
|
Packit |
fc043f |
X( "ECHILD", ), /* No child processes */
|
|
Packit |
fc043f |
X( "EISDIR", ), /* Is a directory */
|
|
Packit |
fc043f |
X( "ENOTTY", ), /* Inappropriate I/O control operation */
|
|
Packit |
fc043f |
X( "EFBIG", ), /* File too large */
|
|
Packit |
fc043f |
#endif
|
|
Packit |
fc043f |
#undef X
|
|
Packit |
fc043f |
#else /*!RESOLVE_MACROS*/
|
|
Packit |
fc043f |
# include "mkw32errmap.tab.h"
|
|
Packit |
fc043f |
#endif /*!RESOLVE_MACROS*/
|
|
Packit |
fc043f |
{ NULL, 0 }
|
|
Packit |
fc043f |
};
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
static int
|
|
Packit |
fc043f |
compare_table (const void *a_v, const void *b_v)
|
|
Packit |
fc043f |
{
|
|
Packit |
fc043f |
const struct table_s *a = a_v;
|
|
Packit |
fc043f |
const struct table_s *b = b_v;
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
return (a->w32code - b->w32code);
|
|
Packit |
fc043f |
}
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
int
|
|
Packit |
fc043f |
main (int argc, char **argv)
|
|
Packit |
fc043f |
{
|
|
Packit |
fc043f |
int idx;
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
for (idx=0; table[idx].name; idx++)
|
|
Packit |
fc043f |
;
|
|
Packit |
fc043f |
qsort (table, idx, sizeof *table, compare_table);
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
if (argc == 2 && !strcmp (argv[1], "--map"))
|
|
Packit |
fc043f |
{
|
|
Packit |
fc043f |
fputs ("static int\n"
|
|
Packit |
fc043f |
"map_w32codes (int err)\n"
|
|
Packit |
fc043f |
"{\n"
|
|
Packit |
fc043f |
" switch (err)\n"
|
|
Packit |
fc043f |
" {\n", stdout );
|
|
Packit |
fc043f |
for (idx=0; table[idx].name; idx++)
|
|
Packit |
fc043f |
if (table[idx].w32code2)
|
|
Packit |
fc043f |
printf (" case %d: return %d;\n",
|
|
Packit |
fc043f |
table[idx].w32code2, table[idx].w32code);
|
|
Packit |
fc043f |
fputs (" default: return err;\n"
|
|
Packit |
fc043f |
" }\n"
|
|
Packit |
fc043f |
"}\n", stdout);
|
|
Packit |
fc043f |
}
|
|
Packit |
fc043f |
else
|
|
Packit |
fc043f |
{
|
|
Packit |
fc043f |
fputs (header_gpg_extra_errno_h, stdout);
|
|
Packit |
fc043f |
for (idx=0; table[idx].name; idx++)
|
|
Packit |
fc043f |
printf ("#define %-12s %5d\n", table[idx].name, table[idx].w32code);
|
|
Packit |
fc043f |
fputs (footer_gpg_extra_errno_h, stdout);
|
|
Packit |
fc043f |
}
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
return 0;
|
|
Packit |
fc043f |
}
|