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