Skip to content

Commit 29c2eda

Browse files
rscharfegitster
authored andcommitted
test-path-utils: handle const parameter of basename and dirname
The parameter to basename(3) and dirname(3) traditionally had the type "char *", but on OpenBSD it's been "const char *" for years. That causes (at least) Clang to throw an incompatible-pointer-types warning for test-path-utils, where we try to pass around pointers to these functions. Avoid this warning (which is fatal in DEVELOPER mode) by ignoring the promise of OpenBSD's implementations to keep input strings unmodified and enclosing them in POSIX-compatible wrappers. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b06d364 commit 29c2eda

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

t/helper/test-path-utils.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ struct test_data {
3838
const char *alternative; /* output: ... or this. */
3939
};
4040

41+
/*
42+
* Compatibility wrappers for OpenBSD, whose basename(3) and dirname(3)
43+
* have const parameters.
44+
*/
45+
static char *posix_basename(char *path)
46+
{
47+
return basename(path);
48+
}
49+
50+
static char *posix_dirname(char *path)
51+
{
52+
return dirname(path);
53+
}
54+
4155
static int test_function(struct test_data *data, char *(*func)(char *input),
4256
const char *funcname)
4357
{
@@ -251,10 +265,10 @@ int cmd_main(int argc, const char **argv)
251265
}
252266

253267
if (argc == 2 && !strcmp(argv[1], "basename"))
254-
return test_function(basename_data, basename, argv[1]);
268+
return test_function(basename_data, posix_basename, argv[1]);
255269

256270
if (argc == 2 && !strcmp(argv[1], "dirname"))
257-
return test_function(dirname_data, dirname, argv[1]);
271+
return test_function(dirname_data, posix_dirname, argv[1]);
258272

259273
fprintf(stderr, "%s: unknown function name: %s\n", argv[0],
260274
argv[1] ? argv[1] : "(there was none)");

0 commit comments

Comments
 (0)