* src/gpath.c (g_find_program_in_path, g_path_is_absolute): implement.
svn path=/trunk/mono/; revision=64332
2006-08-24 Miguel de Icaza <miguel@novell.com>
- * src/gpath.c: Add g_path_get_dirname, g_path_get_basename
+ * src/gpath.c (g_find_program_in_path, g_path_is_absolute): implement.
+
+ Add g_path_get_dirname, g_path_get_basename
* src/gpath.c: Path routines
3 g_thread_init
* Path string manipulation and utilities.
- 2 g_find_program_in_path
2 g_filename_to_uri
2 g_filename_from_uri
- 5 g_path_is_absolute
* Information retrieval
8 g_get_home_dir
#define G_BYTE_ORDER @ORDER@
#define G_GNUC_NORETURN @GNUC_NORETURN@
#define G_SEARCHPATH_SEPARATOR_S "@SEARCHSEP@"
+#define G_SEARCHPATH_SEPARATOR '@SEARCHSEP@'
#define G_DIR_SEPARATOR '@PATHSEP@'
#define G_DIR_SEPARATOR_S "@PATHSEP@"
#define G_BREAKPOINT @BREAKPOINT@
/*
* Path
*/
-gchar *g_build_path (const gchar *separator, const gchar *first_element, ...);
+gchar *g_build_path (const gchar *separator, const gchar *first_element, ...);
#define g_build_filename(x...) g_build_path(G_DIR_SEPARATOR_S, x)
-gchar *g_path_get_dirname (const gchar *filename);
-gchar *g_path_get_basename (const char *filename);
+gchar *g_path_get_dirname (const gchar *filename);
+gchar *g_path_get_basename (const char *filename);
+gchar *g_find_program_in_path (const gchar *program);
#endif
#define _GNU_SOURCE
#include <stdio.h>
#include <glib.h>
+#include <unistd.h>
gchar *
g_build_path (const gchar *separator, const gchar *first_element, ...)
return g_strdup (&r[1]);
}
+
+gboolean
+g_path_is_absolute (const char *filename)
+{
+ return (*filename == '/');
+}
+
+gchar *
+g_find_program_in_path (const gchar *program)
+{
+ char *p = g_strdup (getenv ("PATH"));
+ char *x = p, *l;
+ char *save;
+
+ while ((l = strtok_r (x, G_SEARCHPATH_SEPARATOR_S, &save)) != NULL){
+ char *probe_path;
+
+ x = NULL;
+ probe_path = g_build_path ("/", l, program, NULL);
+ if (access (probe_path, X_OK) == 0){
+ g_free (p);
+ return probe_path;
+ }
+ g_free (probe_path);
+ }
+ g_free (p);
+ return NULL;
+}
return OK;
}
+gchar *
+test_ppath (const gchar *program)
+{
+ char *s;
+
+ g_return_val_if_fail (program != NULL, NULL);
+
+ s = g_find_program_in_path ("ls");
+ if (s == NULL)
+ return FAILED ("No shell on this system (This assumes Unix)?");
+
+ return OK;
+}
+
static Test path_tests [] = {
{"g_buildpath", test_buildpath},
{"g_build_filename", test_buildfname},
{"g_path_get_dirname", test_dirname},
{"g_path_get_basename", test_basename},
+ {"g_find_program_in_path", test_ppath},
{NULL, NULL}
};