aboutsummaryrefslogtreecommitdiff
path: root/src/tools/perf_replies.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/perf_replies.c')
-rw-r--r--src/tools/perf_replies.c46
1 files changed, 5 insertions, 41 deletions
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 @@
26*/ 26*/
27 27
28/** 28/**
29 * @file examples/perf_replies.c 29 * @file tools/perf_replies.c
30 * @brief Implementation of HTTP server optimised for fast replies 30 * @brief Implementation of HTTP server optimised for fast replies
31 * based on MHD. 31 * based on MHD.
32 * @author Karlson2k (Evgeny Grin) 32 * @author Karlson2k (Evgeny Grin)
@@ -38,6 +38,7 @@
38#include <stdint.h> 38#include <stdint.h>
39#include "mhd_options.h" 39#include "mhd_options.h"
40#include "microhttpd.h" 40#include "microhttpd.h"
41#include "mhd_tool_str_to_uint.h"
41 42
42#if defined(MHD_REAL_CPU_COUNT) 43#if defined(MHD_REAL_CPU_COUNT)
43#if MHD_REAL_CPU_COUNT == 0 44#if MHD_REAL_CPU_COUNT == 0
@@ -106,43 +107,6 @@ set_self_name (int argc, char *const *argv)
106} 107}
107 108
108 109
109/**
110 * Convert decimal string to unsigned int.
111 * Function stops at the end of the string or on first non-digit character.
112 * @param str the string to convert
113 * @param[out] value the pointer to put the result
114 * @return return the number of digits converted or
115 * zero if no digits found or result would overflow the output
116 * variable (the output set to UINT_MAX in this case).
117 */
118static size_t
119str_to_uint (const char *str, unsigned int *value)
120{
121 size_t i;
122 unsigned int v = 0;
123 *value = 0;
124
125 for (i = 0; 0 != str[i]; ++i)
126 {
127 const char chr = str[i];
128 unsigned int digit;
129 if (('0' > chr) || ('9' < chr))
130 break;
131 digit = (unsigned char) (chr - '0');
132 if ((((0U - 1) / 10) < v) || ((v * 10 + digit) < v))
133 {
134 /* Overflow */
135 *value = 0U - 1;
136 return 0;
137 }
138 v *= 10;
139 v += digit;
140 }
141 *value = v;
142 return i;
143}
144
145
146#if defined (HAVE_POPEN) && defined(HAVE_PCLOSE) 110#if defined (HAVE_POPEN) && defined(HAVE_PCLOSE)
147/** 111/**
148 * Read the command output as a number and return the number. 112 * Read the command output as a number and return the number.
@@ -175,7 +139,7 @@ get_cmd_out_as_number (const char *cmd)
175 { 139 {
176 size_t digits_found; 140 size_t digits_found;
177 unsigned int out_value; 141 unsigned int out_value;
178 digits_found = str_to_uint (buf, &out_value); 142 digits_found = mhd_tool_str_to_uint (buf, &out_value);
179 if (0 != digits_found) 143 if (0 != digits_found)
180 { 144 {
181 if ((0 == buf[digits_found]) 145 if ((0 == buf[digits_found])
@@ -302,7 +266,7 @@ get_param_value (const char *param_name, const char *param_tail,
302 value_str = next_param; 266 value_str = next_param;
303 267
304 if (NULL != value_str) 268 if (NULL != value_str)
305 digits = str_to_uint (value_str, param_value); 269 digits = mhd_tool_str_to_uint (value_str, param_value);
306 else 270 else
307 digits = 0; 271 digits = 0;
308 272
@@ -1033,7 +997,7 @@ process_params (int argc, char *const *argv)
1033 /* Process the port number */ 997 /* Process the port number */
1034 unsigned int read_port; 998 unsigned int read_port;
1035 size_t num_digits; 999 size_t num_digits;
1036 num_digits = str_to_uint (p, &read_port); 1000 num_digits = mhd_tool_str_to_uint (p, &read_port);
1037 if (0 != p[num_digits]) 1001 if (0 != p[num_digits])
1038 { 1002 {
1039 fprintf (stderr, "Error in specified port number: %s\n", p); 1003 fprintf (stderr, "Error in specified port number: %s\n", p);