From 26a37f80ead11e2e69dddf8d66aa34e0432a145e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 3 Jan 2025 10:38:58 +0100 Subject: [PATCH] gen-uni-tables, get-rusage-data, isatty: Use str_endswith. * lib/gen-uni-tables.c (fill_attributes): Use str_endswith. * lib/get-rusage-data.c (get_rusage_data_via_setrlimit): Likewise. * lib/isatty.c (IsCygwinConsoleHandle): Likewise. * modules/gen-uni-tables (Depends-on): Add str_endswith. * modules/get-rusage-data (Depends-on): Likewise. * modules/isatty (Depends-on): Likewise. --- ChangeLog | 10 ++++++++++ lib/gen-uni-tables.c | 4 ++-- lib/get-rusage-data.c | 5 ++--- lib/isatty.c | 3 +-- modules/gen-uni-tables | 1 + modules/get-rusage-data | 1 + modules/isatty | 1 + 7 files changed, 18 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 50b3f2e22e..b6a71b15e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2025-01-03 Bruno Haible + + gen-uni-tables, get-rusage-data, isatty: Use str_endswith. + * lib/gen-uni-tables.c (fill_attributes): Use str_endswith. + * lib/get-rusage-data.c (get_rusage_data_via_setrlimit): Likewise. + * lib/isatty.c (IsCygwinConsoleHandle): Likewise. + * modules/gen-uni-tables (Depends-on): Add str_endswith. + * modules/get-rusage-data (Depends-on): Likewise. + * modules/isatty (Depends-on): Likewise. + 2025-01-03 Bruno Haible tests: Use str_startswith. diff --git a/lib/gen-uni-tables.c b/lib/gen-uni-tables.c index c676660b07..2bac68c2da 100644 --- a/lib/gen-uni-tables.c +++ b/lib/gen-uni-tables.c @@ -219,7 +219,7 @@ fill_attributes (const char *unicodedata_filename) i = strtoul (field0, NULL, 16); if (field1[0] == '<' && strlen (field1) >= 9 - && strcmp (field1 + strlen (field1) - 8, ", First>") == 0) + && str_endswith (field1, ", First>")) { /* Deal with a range. */ lineno++; @@ -246,7 +246,7 @@ fill_attributes (const char *unicodedata_filename) } if (!(field1[0] == '<' && strlen (field1) >= 8 - && strcmp (field1 + strlen (field1) - 7, ", Last>") == 0)) + && str_endswith (field1, ", Last>"))) { fprintf (stderr, "missing end range in '%s':%d\n", unicodedata_filename, lineno); diff --git a/lib/get-rusage-data.c b/lib/get-rusage-data.c index b4df73f766..0fafc75a20 100644 --- a/lib/get-rusage-data.c +++ b/lib/get-rusage-data.c @@ -174,9 +174,8 @@ get_rusage_data_via_setrlimit (void) struct utsname buf; if (uname (&buf) == 0 - && strlen (buf.release) >= 5 - && (strcmp (buf.release + strlen (buf.release) - 5, "11.00") == 0 - || strcmp (buf.release + strlen (buf.release) - 5, "11.11") == 0)) + && (str_endswith (buf.release, "11.00") + || str_endswith (buf.release, "11.11"))) return 0; } # endif diff --git a/lib/isatty.c b/lib/isatty.c index 69371af607..23e3ab8f6d 100644 --- a/lib/isatty.c +++ b/lib/isatty.c @@ -130,8 +130,7 @@ static BOOL IsCygwinConsoleHandle (HANDLE h) or higher. */ if (QueryFullProcessImageNameFunc (processHandle, 0, buf, &bufsize)) { - if (strlen (buf) >= 11 - && strcmp (buf + strlen (buf) - 11, "\\mintty.exe") == 0) + if (str_endswith (buf, "\\mintty.exe")) result = TRUE; } CloseHandle (processHandle); diff --git a/modules/gen-uni-tables b/modules/gen-uni-tables index 561a39690b..5808aef3ad 100644 --- a/modules/gen-uni-tables +++ b/modules/gen-uni-tables @@ -13,6 +13,7 @@ bool strdup strstr-simple str_startswith +str_endswith configure.ac: AC_REQUIRE([AC_C_INLINE]) diff --git a/modules/get-rusage-data b/modules/get-rusage-data index 1a7bf89903..8d9110ac16 100644 --- a/modules/get-rusage-data +++ b/modules/get-rusage-data @@ -12,6 +12,7 @@ unistd-h extensions getpagesize vma-iter +str_endswith configure.ac: AC_CHECK_FUNCS_ONCE([sbrk setrlimit]) diff --git a/modules/isatty b/modules/isatty index e2fd7f09cd..7499b53933 100644 --- a/modules/isatty +++ b/modules/isatty @@ -9,6 +9,7 @@ Depends-on: unistd-h msvc-inval [test $REPLACE_ISATTY = 1] msvc-nothrow [test $REPLACE_ISATTY = 1] +str_endswith [test $REPLACE_ISATTY = 1] configure.ac: gl_FUNC_ISATTY -- 2.39.5