mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
maint: avoid locale-sensitivity in string case comparisons
strcase{cmp/str} have the drawback of being sensitive to the global
locale; this is unacceptable in a library setting. Prefer a
hard-coded C locale alternative for all but virsh, which is user
facing and where the global locale isn't changing externally.
* .gnulib: Update to latest, for c-strcasestr change.
* bootstrap.conf (gnulib_modules): Drop strcasestr, add c-strcase
and c-strcasestr.
* cfg.mk (sc_avoid_strcase): New rule.
(exclude_file_name_regexp--sc_avoid_strcase): New exception.
* src/internal.h (STRCASEEQ, STRCASENEQ, STRCASEEQLEN)
(STRCASENEQLEN): Adjust offenders.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextEjectMedia):
Likewise.
* tools/virsh.c (namesorter): Document exception.
This commit is contained in:
@@ -44,6 +44,8 @@
|
||||
|
||||
# include "libvirt_internal.h"
|
||||
|
||||
# include "c-strcase.h"
|
||||
|
||||
/* On architectures which lack these limits, define them (ie. Cygwin).
|
||||
* Note that the libvirt code should be robust enough to handle the
|
||||
* case where actual value is longer than these limits (eg. by setting
|
||||
@@ -64,13 +66,13 @@
|
||||
|
||||
/* String equality tests, suggested by Jim Meyering. */
|
||||
# define STREQ(a,b) (strcmp(a,b) == 0)
|
||||
# define STRCASEEQ(a,b) (strcasecmp(a,b) == 0)
|
||||
# define STRCASEEQ(a,b) (c_strcasecmp(a,b) == 0)
|
||||
# define STRNEQ(a,b) (strcmp(a,b) != 0)
|
||||
# define STRCASENEQ(a,b) (strcasecmp(a,b) != 0)
|
||||
# define STRCASENEQ(a,b) (c_strcasecmp(a,b) != 0)
|
||||
# define STREQLEN(a,b,n) (strncmp(a,b,n) == 0)
|
||||
# define STRCASEEQLEN(a,b,n) (strncasecmp(a,b,n) == 0)
|
||||
# define STRCASEEQLEN(a,b,n) (c_strncasecmp(a,b,n) == 0)
|
||||
# define STRNEQLEN(a,b,n) (strncmp(a,b,n) != 0)
|
||||
# define STRCASENEQLEN(a,b,n) (strncasecmp(a,b,n) != 0)
|
||||
# define STRCASENEQLEN(a,b,n) (c_strncasecmp(a,b,n) != 0)
|
||||
# define STRPREFIX(a,b) (strncmp(a,b,strlen(b)) == 0)
|
||||
# define STRSKIP(a,b) (STRPREFIX(a,b) ? (a) + strlen(b) : NULL)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user