2 * parse.c: Parsing for GC options.
4 * Copyright (C) 2015 Xamarin Inc
6 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
19 * mono_gc_parse_environment_string_extract_number:
21 * @str: points to the first digit of the number
22 * @out: pointer to the variable that will receive the value
24 * Tries to extract a number from the passed string, taking in to account m, k
27 * Returns true if passing was successful
30 mono_gc_parse_environment_string_extract_number (const char *str, size_t *out)
33 int len = strlen (str), shift = 0;
35 gboolean is_suffix = FALSE;
41 suffix = str [len - 1];
56 if (!isdigit (suffix))
62 val = strtol (str, &endptr, 10);
64 if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
65 || (errno != 0 && val == 0) || (endptr == str))
71 if (*(endptr + 1)) /* Invalid string. */
74 unshifted = (size_t)val;
76 if (((size_t)val >> shift) != unshifted) /* value too large */