aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2018-09-26 19:57:59 -0700
committerH. Peter Anvin <hpa@zytor.com>2018-09-26 19:57:59 -0700
commit4bbe369ee5a34829b80d0de8e33caed025fb2971 (patch)
treed56ff100ad146a86a77dce1a412c4906f199461a
parent3543fc3c9900aa442fd96a33f9aff3eb80d2ac92 (diff)
downloadabc80sim-4bbe369ee5a34829b80d0de8e33caed025fb2971.tar.gz
abc80sim-4bbe369ee5a34829b80d0de8e33caed025fb2971.tar.xz
abc80sim-4bbe369ee5a34829b80d0de8e33caed025fb2971.zip
Correctly strip the path from a host filename
-rw-r--r--abcfile.c12
-rw-r--r--hostfile.c16
-rw-r--r--hostfile.h3
3 files changed, 21 insertions, 10 deletions
diff --git a/abcfile.c b/abcfile.c
index 3aa35c5..65cb6d3 100644
--- a/abcfile.c
+++ b/abcfile.c
@@ -3,6 +3,7 @@
*/
#include "abcfile.h"
+#include "hostfile.h" /* For host_strip_path() */
#include <wchar.h>
@@ -62,16 +63,7 @@ void mangle_filename(char *dst, const char *src)
int n;
/* Skip any path prefix */
- s = strchr(src, '\0');
- while (--s >= src) {
- if (*s == '/'
-#ifdef __WIN32__
- || *s == ':' || *s == '\\'
-#endif
- )
- break;
- }
- s++;
+ s = host_strip_path(src);
memset(dst, ' ', 11);
dst[11] = '\0';
diff --git a/hostfile.c b/hostfile.c
index 1056d5f..fb2f14c 100644
--- a/hostfile.c
+++ b/hostfile.c
@@ -382,3 +382,19 @@ void hostfile_init(void)
{
atexit(hostfile_cleanup);
}
+
+/*
+ * Strip the path from a (host) filename
+ */
+const char *host_strip_path(const char *path)
+{
+ const char *p;
+
+ p = strrchr(path, '\0');
+ while (--p >= path) {
+ if (is_path_separator(*p))
+ break;
+ }
+
+ return p+1;
+}
diff --git a/hostfile.h b/hostfile.h
index f07590e..8ff8e24 100644
--- a/hostfile.h
+++ b/hostfile.h
@@ -69,4 +69,7 @@ extern int stat_file(const char *dir, const char *filename, struct stat *st);
/* Initialize the hostfile subsystem */
extern void hostfile_init(void);
+/* Point to a filename, without any path */
+extern const char *host_strip_path(const char *path);
+
#endif /* HOSTFILE_H */