[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] branch master updated: perf_replies: moved one function
From: |
gnunet |
Subject: |
[libmicrohttpd] branch master updated: perf_replies: moved one function to separate header |
Date: |
Mon, 10 Jul 2023 12:46:28 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
The following commit(s) were added to refs/heads/master by this push:
new d3519acb perf_replies: moved one function to separate header
d3519acb is described below
commit d3519acbbe19e693c09271d5c1186273a3273469
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Mon Jul 10 13:40:10 2023 +0300
perf_replies: moved one function to separate header
---
src/tools/Makefile.am | 2 +-
src/tools/mhd_tool_str_to_uint.h | 69 ++++++++++++++++++++++++++++++++++++++++
src/tools/perf_replies.c | 46 +++------------------------
3 files changed, 75 insertions(+), 42 deletions(-)
diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am
index 427c659f..d9064969 100644
--- a/src/tools/Makefile.am
+++ b/src/tools/Makefile.am
@@ -36,4 +36,4 @@ endif
perf_replies_SOURCES = \
- perf_replies.c
+ perf_replies.c mhd_tool_str_to_uint.h
diff --git a/src/tools/mhd_tool_str_to_uint.h b/src/tools/mhd_tool_str_to_uint.h
new file mode 100644
index 00000000..5fc91b58
--- /dev/null
+++ b/src/tools/mhd_tool_str_to_uint.h
@@ -0,0 +1,69 @@
+/*
+ This file is part of GNU libmicrohttpd
+ Copyright (C) 2023 Evgeny Grin (Karlson2k)
+
+ This library 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.
+
+ This library 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 tools/mhd_tool_str_to_uint.c
+ * @brief Implementation of HTTP server optimised for fast replies
+ * based on MHD.
+ * @author Karlson2k (Evgeny Grin)
+ */
+
+#ifndef MHD_TOOL_STR_TO_UINT_H_
+#define MHD_TOOL_STR_TO_UINT_H_
+
+#include <stddef.h>
+
+/**
+ * Convert decimal string to unsigned int.
+ * Function stops at the end of the string or on first non-digit character.
+ * @param str the string to convert
+ * @param[out] value the pointer to put the result
+ * @return return the number of digits converted or
+ * zero if no digits found or result would overflow the output
+ * variable (the output set to UINT_MAX in this case).
+ */
+static size_t
+mhd_tool_str_to_uint (const char *str, unsigned int *value)
+{
+ size_t i;
+ unsigned int v = 0;
+ *value = 0;
+
+ for (i = 0; 0 != str[i]; ++i)
+ {
+ const char chr = str[i];
+ unsigned int digit;
+ if (('0' > chr) || ('9' < chr))
+ break;
+ digit = (unsigned char) (chr - '0');
+ if ((((0U - 1) / 10) < v) || ((v * 10 + digit) < v))
+ {
+ /* Overflow */
+ *value = 0U - 1;
+ return 0;
+ }
+ v *= 10;
+ v += digit;
+ }
+ *value = v;
+ return i;
+}
+
+
+#endif /* MHD_TOOL_STR_TO_UINT_H_ */
diff --git a/src/tools/perf_replies.c b/src/tools/perf_replies.c
index 49a7a1f2..1b2fc533 100644
--- a/src/tools/perf_replies.c
+++ b/src/tools/perf_replies.c
@@ -26,7 +26,7 @@
*/
/**
- * @file examples/perf_replies.c
+ * @file tools/perf_replies.c
* @brief Implementation of HTTP server optimised for fast replies
* based on MHD.
* @author Karlson2k (Evgeny Grin)
@@ -38,6 +38,7 @@
#include <stdint.h>
#include "mhd_options.h"
#include "microhttpd.h"
+#include "mhd_tool_str_to_uint.h"
#if defined(MHD_REAL_CPU_COUNT)
#if MHD_REAL_CPU_COUNT == 0
@@ -106,43 +107,6 @@ set_self_name (int argc, char *const *argv)
}
-/**
- * Convert decimal string to unsigned int.
- * Function stops at the end of the string or on first non-digit character.
- * @param str the string to convert
- * @param[out] value the pointer to put the result
- * @return return the number of digits converted or
- * zero if no digits found or result would overflow the output
- * variable (the output set to UINT_MAX in this case).
- */
-static size_t
-str_to_uint (const char *str, unsigned int *value)
-{
- size_t i;
- unsigned int v = 0;
- *value = 0;
-
- for (i = 0; 0 != str[i]; ++i)
- {
- const char chr = str[i];
- unsigned int digit;
- if (('0' > chr) || ('9' < chr))
- break;
- digit = (unsigned char) (chr - '0');
- if ((((0U - 1) / 10) < v) || ((v * 10 + digit) < v))
- {
- /* Overflow */
- *value = 0U - 1;
- return 0;
- }
- v *= 10;
- v += digit;
- }
- *value = v;
- return i;
-}
-
-
#if defined (HAVE_POPEN) && defined(HAVE_PCLOSE)
/**
* Read the command output as a number and return the number.
@@ -175,7 +139,7 @@ get_cmd_out_as_number (const char *cmd)
{
size_t digits_found;
unsigned int out_value;
- digits_found = str_to_uint (buf, &out_value);
+ digits_found = mhd_tool_str_to_uint (buf, &out_value);
if (0 != digits_found)
{
if ((0 == buf[digits_found])
@@ -302,7 +266,7 @@ get_param_value (const char *param_name, const char
*param_tail,
value_str = next_param;
if (NULL != value_str)
- digits = str_to_uint (value_str, param_value);
+ digits = mhd_tool_str_to_uint (value_str, param_value);
else
digits = 0;
@@ -1033,7 +997,7 @@ process_params (int argc, char *const *argv)
/* Process the port number */
unsigned int read_port;
size_t num_digits;
- num_digits = str_to_uint (p, &read_port);
+ num_digits = mhd_tool_str_to_uint (p, &read_port);
if (0 != p[num_digits])
{
fprintf (stderr, "Error in specified port number: %s\n", p);
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libmicrohttpd] branch master updated: perf_replies: moved one function to separate header,
gnunet <=