aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-04-09 01:03:44 +0200
committerMax Kellermann <max@duempel.org>2013-04-09 01:03:44 +0200
commit14df240f5b16822da0901b35f7d0cb053c895129 (patch)
treea7f3be85b1bbf8f98c42ec34cba91c2fad8ccd0d
parent2090911363a131b2a38d39d3b8458eae02889e57 (diff)
downloadmpd-14df240f5b16822da0901b35f7d0cb053c895129.tar.gz
mpd-14df240f5b16822da0901b35f7d0cb053c895129.tar.xz
mpd-14df240f5b16822da0901b35f7d0cb053c895129.zip
OpusReader: don't use strndup()
Eliminate the fallback strndup() and strnlen() implementations.
-rw-r--r--configure.ac2
-rw-r--r--src/decoder/OpusReader.hxx6
-rw-r--r--src/string_util.c37
-rw-r--r--src/string_util.h26
4 files changed, 4 insertions, 67 deletions
diff --git a/configure.ac b/configure.ac
index 65c591200..043cc2956 100644
--- a/configure.ac
+++ b/configure.ac
@@ -136,8 +136,6 @@ AC_SEARCH_LIBS([gethostbyname], [nsl])
AC_CHECK_FUNCS(pipe2 accept4 eventfd)
-AC_CHECK_FUNCS(strnlen strndup)
-
AC_SEARCH_LIBS([exp], [m],,
[AC_MSG_ERROR([exp() not found])])
diff --git a/src/decoder/OpusReader.hxx b/src/decoder/OpusReader.hxx
index 1fd07b55c..7e161fd0f 100644
--- a/src/decoder/OpusReader.hxx
+++ b/src/decoder/OpusReader.hxx
@@ -21,7 +21,6 @@
#define MPD_OPUS_READER_HXX
#include "check.h"
-#include "string_util.h"
#include <stdint.h>
#include <string.h>
@@ -91,7 +90,10 @@ public:
if (src == nullptr)
return nullptr;
- return strndup(src, length);
+ char *dest = new char[length + 1];
+ memcpy(dest, src, length);
+ dest[length] = 0;
+ return dest;
}
};
diff --git a/src/string_util.c b/src/string_util.c
index 5d9feccf9..00c36892b 100644
--- a/src/string_util.c
+++ b/src/string_util.c
@@ -17,11 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "config.h"
#include "string_util.h"
-#include <stdlib.h> /* for malloc() */
-#include <string.h> /* for strnlen() */
#include <glib.h>
#include <assert.h>
@@ -47,37 +44,3 @@ string_array_contains(const char *const* haystack, const char *needle)
return false;
}
-
-#ifndef HAVE_STRNLEN
-
-size_t
-strnlen(const char *s, size_t max)
-{
- assert(s != NULL);
-
- const char *t = memchr(s, 0, max);
- return t != NULL
- ? (size_t)(t - s)
- : max;
-}
-
-#endif
-
-#if !defined(HAVE_STRNDUP)
-
-char *
-strndup(const char *str, size_t n)
-{
- assert(str != NULL);
-
- size_t len = strnlen(str, n);
- char* ret = (char *) malloc(len + 1);
- if (ret == NULL)
- return NULL;
-
- memcpy(ret, str, len);
- ret[len] = '\0';
- return ret;
-}
-
-#endif
diff --git a/src/string_util.h b/src/string_util.h
index 62de53873..5b76c980b 100644
--- a/src/string_util.h
+++ b/src/string_util.h
@@ -23,7 +23,6 @@
#include "gcc.h"
#include <stdbool.h>
-#include <stdlib.h> /* for size_t */
#ifdef __cplusplus
extern "C" {
@@ -83,31 +82,6 @@ strchug_fast(char *p)
bool
string_array_contains(const char *const* haystack, const char *needle);
-#ifndef HAVE_STRNLEN
-
-gcc_pure
-size_t
-strnlen(const char *s, size_t max);
-
-#endif
-
-#if !defined(HAVE_STRNDUP)
-
-/**
- * Duplicates the string to a newly allocated buffer
- * copying at most n characters.
- *
- * @param str a string to duplicate
- * @param n maximal number of characters to copy
- * @return a pointer to the duplicated string,
- * or NULL if memory allocation failed.
- */
-gcc_malloc
-char *
-strndup(const char *str, size_t n);
-
-#endif
-
#ifdef __cplusplus
} /* extern "C" */
#endif