Last change
on this file since 543 was
444,
checked in by satin@…, 6 years ago
|
add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc
|
File size:
401 bytes
|
Line | |
---|
1 | #include <reent.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <string.h> |
---|
4 | |
---|
5 | char * |
---|
6 | _strndup_r (struct _reent *reent_ptr, |
---|
7 | const char *str, |
---|
8 | size_t n) |
---|
9 | { |
---|
10 | const char *ptr = str; |
---|
11 | size_t len; |
---|
12 | char *copy; |
---|
13 | |
---|
14 | while (n-- > 0 && *ptr) |
---|
15 | ptr++; |
---|
16 | |
---|
17 | len = ptr - str; |
---|
18 | |
---|
19 | copy = _malloc_r (reent_ptr, len + 1); |
---|
20 | if (copy) |
---|
21 | { |
---|
22 | memcpy (copy, str, len); |
---|
23 | copy[len] = '\0'; |
---|
24 | } |
---|
25 | return copy; |
---|
26 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.