summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Vignaud <tv@mageia.org>2012-02-26 01:22:33 +0000
committerThierry Vignaud <tv@mageia.org>2012-02-26 01:22:33 +0000
commit06d5f1bcc9aee5ab94a6c78c99a876408ecc9f1f (patch)
treeb641c57fc77dda94934f2536756c2ae1e5c1eb42
parent1e78878284ac272034530baee6e42e1062b07b6e (diff)
downloaddrakx-06d5f1bcc9aee5ab94a6c78c99a876408ecc9f1f.tar
drakx-06d5f1bcc9aee5ab94a6c78c99a876408ecc9f1f.tar.gz
drakx-06d5f1bcc9aee5ab94a6c78c99a876408ecc9f1f.tar.bz2
drakx-06d5f1bcc9aee5ab94a6c78c99a876408ecc9f1f.tar.xz
drakx-06d5f1bcc9aee5ab94a6c78c99a876408ecc9f1f.zip
(my_dirname) introduce a non segfaulting dirname()
-rw-r--r--mdk-stage1/utils.c14
-rw-r--r--mdk-stage1/utils.h1
2 files changed, 15 insertions, 0 deletions
diff --git a/mdk-stage1/utils.c b/mdk-stage1/utils.c
index 492061887..af5ee9af3 100644
--- a/mdk-stage1/utils.c
+++ b/mdk-stage1/utils.c
@@ -179,3 +179,17 @@ void lowercase(char *s)
i++;
}
}
+
+char *my_dirname(char *path) {
+ char *p = strrchr (path, '/');
+ char *tmp;
+ int len;
+ if (!p)
+ return path;
+ len = p-path+1;
+ tmp = malloc(len);
+ strncpy(tmp, path, len-1);
+ tmp[len-1] = '\0';
+ return tmp;
+}
+
diff --git a/mdk-stage1/utils.h b/mdk-stage1/utils.h
index d0d7ae617..d42c52d06 100644
--- a/mdk-stage1/utils.h
+++ b/mdk-stage1/utils.h
@@ -28,6 +28,7 @@ char ** list_directory(char * direct);
int string_array_length(char ** a);
char * asprintf_(const char *msg, ...);
int scall_(int retval, char * msg, char * file, int line);
+char *my_dirname(char *path);
#define scall(retval, msg) scall_(retval, msg, __FILE__, __LINE__)
void lowercase(char *s);