1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-13 10:02:38 +00:00

Add non-sleepable strdup variant strdup_flags

debugfs expects to do non-sleepable allocations

Reviewed by:	hps@
MFC after:	1 week
Sponsored by:	iX Systems
Differential Revision:	https://reviews.freebsd.org/D19259
This commit is contained in:
Matt Macy 2019-02-20 20:48:10 +00:00
parent 281bdc30df
commit 744799ead2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=344384
2 changed files with 12 additions and 2 deletions

View File

@ -40,13 +40,22 @@ __FBSDID("$FreeBSD$");
#include <sys/malloc.h>
char *
strdup(const char *string, struct malloc_type *type)
strdup_flags(const char *string, struct malloc_type *type, int flags)
{
size_t len;
char *copy;
len = strlen(string) + 1;
copy = malloc(len, type, M_WAITOK);
copy = malloc(len, type, flags);
if (copy == NULL)
return (NULL);
bcopy(string, copy, len);
return (copy);
}
char *
strdup(const char *string, struct malloc_type *type)
{
return (strdup_flags(string, type, M_WAITOK));
}

View File

@ -173,6 +173,7 @@ char *strchr(const char *, int);
int strcmp(const char *, const char *);
char *strcpy(char * __restrict, const char * __restrict);
size_t strcspn(const char * __restrict, const char * __restrict) __pure;
char *strdup_flags(const char *__restrict, struct malloc_type *, int);
char *strdup(const char *__restrict, struct malloc_type *);
char *strncat(char *, const char *, size_t);
char *strndup(const char *__restrict, size_t, struct malloc_type *);