summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip@tecnocode.co.uk>2023-02-13 17:31:28 +0000
committerPhilip Withnall <philip@tecnocode.co.uk>2023-02-13 17:31:28 +0000
commitf5b2aeaf395c07992b230b5dbccbfc8c01ee6618 (patch)
treeb00ea4c33c57524990d48827e4eee4117b1573b7
parent585c7d2db6660aece666090cece84efcef0b0ab9 (diff)
parenta359e56f58864e0845a6c9a1071c9fbc0a1ed6c5 (diff)
downloadglib-f5b2aeaf395c07992b230b5dbccbfc8c01ee6618.tar.gz
Merge branch '2876-api-public-or-internal' into 'main'
gutils: Make g_find_program_for_path() a proper private API Closes #2876 See merge request GNOME/glib!3267
-rw-r--r--gio/gdesktopappinfo.c14
-rw-r--r--glib/glib-private.c2
-rw-r--r--glib/glib-private.h9
-rw-r--r--glib/gutilsprivate.h6
-rw-r--r--glib/tests/utils.c34
5 files changed, 39 insertions, 26 deletions
diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c
index 5429983da..30fcb2937 100644
--- a/gio/gdesktopappinfo.c
+++ b/gio/gdesktopappinfo.c
@@ -1914,7 +1914,7 @@ g_desktop_app_info_load_from_keyfile (GDesktopAppInfo *info,
{
char *t;
/* Use the desktop file path (if any) as working dir to search program */
- t = g_find_program_for_path (try_exec, NULL, path);
+ t = GLIB_PRIVATE_CALL (g_find_program_for_path) (try_exec, NULL, path);
if (t == NULL)
{
g_free (path);
@@ -1947,7 +1947,7 @@ g_desktop_app_info_load_from_keyfile (GDesktopAppInfo *info,
* argument, so dereferencing argv[0] should return non-NULL. */
g_assert (argc > 0);
/* Use the desktop file path (if any) as working dir to search program */
- t = g_find_program_for_path (argv[0], NULL, path);
+ t = GLIB_PRIVATE_CALL (g_find_program_for_path) (argv[0], NULL, path);
g_strfreev (argv);
if (t == NULL)
@@ -2731,8 +2731,8 @@ prepend_terminal_to_vector (int *argc,
for (i = 0, found_terminal = NULL; i < G_N_ELEMENTS (known_terminals); i++)
{
- found_terminal = g_find_program_for_path (known_terminals[i].exec,
- path, working_dir);
+ found_terminal = GLIB_PRIVATE_CALL (g_find_program_for_path) (known_terminals[i].exec,
+ path, working_dir);
if (found_terminal != NULL)
{
term_arg = known_terminals[i].exec_arg;
@@ -2984,9 +2984,9 @@ g_desktop_app_info_launch_uris_with_spawn (GDesktopAppInfo *info,
{
const char *env_path = g_environ_getenv (envp, "PATH");
- program_path = g_find_program_for_path (program,
- env_path,
- info->path);
+ program_path = GLIB_PRIVATE_CALL (g_find_program_for_path) (program,
+ env_path,
+ info->path);
}
if (program_path)
diff --git a/glib/glib-private.c b/glib/glib-private.c
index 905da361a..6b2205f86 100644
--- a/glib/glib-private.c
+++ b/glib/glib-private.c
@@ -67,6 +67,8 @@ glib__private__ (void)
g_win32_push_empty_invalid_parameter_handler,
g_win32_pop_invalid_parameter_handler,
+
+ g_find_program_for_path,
};
return &table;
diff --git a/glib/glib-private.h b/glib/glib-private.h
index e3a4f1d73..85bea5ffe 100644
--- a/glib/glib-private.h
+++ b/glib/glib-private.h
@@ -154,6 +154,10 @@ typedef struct _GWin32InvalidParameterHandler GWin32InvalidParameterHandler;
void g_win32_push_empty_invalid_parameter_handler (GWin32InvalidParameterHandler *items);
void g_win32_pop_invalid_parameter_handler (GWin32InvalidParameterHandler *items);
+char *g_find_program_for_path (const char *program,
+ const char *path,
+ const char *working_dir);
+
#define GLIB_PRIVATE_CALL(symbol) (glib__private__()->symbol)
@@ -213,6 +217,11 @@ typedef struct {
void (* g_win32_pop_invalid_parameter_handler) (GWin32InvalidParameterHandler *items);
+ /* See gutils.c */
+ char *(* g_find_program_for_path) (const char *program,
+ const char *path,
+ const char *working_dir);
+
/* Add other private functions here, initialize them in glib-private.c */
} GLibPrivateVTable;
diff --git a/glib/gutilsprivate.h b/glib/gutilsprivate.h
index 0d9b0df14..24c199305 100644
--- a/glib/gutilsprivate.h
+++ b/glib/gutilsprivate.h
@@ -28,15 +28,9 @@
G_BEGIN_DECLS
-GLIB_AVAILABLE_IN_2_60
void g_set_user_dirs (const gchar *first_dir_type,
...) G_GNUC_NULL_TERMINATED;
-GLIB_AVAILABLE_IN_2_76
-char * g_find_program_for_path (const char *program,
- const char *path,
- const char *working_dir);
-
/* Returns the smallest power of 2 greater than or equal to n,
* or 0 if such power does not fit in a gsize
*/
diff --git a/glib/tests/utils.c b/glib/tests/utils.c
index afa6cad9f..c570c8000 100644
--- a/glib/tests/utils.c
+++ b/glib/tests/utils.c
@@ -487,6 +487,14 @@ test_find_program (void)
g_assert (res == NULL);
}
+static char *
+find_program_for_path (const char *program,
+ const char *path,
+ const char *working_dir)
+{
+ return GLIB_PRIVATE_CALL(g_find_program_for_path) (program, path, working_dir);
+}
+
static void
test_find_program_for_path (void)
{
@@ -517,9 +525,9 @@ test_find_program_for_path (void)
g_assert_true (g_file_test (exe_path, G_FILE_TEST_IS_EXECUTABLE));
g_assert_null (g_find_program_in_path (command_to_find));
- g_assert_null (g_find_program_for_path (command_to_find, NULL, NULL));
+ g_assert_null (find_program_for_path (command_to_find, NULL, NULL));
- found_path = g_find_program_for_path (command_to_find, path, NULL);
+ found_path = find_program_for_path (command_to_find, path, NULL);
#ifdef __APPLE__
g_assert_nonnull (found_path);
g_assert_true (g_str_has_suffix (found_path, exe_path));
@@ -528,7 +536,7 @@ test_find_program_for_path (void)
#endif
g_clear_pointer (&found_path, g_free);
- found_path = g_find_program_for_path (command_to_find, path, path);
+ found_path = find_program_for_path (command_to_find, path, path);
#ifdef __APPLE__
g_assert_nonnull (found_path);
g_assert_true (g_str_has_suffix (found_path, exe_path));
@@ -537,7 +545,7 @@ test_find_program_for_path (void)
#endif
g_clear_pointer (&found_path, g_free);
- found_path = g_find_program_for_path (command_to_find, NULL, path);
+ found_path = find_program_for_path (command_to_find, NULL, path);
#ifdef __APPLE__
g_assert_nonnull (found_path);
g_assert_true (g_str_has_suffix (found_path, exe_path));
@@ -546,7 +554,7 @@ test_find_program_for_path (void)
#endif
g_clear_pointer (&found_path, g_free);
- found_path = g_find_program_for_path (command_to_find, "::", path);
+ found_path = find_program_for_path (command_to_find, "::", path);
#ifdef __APPLE__
g_assert_nonnull (found_path);
g_assert_true (g_str_has_suffix (found_path, exe_path));
@@ -558,7 +566,7 @@ test_find_program_for_path (void)
old_cwd = g_get_current_dir ();
g_chdir (path);
found_path =
- g_find_program_for_path (command_to_find,
+ find_program_for_path (command_to_find,
G_SEARCHPATH_SEPARATOR_S G_SEARCHPATH_SEPARATOR_S, NULL);
g_chdir (old_cwd);
g_clear_pointer (&old_cwd, g_free);
@@ -573,7 +581,7 @@ test_find_program_for_path (void)
old_cwd = g_get_current_dir ();
g_chdir (tmp);
found_path =
- g_find_program_for_path (command_to_find,
+ find_program_for_path (command_to_find,
G_SEARCHPATH_SEPARATOR_S G_SEARCHPATH_SEPARATOR_S, "sub-path");
g_chdir (old_cwd);
g_clear_pointer (&old_cwd, g_free);
@@ -586,10 +594,10 @@ test_find_program_for_path (void)
g_clear_pointer (&found_path, g_free);
g_assert_null (
- g_find_program_for_path (command_to_find,
+ find_program_for_path (command_to_find,
G_SEARCHPATH_SEPARATOR_S G_SEARCHPATH_SEPARATOR_S, "other-sub-path"));
- found_path = g_find_program_for_path (command_to_find,
+ found_path = find_program_for_path (command_to_find,
G_SEARCHPATH_SEPARATOR_S "sub-path" G_SEARCHPATH_SEPARATOR_S, tmp);
#ifdef __APPLE__
g_assert_nonnull (found_path);
@@ -599,23 +607,23 @@ test_find_program_for_path (void)
#endif
g_clear_pointer (&found_path, g_free);
- g_assert_null (g_find_program_for_path (command_to_find,
+ g_assert_null (find_program_for_path (command_to_find,
G_SEARCHPATH_SEPARATOR_S "other-sub-path" G_SEARCHPATH_SEPARATOR_S, tmp));
#ifdef G_OS_UNIX
- found_path = g_find_program_for_path ("sh", NULL, tmp);
+ found_path = find_program_for_path ("sh", NULL, tmp);
g_assert_nonnull (found_path);
g_clear_pointer (&found_path, g_free);
old_cwd = g_get_current_dir ();
g_chdir ("/");
- found_path = g_find_program_for_path ("sh", "sbin:bin:usr/bin:usr/sbin", NULL);
+ found_path = find_program_for_path ("sh", "sbin:bin:usr/bin:usr/sbin", NULL);
g_chdir (old_cwd);
g_clear_pointer (&old_cwd, g_free);
g_assert_nonnull (found_path);
g_clear_pointer (&found_path, g_free);
- found_path = g_find_program_for_path ("sh", "sbin:bin:usr/bin:usr/sbin", "/");
+ found_path = find_program_for_path ("sh", "sbin:bin:usr/bin:usr/sbin", "/");
g_assert_nonnull (found_path);
g_clear_pointer (&found_path, g_free);
#endif /* G_OS_UNIX */