From a3c74fcd8c05abcf16a3fcd3491150837e639fd0 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 8 Apr 2009 10:57:46 +0000 Subject: [PATCH] Added a strsep() to our BSD compatibility library. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30022 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/compatibility/bsd/string.h | 22 ++++++++++++++++++++++ src/libs/bsd/Jamfile | 1 + src/libs/bsd/string.cpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 headers/compatibility/bsd/string.h create mode 100644 src/libs/bsd/string.cpp diff --git a/headers/compatibility/bsd/string.h b/headers/compatibility/bsd/string.h new file mode 100644 index 0000000000..01707f73ca --- /dev/null +++ b/headers/compatibility/bsd/string.h @@ -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 + + +#ifdef __cplusplus +extern "C" { +#endif + +char* strsep(char** string, const char* delimiters); + +#ifdef __cplusplus +} +#endif + +#endif /* _BSD_STRING_H_ */ diff --git a/src/libs/bsd/Jamfile b/src/libs/bsd/Jamfile index 0e54903cfd..4505ad6739 100644 --- a/src/libs/bsd/Jamfile +++ b/src/libs/bsd/Jamfile @@ -13,6 +13,7 @@ SharedLibrary libbsd.so : progname.c pty.cpp signal.c + string.cpp stringlist.c unvis.c usershell.c diff --git a/src/libs/bsd/string.cpp b/src/libs/bsd/string.cpp new file mode 100644 index 0000000000..e51e8ac2b1 --- /dev/null +++ b/src/libs/bsd/string.cpp @@ -0,0 +1,29 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include + + +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; +}