Revert "Windows: Use a customized struct stat that also has the st_blocks member."
[gitweb.git] / compat / mingw.c
index 2e4755544320b78e71e00a187b95973079be9054..ccfa2a0a3d3263862beb0d2796be1aba78574986 100644 (file)
@@ -346,6 +346,19 @@ char *mingw_getcwd(char *pointer, int len)
        return ret;
 }
 
+#undef getenv
+char *mingw_getenv(const char *name)
+{
+       char *result = getenv(name);
+       if (!result && !strcmp(name, "TMPDIR")) {
+               /* on Windows it is TMP and TEMP */
+               result = getenv("TMP");
+               if (!result)
+                       result = getenv("TEMP");
+       }
+       return result;
+}
+
 /*
  * See http://msdn2.microsoft.com/en-us/library/17w5ykft(vs.71).aspx
  * (Parsing C++ Command-Line Arguments)
@@ -503,7 +516,8 @@ static char *lookup_prog(const char *dir, const char *cmd, int isexe, int exe_on
                return xstrdup(path);
        path[strlen(path)-4] = '\0';
        if ((!exe_only || isexe) && access(path, F_OK) == 0)
-               return xstrdup(path);
+               if (!(GetFileAttributes(path) & FILE_ATTRIBUTE_DIRECTORY))
+                       return xstrdup(path);
        return NULL;
 }
 
@@ -984,3 +998,25 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler)
        timer_fn = handler;
        return old;
 }
+
+static const char *make_backslash_path(const char *path)
+{
+       static char buf[PATH_MAX + 1];
+       char *c;
+
+       if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
+               die("Too long path: %.*s", 60, path);
+
+       for (c = buf; *c; c++) {
+               if (*c == '/')
+                       *c = '\\';
+       }
+       return buf;
+}
+
+void mingw_open_html(const char *unixpath)
+{
+       const char *htmlpath = make_backslash_path(unixpath);
+       printf("Launching default browser to display HTML ...\n");
+       ShellExecute(NULL, "open", htmlpath, NULL, "\\", 0);
+}