summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Fonseca <jfonseca@vmware.com>2015-06-08 13:16:48 +0100
committerJose Fonseca <jfonseca@vmware.com>2015-06-08 15:04:43 +0100
commit540972b46e51ee1d4acbb3757b731a066e2b6ba5 (patch)
tree60931813ee5ebdfcc8ca830ac6b7e634b4cb7bf6
parent83681bad9ef9d94ddf0babb6998406932d818de7 (diff)
util: Implement basename for MSVC.
Not really tested, but it should hopefully work, and at very least it prevents link failures on MSVC due to absence of basename. Reviewed-by: Brian Paul <brianp@vmware.com>
-rw-r--r--tests/util/piglit-util.c29
-rw-r--r--tests/util/piglit-util.h2
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index 9bd0cd2ce..0a66a851c 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -118,6 +118,35 @@ int asprintf(char **strp, const char *fmt, ...)
#endif /* HAVE_ASPRINTF */
+#ifdef _MSC_VER
+
+char *
+basename(char *path)
+{
+ char *res;
+
+ // Skip drive letter
+ if (path[0] != '\0' && path[1] == ':') {
+ path += 2;
+ }
+
+ // Return pointer to the char after the last directory separator
+ res = path;
+ while (true) {
+ char c = *path++;
+ switch (c) {
+ case '\0':
+ return res;
+ case '\\':
+ case '/':
+ res = ++path;
+ break;
+ }
+ }
+}
+
+#endif /* _MSC_VER */
+
/**
* \brief Split \a string into an array of strings.
*
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index 98b134023..985ebbdac 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -82,6 +82,8 @@ extern "C" {
#define usleep(__usec) Sleep(((__usec) + 999)/1000)
+char *basename(char *path);
+
#endif /* defined(_MSC_VER) */
#if (__GNUC__ >= 3)