summaryrefslogtreecommitdiff
path: root/repo/lshw/wrapper-for-basename.patch
blob: dabfa79b6c6c3ea8dee73e4c190f2a95742952fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
From 49a2c103c7d1127045ced8e8c887279a36a3f357 Mon Sep 17 00:00:00 2001
From: Felix Janda <felix.janda@posteo.de>
Date: Wed, 12 Apr 2017 21:29:11 -0400
Subject: [PATCH 1/2] Add wrapper for basename

basename comes in two variants. A GNU and a POSIX version. Currently,
the GNU version is mostly used, but this breaks compilation on systems
without glibc.

Switch to the portable version. Because this variant modifies its
argument, similarly to dirname, a wrapper is needed.
---
 src/core/osutils.cc | 10 ++++++++++
 src/core/osutils.h  |  1 +
 src/core/pci.cc     |  4 ++--
 src/core/sysfs.cc   |  8 ++++----
 5 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/core/osutils.cc b/src/core/osutils.cc
index e93b79e..1624ab1 100644
--- a/src/core/osutils.cc
+++ b/src/core/osutils.cc
@@ -426,6 +426,16 @@ string dirname(const string & path)
   return result;
 }
 
+string basename(const string & path)
+{
+  size_t len = path.length();
+  char *buffer = new char[len + 1];
+  path.copy(buffer, len);
+  buffer[len] = '\0';
+  string result = basename(buffer);
+  delete[] buffer;
+  return result;
+}
 
 string spaces(unsigned int count, const string & space)
 {
diff --git a/src/core/osutils.h b/src/core/osutils.h
index 549258e..55f5548 100644
--- a/src/core/osutils.h
+++ b/src/core/osutils.h
@@ -15,6 +15,7 @@ bool samefile(const std::string & path1, const std::string & path2);
 std::string readlink(const std::string & path);
 std::string realpath(const std::string & path);
 std::string dirname(const std::string & path);
+std::string basename(const std::string & path);
 bool loadfile(const std::string & file, std::vector < std::string > &lines);
 
 size_t splitlines(const std::string & s,
diff --git a/src/core/pci.cc b/src/core/pci.cc
index d1625cf..1163ad2 100644
--- a/src/core/pci.cc
+++ b/src/core/pci.cc
@@ -1131,9 +1131,9 @@ bool scan_pci(hwNode & n)
           string drivername = readlink(string(devices[i]->d_name)+"/driver");
           string modulename = readlink(string(devices[i]->d_name)+"/driver/module");
 
-          device->setConfig("driver", basename(const_cast<char *>(drivername.c_str())));
+          device->setConfig("driver", basename(drivername));
           if(exists(modulename))
-            device->setConfig("module", basename(const_cast<char *>(modulename.c_str())));
+            device->setConfig("module", basename(modulename));
 
           if(exists(string(devices[i]->d_name)+"/rom"))
           {
diff --git a/src/core/sysfs.cc b/src/core/sysfs.cc
index 97dbab5..0fc4855 100644
--- a/src/core/sysfs.cc
+++ b/src/core/sysfs.cc
@@ -99,7 +99,7 @@ static string sysfs_getbustype(const string & path)
   {
     devname =
       string(fs.path + "/bus/") + string(namelist[i]->d_name) +
-      "/devices/" + basename(path.c_str());
+      "/devices/" + basename(path);
 
     if (samefile(devname, path))
       return string(namelist[i]->d_name);
@@ -139,7 +139,7 @@ static string sysfstobusinfo(const string & path)
 
   if (bustype == "virtio")
   {
-    string name = basename(path.c_str());
+    string name = basename(path);
     if (name.compare(0, 6, "virtio") == 0)
       return "virtio@" + name.substr(6);
     else
@@ -207,7 +207,7 @@ string entry::driver() const
   string driverlink = This->devpath + "/driver";
   if (!exists(driverlink))
     return "";
-  return basename(readlink(driverlink).c_str());
+  return basename(readlink(driverlink));
 }
 
 
@@ -288,7 +288,7 @@ string entry::name_in_class(const string & classname) const
 
 string entry::name() const
 {
-  return basename(This->devpath.c_str());
+  return basename(This->devpath);
 }