summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2010-03-31 21:12:35 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2010-03-31 21:12:35 (GMT)
commit7cbdd17b441b35d48624956aa438bde69f18bc37 (patch)
tree438af8d0a994d6e203cf66ea91cf336bb071ee44 /src/common
parentd5e55f2ad015781bd7bee0e3216e47d6218e0841 (diff)
Implemented first steps to a Python plugins support.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@146 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/common')
-rwxr-xr-xsrc/common/Makefile.am1
-rw-r--r--src/common/dllist.h7
-rw-r--r--src/common/environment.c94
-rw-r--r--src/common/environment.h40
4 files changed, 140 insertions, 2 deletions
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index c4937dd..7aa255e 100755
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -4,6 +4,7 @@ lib_LTLIBRARIES = libcommon.la
libcommon_la_SOURCES = \
dllist.h dllist.c \
endianness.h endianness.c \
+ environment.h environment.c \
extstr.h extstr.c \
macros.h \
xml.h xml.c
diff --git a/src/common/dllist.h b/src/common/dllist.h
index 499151e..504291e 100644
--- a/src/common/dllist.h
+++ b/src/common/dllist.h
@@ -121,6 +121,10 @@ void __dl_list_del(dl_list_item *, dl_list_head *);
(iter->member.next == &head->member ? \
NULL : container_of(iter->member.next, type, member))
+#define dl_list_prev_iter(iter, head, type, member) \
+ (&iter->member == &head->member ? \
+ NULL : container_of(iter->member.prev, type, member))
+
#define dl_list_for_each(pos, head, type, member) \
for (pos = head; \
pos != NULL; \
@@ -140,8 +144,7 @@ void __dl_list_del(dl_list_item *, dl_list_head *);
#define dl_list_for_each_rev(pos, head, type, member) \
for (pos = dl_list_last(head, type, member); \
pos != NULL; \
- pos = (pos == head ? \
- NULL : container_of(pos->member.prev, type, member)))
+ pos = dl_list_prev_iter(pos, (head), type, member))
diff --git a/src/common/environment.c b/src/common/environment.c
new file mode 100644
index 0000000..a0fa568
--- /dev/null
+++ b/src/common/environment.c
@@ -0,0 +1,94 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * environment.c - manipulations des variables d'environnement.
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "environment.h"
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+#include "extstr.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : name = désignation de la variable à traiter. *
+* *
+* Description : Fournit le contenu d'une variable d'environnement. *
+* *
+* Retour : Chaîne à libérer de la mémoire après usage. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+char *get_env_var(const char *name)
+{
+ char *result; /* Chaîne à retourner */
+
+ result = getenv(name);
+
+ if (result == NULL) result = strdup("");
+ else result = strdup(name);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : name = désignation de la variable à traiter. *
+* value = valeur à ajouter à la variable. *
+* sep = séparateur entre champs. *
+* *
+* Description : Complète le contenu d'une variable d'environnement. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool add_to_env_var(const char *name, const char *value, const char *sep)
+{
+ char *content; /* Contenu final à définir */
+ int ret; /* Bilan d'un appel système */
+
+ content = get_env_var(name);
+
+ if (strlen(content) > 0) content = stradd(content, sep);
+
+ content = stradd(content, value);
+
+ ret = setenv(name, content, 1);
+ if (ret != 0) perror(setenv);
+
+ free(content);
+
+ return (ret == 0);
+
+}
diff --git a/src/common/environment.h b/src/common/environment.h
new file mode 100644
index 0000000..a96c6eb
--- /dev/null
+++ b/src/common/environment.h
@@ -0,0 +1,40 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * environment.h - prototypes pour la manipulations des variables d'environnement.
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _COMMON_ENVIRONMENT_H
+#define _COMMON_ENVIRONMENT_H
+
+
+#include <stdbool.h>
+
+
+
+/* Fournit le contenu d'une variable d'environnement. */
+char *get_env_var(const char *);
+
+/* Complète le contenu d'une variable d'environnement. */
+bool add_to_env_var(const char *, const char *, const char *);
+
+
+
+#endif /* _COMMON_ENVIRONMENT_H */