Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>2011-11-02 23:17:25 +0400
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>2011-11-03 22:25:26 +0400
commit96949dafcca87f65902bd77a0bc56007d9cead70 (patch)
treee394623e56efc86b70d3e7fbdefc2555457b3aa3 /libavutil
parent475fb67d0b391ad1e8e3e8e3d65d7e6892e17e7a (diff)
Replace all strcasecmp/strncasecmp usages.
All current usages of it are incompatible with localization. For example strcasecmp("i", "I") != 0 is possible, but would break many of the places where it is used. Instead use our own implementations that always treat the data as ASCII. Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/avstring.c27
-rw-r--r--libavutil/avstring.h12
-rw-r--r--libavutil/internal.h4
-rw-r--r--libavutil/parseutils.c7
4 files changed, 46 insertions, 4 deletions
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index 247cd71745..d167d5245e 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -189,6 +189,33 @@ char *av_strtok(char *s, const char *delim, char **saveptr)
return tok;
}
+#define TOUPPER(c) do { if (c >= 'a' && c <= 'z') c -= 'a' - 'A'; } while (0)
+
+int av_strcasecmp(const char *a, const char *b)
+{
+ uint8_t c1, c2;
+ do {
+ c1 = *a++;
+ c2 = *b++;
+ TOUPPER(c1);
+ TOUPPER(c2);
+ } while (c1 && c1 == c2);
+ return c1 - c2;
+}
+
+int av_strncasecmp(const char *a, const char *b, size_t n)
+{
+ const char *end = a + n;
+ uint8_t c1, c2;
+ do {
+ c1 = *a++;
+ c2 = *b++;
+ TOUPPER(c1);
+ TOUPPER(c2);
+ } while (a < end && c1 && c1 == c2);
+ return c1 - c2;
+}
+
#ifdef TEST
#undef printf
diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index 0b2205a9be..3fb3fbaf04 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -165,4 +165,16 @@ char *av_get_token(const char **buf, const char *term);
*/
char *av_strtok(char *s, const char *delim, char **saveptr);
+/**
+ * Locale independent case-insensitive compare.
+ * Note: This means only ASCII-range characters are case-insensitive
+ */
+int av_strcasecmp(const char *a, const char *b);
+
+/**
+ * Locale independent case-insensitive compare.
+ * Note: This means only ASCII-range characters are case-insensitive
+ */
+int av_strncasecmp(const char *a, const char *b, size_t n);
+
#endif /* AVUTIL_AVSTRING_H */
diff --git a/libavutil/internal.h b/libavutil/internal.h
index eecc1280df..46a05e124c 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -156,6 +156,10 @@ struct AVDictionary {
#define puts please_use_av_log_instead_of_puts
#undef perror
#define perror please_use_av_log_instead_of_perror
+#undef strcasecmp
+#define strcasecmp please_use_av_strcasecmp
+#undef strncasecmp
+#define strncasecmp please_use_av_strncasecmp
#define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
{\
diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
index e2c8ea2719..0c787d6fae 100644
--- a/libavutil/parseutils.c
+++ b/libavutil/parseutils.c
@@ -21,7 +21,6 @@
* misc parsing utilities
*/
-#include <strings.h>
#include <sys/time.h>
#include <time.h>
@@ -294,7 +293,7 @@ static ColorEntry color_table[] = {
static int color_table_compare(const void *lhs, const void *rhs)
{
- return strcasecmp(lhs, ((const ColorEntry *)rhs)->name);
+ return av_strcasecmp(lhs, ((const ColorEntry *)rhs)->name);
}
#define ALPHA_SEP '@'
@@ -320,7 +319,7 @@ int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen,
len = strlen(color_string2);
rgba_color[3] = 255;
- if (!strcasecmp(color_string2, "random") || !strcasecmp(color_string2, "bikeshed")) {
+ if (!av_strcasecmp(color_string2, "random") || !av_strcasecmp(color_string2, "bikeshed")) {
int rgba = av_get_random_seed();
rgba_color[0] = rgba >> 24;
rgba_color[1] = rgba >> 16;
@@ -525,7 +524,7 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
p = timestr;
q = NULL;
if (!duration) {
- if (!strncasecmp(timestr, "now", len)) {
+ if (!av_strncasecmp(timestr, "now", len)) {
*timeval = (int64_t) now * 1000000;
return 0;
}