Blame SOURCES/0045-improve-portability-esp.-musl.patch

121cca
From d3c66a6b2a0799d6982f4dc77b291934fcba80c9 Mon Sep 17 00:00:00 2001
121cca
From: Lyonel Vincent <lyonel@ezix.org>
121cca
Date: Sun, 10 Jan 2021 01:19:24 +0100
121cca
Subject: [PATCH 45/65] improve portability (esp. musl)
121cca
121cca
cf. Github PR#56
121cca
---
121cca
 src/core/abi.cc   |  4 +---
121cca
 src/core/sysfs.cc | 21 +++++++++++----------
121cca
 2 files changed, 12 insertions(+), 13 deletions(-)
121cca
121cca
diff --git a/src/core/abi.cc b/src/core/abi.cc
121cca
index adff7b5..76c664c 100644
121cca
--- a/src/core/abi.cc
121cca
+++ b/src/core/abi.cc
121cca
@@ -20,9 +20,7 @@ __ID("@(#) $Id: mem.cc 1352 2006-05-27 23:54:13Z ezix $");
121cca
 bool scan_abi(hwNode & system)
121cca
 {
121cca
   // are we compiled as 32- or 64-bit process ?
121cca
-  long sc = sysconf(LONG_BIT);
121cca
-  if(sc==-1) sc = sysconf(_SC_LONG_BIT);
121cca
-  if(sc!=-1) system.setWidth(sc);
121cca
+  system.setWidth(LONG_BIT);
121cca
 
121cca
   pushd(PROC_SYS);
121cca
 
121cca
diff --git a/src/core/sysfs.cc b/src/core/sysfs.cc
121cca
index 4e2df1c..d7a20c9 100644
121cca
--- a/src/core/sysfs.cc
121cca
+++ b/src/core/sysfs.cc
121cca
@@ -16,6 +16,7 @@
121cca
 #include <sys/stat.h>
121cca
 #include <sys/types.h>
121cca
 #include <sys/mount.h>
121cca
+#include <libgen.h>
121cca
 
121cca
 
121cca
 __ID("@(#) $Id$");
121cca
@@ -103,7 +104,7 @@ static string sysfs_getbustype(const string & path)
121cca
   {
121cca
     string devname =
121cca
       string(fs.path + "/bus/") + string(namelist[i]->d_name) +
121cca
-      "/devices/" + basename(path.c_str());
121cca
+      "/devices/" + basename(const_cast<char*>(path.c_str()));
121cca
 
121cca
     if (samefile(devname, path))
121cca
     {
121cca
@@ -151,7 +152,7 @@ static string sysfstobusinfo(const string & path)
121cca
 
121cca
   if (bustype == "usb")
121cca
   {
121cca
-    string name = basename(path.c_str());
121cca
+    string name = basename(const_cast<char*>(path.c_str()));
121cca
     if (matches(name, "^[0-9]+-[0-9]+(\\.[0-9]+)*:[0-9]+\\.[0-9]+$"))
121cca
     {
121cca
       size_t colon = name.rfind(":");
121cca
@@ -162,7 +163,7 @@ static string sysfstobusinfo(const string & path)
121cca
 
121cca
   if (bustype == "virtio")
121cca
   {
121cca
-    string name = basename(path.c_str());
121cca
+    string name = basename(const_cast<char*>(path.c_str()));
121cca
     if (name.compare(0, 6, "virtio") == 0)
121cca
       return "virtio@" + name.substr(6);
121cca
     else
121cca
@@ -170,10 +171,10 @@ static string sysfstobusinfo(const string & path)
121cca
   }
121cca
 
121cca
   if (bustype == "vio")
121cca
-    return string("vio@") + basename(path.c_str());
121cca
+    return string("vio@") + basename(const_cast<char*>(path.c_str()));
121cca
 
121cca
   if (bustype == "ccw")
121cca
-    return string("ccw@") + basename(path.c_str());
121cca
+    return string("ccw@") + basename(const_cast<char*>(path.c_str()));
121cca
 
121cca
   if (bustype == "ccwgroup")
121cca
   {
121cca
@@ -251,7 +252,7 @@ string entry::driver() const
121cca
   string driverlink = This->devpath + "/driver";
121cca
   if (!exists(driverlink))
121cca
     return "";
121cca
-  return basename(readlink(driverlink).c_str());
121cca
+  return basename(const_cast<char*>(readlink(driverlink).c_str()));
121cca
 }
121cca
 
121cca
 
121cca
@@ -339,7 +340,7 @@ string entry::name_in_class(const string & classname) const
121cca
 
121cca
 string entry::name() const
121cca
 {
121cca
-  return basename(This->devpath.c_str());
121cca
+  return basename(const_cast<char*>(This->devpath.c_str()));
121cca
 }
121cca
 
121cca
 
121cca
@@ -351,17 +352,17 @@ entry entry::parent() const
121cca
 
121cca
 string entry::classname() const
121cca
 {
121cca
-  return basename(dirname(This->devpath).c_str());
121cca
+  return basename(const_cast<char*>(dirname(This->devpath).c_str()));
121cca
 }
121cca
 
121cca
 string entry::subsystem() const
121cca
 {
121cca
-  return basename(realpath(This->devpath+"/subsystem").c_str());
121cca
+  return basename(const_cast<char*>(realpath(This->devpath+"/subsystem").c_str()));
121cca
 }
121cca
 
121cca
 bool entry::isvirtual() const
121cca
 {
121cca
-  return string(basename(dirname(dirname(This->devpath)).c_str())) == "virtual";
121cca
+  return string(basename(const_cast<char*>(dirname(dirname(This->devpath)).c_str()))) == "virtual";
121cca
 }
121cca
 
121cca
 string entry::string_attr(const string & name, const string & def) const
121cca
-- 
121cca
2.33.1
121cca