repo.or.cz
/
zpugcc
/
jano.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
fixes for host gcc 4.6.1
[zpugcc/jano.git]
/
toolchain
/
gcc
/
newlib
/
libc
/
string
/
strndup_r.c
blob
86d9eec44019fa9d2b5ef2bb715bf754895fb61a
1
#include <reent.h>
2
#include <stdlib.h>
3
#include <string.h>
4
5
#define MIN(a,b) ((a) < (b) ? (a) : (b))
6
7
char
*
8
_DEFUN
(
_strndup_r
, (
reent_ptr
,
str
,
n
),
9
struct
_reent
*
reent_ptr _AND
10
_CONST
char
*
str _AND
11
size_t
n
)
12
{
13
size_t
len
=
MIN
(
strlen
(
str
),
n
);
14
char
*
copy
=
_malloc_r
(
reent_ptr
,
len
+
1
);
15
if
(
copy
)
16
{
17
memcpy
(
copy
,
str
,
len
);
18
copy
[
len
] =
'\0'
;
19
}
20
return
copy
;
21
}