1 From d667b13a87cf3207599a19eb981a893a1d7a67ee Mon Sep 17 00:00:00 2001
2 From: Brendan Heading <brendanheading@gmail.com>
3 Date: Mon, 14 Sep 2015 23:25:52 +0100
4 Subject: [PATCH 1/1] ibrcommon/data/File.cpp: support POSIX basename call
6 Firstly, and somewhat strangely, musl chooses not to provide a basename(3)
7 prototype within <string.h> whenever __cplusplus is defined. This can be
8 solved by including the <libgen.h> header defined by POSIX 1003.1 whenever
9 __GLIBC__ is not defined.
11 However, this leads to a second problem. POSIX defines the function as
12 char* basename(char*) and this is the only version supported by musl.
13 However, the std::string.cstr() method returns a const char*.
15 POSIX says that the string parameter can be modified. However the GNU
16 implementation never modifies it. glibc therefore supports an extension
17 when compiling under C++ by also supplying
18 const char* basename(const char*). This extension is not present on musl
19 which is the cause of the failure.
21 The solution is reasonably straightforward; test if __GLIBC__ is defined
22 before calling basename. If not, use the fallback already provided for
23 other platforms whereby basename() is called on a temporary copy.
25 Signed-off-by: Brendan Heading <brendanheading@gmail.com>
26 Upstream-status: pending
28 ibrcommon/data/File.cpp | 4 ++--
29 1 file changed, 2 insertions(+), 2 deletions(-)
31 diff --git a/ibrcommon/data/File.cpp b/ibrcommon/data/File.cpp
32 index 31af4ae..68e9b4f 100644
33 --- a/ibrcommon/data/File.cpp
34 +++ b/ibrcommon/data/File.cpp
39 -#if !defined(HAVE_FEATURES_H) || defined(ANDROID)
40 +#if !defined(HAVE_FEATURES_H) || !defined(__GLIBC__) || defined(ANDROID)
44 @@ -225,7 +225,7 @@ namespace ibrcommon
46 std::string File::getBasename() const
48 -#if !defined(ANDROID) && defined(HAVE_FEATURES_H)
49 +#if !defined(ANDROID) && defined(HAVE_FEATURES_H) && defined(__GLIBC__)
50 return std::string(basename(_path.c_str()));
52 char path[_path.length()+1];