{"thread":{"id":"46527","subject":"[PATCH] test-path-utils: handle const parameter of basename and dirname","startedAt":"2017-08-07T13:57:44Z","lastAt":"2017-08-07T21:15:13Z","messageCount":2,"participants":["René Scharfe","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"325679","messageId":"5bfd3c7c-c3c8-5115-713a-63f6f8cd7eb7@web.de","threadId":"46527","inReplyTo":null,"subject":"[PATCH] test-path-utils: handle const parameter of basename and dirname","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2017-08-07T13:57:31Z","receivedAt":"2017-08-07T13:57:44Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"The parameter to basename(3) and dirname(3) traditionally had the type\n\"char *\", but on OpenBSD it's been \"const char *\" for years.  That\ncauses (at least) Clang to throw an incompatible-pointer-types warning\nfor test-path-utils, where we try to pass around pointers to these\nfunctions.\n\nAvoid this warning (which is fatal in DEVELOPER mode) by ignoring the\npromise of OpenBSD's implementations to keep input strings unmodified\nand enclosing them in POSIX-compatible wrappers.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n t/helper/test-path-utils.c | 18 ++++++++++++++++--\n 1 file changed, 16 insertions(+), 2 deletions(-)\n\ndiff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c\nindex 1ebe0f750c..2b3c5092a1 100644\n--- a/t/helper/test-path-utils.c\n+++ b/t/helper/test-path-utils.c\n@@ -38,6 +38,20 @@ struct test_data {\n \tconst char *alternative; /* output: ... or this.      */\n };\n \n+/*\n+ * Compatibility wrappers for OpenBSD, whose basename(3) and dirname(3)\n+ * have const parameters.\n+ */\n+static char *posix_basename(char *path)\n+{\n+\treturn basename(path);\n+}\n+\n+static char *posix_dirname(char *path)\n+{\n+\treturn dirname(path);\n+}\n+\n static int test_function(struct test_data *data, char *(*func)(char *input),\n \tconst char *funcname)\n {\n@@ -251,10 +265,10 @@ int cmd_main(int argc, const char **argv)\n \t}\n \n \tif (argc == 2 && !strcmp(argv[1], \"basename\"))\n-\t\treturn test_function(basename_data, basename, argv[1]);\n+\t\treturn test_function(basename_data, posix_basename, argv[1]);\n \n \tif (argc == 2 && !strcmp(argv[1], \"dirname\"))\n-\t\treturn test_function(dirname_data, dirname, argv[1]);\n+\t\treturn test_function(dirname_data, posix_dirname, argv[1]);\n \n \tfprintf(stderr, \"%s: unknown function name: %s\\n\", argv[0],\n \t\targv[1] ? argv[1] : \"(there was none)\");\n-- \n2.14.0\n\n"},{"id":"325746","messageId":"alpine.DEB.2.21.1.1708072314420.4271@virtualbox","threadId":"46527","inReplyTo":"5bfd3c7c-c3c8-5115-713a-63f6f8cd7eb7@web.de","subject":"Re: [PATCH] test-path-utils: handle const parameter of basename and dirname","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2017-08-07T21:15:01Z","receivedAt":"2017-08-07T21:15:13Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi René,\n\nOn Mon, 7 Aug 2017, René Scharfe wrote:\n\n> The parameter to basename(3) and dirname(3) traditionally had the type\n> \"char *\", but on OpenBSD it's been \"const char *\" for years.  That\n> causes (at least) Clang to throw an incompatible-pointer-types warning\n> for test-path-utils, where we try to pass around pointers to these\n> functions.\n> \n> Avoid this warning (which is fatal in DEVELOPER mode) by ignoring the\n> promise of OpenBSD's implementations to keep input strings unmodified\n> and enclosing them in POSIX-compatible wrappers.\n> \n> Signed-off-by: Rene Scharfe <l.s.r@web.de>\n> ---\n\nThis patch is Fine By Me.\n\nThanks,\nDscho"}]}