0001-ibrcommon-data-File.cpp-support-POSIX-basename-call.patch 2.0 KB

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