diff options
author | Christian Franke <christian.franke@t-online.de> | 2024-02-26 13:37:33 +0100 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2024-02-26 15:56:10 +0100 |
commit | b55eed943b85a72b76a0a2f5738dfb9aad1982ea (patch) | |
tree | a87317974af5fe2d11ab0ad43028902df9f99183 /winsup | |
parent | 4af5f9d51e1da51647c365754dadc202ac33f8f2 (diff) | |
download | newlib-b55eed943b85a72b76a0a2f5738dfb9aad1982ea.zip newlib-b55eed943b85a72b76a0a2f5738dfb9aad1982ea.tar.gz newlib-b55eed943b85a72b76a0a2f5738dfb9aad1982ea.tar.bz2 |
Cygwin: introduce constexpr errmap_size and errmap[] consistency checks
Use constexpr instead of const for errmap[] to allow static_assert
checks on its values.
Signed-off-by: Christian Franke <christian.franke@t-online.de>
Diffstat (limited to 'winsup')
-rw-r--r-- | winsup/cygwin/errno.cc | 2 | ||||
-rw-r--r-- | winsup/cygwin/local_includes/errmap.h | 11 |
2 files changed, 11 insertions, 2 deletions
diff --git a/winsup/cygwin/errno.cc b/winsup/cygwin/errno.cc index 1c85e9a..7d58e62 100644 --- a/winsup/cygwin/errno.cc +++ b/winsup/cygwin/errno.cc @@ -185,7 +185,7 @@ geterrno_from_win_error (DWORD code, int deferrno) { /* A 0-value in errmap means, we don't handle this windows error explicitely. Fall back to deferrno in these cases. */ - if (code < sizeof errmap / sizeof errmap[0] && errmap[code]) + if (code < errmap_size && errmap[code]) { syscall_printf ("windows error %u == errno %d", code, errmap[code]); return errmap[code]; diff --git a/winsup/cygwin/local_includes/errmap.h b/winsup/cygwin/local_includes/errmap.h index a0b3ff4..737c01c 100644 --- a/winsup/cygwin/local_includes/errmap.h +++ b/winsup/cygwin/local_includes/errmap.h @@ -3,7 +3,7 @@ to this new array manually on demand. */ /* FIXME: Some of these choices are arbitrary! */ -static const int errmap[] = +constexpr int errmap[] = { 0, /* ERROR_SUCCESS */ EBADRQC, /* ERROR_INVALID_FUNCTION */ @@ -9006,3 +9006,12 @@ static const int errmap[] = 0, /* 8998 */ 0, /* 8999 */ }; + +constexpr unsigned errmap_size = sizeof (errmap) / sizeof (errmap[0]); + +/* Some consistency checks. */ +static_assert (errmap_size == 8999 + 1); +static_assert (EINTR == errmap[/* 104 */ ERROR_INVALID_AT_INTERRUPT_TIME]); +static_assert (ENXIO == errmap[/* 1006 */ ERROR_FILE_INVALID]); +static_assert (EAGAIN == errmap[/* 2404 */ ERROR_DEVICE_IN_USE]); +static_assert (EIO == errmap[/* 8341 */ ERROR_DS_GENERIC_ERROR]); |