GNU libmicrohttpd 1.0.1
Loading...
Searching...
No Matches
mhd_tool_str_to_uint.h
Go to the documentation of this file.
1/*
2 This file is part of GNU libmicrohttpd
3 Copyright (C) 2023 Evgeny Grin (Karlson2k)
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
26#ifndef MHD_TOOL_STR_TO_UINT_H_
27#define MHD_TOOL_STR_TO_UINT_H_ 1
28
29#include <stddef.h>
30
40static size_t
41mhd_tool_str_to_uint (const char *str, unsigned int *value)
42{
43 size_t i;
44 unsigned int v = 0;
45 *value = 0;
46
47 for (i = 0; 0 != str[i]; ++i)
48 {
49 const char chr = str[i];
50 unsigned int digit;
51 if (('0' > chr) || ('9' < chr))
52 break;
53 digit = (unsigned char) (chr - '0');
54 if ((((0U - 1) / 10) < v) || ((v * 10 + digit) < v))
55 {
56 /* Overflow */
57 *value = 0U - 1;
58 return 0;
59 }
60 v *= 10;
61 v += digit;
62 }
63 *value = v;
64 return i;
65}
66
67
68#endif /* MHD_TOOL_STR_TO_UINT_H_ */
#define MHD_HTTP_OK
Definition microhttpd.h:344
static size_t mhd_tool_str_to_uint(const char *str, unsigned int *value)