aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil
diff options
context:
space:
mode:
authorVladimir Pantelic <vladoman@gmail.com>2013-01-24 14:09:48 +0000
committerLuca Barbato <lu_zero@gentoo.org>2013-01-25 10:47:51 +0100
commitb85a5e87af4254b80913fe33591d96361f30832b (patch)
treec455a00d43d40bfb52080ab6f4ad8da3d2cdb4fb /libavutil
parenta84fb6e06f7f13e61b5dad0224fa392ebe65e294 (diff)
downloadffmpeg-b85a5e87af4254b80913fe33591d96361f30832b.tar.gz
lavu: Add av_strnstr()
This is a length limited version of strstr() Signed-off-by: Vladimir Pantelic <vladoman@gmail.com> Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/avstring.c14
-rw-r--r--libavutil/avstring.h15
-rw-r--r--libavutil/version.h2
3 files changed, 30 insertions, 1 deletions
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index a16adcb3fe..625f723686 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -65,6 +65,20 @@ char *av_stristr(const char *s1, const char *s2)
return NULL;
}
+char *av_strnstr(const char *haystack, const char *needle, size_t hay_length)
+{
+ size_t needle_len = strlen(needle);
+ if (!needle_len)
+ return haystack;
+ while (hay_length >= needle_len) {
+ hay_length--;
+ if (!memcmp(haystack, needle, needle_len))
+ return haystack;
+ haystack++;
+ }
+ return NULL;
+}
+
size_t av_strlcpy(char *dst, const char *src, size_t size)
{
size_t len = 0;
diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index acd6610d38..e0e6ed26f5 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -67,6 +67,21 @@ int av_stristart(const char *str, const char *pfx, const char **ptr);
char *av_stristr(const char *haystack, const char *needle);
/**
+ * Locate the first occurrence of the string needle in the string haystack
+ * where not more than hay_length characters are searched. A zero-length
+ * string needle is considered to match at the start of haystack.
+ *
+ * This function is a length-limited version of the standard strstr().
+ *
+ * @param haystack string to search in
+ * @param needle string to search for
+ * @param hay_length length of string to search in
+ * @return pointer to the located match within haystack
+ * or a null pointer if no match
+ */
+char *av_strnstr(const char *haystack, const char *needle, size_t hay_length);
+
+/**
* Copy the string src to dst, but no more than size - 1 bytes, and
* null-terminate dst.
*
diff --git a/libavutil/version.h b/libavutil/version.h
index 68f5752f05..4c9651fae2 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -37,7 +37,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 52
-#define LIBAVUTIL_VERSION_MINOR 5
+#define LIBAVUTIL_VERSION_MINOR 6
#define LIBAVUTIL_VERSION_MICRO 0
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \