Add wrapper for strndup()

This commit is contained in:
Sebastian Huber
2019-09-11 10:18:30 +02:00
parent 951c4b92cf
commit 7b1aea98a1
4 changed files with 56 additions and 16 deletions

View File

@@ -47,6 +47,7 @@
#undef printf
#define RTEMS_BSD_PROGRAM_NO_STRDUP_WRAP
#define RTEMS_BSD_PROGRAM_NO_STRNDUP_WRAP
#include <machine/rtems-bsd-program.h>
struct rtems_bsd_program_control *

View File

@@ -546,18 +546,32 @@ rtems_bsd_program_reallocf(void *ptr, size_t size)
}
char *
rtems_bsd_program_strdup(const char *s1)
rtems_bsd_program_strdup(const char *s)
{
size_t size = strlen(s1) + 1; /* add one for null termination */
char *item;
size_t size;
void *s2;
item = rtems_bsd_program_alloc(size, NULL);
if (item != NULL) {
memcpy(item, s1, size);
size = strlen(s) + 1;
s2 = rtems_bsd_program_alloc(size, NULL);
if (s2 == NULL) {
return (NULL);
}
return item;
return (memcpy(s2, s, size));
}
char *
rtems_bsd_program_strndup(const char *s, size_t size)
{
void *s2;
size = strnlen(s, size) + 1;
s2 = rtems_bsd_program_alloc(size, NULL);
if (s2 == NULL) {
return (NULL);
}
return (memcpy(s2, s, size));
}
int