summaryrefslogtreecommitdiff
path: root/src/port/path.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/port/path.c')
-rw-r--r--src/port/path.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/port/path.c b/src/port/path.c
new file mode 100644
index 00000000000..9cca1586f17
--- /dev/null
+++ b/src/port/path.c
@@ -0,0 +1,78 @@
+/* $Id: path.c,v 1.1 2003/04/04 20:42:13 momjian Exp $ */
+
+#include "c.h"
+#include <ctype.h>
+
+/*
+ * is_absolute_path
+ */
+bool is_absolute_path(const char *filename)
+{
+ return filename[0] == '/'
+#ifdef WIN32 /* WIN32 paths can either have forward or backward slashes */
+ || filename[0] == '\\'
+ || (isalpha(filename[0]) && filename[1] == ':'
+ && (filename[2] == '\\' || filename[2] == '/'))
+#endif
+ ;
+}
+
+
+
+/*
+ * first_path_separator
+ */
+char *first_path_separator(const char *filename)
+{
+#ifndef WIN32
+ return strchr(filename, '/');
+#else
+ char *slash, *bslash;
+
+ /* How should we handle "C:file.c"? */
+ slash = strchr(filename, '/');
+ bslash = strchr(filename, '\\');
+ if (slash == NULL)
+ return bslash;
+ else if (bslash == NULL)
+ return slash;
+ else
+ return (slash < bslash) ? slash : bslash;
+#endif
+}
+
+
+/*
+ * last_path_separator
+ */
+char *last_path_separator(const char *filename)
+{
+#ifndef WIN32
+ return strrchr(filename, '/');
+#else
+ char *slash, *bslash;
+
+ /* How should we handle "C:file.c"? */
+ slash = strrchr(filename, '/');
+ bslash = strrchr(filename, '\\');
+ if (slash == NULL)
+ return bslash;
+ else if (bslash == NULL)
+ return slash;
+ else
+ return (slash > bslash) ? slash : bslash;
+#endif
+}
+
+
+/*
+ * Extracts the actual name of the program as called.
+ */
+char *
+get_progname(char *argv0)
+{
+ if (!last_path_separator(argv0))
+ return argv0;
+ else
+ return last_path_separator(argv0) + 1;
+}