[gnome-commander] Added gnome_cmd_prepend_su_to_vector() function for *su detection
- From: Piotr Eljasiak <epiotr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] Added gnome_cmd_prepend_su_to_vector() function for *su detection
- Date: Thu, 16 Dec 2010 22:22:48 +0000 (UTC)
commit 5945a2982e8f84d1fb39921792d0a6aed8eabd37
Author: Piotr Eljasiak <epiotr src gnome org>
Date: Thu Dec 16 23:05:35 2010 +0100
Added gnome_cmd_prepend_su_to_vector() function for *su detection
src/utils.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/utils.h | 2 ++
2 files changed, 56 insertions(+), 0 deletions(-)
---
diff --git a/src/utils.cc b/src/utils.cc
index c22ecfa..02fd874 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -1354,6 +1354,60 @@ void gnome_cmd_toggle_file_name_selection (GtkWidget *entry)
}
+gboolean gnome_cmd_prepend_su_to_vector (int &argc, char **&argv)
+{
+ // sanity
+ if(!argv)
+ argc = 0;
+
+ char *su = NULL;
+ gboolean need_c = FALSE;
+
+ if ((su = g_find_program_in_path ("xdg-su")))
+ goto with_c_param;
+ if ((su = g_find_program_in_path ("gksu")))
+ goto without_c_param;
+ if ((su = g_find_program_in_path ("gnomesu")))
+ goto with_c_param;
+ if ((su = g_find_program_in_path ("beesu")))
+ goto without_c_param;
+ if ((su = g_find_program_in_path ("kdesu")))
+ goto without_c_param;
+
+ return FALSE;
+
+ with_c_param:
+
+ need_c = TRUE;
+
+ without_c_param:
+
+ char **su_argv = g_new0 (char *, 3);
+ int su_argc = 0;
+
+ su_argv[su_argc++] = su;
+ if (need_c)
+ su_argv[su_argc++] = g_strdup("-c");
+
+ // compute size if not given
+ if (argc < 0)
+ for (argc=0; argv[argc]; ++argc);
+
+ int real_argc = su_argc + argc;
+ char **real_argv = g_new0 (char *, real_argc+1);
+
+ g_memmove (real_argv, su_argv, su_argc*sizeof(char *));
+ g_memmove (real_argv+su_argc, argv, argc*sizeof(char *));
+
+ g_free (argv);
+
+ argv = real_argv;
+ argc = real_argc;
+
+ return TRUE;
+}
+
+
int split(const string &s, vector<string> &coll, const char *sep)
{
coll.clear();
diff --git a/src/utils.h b/src/utils.h
index 09acf5f..06178dc 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -259,6 +259,8 @@ gboolean patlist_matches (GList *pattern_list, const gchar *s);
void gnome_cmd_toggle_file_name_selection (GtkWidget *entry);
+gboolean gnome_cmd_prepend_su_to_vector (int &argc, char **&argv);
+
inline void gnome_cmd_show_message (GtkWindow *parent, std::string message, const gchar *secondary_text=NULL)
{
GtkWidget *dlg = gtk_message_dialog_new (parent,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]