Paul Eggert wrote: > Right, and if we're going to change that kind of code, I suggest this: > > bool output_is_library = str_endswith (output_file, ".dll"); > > instead of using strnul.
I agree. Done: 2026-02-20 Bruno Haible <[email protected]> csharpcomp: Use str_endswith. Suggested by Paul Eggert in <https://lists.gnu.org/archive/html/bug-gnulib/2026-02/msg00129.html>. * lib/csharpcomp.c (compile_csharp_using_mono, compile_csharp_using_dotnet, compile_csharp_using_sscli, compile_csharp_class): Use str_endswith. * modules/csharpcomp (Depends-on): Add str_endswith. diff --git a/lib/csharpcomp.c b/lib/csharpcomp.c index afbd65a9da..1a17addcf1 100644 --- a/lib/csharpcomp.c +++ b/lib/csharpcomp.c @@ -177,9 +177,7 @@ compile_csharp_using_mono (const char * const *sources, for (unsigned int i = 0; i < sources_count; i++) { const char *source_file = sources[i]; - if (strlen (source_file) >= 10 - && memeq (source_file + strlen (source_file) - 10, - ".resources", 10)) + if (str_endswith (source_file, ".resources")) { char *option = (char *) xmalloca (10 + strlen (source_file) + 1); @@ -588,10 +586,7 @@ compile_csharp_using_dotnet (const char * const *sources, const char *source_file = sources[i]; char *source_file_converted = cygpath_w (source_file); *mallocedp++ = source_file_converted; - if (strlen (source_file_converted) >= 10 - && memeq ((source_file_converted - + strlen (source_file_converted) - 10), - ".resources", 10)) + if (str_endswith (source_file_converted, ".resources")) { char *option = (char *) xmalloc (10 + strlen (source_file_converted) + 1); @@ -771,10 +766,7 @@ compile_csharp_using_dotnet (const char * const *sources, const char *source_file = sources[i]; char *source_file_converted = cygpath_w (source_file); *mallocedp++ = source_file_converted; - if (strlen (source_file_converted) >= 10 - && memeq ((source_file_converted - + strlen (source_file_converted) - 10), - ".resources", 10)) + if (str_endswith (source_file_converted, ".resources")) { char *option = (char *) xmalloc (10 + strlen (source_file_converted) + 1); @@ -934,10 +926,7 @@ compile_csharp_using_sscli (const char * const *sources, const char *source_file = sources[i]; char *source_file_converted = cygpath_w (source_file); *mallocedp++ = source_file_converted; - if (strlen (source_file_converted) >= 10 - && memeq ((source_file_converted - + strlen (source_file_converted) - 10), - ".resources", 10)) + if (str_endswith (source_file_converted, ".resources")) { char *option = (char *) xmalloc (10 + strlen (source_file_converted) + 1); @@ -990,9 +979,7 @@ compile_csharp_class (const char * const *sources, bool optimize, bool debug, bool verbose) { - bool output_is_library = - (strlen (output_file) >= 4 - && memeq (output_file + strlen (output_file) - 4, ".dll", 4)); + bool output_is_library = str_endswith (output_file, ".dll"); int result; diff --git a/modules/csharpcomp b/modules/csharpcomp index 0e9c226fae..76d7ddb268 100644 --- a/modules/csharpcomp +++ b/modules/csharpcomp @@ -19,6 +19,7 @@ alphasort sh-quote safe-read stringeq +str_endswith xmalloca xvasprintf gettext-h
