>From d09072fcdfdbf7d5aa860e60a7e8697a999de820 Mon Sep 17 00:00:00 2001
From: Vladimir Pantelic <[email protected]>
Date: Wed, 23 Jan 2013 16:56:16 +0100
Subject: [PATCH] lavu: Add av_strnstr()

This is a length limited version of strstr()

Signed-off-by: Vladimir Pantelic <[email protected]>
---
 Changelog            |    1 +
 doc/APIchanges       |    3 +++
 libavutil/avstring.c |   16 ++++++++++++++++
 libavutil/avstring.h |   15 +++++++++++++++
 libavutil/version.h  |    2 +-
 5 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/Changelog b/Changelog
index 24f0791..dd03e6e 100644
--- a/Changelog
+++ b/Changelog
@@ -2,6 +2,7 @@ Entries are sorted chronologically from oldest to youngest within each release,
 releases are sorted from youngest to oldest.
 
 version 9:
+- av_strnstr
 - av_basename and av_dirname
 - adobe and limelight publisher authentication in RTMP
 - VDPAU hardware acceleration through normal hwaccel
diff --git a/doc/APIchanges b/doc/APIchanges
index 3120f7e..79e3cb7 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil:     2012-10-22
 
 API changes, most recent first:
 
+2013-01-xx - xxxxxxx - lavu 52.6.0 - avstring.h
+  Add av_strnstr()
+
 2013-01-xx - xxxxxxx - lavu 52.5.0 - hmac.h
   Add AVHMAC.
 
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index 2c88bd3..db9eee2 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -64,6 +64,22 @@ char *av_stristr(const char *s1, const char *s2)
     return NULL;
 }
 
+char *av_strnstr(const char *s1, const char *s2, size_t len)
+{
+        size_t l2;
+
+        l2 = strlen(s2);
+        if (!l2)
+                return s1;
+        while (len >= l2) {
+                len--;
+                if (!memcmp(s1, s2, l2))
+                        return s1;
+                s1++;
+        }
+        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 acd6610..da34105 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 in the string haystack of the string needle
+ * where not more than 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 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 haystack_size);
+
+/**
  * 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 68f5752..4c9651f 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, \
-- 
1.7.6.rc1.1.g2c162b

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to