From cb09c6e71da46cab4d4b964355db7e9f3bb63eb4 Mon Sep 17 00:00:00 2001 From: "Evgeny Grin (Karlson2k)" Date: Mon, 18 Nov 2024 16:49:27 +0300 Subject: [PATCH] mhd_arr_num_elems: added new helper macro --- src/mhd2/Makefile.am | 2 +- src/mhd2/http_status_str.c | 3 ++- src/mhd2/mhd_arr_num_elems.h | 37 ++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/mhd2/mhd_arr_num_elems.h diff --git a/src/mhd2/Makefile.am b/src/mhd2/Makefile.am index ef7cec2c..70fc8696 100644 --- a/src/mhd2/Makefile.am +++ b/src/mhd2/Makefile.am @@ -33,7 +33,7 @@ libmicrohttpd2_la_SOURCES = \ compat_calloc.h \ sys_w32_ver.h \ mhd_assert.h \ - mhd_cntnr_ptr.h \ + mhd_cntnr_ptr.h mhd_arr_num_elems.h \ mhd_tristate.h \ mhd_socket_type.h mhd_sockets_macros.h \ mhd_sockets_funcs.c mhd_sockets_funcs.h \ diff --git a/src/mhd2/http_status_str.c b/src/mhd2/http_status_str.c index f00c46e7..64919844 100644 --- a/src/mhd2/http_status_str.c +++ b/src/mhd2/http_status_str.c @@ -32,6 +32,7 @@ #include "sys_base_types.h" #include "mhd_public_api.h" #include "mhd_str_macros.h" +#include "mhd_arr_num_elems.h" #define UNUSED_STATUS {0, NULL} @@ -165,7 +166,7 @@ struct mhd_HttpStatusesBlock const struct MHD_String *const data; }; -#define STATUSES_BLOCK(m) { (sizeof(m) / sizeof(m[0])), m} +#define STATUSES_BLOCK(m) { mhd_ARR_NUM_ELEMS (m), m} static const struct mhd_HttpStatusesBlock statuses[] = { STATUSES_BLOCK (invalid_hundred), diff --git a/src/mhd2/mhd_arr_num_elems.h b/src/mhd2/mhd_arr_num_elems.h new file mode 100644 index 00000000..7caecad0 --- /dev/null +++ b/src/mhd2/mhd_arr_num_elems.h @@ -0,0 +1,37 @@ +/* + This file is part of GNU libmicrohttpd + Copyright (C) 2024 Evgeny Grin (Karlson2k) + + GNU libmicrohttpd is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + GNU libmicrohttpd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/** + * @file src/mhd2/mhd_arr_num_elements.h + * @brief The definition of mhd_ARR_NUM_ELEMS macro + * @author Karlson2k (Evgeny Grin) + */ + +#ifndef MHD_ARR_NUM_ELEMS_H +#define MHD_ARR_NUM_ELEMS_H 1 + +#include "mhd_sys_options.h" + +/** + * Get the number of elements in the array + */ +#define mhd_ARR_NUM_ELEMS(arr) (sizeof(arr) / sizeof(arr[0])) + +#endif /* ! MHD_ARR_NUM_ELEMS_H */