0003-sysfs-Fix-basename-build-with-musl.patch 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. From a89f2ba8496994c8b5e28a89202df15d64c648f9 Mon Sep 17 00:00:00 2001
  2. From: Krzysztof Kozlowski <krzk@kernel.org>
  3. Date: Wed, 6 Jun 2018 12:47:02 +0200
  4. Subject: [PATCH] sysfs: Fix basename() build with musl
  5. musl provides only standard basename() which accepts non-const string.
  6. This fixes build error with musl C library:
  7. | sysfs.cc: In function 'std::__cxx11::string sysfs_getbustype(const string&)':
  8. | sysfs.cc:102:21: error: 'basename' was not declared in this scope
  9. | "/devices/" + basename(path.c_str());
  10. | ^~~~~~~~
  11. Upstream-Status: Submitted
  12. Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
  13. ---
  14. src/core/dasd.cc | 3 ++-
  15. src/core/sysfs.cc | 9 +++++----
  16. 2 files changed, 7 insertions(+), 5 deletions(-)
  17. diff --git a/src/core/dasd.cc b/src/core/dasd.cc
  18. index 626b8a872b0f..b27844215cc4 100644
  19. --- a/src/core/dasd.cc
  20. +++ b/src/core/dasd.cc
  21. @@ -2,6 +2,7 @@
  22. #include "osutils.h"
  23. #include "dasd.h"
  24. #include <glob.h>
  25. +#include <libgen.h>
  26. #include <string.h>
  27. #include <fcntl.h>
  28. #include <unistd.h>
  29. @@ -42,7 +43,7 @@ bool scan_dasd(hwNode & n)
  30. {
  31. for(dev_num=0;dev_num<devices.gl_pathc;dev_num++)
  32. {
  33. - dev_name = basename(devices.gl_pathv[dev_num]);
  34. + dev_name = basename(const_cast<char *>(devices.gl_pathv[dev_num]));
  35. for (std::vector<std::string>::iterator it = sysfs_attribs.begin(); it != sysfs_attribs.end(); ++it)
  36. {
  37. std::string attrib_fname = std::string(SYSFS_PREFIX) + dev_name + "/device/" + *it;
  38. diff --git a/src/core/sysfs.cc b/src/core/sysfs.cc
  39. index acc9d0056d5e..c56bab7b3b9f 100644
  40. --- a/src/core/sysfs.cc
  41. +++ b/src/core/sysfs.cc
  42. @@ -7,6 +7,7 @@
  43. #include "version.h"
  44. #include "sysfs.h"
  45. #include "osutils.h"
  46. +#include <libgen.h>
  47. #include <limits.h>
  48. #include <unistd.h>
  49. #include <stdlib.h>
  50. @@ -99,7 +100,7 @@ static string sysfs_getbustype(const string & path)
  51. {
  52. devname =
  53. string(fs.path + "/bus/") + string(namelist[i]->d_name) +
  54. - "/devices/" + basename(path.c_str());
  55. + "/devices/" + basename(const_cast<char *>(path.c_str()));
  56. if (samefile(devname, path))
  57. return string(namelist[i]->d_name);
  58. @@ -139,7 +140,7 @@ static string sysfstobusinfo(const string & path)
  59. if (bustype == "virtio")
  60. {
  61. - string name = basename(path.c_str());
  62. + string name = basename(const_cast<char *>(path.c_str()));
  63. if (name.compare(0, 6, "virtio") == 0)
  64. return "virtio@" + name.substr(6);
  65. else
  66. @@ -207,7 +208,7 @@ string entry::driver() const
  67. string driverlink = This->devpath + "/driver";
  68. if (!exists(driverlink))
  69. return "";
  70. - return basename(readlink(driverlink).c_str());
  71. + return basename(const_cast<char *>(readlink(driverlink).c_str()));
  72. }
  73. @@ -288,7 +289,7 @@ string entry::name_in_class(const string & classname) const
  74. string entry::name() const
  75. {
  76. - return basename(This->devpath.c_str());
  77. + return basename(const_cast<char *>(This->devpath.c_str()));
  78. }
  79. --
  80. 2.7.4