[Piglit] [PATCH 3/3] util: Implement basename for MSVC.

Brian Paul brianp at vmware.com
Mon Jun 8 06:47:30 PDT 2015


On 06/08/2015 06:17 AM, Jose Fonseca wrote:
> Not really tested, but it should hopefully work, and at very least it
> prevents link failures on MSVC due to absence of basename.
> ---
>   tests/util/piglit-util.c | 29 +++++++++++++++++++++++++++++
>   tests/util/piglit-util.h |  2 ++
>   2 files changed, 31 insertions(+)
>
> diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
> index 9bd0cd2..f631bde 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 '//':

Shouldn't that be a single '/'?


> +			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 98b1340..985ebbd 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)
>

Looks OK otherwise.

Reviewed-by: Brian Paul <brianp at vmware.com>



More information about the Piglit mailing list