3 * Parsing for GC options.
5 * Copyright (C) 2015 Xamarin Inc
7 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
20 * mono_gc_parse_environment_string_extract_number:
22 * @str: points to the first digit of the number
23 * @out: pointer to the variable that will receive the value
25 * Tries to extract a number from the passed string, taking in to account m, k
28 * Returns true if passing was successful
31 mono_gc_parse_environment_string_extract_number (const char *str, size_t *out)
34 int len = strlen (str), shift = 0;
36 gboolean is_suffix = FALSE;
42 suffix = str [len - 1];
57 if (!isdigit (suffix))
63 val = strtol (str, &endptr, 10);
65 if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
66 || (errno != 0 && val == 0) || (endptr == str))
72 if (*(endptr + 1)) /* Invalid string. */
75 unshifted = (size_t)val;
77 if (((size_t)val >> shift) != unshifted) /* value too large */