use labs() for variables of type long instead of abs()
[gitweb.git] / compat / mingw.c
index 968e8d3c3ec9b579c77110dc8991b99d7dd7649e..c5c37e53ce0fc534b1739a75c4abde0c67027d14 100644 (file)
@@ -1251,7 +1251,7 @@ static int do_putenv(char **env, const char *name, int size, int free_old)
        return size;
 }
 
-static char *do_getenv(const char *name)
+char *mingw_getenv(const char *name)
 {
        char *value;
        int pos = bsearchenv(environ, name, environ_size - 1);
@@ -1261,18 +1261,6 @@ static char *do_getenv(const char *name)
        return value ? &value[1] : NULL;
 }
 
-char *mingw_getenv(const char *name)
-{
-       char *result = do_getenv(name);
-       if (!result && !strcmp(name, "TMPDIR")) {
-               /* on Windows it is TMP and TEMP */
-               result = do_getenv("TMP");
-               if (!result)
-                       result = do_getenv("TEMP");
-       }
-       return result;
-}
-
 int mingw_putenv(const char *namevalue)
 {
        ALLOC_GROW(environ, (environ_size + 1) * sizeof(char*), environ_alloc);
@@ -1322,8 +1310,7 @@ static int WSAAPI getaddrinfo_stub(const char *node, const char *service,
        else
                ai->ai_canonname = NULL;
 
-       sin = xmalloc(ai->ai_addrlen);
-       memset(sin, 0, ai->ai_addrlen);
+       sin = xcalloc(1, ai->ai_addrlen);
        sin->sin_family = AF_INET;
        /* Note: getaddrinfo is supposed to allow service to be a string,
         * which should be looked up using getservbyname. This is
@@ -2114,6 +2101,21 @@ void mingw_startup()
        /* sort environment for O(log n) getenv / putenv */
        qsort(environ, i, sizeof(char*), compareenv);
 
+       /* fix Windows specific environment settings */
+
+       /* on Windows it is TMP and TEMP */
+       if (!mingw_getenv("TMPDIR")) {
+               const char *tmp = mingw_getenv("TMP");
+               if (!tmp)
+                       tmp = mingw_getenv("TEMP");
+               if (tmp)
+                       setenv("TMPDIR", tmp, 1);
+       }
+
+       /* simulate TERM to enable auto-color (see color.c) */
+       if (!getenv("TERM"))
+               setenv("TERM", "cygwin", 1);
+
        /* initialize critical section for waitpid pinfo_t list */
        InitializeCriticalSection(&pinfo_cs);