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