Просмотр исходного кода

2009-06-02 Bill Holmes <[email protected]>

	* src/gpath.c (g_find_program_in_path):  While searching on Windows
	  also try additional suffixes .exe, .cmd, .bat, and.com.

	Contributed under MIT/X11 license.



svn path=/trunk/mono/; revision=135235
Bill Holmes 16 лет назад
Родитель
Сommit
bad8da7a7c
2 измененных файлов с 42 добавлено и 0 удалено
  1. 7 0
      eglib/ChangeLog
  2. 35 0
      eglib/src/gpath.c

+ 7 - 0
eglib/ChangeLog

@@ -1,3 +1,10 @@
+2009-06-02  Bill Holmes  <[email protected]>
+
+	* src/gpath.c (g_find_program_in_path):  While searching on Windows
+	  also try additional suffixes .exe, .cmd, .bat, and.com.
+
+	Contributed under MIT/X11 license.
+
 2009-05-27  Geoff Norton  <[email protected]>
 
 	* src/gfile-posix.c: Fix g_get_current_dir on amd64

+ 35 - 0
eglib/src/gpath.c

@@ -195,6 +195,12 @@ g_find_program_in_path (const gchar *program)
 	char *x = p, *l;
 	gchar *curdir = NULL;
 	char *save;
+#ifdef G_OS_WIN32
+	char *program_exe;
+	char *suffix_list[5] = {".exe",".cmd",".bat",".com",NULL};
+	int listx;
+	gboolean hasSuffix;
+#endif
 
 	g_return_val_if_fail (program != NULL, NULL);
 
@@ -203,6 +209,15 @@ g_find_program_in_path (const gchar *program)
 		x = curdir;
 	}
 
+#ifdef G_OS_WIN32
+	/* see if program already has a suffix */
+	listx = 0;
+	hasSuffix = FALSE;
+	while (!hasSuffix && suffix_list[listx]) {
+		hasSuffix = g_str_has_suffix(program,suffix_list[listx++]);
+	}
+#endif
+
 	while ((l = strtok_r (x, G_SEARCHPATH_SEPARATOR_S, &save)) != NULL){
 		char *probe_path; 
 		
@@ -214,6 +229,26 @@ g_find_program_in_path (const gchar *program)
 			return probe_path;
 		}
 		g_free (probe_path);
+
+#ifdef G_OS_WIN32
+		/* check for program with a suffix attached */
+		if (!hasSuffix) {
+			listx = 0;
+			while (suffix_list[listx]) {
+				program_exe = g_strjoin(NULL,program,suffix_list[listx],NULL);
+				probe_path = g_build_path (G_DIR_SEPARATOR_S, l, program_exe, NULL);
+				if (access (probe_path, X_OK) == 0){ /* FIXME: on windows this is just a read permissions test */
+					g_free (curdir);
+					g_free (p);
+					g_free (program_exe);
+					return probe_path;
+				}
+				listx++;
+				g_free (probe_path);
+				g_free (program_exe);
+			}
+		}
+#endif
 	}
 	g_free (curdir);
 	g_free (p);