1
0
mirror of https://https.git.savannah.gnu.org/git/gnulib.git synced 2026-05-13 15:13:36 +00:00

stringeq: prefer memeq to memcmp in other modules

* lib/argmatch.c, lib/argmatch.h, lib/backupfile.c, lib/bcp47.c:
* lib/boot-time.c, lib/csharpcomp.c, lib/csharpexec.c:
* lib/file-has-acl.c, lib/gen-uni-tables.c, lib/get_ppid_of.c:
* lib/get_progname_of.c, lib/getlogin_r.c, lib/getprogname.c:
* lib/getumask.c, lib/isnan.c, lib/mbchar.h, lib/mem-hash-map.c:
* lib/memcoll.c, lib/progname.c, lib/progreloc.c:
* lib/pthread_sigmask.c, lib/quotearg.c, lib/readutmp.c:
* lib/same.c, lib/signbitd.c, lib/signbitf.c, lib/signbitl.c:
* lib/string-desc.c, lib/string.c, lib/string.in.h:
* lib/unictype/3level.h, lib/unictype/3levelbit.h:
* lib/uniname/uniname.c, lib/vc-mtime.c:
Prefer memeq to memcmp when either will do.
Do not make this change to files shared with glibc.
Do not make the change to test files, at least not for now.
* lib/gen-uni-tables.c (memeq): New static function, in same style.
* modules/argmatch, modules/backupfile, modules/bcp47:
* modules/boot-time, modules/csharpcomp, modules/csharpexec:
* modules/file-has-acl:
* modules/get_ppid_of, modules/get_progname_of:
* modules/getlogin_r, modules/getprogname, modules/getumask:
* modules/isnan, modules/mbchar, modules/mem-hash-map:
* modules/memcoll, modules/progname, modules/pthread_sigmask:
* modules/quotearg, modules/readutmp, modules/relocatable-prog:
* modules/relocatable-prog-wrapper, modules/same, modules/signbit:
* modules/string-desc, modules/stringeq, modules/uniname/uniname:
* modules/vc-mtime:
(Depends-on): Add stringeq.
This commit is contained in:
Paul Eggert
2025-09-16 18:57:41 -07:00
parent 60b0949c93
commit 6ca831b019
60 changed files with 190 additions and 132 deletions

View File

@@ -1,5 +1,34 @@
2025-09-17 Paul Eggert <eggert@cs.ucla.edu>
stringeq: prefer memeq to memcmp in other modules
* lib/argmatch.c, lib/argmatch.h, lib/backupfile.c, lib/bcp47.c:
* lib/boot-time.c, lib/csharpcomp.c, lib/csharpexec.c:
* lib/file-has-acl.c, lib/gen-uni-tables.c, lib/get_ppid_of.c:
* lib/get_progname_of.c, lib/getlogin_r.c, lib/getprogname.c:
* lib/getumask.c, lib/isnan.c, lib/mbchar.h, lib/mem-hash-map.c:
* lib/memcoll.c, lib/progname.c, lib/progreloc.c:
* lib/pthread_sigmask.c, lib/quotearg.c, lib/readutmp.c:
* lib/same.c, lib/signbitd.c, lib/signbitf.c, lib/signbitl.c:
* lib/string-desc.c, lib/string.c, lib/string.in.h:
* lib/unictype/3level.h, lib/unictype/3levelbit.h:
* lib/uniname/uniname.c, lib/vc-mtime.c:
Prefer memeq to memcmp when either will do.
Do not make this change to files shared with glibc.
Do not make the change to test files, at least not for now.
* lib/gen-uni-tables.c (memeq): New static function, in same style.
* modules/argmatch, modules/backupfile, modules/bcp47:
* modules/boot-time, modules/csharpcomp, modules/csharpexec:
* modules/file-has-acl:
* modules/get_ppid_of, modules/get_progname_of:
* modules/getlogin_r, modules/getprogname, modules/getumask:
* modules/isnan, modules/mbchar, modules/mem-hash-map:
* modules/memcoll, modules/progname, modules/pthread_sigmask:
* modules/quotearg, modules/readutmp, modules/relocatable-prog:
* modules/relocatable-prog-wrapper, modules/same, modules/signbit:
* modules/string-desc, modules/stringeq, modules/uniname/uniname:
* modules/vc-mtime:
(Depends-on): Add stringeq.
stringeq: new module
* MODULES.html.sh (func_all_modules): Add stringeq.
* lib/string.c, modules/stringeq: New files.

View File

