Added a strsep() to our BSD compatibility library.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30022 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
ff81d306d4
commit
a3c74fcd8c
22
headers/compatibility/bsd/string.h
Normal file
22
headers/compatibility/bsd/string.h
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2009, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _BSD_STRING_H_
|
||||
#define _BSD_STRING_H_
|
||||
|
||||
|
||||
#include_next <string.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
char* strsep(char** string, const char* delimiters);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _BSD_STRING_H_ */
|
@ -13,6 +13,7 @@ SharedLibrary libbsd.so :
|
||||
progname.c
|
||||
pty.cpp
|
||||
signal.c
|
||||
string.cpp
|
||||
stringlist.c
|
||||
unvis.c
|
||||
usershell.c
|
||||
|
29
src/libs/bsd/string.cpp
Normal file
29
src/libs/bsd/string.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
char*
|
||||
strsep(char** string, const char* delimiters)
|
||||
{
|
||||
if (*string == NULL)
|
||||
return NULL;
|
||||
|
||||
// find the end of the token
|
||||
char* token = *string;
|
||||
char* end = token;
|
||||
while (*end != '\0' && strchr(delimiters, *end) == NULL)
|
||||
end++;
|
||||
|
||||
// terminate the token and update the string pointer
|
||||
if (*end != '\0') {
|
||||
*end = '\0';
|
||||
*string = end + 1;
|
||||
} else
|
||||
*string = NULL;
|
||||
|
||||
return token;
|
||||
}
|
Loading…
Reference in New Issue
Block a user