summaryrefslogtreecommitdiffstats
path: root/util/fileutil.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>1998-10-25 20:00:01 +0100
committerWerner Koch <wk@gnupg.org>1998-10-25 20:00:01 +0100
commit5ccb92591e5ff9cf90efeb5ef527cf7a5fb08fcf (patch)
tree241529d030ede38fcdaee1a708c5956693ed159d /util/fileutil.c
parentEpxerimenta support for GDBM keyings. (diff)
downloadgnupg2-5ccb92591e5ff9cf90efeb5ef527cf7a5fb08fcf.tar.xz
gnupg2-5ccb92591e5ff9cf90efeb5ef527cf7a5fb08fcf.zip
some random changes
Diffstat (limited to '')
-rw-r--r--util/fileutil.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/util/fileutil.c b/util/fileutil.c
index 2cedf0f9e..2169f9572 100644
--- a/util/fileutil.c
+++ b/util/fileutil.c
@@ -30,6 +30,61 @@
#include "ttyio.h"
+/***************
+ * Extract from a given path the filename component.
+ *
+ */
+char *
+make_basename(const char *filepath)
+{
+ char *p;
+
+ if ( !(p=strrchr(filepath, '/')) )
+ #ifdef __MINGW32__
+ if ( !(p=strrchr(filepath, '\\')) )
+ if ( !(p=strrchr(filepath, ':')) )
+ #endif
+ {
+ return m_strdup(filepath);
+ }
+
+ return m_strdup(p+1);
+}
+
+
+
+/***************
+ * Extract from a given filename the path prepended to it.
+ * If their isn't a path prepended to the filename, a dot
+ * is returned ('.').
+ *
+ */
+char *
+make_dirname(const char *filepath)
+{
+ char *dirname;
+ int dirname_length;
+ char *p;
+
+ if ( !(p=strrchr(filepath, '/')) )
+ #ifdef __MINGW32__
+ if ( !(p=strrchr(filepath, '\\')) )
+ if ( !(p=strrchr(filepath, ':')) )
+ #endif
+ {
+ return m_strdup(".");
+ }
+
+ dirname_length = p-filepath;
+ dirname = m_alloc(dirname_length+1);
+ strncpy(dirname, filepath, dirname_length);
+ dirname[dirname_length] = 0;
+
+ return dirname;
+}
+
+
+
/****************
* Construct a filename from the NULL terminated list of parts.
* Tilde expansion is done here.