Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
14df240f
Commit
14df240f
authored
Apr 09, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
OpusReader: don't use strndup()
Eliminate the fallback strndup() and strnlen() implementations.
parent
20909113
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
4 additions
and
67 deletions
+4
-67
configure.ac
configure.ac
+0
-2
OpusReader.hxx
src/decoder/OpusReader.hxx
+4
-2
string_util.c
src/string_util.c
+0
-37
string_util.h
src/string_util.h
+0
-26
No files found.
configure.ac
View file @
14df240f
...
...
@@ -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])])
...
...
src/decoder/OpusReader.hxx
View file @
14df240f
...
...
@@ -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
;
}
};
...
...
src/string_util.c
View file @
14df240f
...
...
@@ -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
src/string_util.h
View file @
14df240f
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment