diff options
| author | Werner Koch <[email protected]> | 2026-06-24 13:40:14 +0200 |
|---|---|---|
| committer | Werner Koch <[email protected]> | 2026-06-24 13:40:14 +0200 |
| commit | e5148b95492855abc9e5786d7945ad82b780a440 (patch) | |
| tree | acc93ed3cea8c2d80b1a04300f6981028364b334 /src | |
| parent | build: No use of awk with gen-lock-obj.sh. (diff) | |
| download | libgpg-error-e5148b95492855abc9e5786d7945ad82b780a440.tar.gz libgpg-error-e5148b95492855abc9e5786d7945ad82b780a440.zip | |
w32: New function gpgrt_w32_set_errno.
* src/visibility.c (gpgrt_w32_set_errno): New.
* src/w32-add.h: Add function.
* src/gpg-error.def.in: Ditto.
* src/estream.c (_gpgrt_w32_set_errno): Return the windows error code.
* src/gpg-error.c (main): Add CMD_MAPW32ERR with name "mapw32err" and
implement it.
--
We use various mappings from Windows Error codes to ERRNO and thus to
gpg-error. it is better to eventuially have one central place for
such mappings.
Diffstat (limited to 'src')
| -rw-r--r-- | src/estream.c | 3 | ||||
| -rw-r--r-- | src/gpg-error.c | 16 | ||||
| -rw-r--r-- | src/gpg-error.def.in | 2 | ||||
| -rw-r--r-- | src/protos.h | 2 | ||||
| -rw-r--r-- | src/visibility.c | 6 | ||||
| -rw-r--r-- | src/visibility.h | 2 | ||||
| -rw-r--r-- | src/w32-add.h | 5 |
7 files changed, 33 insertions, 3 deletions
diff --git a/src/estream.c b/src/estream.c index d2cdc12..d47f40c 100644 --- a/src/estream.c +++ b/src/estream.c @@ -370,12 +370,13 @@ map_w32_to_errno (DWORD w32_err) /* Wrapper to be used by other modules to set ERRNO from the Windows * error. EC may be -1 to get the last error. */ -void +int _gpgrt_w32_set_errno (int ec) { if (ec == -1) ec = GetLastError (); _set_errno (map_w32_to_errno (ec)); + return ec; } diff --git a/src/gpg-error.c b/src/gpg-error.c index e0b5920..f0d7a08 100644 --- a/src/gpg-error.c +++ b/src/gpg-error.c @@ -561,6 +561,7 @@ main (int argc, char *argv[]) CMD_DEFINES, CMD_LOCALE, CMD_GETREG, + CMD_MAPW32ERR, CMD_FOPEN, OPT_OPENMODE, CMD_FCONCAT, @@ -580,11 +581,15 @@ main (int argc, char *argv[]) "Print the locale used for gettext"), ARGPARSE_c (CMD_GETREG, "getreg", "Print string from the Registry"), + ARGPARSE_c (CMD_MAPW32ERR, "mapw32err", + "Print the errno mapped from Windows error"), #else ARGPARSE_c (CMD_LOCALE, "locale", "@"), ARGPARSE_c (CMD_GETREG, "getreg", "@"), + ARGPARSE_c (CMD_MAPW32ERR, "mapw32err", + "@"), #endif ARGPARSE_c (CMD_FOPEN, "fopen", "Open the given file"), ARGPARSE_c (CMD_CHDIR, "chdir", "Try a chdir to the given directory"), @@ -629,6 +634,7 @@ main (int argc, char *argv[]) case CMD_LOCALE: localemode = 1; break; case CMD_GETREG: getregmode = 1; break; + case CMD_MAPW32ERR: case CMD_FOPEN: case CMD_CHDIR: case CMD_MKDIR: @@ -780,6 +786,16 @@ main (int argc, char *argv[]) else if (!quiet) printf ("success mkdir '%s'\n", *argv); } + else if (mycmd == CMD_MAPW32ERR) + { +#if HAVE_W32_SYSTEM + i = gpgrt_w32_set_errno ((int)strtol (*argv, NULL, 0)); + err = gpg_err_code_from_syserror (); + printf ("%d 0x%04x -> %d %s\n", i, i, err, gpg_strerror (err)); +#else + log_info ("this command is only useful on Windows\n"); +#endif + } else if (getregmode) { #if HAVE_W32_SYSTEM diff --git a/src/gpg-error.def.in b/src/gpg-error.def.in index 53c21d8..e45de3f 100644 --- a/src/gpg-error.def.in +++ b/src/gpg-error.def.in @@ -286,4 +286,6 @@ EXPORTS gpgrt_fconcat @223 + gpgrt_w32_set_errno @224 + ;; end of file with public symbols for Windows. diff --git a/src/protos.h b/src/protos.h index 407caf6..3360a00 100644 --- a/src/protos.h +++ b/src/protos.h @@ -27,7 +27,7 @@ void _gpgrt_free_wchar (wchar_t *wstring); char *_gpgrt_wchar_to_utf8 (const wchar_t *string, size_t length); /*-- estream.c --*/ -void _gpgrt_w32_set_errno (int ec); +int _gpgrt_w32_set_errno (int ec); gpg_err_code_t _gpgrt_w32_get_last_err_code (void); diff --git a/src/visibility.c b/src/visibility.c index 5574f33..0094c6e 100644 --- a/src/visibility.c +++ b/src/visibility.c @@ -1550,4 +1550,10 @@ gpgrt_w32_reg_get_string (const char *key) return _gpgrt_w32_reg_get_string (key); } +int +gpgrt_w32_set_errno (int ec) +{ + return _gpgrt_w32_set_errno (ec); +} + #endif /*HAVE_W32_SYSTEM*/ diff --git a/src/visibility.h b/src/visibility.h index fa2a990..2a25ca8 100644 --- a/src/visibility.h +++ b/src/visibility.h @@ -510,7 +510,7 @@ MARK_VISIBLE (gpgrt_spawn_actions_set_atfork) #define gpgrt_fname_to_wchar _gpgrt_USE_UNDERSCORED_FUNCTION #define gpgrt_w32_reg_query_string _gpgrt_USE_UNDERSCORED_FUNCTION #define gpgrt_w32_reg_get_string _gpgrt_USE_UNDERSCORED_FUNCTION - +#define gpgrt_w32_set_errno _gpgrt_USE_UNDERSCORED_FUNCTION #endif /*!_GPGRT_INCL_BY_VISIBILITY_C*/ diff --git a/src/w32-add.h b/src/w32-add.h index dd6db5d..0a9e2b9 100644 --- a/src/w32-add.h +++ b/src/w32-add.h @@ -91,3 +91,8 @@ char *gpgrt_w32_reg_query_string (const char *root, /* Query a string in the registry using a unified key representation. */ char *gpgrt_w32_reg_get_string (const char *key); + +/* Set the ERRNO from a Windows error code. This is the same mapping + * as used internally by gpgrt. If EC is -1 GetLastError() is used. + * The function returns EC or the result of GetLastError(). */ +int gpgrt_w32_set_errno (int ec); |
