mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-10-17 21:47:56 +08:00
Add wrapper for strndup()
This commit is contained in:
@@ -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 *
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user