@@ -102,7 +102,7 @@ argmatch (const char *arg, const char *const *arglist,
{
/* Second nonexact match found. */
if (vallist == NULL
|| memcmp ((char const *) vallist + valsize * matchind,
|| !memeq ((char const *) vallist + valsize * matchind,
(char const *) vallist + valsize * i, valsize))
{
/* There is a real ambiguity, or we could not
@@ -165,7 +165,7 @@ argmatch_valid (const char *const *arglist,
fputs (_("Valid arguments are:"), stderr);
for (i = 0; arglist[i]; i++)
if ((i == 0)
|| memcmp (last_val, (char const *) vallist + valsize * i, valsize))
|| !memeq (last_val, (char const *) vallist + valsize * i, valsize))
{
fprintf (stderr, "\n - %s", quote (arglist[i]));
last_val = (char const *) vallist + valsize * i;
@@ -219,7 +219,7 @@ argmatch_to_argument (const void *value,
size_t i;
for (i = 0; arglist[i]; i++)
if (!memcmp (value, (char const *) vallist + valsize * i, valsize))
if (memeq (value, (char const *) vallist + valsize * i, valsize))
return arglist[i];
return NULL;
}

View File

@@ -30,7 +30,7 @@
# include <limits.h>
# include <stddef.h>
# include <stdio.h>
# include <string.h> /* memcmp */
# include <string.h> /* memeq */
# include "gettext.h"
# include "quote.h"
@@ -210,7 +210,7 @@ char const *argmatch_to_argument (void const *value,
else if (res == -1) \
/* First nonexact match found. */ \
res = i; \
else if (memcmp (&g->args[res].val, &g->args[i].val, size)) \
else if (!memeq (&g->args[res].val, &g->args[i].val, size)) \
/* Second nonexact match found. */ \
/* There is a real ambiguity, or we could not \
disambiguate. */ \
@@ -225,7 +225,7 @@ char const *argmatch_to_argument (void const *value,
const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \
size_t size = argmatch_##Name##_size; \
for (size_t i = 0; g->args[i].arg; i++) \
if (!memcmp (val, &g->args[i].val, size)) \
if (memeq (val, &g->args[i].val, size)) \
return g->args[i].arg; \
return NULL; \
} \
@@ -242,7 +242,7 @@ char const *argmatch_to_argument (void const *value,
fputs (dgettext (GNULIB_TEXT_DOMAIN, "Valid arguments are:"), out); \
for (int i = 0; g->args[i].arg; i++) \
if (i == 0 \
|| memcmp (&g->args[i-1].val, &g->args[i].val, size)) \
|| !memeq (&g->args[i-1].val, &g->args[i].val, size)) \
fprintf (out, "\n - %s", quote (g->args[i].arg)); \
else \
fprintf (out, ", %s", quote (g->args[i].arg)); \
@@ -281,7 +281,7 @@ char const *argmatch_to_argument (void const *value,
else \
/* Genuine argument, display it with its synonyms. */ \
for (int j = 0; g->args[j].arg; ++j) \
if (! memcmp (&g->args[ival].val, &g->args[j].val, size)) \
if (memeq (&g->args[ival].val, &g->args[j].val, size)) \
col += (col == 4 ? 0 : 2) + strlen (g->args[j].arg); \
if (res <= col) \
res = col <= 20 ? col : 20; \
@@ -312,7 +312,7 @@ char const *argmatch_to_argument (void const *value,
else \
/* Genuine argument, display it with its synonyms. */ \
for (int j = 0; g->args[j].arg; ++j) \
if (! memcmp (&g->args[ival].val, &g->args[j].val, size)) \
if (memeq (&g->args[ival].val, &g->args[j].val, size)) \
{ \
if (!first \
&& screen_width < col + 2 + strlen (g->args[j].arg)) \

View File

@@ -239,7 +239,7 @@ numbered_backup (int dir_fd, char **buffer, idx_t buffer_size, idx_t filelen,
if (_D_EXACT_NAMLEN (dp) < baselen + 4)
continue;
if (memcmp (buf + base_offset, dp->d_name, baselen + 2) != 0)
if (!memeq (buf + base_offset, dp->d_name, baselen + 2))
continue;
char const *p = dp->d_name + baselen + 2;

View File

@@ -124,27 +124,27 @@ static const struct script scripts[] =
static const struct script *
default_script_in_territory (const char language[2], const char territory[2])
{
if (memcmp (language, "az", 2) == 0)
if (memeq (language, "az", 2))
{
if (memcmp (territory, "AZ", 2) == 0)
if (memeq (territory, "AZ", 2))
return &scripts[SCRIPT_LATIN];
else if (memcmp (territory, "IR", 2) == 0)
else if (memeq (territory, "IR", 2))
return &scripts[SCRIPT_ARABIC];
}
else if (memcmp (language, "ku", 2) == 0)
else if (memeq (language, "ku", 2))
{
if (memcmp (territory, "IQ", 2) == 0
|| memcmp (territory, "IR", 2) == 0)
if (memeq (territory, "IQ", 2)
|| memeq (territory, "IR", 2))
return &scripts[SCRIPT_ARABIC];
else if (memcmp (territory, "SY", 2) == 0
|| memcmp (territory, "TR", 2) == 0)
else if (memeq (territory, "SY", 2)
|| memeq (territory, "TR", 2))
return &scripts[SCRIPT_LATIN];
}
else if (memcmp (language, "pa", 2) == 0)
else if (memeq (language, "pa", 2))
{
if (memcmp (territory, "PK", 2) == 0)
if (memeq (territory, "PK", 2))
return &scripts[SCRIPT_ARABIC];
else if (memcmp (territory, "IN", 2) == 0)
else if (memeq (territory, "IN", 2))
return &scripts[SCRIPT_GURMUKHI];
}
return NULL;
@@ -156,32 +156,32 @@ default_script_in_territory (const char language[2], const char territory[2])
static const struct script *
default_script_for_language2 (const char language[2])
{
if (memcmp (language, "be", 2) == 0)
if (memeq (language, "be", 2))
return &scripts[SCRIPT_CYRILLIC];
else if (memcmp (language, "bs", 2) == 0)
else if (memeq (language, "bs", 2))
return &scripts[SCRIPT_LATIN];
else if (memcmp (language, "ha", 2) == 0)
else if (memeq (language, "ha", 2))
return &scripts[SCRIPT_LATIN];
else if (memcmp (language, "kk", 2) == 0)
else if (memeq (language, "kk", 2))
return &scripts[SCRIPT_CYRILLIC];
else if (memcmp (language, "ks", 2) == 0)
else if (memeq (language, "ks", 2))
return &scripts[SCRIPT_ARABIC];
else if (memcmp (language, "mn", 2) == 0)
else if (memeq (language, "mn", 2))
return &scripts[SCRIPT_CYRILLIC];
else if (memcmp (language, "sd", 2) == 0)
else if (memeq (language, "sd", 2))
return &scripts[SCRIPT_ARABIC];
else if (memcmp (language, "sr", 2) == 0)
else if (memeq (language, "sr", 2))
return &scripts[SCRIPT_CYRILLIC];
else if (memcmp (language, "uz", 2) == 0)
else if (memeq (language, "uz", 2))
return &scripts[SCRIPT_LATIN];
else if (memcmp (language, "yi", 2) == 0)
else if (memeq (language, "yi", 2))
return &scripts[SCRIPT_HEBREW];
return NULL;
}
static const struct script *
default_script_for_language3 (const char language[3])
{
if (memcmp (language, "ber", 3) == 0)
if (memeq (language, "ber", 3))
return &scripts[SCRIPT_LATIN];
return NULL;
}
@@ -254,14 +254,14 @@ xpg_to_bcp47 (char *bcp47, const char *xpg)
/* Canonicalize the language. */
/* For Quechua, Microsoft uses the ISO 639-3 code "quz" instead of the
ISO 639-1 code "qu". */
if (language_len == 3 && memcmp (language_start, "quz", 3) == 0)
if (language_len == 3 && memeq (language_start, "quz", 3))
{
language_start = "qu";
language_len = 2;
}
/* For Tamazight, Microsoft uses the ISO 639-3 code "tzm" instead of the
ISO 639-2 code "ber". */
else if (language_len == 3 && memcmp (language_start, "tzm", 3) == 0)
else if (language_len == 3 && memeq (language_start, "tzm", 3))
{
language_start = "ber";
language_len = 3;
@@ -277,7 +277,7 @@ xpg_to_bcp47 (char *bcp47, const char *xpg)
size_t i;
for (i = 0; i < NUM_SCRIPTS; i++)
if (strlen (scripts[i].name) == modifier_len
&& memcmp (scripts[i].name, modifier_start, modifier_len) == 0)
&& memeq (scripts[i].name, modifier_start, modifier_len))
script_subtag = scripts[i].code;
if (script_subtag == NULL)
{
@@ -298,10 +298,10 @@ xpg_to_bcp47 (char *bcp47, const char *xpg)
default_script_in_territory (language_start, territory_start);
if (sp != NULL)
script_subtag = sp->code;
else if (memcmp (language_start, "zh", 2) == 0)
else if (memeq (language_start, "zh", 2))
{
if (memcmp (territory_start, "CN", 2) == 0
|| memcmp (territory_start, "SG", 2) == 0)
if (memeq (territory_start, "CN", 2)
|| memeq (territory_start, "SG", 2))
script_subtag = "Hans";
else
script_subtag = "Hant";
@@ -314,7 +314,7 @@ xpg_to_bcp47 (char *bcp47, const char *xpg)
default_script_for_language2 (language_start);
if (sp != NULL)
script_subtag = sp->code;
else if (memcmp (language_start, "iu", 2) == 0)
else if (memeq (language_start, "iu", 2))
script_subtag = "Cans";
}
else if (language_len == 3)
@@ -323,7 +323,7 @@ xpg_to_bcp47 (char *bcp47, const char *xpg)
default_script_for_language3 (language_start);
if (sp != NULL)
script_subtag = sp->code;
else if (memcmp (language_start, "nan", 3) == 0)
else if (memeq (language_start, "nan", 3))
script_subtag = "Hant";
}
}
@@ -466,14 +466,14 @@ bcp47_to_xpg (char *xpg, const char *bcp47, const char *codeset)
/* Canonicalize the language. */
/* For Quechua, Microsoft uses the ISO 639-3 code "quz" instead of the
ISO 639-1 code "qu". */
if (language_len == 3 && memcmp (xpg, "quz", 3) == 0)
if (language_len == 3 && memeq (xpg, "quz", 3))
{
language_len = 2;
memcpy (xpg, "qu", language_len);
}
/* For Tamazight, Microsoft uses the ISO 639-3 code "tzm" instead of the
ISO 639-2 code "ber". */
else if (language_len == 3 && memcmp (xpg, "tzm", 3) == 0)
else if (language_len == 3 && memeq (xpg, "tzm", 3))
{
language_len = 3;
memcpy (xpg, "ber", language_len);
@@ -517,7 +517,7 @@ bcp47_to_xpg (char *xpg, const char *bcp47, const char *codeset)
if (strcmp (script, sp->name) == 0)
script = NULL;
}
else if (memcmp (xpg, "zh", 2) == 0)
else if (memeq (xpg, "zh", 2))
{
/* "Hans" and "Hant" are not present in the scripts[] table,
therefore nothing to do here. */
@@ -533,7 +533,7 @@ bcp47_to_xpg (char *xpg, const char *bcp47, const char *codeset)
if (strcmp (script, sp->name) == 0)
script = NULL;
}
else if (memcmp (xpg, "iu", 2) == 0)
else if (memeq (xpg, "iu", 2))
{
/* "Cans" is not present in the scripts[] table,
therefore nothing to do here. */
@@ -548,7 +548,7 @@ bcp47_to_xpg (char *xpg, const char *bcp47, const char *codeset)
if (strcmp (script, sp->name) == 0)
script = NULL;
}
else if (memcmp (xpg, "nan", 3) == 0)
else if (memeq (xpg, "nan", 3))
{
/* "Hant" is not present in the scripts[] table,
therefore nothing to do here. */

View File

@@ -120,13 +120,13 @@ get_boot_time_uncached (struct timespec *p_boot_time)
found_boot_time = ts;
# if defined __linux__ && !defined __ANDROID__
if (memcmp (UT_USER (ut), "runlevel", strlen ("runlevel") + 1) == 0
&& memcmp (ut->ut_line, "~", strlen ("~") + 1) == 0)
if (memeq (UT_USER (ut), "runlevel", strlen ("runlevel") + 1)
&& memeq (ut->ut_line, "~", strlen ("~") + 1))
runlevel_ts = ts;
# endif
# if defined __minix
if (UT_USER (ut)[0] == '\0'
&& memcmp (ut->ut_line, "run-level ", strlen ("run-level ")) == 0)
&& memeq (ut->ut_line, "run-level ", strlen ("run-level ")))
runlevel_ts = ts;
# endif
}

View File

@@ -68,7 +68,7 @@ name_is_dll (const struct dirent *d)
if (d->d_name[0] != '.')
{
size_t d_name_len = strlen (d->d_name);
if (d_name_len > 4 && memcmp (d->d_name + d_name_len - 4, ".dll", 4) == 0)
if (d_name_len > 4 && memeq (d->d_name + d_name_len - 4, ".dll", 4))
/* Filter out files that start with a lowercase letter and files that
contain the substring ".Native.", since on Windows these files
produce an error "PE image doesn't contain managed metadata". */
@@ -122,7 +122,7 @@ compile_csharp_using_mono (const char * const *sources,
count++;
if (count == 4)
{
if (memcmp (c, "Mono", 4) == 0)
if (memeq (c, "Mono", 4))
mcs_present = true;
c[0] = c[1]; c[1] = c[2]; c[2] = c[3];
count--;
@@ -192,8 +192,8 @@ compile_csharp_using_mono (const char * const *sources,
{
const char *source_file = sources[i];
if (strlen (source_file) >= 10
&& memcmp (source_file + strlen (source_file) - 10, ".resources",
10) == 0)
&& memeq (source_file + strlen (source_file) - 10,
".resources", 10))
{
char *option = (char *) xmalloca (10 + strlen (source_file) + 1);
@@ -239,7 +239,7 @@ compile_csharp_using_mono (const char * const *sources,
l = (l + 1) % 2;
if (line[l] != NULL
&& !(linelen[l] >= 21
&& memcmp (line[l], "Compilation succeeded", 21) == 0))
&& memeq (line[l], "Compilation succeeded", 21)))
fwrite (line[l], 1, linelen[l], stderr);
if (line[0] != NULL)
free (line[0]);
@@ -399,7 +399,7 @@ compile_csharp_using_dotnet (const char * const *sources,
/* The line has the structure
Microsoft.SUBSYSTEM VERSION [DIRECTORY] */
if (linelen > 22
&& memcmp (line, "Microsoft.NETCore.App ", 22) == 0)
&& memeq (line, "Microsoft.NETCore.App ", 22))
{
char *version = line + 22;
char *version_end = strchr (version, ' ');
@@ -613,10 +613,9 @@ compile_csharp_using_dotnet (const char * const *sources,
char *source_file_converted = cygpath_w (source_file);
*mallocedp++ = source_file_converted;
if (strlen (source_file_converted) >= 10
&& memcmp (source_file_converted
+ strlen (source_file_converted) - 10,
".resources",
10) == 0)
&& memeq ((source_file_converted
+ strlen (source_file_converted) - 10),
".resources", 10))
{
char *option =
(char *) xmalloc (10 + strlen (source_file_converted) + 1);
@@ -717,12 +716,12 @@ compile_csharp_using_dotnet (const char * const *sources,
count++;
if (count >= 7)
{
if (memcmp (c, "chicken", 7) == 0)
if (memeq (c, "chicken", 7))
seen_chicken = true;
}
if (count == 8)
{
if (memcmp (c, "analyzer", 8) == 0)
if (memeq (c, "analyzer", 8))
seen_analyzer = true;
c[0] = c[1]; c[1] = c[2]; c[2] = c[3]; c[3] = c[4];
c[4] = c[5]; c[5] = c[6]; c[6] = c[7];
@@ -805,10 +804,9 @@ compile_csharp_using_dotnet (const char * const *sources,
char *source_file_converted = cygpath_w (source_file);
*mallocedp++ = source_file_converted;
if (strlen (source_file_converted) >= 10
&& memcmp (source_file_converted
+ strlen (source_file_converted) - 10,
".resources",
10) == 0)
&& memeq ((source_file_converted
+ strlen (source_file_converted) - 10),
".resources", 10))
{
char *option =
(char *) xmalloc (10 + strlen (source_file_converted) + 1);
@@ -895,7 +893,7 @@ compile_csharp_using_sscli (const char * const *sources,
count++;
if (count == 7)
{
if (memcmp (c, "chicken", 7) == 0)
if (memeq (c, "chicken", 7))
csc_present = false;
c[0] = c[1]; c[1] = c[2]; c[2] = c[3];
c[3] = c[4]; c[4] = c[5]; c[5] = c[6];
@@ -977,10 +975,9 @@ compile_csharp_using_sscli (const char * const *sources,
char *source_file_converted = cygpath_w (source_file);
*mallocedp++ = source_file_converted;
if (strlen (source_file_converted) >= 10
&& memcmp (source_file_converted
+ strlen (source_file_converted) - 10,
".resources",
10) == 0)
&& memeq ((source_file_converted
+ strlen (source_file_converted) - 10),
".resources", 10))
{
char *option =
(char *) xmalloc (10 + strlen (source_file_converted) + 1);
@@ -1034,7 +1031,7 @@ compile_csharp_class (const char * const *sources,
{
bool output_is_library =
(strlen (output_file) >= 4
&& memcmp (output_file + strlen (output_file) - 4, ".dll", 4) == 0);
&& memeq (output_file + strlen (output_file) - 4, ".dll", 4));
int result;
/* First try the C# implementation specified through --enable-csharp. */

View File

@@ -105,7 +105,7 @@ name_is_dll (const struct dirent *d)
if (d->d_name[0] != '.')
{
size_t d_name_len = strlen (d->d_name);
if (d_name_len > 4 && memcmp (d->d_name + d_name_len - 4, ".dll", 4) == 0)
if (d_name_len > 4 && memeq (d->d_name + d_name_len - 4, ".dll", 4))
return 1;
}
return 0;
@@ -327,7 +327,7 @@ execute_csharp_using_dotnet (const char *assembly_path,
{
size_t assembly_path_len = strlen (assembly_path);
if (assembly_path_len > 4
&& memcmp (assembly_path + (assembly_path_len - 4), ".exe", 4) == 0)
&& memeq (assembly_path + (assembly_path_len - 4), ".exe", 4))
assembly_path_len -= 4;
char *p = runtimeconfig_filename;
memcpy (p, assembly_path, assembly_path_len);
@@ -421,7 +421,7 @@ execute_csharp_using_dotnet (const char *assembly_path,
/* The line has the structure
Microsoft.SUBSYSTEM VERSION [DIRECTORY] */
if (linelen > 22
&& memcmp (line, "Microsoft.NETCore.App ", 22) == 0)
&& memeq (line, "Microsoft.NETCore.App ", 22))
{
char *version = line + 22;
char *version_end = strchr (version, ' ');

View File

@@ -261,7 +261,7 @@ get_aclinfo (int fd, char const *name, struct aclinfo *ai, int flags)
first case, and ENODATA in the latter. */
if (r == 0)
scontext_err = ENOTSUP;
if (r == 10 && memcmp (ai->scontext, "unlabeled", 10) == 0)
if (r == 10 && memeq (ai->scontext, "unlabeled", 10))
{
freecon (ai->scontext);
scontext_err = ENODATA;
@@ -364,9 +364,9 @@ acl_nfs4_nontrivial (uint32_t *xattr, ssize_t nbytes)
/* For a trivial ACL, max 6 (typically 3) ACEs, 3 allow, 3 deny.
Check that there is at most one ACE of each TYPE and WHO. */
int who2
= (wholen == 6 && memcmp (xattr, "OWNER@", 6) == 0 ? 0
: wholen == 6 && memcmp (xattr, "GROUP@", 6) == 0 ? 2
: wholen == 9 && memcmp (xattr, "EVERYONE@", 9) == 0 ? 4
= (wholen == 6 && memeq (xattr, "OWNER@", 6) ? 0
: wholen == 6 && memeq (xattr, "GROUP@", 6) ? 2
: wholen == 9 && memeq (xattr, "EVERYONE@", 9) ? 4
: -1);
if (who2 < 0)
return 1;

View File

@@ -67,6 +67,12 @@ str_endswith (const char *string, const char *suffix)
return len >= n && strcmp (string + len - n, suffix) == 0;
}
static bool
memeq (void const *s1, void const *s2, size_t n)
{
return !memcmp (s1, s2, n);
}
/* ========================================================================= */
/* Reading UnicodeData.txt. */
@@ -10539,7 +10545,7 @@ get_decomposition (unsigned int ch,
assert (rangle != NULL);
typelen = rangle + 1 - decomposition;
#define TYPE(t1,t2) \
if (typelen == (sizeof (t1) - 1) && memcmp (decomposition, t1, typelen) == 0) \
if (typelen == (sizeof (t1) - 1) && memeq (decomposition, t1, typelen)) \
type = t2; \
else
TYPE ("<font>", UC_DECOMP_FONT)
@@ -11426,20 +11432,20 @@ fill_casing_rules (const char *specialcasing_filename)
{
bool negate = false;
if (word_end - word_begin >= 4 && memcmp (word_begin, "Not_", 4) == 0)
if (word_end - word_begin >= 4 && memeq (word_begin, "Not_", 4))
{
word_begin += 4;
negate = true;
}
if (word_end - word_begin == 11 && memcmp (word_begin, "Final_Sigma", 11) == 0)
if (word_end - word_begin == 11 && memeq (word_begin, "Final_Sigma", 11))
context = SCC_FINAL_SIGMA;
else if (word_end - word_begin == 17 && memcmp (word_begin, "After_Soft_Dotted", 17) == 0)
else if (word_end - word_begin == 17 && memeq (word_begin, "After_Soft_Dotted", 17))
context = SCC_AFTER_SOFT_DOTTED;
else if (word_end - word_begin == 10 && memcmp (word_begin, "More_Above", 10) == 0)
else if (word_end - word_begin == 10 && memeq (word_begin, "More_Above", 10))
context = SCC_MORE_ABOVE;
else if (word_end - word_begin == 10 && memcmp (word_begin, "Before_Dot", 10) == 0)
else if (word_end - word_begin == 10 && memeq (word_begin, "Before_Dot", 10))
context = SCC_BEFORE_DOT;
else if (word_end - word_begin == 7 && memcmp (word_begin, "After_I", 7) == 0)
else if (word_end - word_begin == 7 && memeq (word_begin, "After_I", 7))
context = SCC_AFTER_I;
else
{

View File

@@ -97,7 +97,7 @@ get_ppid_of (pid_t pid)
/* Search for a line that starts with "PPid:". */
for (p = buf;;)
{
if (bufend - p >= 5 && memcmp (p, "PPid:", 5) == 0)
if (bufend - p >= 5 && memeq (p, "PPid:", 5))
{
unsigned int ppid = 0;
if (sscanf (p + 5, "%u", &ppid) > 0)

View File

@@ -341,7 +341,7 @@ get_progname_of (pid_t pid)
else
p = cmd;
if (strlen (p) > PST_UCOMMLEN - 1
&& memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0)
&& memeq (p, ucomm, PST_UCOMMLEN - 1))
/* p is less truncated than ucomm. */
;
else
@@ -377,7 +377,7 @@ get_progname_of (pid_t pid)
else
p = cmd;
if (strlen (p) > PST_UCOMMLEN - 1
&& memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0)
&& memeq (p, ucomm, PST_UCOMMLEN - 1))
/* p is less truncated than ucomm. */
;
else

View File

@@ -157,7 +157,7 @@ getlogin_r (char *name, size_t size)
return ENOMEM;
ret = getlogin_r (room, size + 1);
/* The untruncated result should be the same as in the first call. */
if (ret == 0 && memcmp (name, room, size) != 0)
if (ret == 0 && !memeq (name, room, size))
/* The untruncated result would have been different. */
ret = ERANGE;
freea (room);

View File

@@ -129,7 +129,7 @@ getprogname (void)
else
p = cmd;
if (strlen (p) > PST_UCOMMLEN - 1
&& memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0)
&& memeq (p, ucomm, PST_UCOMMLEN - 1))
/* p is less truncated than ucomm. */
;
else
@@ -165,7 +165,7 @@ getprogname (void)
else
p = cmd;
if (strlen (p) > PST_UCOMMLEN - 1
&& memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0)
&& memeq (p, ucomm, PST_UCOMMLEN - 1))
/* p is less truncated than ucomm. */
;
else

View File

@@ -80,7 +80,7 @@ getumask (void)
for (;;)
{
/* Here we're at the beginning of a line. */
if (p_end - p > 8 && memcmp (p, "Umask:\t0", 8) == 0)
if (p_end - p > 8 && memeq (p, "Umask:\t0", 8))
{
unsigned int value = 0;
p += 8;

View File

@@ -156,8 +156,8 @@ FUNC (DOUBLE x)
if (((m.word[EXPBIT0_WORD] ^ nan.word[EXPBIT0_WORD])
& (EXP_MASK << EXPBIT0_BIT))
== 0)
return (memcmp (&m.value, &plus_inf, SIZE) != 0
&& memcmp (&m.value, &minus_inf, SIZE) != 0);
return (!memeq (&m.value, &plus_inf, SIZE)
&& !memeq (&m.value, &minus_inf, SIZE));
else
return 0;
}
@@ -177,7 +177,7 @@ FUNC (DOUBLE x)
memset (&m2.value, 0, SIZE);
m1.value = x;
m2.value = x + (x ? 0.0L : -0.0L);
if (memcmp (&m1.value, &m2.value, SIZE) != 0)
if (!memeq (&m1.value, &m2.value, SIZE))
return 1;
# endif
return 0;

View File

@@ -217,12 +217,12 @@ typedef struct mbchar mbchar_t;
((mbc1).wc_valid && (mbc2).wc_valid \
? (mbc1).wc == (mbc2).wc \
: (mbc1).bytes == (mbc2).bytes \
&& memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0)
&& memeq ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes))
#define mb_caseequal(mbc1, mbc2) \
((mbc1).wc_valid && (mbc2).wc_valid \
? c32tolower ((mbc1).wc) == c32tolower ((mbc2).wc) \
: (mbc1).bytes == (mbc2).bytes \
&& memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0)
&& memeq ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes))
/* <ctype.h>, <wctype.h> classification. */
#define mb_isascii(mbc) \

View File

@@ -129,7 +129,7 @@ lookup (const hash_table *htab,
if (table[idx].used)
{
if (table[idx].used == hval && table[idx].keylen == keylen
&& memcmp (table[idx].key, key, keylen) == 0)
&& memeq (table[idx].key, key, keylen))
return idx;
/* Second hash function as suggested in [Knuth]. */
@@ -144,7 +144,7 @@ lookup (const hash_table *htab,
/* If entry is found use it. */
if (table[idx].used == hval && table[idx].keylen == keylen
&& memcmp (table[idx].key, key, keylen) == 0)
&& memeq (table[idx].key, key, keylen))
return idx;
}
while (table[idx].used);

View File

@@ -71,7 +71,7 @@ memcoll (char *s1, size_t s1len, char *s2, size_t s2len)
where the arguments are bytewise equal. Otherwise, walk through
the buffers using strcoll on each substring. */
if (s1len == s2len && memcmp (s1, s2, s1len) == 0)
if (s1len == s2len && memeq (s1, s2, s1len))
{
errno = 0;
diff = 0;
@@ -101,7 +101,7 @@ memcoll (char *s1, size_t s1len, char *s2, size_t s2len)
int
memcoll0 (char const *s1, size_t s1size, char const *s2, size_t s2size)
{
if (s1size == s2size && memcmp (s1, s2, s1size) == 0)
if (s1size == s2size && memeq (s1, s2, s1size))
{
errno = 0;
return 0;

View File

@@ -43,7 +43,7 @@ set_program_name (const char *argv0)
Remove this "<dirname>/.libs/" or "<dirname>/.libs/lt-" prefix here. */
char const *slash = strrchr (argv0, '/');
char const *base = slash ? slash + 1 : argv0;
if (7 <= base - argv0 && memcmp (base - 7, "/.libs/", 7) == 0)
if (7 <= base - argv0 && memeq (base - 7, "/.libs/", 7))
{
argv0 = base;
if (strncmp (base, "lt-", 3) == 0)

View File

@@ -454,7 +454,7 @@ set_program_name_and_installdir (const char *argv0,
size_t argv0_len = strlen (argv0);
const size_t exeext_len = sizeof (EXEEXT) - sizeof ("");
if (argv0_len > 4 + exeext_len)
if (memcmp (argv0 + argv0_len - exeext_len - 4, ".bin", 4) == 0)
if (memeq (argv0 + argv0_len - exeext_len - 4, ".bin", 4))
{
if (sizeof (EXEEXT) > sizeof (""))
{

View File

@@ -54,7 +54,7 @@ pthread_sigmask (int how, const sigset_t *new_mask, sigset_t *old_mask)
Don't cache the information: libpthread.so could be dynamically
loaded after the program started and after pthread_sigmask was
called for the first time. */
if (memcmp (&omask_copy, &omask, sizeof omask) == 0
if (memeq (&omask_copy, &omask, sizeof omask)
&& pthread_sigmask (1729, &omask_copy, NULL) == 0)
{
/* pthread_sigmask is currently ineffective. The program is not

View File

@@ -410,7 +410,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
and when the quote string is more than 1 byte long.
If we do call strlen, save the result. */
? (argsize = strlen (arg)) : argsize))
&& memcmp (arg + i, quote_string, quote_string_len) == 0)
&& memeq (arg + i, quote_string, quote_string_len))
{
if (elide_outer_quotes)
goto force_outer_quoting_style;

View File

@@ -394,14 +394,14 @@ read_utmp_from_file (char const *file, idx_t *n_entries, STRUCT_UTMP **utmp_buf,
);
# if defined __linux__ && !defined __ANDROID__
if (file_is_utmp
&& memcmp (UT_USER (ut), "runlevel", strlen ("runlevel") + 1) == 0
&& memcmp (ut->ut_line, "~", strlen ("~") + 1) == 0)
&& memeq (UT_USER (ut), "runlevel", strlen ("runlevel") + 1)
&& memeq (ut->ut_line, "~", strlen ("~") + 1))
runlevel_ts = ts;
# endif
# if defined __minix
if (file_is_utmp
&& UT_USER (ut)[0] == '\0'
&& memcmp (ut->ut_line, "run-level ", strlen ("run-level ")) == 0)
&& memeq (ut->ut_line, "run-level ", strlen ("run-level ")))
runlevel_ts = ts;
# endif
}

View File

@@ -76,7 +76,7 @@ same_nameat (int source_dfd, char const *source,
size_t dest_baselen = base_len (dest_basename);
bool identical_basenames =
(source_baselen == dest_baselen
&& memcmp (source_basename, dest_basename, dest_baselen) == 0);
&& memeq (source_basename, dest_basename, dest_baselen));
bool compare_dirs = identical_basenames;
bool same = false;
@@ -84,7 +84,7 @@ same_nameat (int source_dfd, char const *source,
size_t slen_max = HAVE_LONG_FILE_NAMES ? 255 : _POSIX_NAME_MAX;
size_t min_baselen = MIN (source_baselen, dest_baselen);
if (slen_max <= min_baselen
&& memcmp (source_basename, dest_basename, slen_max) == 0)
&& memeq (source_basename, dest_basename, slen_max))
compare_dirs = true;
#endif
@@ -122,8 +122,7 @@ same_nameat (int source_dfd, char const *source,
destdir_errno = errno;
else
same = (name_max <= min_baselen
&& (memcmp (source_basename, dest_basename, name_max)
== 0));
&& memeq (source_basename, dest_basename, name_max));
}
}
close (destdir_fd);

View File

@@ -56,7 +56,7 @@ gl_signbitd (double arg)
/* Distinguish 0.0 and -0.0. */
static double plus_zero = 0.0;
double arg_mem = arg;
return (memcmp (&plus_zero, &arg_mem, SIZEOF_DBL) != 0);
return !memeq (&plus_zero, &arg_mem, SIZEOF_DBL);
}
else
return 0;

View File

@@ -56,7 +56,7 @@ gl_signbitf (float arg)
/* Distinguish 0.0f and -0.0f. */
static float plus_zero = 0.0f;
float arg_mem = arg;
return (memcmp (&plus_zero, &arg_mem, SIZEOF_FLT) != 0);
return !memeq (&plus_zero, &arg_mem, SIZEOF_FLT);
}
else
return 0;

View File

@@ -56,7 +56,7 @@ gl_signbitl (long double arg)
/* Distinguish 0.0L and -0.0L. */
static long double plus_zero = 0.0L;
long double arg_mem = arg;
return (memcmp (&plus_zero, &arg_mem, SIZEOF_LDBL) != 0);
return !memeq (&plus_zero, &arg_mem, SIZEOF_LDBL);
}
else
return 0;

View File

@@ -41,7 +41,7 @@ _sd_equals (idx_t a_nbytes, const char *a_data,
idx_t b_nbytes, const char *b_data)
{
return (a_nbytes == b_nbytes
&& (a_nbytes == 0 || memcmp (a_data, b_data, a_nbytes) == 0));
&& (a_nbytes == 0 || memeq (a_data, b_data, a_nbytes)));
}
bool
@@ -50,7 +50,7 @@ _sd_startswith (idx_t s_nbytes, const char *s_data,
{
return (s_nbytes >= prefix_nbytes
&& (prefix_nbytes == 0
|| memcmp (s_data, prefix_data, prefix_nbytes) == 0));
|| memeq (s_data, prefix_data, prefix_nbytes)));
}
bool
@@ -59,8 +59,8 @@ _sd_endswith (idx_t s_nbytes, const char *s_data,
{
return (s_nbytes >= suffix_nbytes
&& (suffix_nbytes == 0
|| memcmp (s_data + (s_nbytes - suffix_nbytes), suffix_data,
suffix_nbytes) == 0));
|| memeq (s_data + (s_nbytes - suffix_nbytes), suffix_data,
suffix_nbytes)));
}
int

View File

@@ -222,8 +222,8 @@ CONCAT(TABLE,_finalize) (struct TABLE *t)
for (j = 0; j < t->level3_size; j++)
{
for (i = 0; i < k; i++)
if (memcmp (&t->level3[i << t->p], &t->level3[j << t->p],
(1 << t->p) * sizeof (ELEMENT)) == 0)
if (memeq (&t->level3[i << t->p], &t->level3[j << t->p],
(1 << t->p) * sizeof (ELEMENT)))
break;
/* Relocate block j to block i. */
reorder3[j] = i;
@@ -246,8 +246,8 @@ CONCAT(TABLE,_finalize) (struct TABLE *t)
for (j = 0; j < t->level2_size; j++)
{
for (i = 0; i < k; i++)
if (memcmp (&t->level2[i << t->q], &t->level2[j << t->q],
(1 << t->q) * sizeof (uint32_t)) == 0)
if (memeq (&t->level2[i << t->q], &t->level2[j << t->q],
(1 << t->q) * sizeof (uint32_t)))
break;
/* Relocate block j to block i. */
reorder2[j] = i;

View File

@@ -218,8 +218,8 @@ CONCAT(TABLE,_finalize) (struct TABLE *t)
for (j = 0; j < t->level3_size; j++)
{
for (i = 0; i < k; i++)
if (memcmp (&t->level3[i << t->p], &t->level3[j << t->p],
(1 << t->p) * sizeof (uint32_t)) == 0)
if (memeq (&t->level3[i << t->p], &t->level3[j << t->p],
(1 << t->p) * sizeof (uint32_t)))
break;
/* Relocate block j to block i. */
reorder3[j] = i;
@@ -242,8 +242,8 @@ CONCAT(TABLE,_finalize) (struct TABLE *t)
for (j = 0; j < t->level2_size; j++)
{
for (i = 0; i < k; i++)
if (memcmp (&t->level2[i << t->q], &t->level2[j << t->q],
(1 << t->q) * sizeof (uint32_t)) == 0)
if (memeq (&t->level2[i << t->q], &t->level2[j << t->q],
(1 << t->q) * sizeof (uint32_t)))
break;
/* Relocate block j to block i. */
reorder2[j] = i;

View File

@@ -485,19 +485,19 @@ unicode_name_character (const char *name)
unsigned int index1;
for (index1 = 0; index1 < 19; index1++)
if (memcmp (jamo_initial_short_name[index1], p1, n1) == 0
if (memeq (jamo_initial_short_name[index1], p1, n1)
&& jamo_initial_short_name[index1][n1] == '\0')
{
unsigned int index2;
for (index2 = 0; index2 < 21; index2++)
if (memcmp (jamo_medial_short_name[index2], p2, n2) == 0
if (memeq (jamo_medial_short_name[index2], p2, n2)
&& jamo_medial_short_name[index2][n2] == '\0')
{
unsigned int index3;
for (index3 = 0; index3 < 28; index3++)
if (memcmp (jamo_final_short_name[index3], p3, n3) == 0
if (memeq (jamo_final_short_name[index3], p3, n3)
&& jamo_final_short_name[index3][n3] == '\0')
{
return 0xAC00 + (index1 * 21 + index2) * 28 + index3;
@@ -516,7 +516,7 @@ unicode_name_character (const char *name)
&& words[1] == UNICODE_CHARNAME_WORD_COMPATIBILITY
&& p1 + 14 <= ptr
&& p1 + 15 >= ptr
&& memcmp (p1, "IDEOGRAPH-", 10) == 0)
&& memeq (p1, "IDEOGRAPH-", 10))
{
const char *p2 = p1 + 10;
@@ -553,7 +553,7 @@ unicode_name_character (const char *name)
&& words[0] == UNICODE_CHARNAME_WORD_VARIATION
&& p1 + 10 <= ptr
&& p1 + 12 >= ptr
&& memcmp (p1, "SELECTOR-", 9) == 0)
&& memeq (p1, "SELECTOR-", 9))
{
const char *p2 = p1 + 9;

View File

@@ -452,7 +452,7 @@ relativize (const char *filename,
break;
/* Did the components match? */
if (!(filename_s - filename == dir2_s - dir2
&& memcmp (filename, dir2, dir2_s - dir2) == 0))
&& memeq (filename, dir2, dir2_s - dir2)))
break;
dir2 = dir2_s;
filename = filename_s;

View File

@@ -18,6 +18,7 @@ quote
quotearg
bool
stdlib-h
stringeq
configure.ac:

View File

@@ -24,6 +24,7 @@ renameatu
bool
stdckdint-h
stdint-h
stringeq
xalloc-die
configure.ac:

View File

@@ -8,6 +8,7 @@ lib/bcp47.c
Depends-on:
bool
c-ctype
stringeq
configure.ac:

View File

@@ -11,6 +11,7 @@ m4/readutmp.m4
Depends-on:
extensions
idx
stringeq
stat-time
gettimeofday
bool

View File

@@ -18,6 +18,7 @@ scandir
alphasort
sh-quote
safe-read
stringeq
xmalloca
xvasprintf
gettext-h

View File

@@ -22,6 +22,7 @@ xsetenv
scandir
alphasort
sh-quote
stringeq
xalloc
xmalloca
copy-file

View File

@@ -18,6 +18,7 @@ minmax
free-posix
limits-h
stdint-h
stringeq
malloc-posix
ssize_t
stat

View File

@@ -7,6 +7,7 @@ lib/get_ppid_of.c
Depends-on:
extensions
stringeq
sys_types-h
unistd-h
open

View File

@@ -7,6 +7,7 @@ lib/get_progname_of.c
Depends-on:
extensions
stringeq
unistd-h
open

View File

@@ -11,6 +11,7 @@ unistd-h
extensions
malloca [test $HAVE_GETLOGIN_R = 0 || test $REPLACE_GETLOGIN_R = 1]
memchr [test $HAVE_GETLOGIN_R = 0 || test $REPLACE_GETLOGIN_R = 1]
stringeq [test $HAVE_GETLOGIN_R = 0 || test $REPLACE_GETLOGIN_R = 1]
configure.ac:
gl_FUNC_GETLOGIN_R

View File

@@ -11,6 +11,7 @@ stdlib-h
basename-lgpl [test $HAVE_GETPROGNAME = 0]
extensions [test $HAVE_GETPROGNAME = 0]
open [test $HAVE_GETPROGNAME = 0 && case "$host_os" in sco* | unixware*) true;; *) false;; esac]
stringeq [test $HAVE_GETPROGNAME = 0]
configure.ac:
AC_REQUIRE([AC_CANONICAL_HOST])

View File

@@ -9,6 +9,7 @@ Depends-on:
sys_stat-h
extensions
c99 [test $HAVE_GETUMASK = 0]
stringeq [test $HAVE_GETUMASK = 0]
unistd-h [test $HAVE_GETUMASK = 0]
clean-temp [test $HAVE_GETUMASK = 0]
tempname [test $HAVE_GETUMASK = 0]

View File

@@ -9,6 +9,7 @@ isnanf
isnand
isnanl
math-h
stringeq
extensions
configure.ac:

View File

@@ -26,6 +26,7 @@ c32isxdigit
c32tolower
c32width
memcmp
stringeq
configure.ac:
gl_MBCHAR

View File

@@ -8,6 +8,7 @@ lib/mem-hash-map.c
Depends-on:
next-prime
obstack
stringeq
xalloc
configure.ac:

View File

@@ -8,6 +8,7 @@ m4/memcoll.m4
Depends-on:
memcmp
stringeq
configure.ac:
gl_MEMCOLL

View File

@@ -7,6 +7,7 @@ lib/progname.c
Depends-on:
snippet/arg-nonnull
stringeq
configure.ac:
AC_CHECK_DECLS([program_invocation_name], [], [], [#include <errno.h>])

View File

@@ -9,6 +9,7 @@ Depends-on:
signal-h
threadlib
sigprocmask [test $HAVE_PTHREAD_SIGMASK = 0 || test $REPLACE_PTHREAD_SIGMASK = 1]
stringeq [test $HAVE_PTHREAD_SIGMASK = 0 || test $REPLACE_PTHREAD_SIGMASK = 1]
configure.ac:
gl_FUNC_PTHREAD_SIGMASK

View File

@@ -22,6 +22,7 @@ minmax
quotearg-simple
bool
stdint-h
stringeq
uchar-h
xalloc

View File

@@ -15,6 +15,7 @@ stat-time
gettimeofday
bool
stdint-h
stringeq
strnlen
time-h
unlocked-io-internal

View File

@@ -19,6 +19,7 @@ Depends-on:
relocatable-prog-wrapper
progname
canonicalize-lgpl
stringeq
xalloc
xreadlink
open

View File

@@ -75,6 +75,7 @@ stdckdint-h
stdint-h
stdlib-h
string-h
stringeq
sys_stat-h
unistd-h
xalloc-oversized

View File

@@ -15,6 +15,7 @@ fstat
fstatat
openat
same-inode
stringeq
bool
memcmp

View File

@@ -16,6 +16,7 @@ isnand-nolibm [test $REPLACE_SIGNBIT = 1]
isnanl-nolibm [test $REPLACE_SIGNBIT = 1]
fpieee [test $REPLACE_SIGNBIT = 1]
memcmp [test $REPLACE_SIGNBIT = 1]
stringeq [test $REPLACE_SIGNBIT = 1]
configure.ac:
gl_SIGNBIT

View File

@@ -16,6 +16,7 @@ memchr
memrchr
memmem
full-write
stringeq
configure.ac:

View File

@@ -10,6 +10,7 @@ Depends-on:
uniname/base
attribute
memcmp
stringeq
bool
c99

View File

@@ -9,6 +9,7 @@ Depends-on:
time-h
bool
spawn-pipe
stringeq
wait-process
execute
safe-read