+/* Parse the OMP_STACKSIZE environment varible. Return true if one was
+ present and it was successfully parsed. */
+
+static bool
+parse_stacksize (const char *name, unsigned long *pvalue)
+{
+ char *env, *end;
+ unsigned long value, shift = 10;
+
+ env = getenv (name);
+ if (env == NULL)
+ return false;
+
+ while (isspace ((unsigned char) *env))
+ ++env;
+ if (*env == '\0')
+ goto invalid;
+
+ errno = 0;
+ value = strtoul (env, &end, 10);
+ if (errno)
+ goto invalid;
+
+ while (isspace ((unsigned char) *end))
+ ++end;
+ if (*end != '\0')
+ {
+ switch (tolower ((unsigned char) *end))
+ {
+ case 'b':
+ shift = 0;
+ break;
+ case 'k':
+ break;
+ case 'm':
+ shift = 20;
+ break;
+ case 'g':
+ shift = 30;
+ break;
+ default:
+ goto invalid;
+ }
+ ++end;
+ while (isspace ((unsigned char) *end))
+ ++end;
+ if (*end != '\0')
+ goto invalid;
+ }
+
+ if (((value << shift) >> shift) != value)
+ goto invalid;
+
+ *pvalue = value << shift;
+ return true;
+
+ invalid:
+ gomp_error ("Invalid value for environment variable %s", name);
+ return false;
+}
+
+/* Parse the GOMP_SPINCOUNT environment varible. Return true if one was
+ present and it was successfully parsed. */
+
+static bool
+parse_spincount (const char *name, unsigned long long *pvalue)
+{
+ char *env, *end;
+ unsigned long long value, mult = 1;
+
+ env = getenv (name);
+ if (env == NULL)
+ return false;
+
+ while (isspace ((unsigned char) *env))
+ ++env;
+ if (*env == '\0')
+ goto invalid;
+
+ if (strncasecmp (env, "infinite", 8) == 0
+ || strncasecmp (env, "infinity", 8) == 0)
+ {
+ value = ~0ULL;
+ end = env + 8;
+ goto check_tail;
+ }
+
+ errno = 0;
+ value = strtoull (env, &end, 10);
+ if (errno)
+ goto invalid;
+
+ while (isspace ((unsigned char) *end))
+ ++end;
+ if (*end != '\0')
+ {
+ switch (tolower ((unsigned char) *end))
+ {
+ case 'k':
+ mult = 1000LL;
+ break;
+ case 'm':
+ mult = 1000LL * 1000LL;
+ break;
+ case 'g':
+ mult = 1000LL * 1000LL * 1000LL;
+ break;
+ case 't':
+ mult = 1000LL * 1000LL * 1000LL * 1000LL;
+ break;
+ default:
+ goto invalid;
+ }
+ ++end;
+ check_tail:
+ while (isspace ((unsigned char) *end))
+ ++end;
+ if (*end != '\0')
+ goto invalid;
+ }
+
+ if (value > ~0ULL / mult)
+ value = ~0ULL;
+ else
+ value *= mult;
+
+ *pvalue = value;
+ return true;
+
+ invalid:
+ gomp_error ("Invalid value for environment variable %s", name);
+ return false;
+}
+
+/* Parse a boolean value for environment variable NAME and store the