2 * parse.c: Parsing for GC options.
4 * Copyright (C) 2015 Xamarin Inc
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License 2.0 as published by the Free Software Foundation;
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 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License 2.0 along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 * mono_gc_parse_environment_string_extract_number:
32 * @str: points to the first digit of the number
33 * @out: pointer to the variable that will receive the value
35 * Tries to extract a number from the passed string, taking in to account m, k
38 * Returns true if passing was successful
41 mono_gc_parse_environment_string_extract_number (const char *str, size_t *out)
44 int len = strlen (str), shift = 0;
46 gboolean is_suffix = FALSE;
52 suffix = str [len - 1];
67 if (!isdigit (suffix))
73 val = strtol (str, &endptr, 10);
75 if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
76 || (errno != 0 && val == 0) || (endptr == str))
82 if (*(endptr + 1)) /* Invalid string. */
85 unshifted = (size_t)val;
87 if (((size_t)val >> shift) != unshifted) /* value too large */