2006-08-24 Miguel de Icaza <miguel@novell.com>
authorMiguel de Icaza <miguel@gnome.org>
Fri, 25 Aug 2006 02:45:42 +0000 (02:45 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Fri, 25 Aug 2006 02:45:42 +0000 (02:45 -0000)
* src/gpath.c (g_find_program_in_path, g_path_is_absolute): implement.

svn path=/trunk/mono/; revision=64332

eglib/ChangeLog
eglib/TODO
eglib/src/eglib-config.h.in
eglib/src/glib.h
eglib/src/gpath.c
eglib/test/path.c

index ab0b659b56a4704125b2f2b3aba0ec871319c4cb..33290cae7845fc47fbb6d2de007b061740b5d764 100644 (file)
@@ -1,6 +1,8 @@
 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
 
index 99a919fd7cd822e5b26c43971cd39cb70bd54761..bd1db79ebdc1d97d3f3aa2a9b5f97b46170778eb 100644 (file)
@@ -51,10 +51,8 @@ Important Groups:
              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
index eaeb9c8e17872c5653d14deedf91f1d6abeee5db..80a1c0c546de27f0d54590c91a99655b76d9eefe 100644 (file)
@@ -6,6 +6,7 @@
 #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@
index 3e131c953c2b1ee3a2ba42b4f5d7cbf792c816d9..5868a0dac2b05b08b442f42cea2899352ca26b60 100644 (file)
@@ -430,9 +430,10 @@ GError *g_error_new (gpointer domain, gint code, const char *format, ...);
 /*
  * 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
index 066fc5e73f46e64aed3dfb13c098a727d4ef5971..56114c5fc7ec70bb3c293fa1453f78a7a3d2f9f3 100644 (file)
@@ -28,6 +28,7 @@
 #define _GNU_SOURCE
 #include <stdio.h>
 #include <glib.h>
+#include <unistd.h>
 
 gchar *
 g_build_path (const gchar *separator, const gchar *first_element, ...)
@@ -118,3 +119,31 @@ g_path_get_basename (const char *filename)
 
        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;
+}
index faac40f3628914f62d1a7cdc1898d76e158d23a5..9c9888f4c661b220f8acd7237632fa0fafedf59e 100644 (file)
@@ -133,11 +133,26 @@ test_basename ()
        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}
 };