Index: trunk/src/emx/include/stdlib.h
===================================================================
--- trunk/src/emx/include/stdlib.h	(revision 1982)
+++ trunk/src/emx/include/stdlib.h	(revision 1983)
@@ -292,5 +292,8 @@
 #ifdef __BSD_VISIBLE
 char    *_getcwdux(char *, size_t);
-char	*_realrealpath(const char *, char *, size_t);
+char    *_realrealpath(const char *, char *, size_t);
+int     _getenv_longlong(const char *, long long *);
+int     _getenv_long(const char *, long *);
+int     _getenv_int(const char *, int *);
 #endif
 #ifdef  __USE_GNU
Index: trunk/src/emx/src/lib/app/_getenv_int.c
===================================================================
--- trunk/src/emx/src/lib/app/_getenv_int.c	(revision 1983)
+++ trunk/src/emx/src/lib/app/_getenv_int.c	(revision 1983)
@@ -0,0 +1,115 @@
+/* $Id$ */
+/** @file
+ *
+ * LIBC - _getenv_int
+ *
+ * Copyright (c) 2005 knut st. osmundsen <bird@anduin.net>
+ *
+ *
+ * This file is part of kBuild.
+ *
+ * kBuild is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * kBuild is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with kBuild; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include "libc-alias.h"
+#include <stdlib.h>
+
+
+/**
+ * Gets a long long value from an environment variable.
+ *
+ * @return 0 on success.
+ * @return -1 on failure.
+ *
+ * @param   pszEnvVar       The name of the environment variable.
+ * @param   pll             Where to store the result.
+ * @remark  This is a LIBC extension.
+ */
+int _getenv_longlong(const char *pszEnvVar, long long *pll)
+{
+    const char *pszValue = getenv(pszEnvVar);
+    if (pszValue)
+    {
+        char *pszType;
+        long long ll = strtoll(pszValue, &pszType, 0);
+        if (    pszType != pszValue
+            &&  (!pszType[0] || !pszType[1]))
+        {
+            switch (pszType[0])
+            {
+                case 't': case 'T': ll *= 1024LL*1024LL*1024LL*1024LL; break;
+                case 'g': case 'G': ll *= 1024*1024*1024; break;
+                case 'm': case 'M': ll *= 1024*1024; break;
+                case 'k': case 'K': ll *= 1024; break;
+                case '\0': break;
+                default:
+                    return -1;
+            }
+            *pll = ll;
+            return 0;
+        }
+    }
+    return -1;
+}
+
+
+/**
+ * Gets a long value from an environment variable.
+ *
+ * @return 0 on success.
+ * @return -1 on failure.
+ *
+ * @param   pszEnvVar       The name of the environment variable.
+ * @param   pl              Where to store the result.
+ * @remark  This is a LIBC extension.
+ */
+int _getenv_long(const char *pszEnvVar, long *pl)
+{
+    long long ll;
+    if (!_getenv_longlong(pszEnvVar, &ll))
+    {
+        *pl = (long)ll;
+        return 0;
+    }
+    return -1;
+}
+
+
+/**
+ * Gets an integer value from an environment variable.
+ *
+ * @return 0 on success.
+ * @return -1 on failure.
+ *
+ * @param   pszEnvVar       The name of the environment variable.
+ * @param   pi              Where to store the result.
+ * @remark  This is a LIBC extension.
+ */
+int _getenv_int(const char *pszEnvVar, int *pi)
+{
+    long long ll;
+    if (!_getenv_longlong(pszEnvVar, &ll))
+    {
+        *pi = (int)ll;
+        return 0;
+    }
+    return -1;
+}
+
Index: trunk/src/emx/src/lib/process/beginthr.c
===================================================================
--- trunk/src/emx/src/lib/process/beginthr.c	(revision 1982)
+++ trunk/src/emx/src/lib/process/beginthr.c	(revision 1983)
@@ -66,12 +66,6 @@
         if (!cbStackMin)
         {
-            const char *psz = getenv("LIBC_THREAD_MIN_STACK_SIZE");
             int cb = 4096;
-            if (psz)
-            {
-                cb = atol(psz);
-                if (!cb)
-                    cb = 512*1024;
-            }
+            _getenv_int("LIBC_THREAD_MIN_STACK_SIZE", &cb);
             __atomic_xchg((unsigned volatile *)&cbStackMin, cb);
         }
