Skip to content

Commit

Permalink
improve portability (esp. musl)
Browse files Browse the repository at this point in the history
cf. Github PR#56
  • Loading branch information
lyonel committed Jan 10, 2021
1 parent ff634c9 commit d3c66a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/core/abi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ __ID("@(#) $Id: mem.cc 1352 2006-05-27 23:54:13Z ezix $");
bool scan_abi(hwNode & system)
{
// are we compiled as 32- or 64-bit process ?
long sc = sysconf(LONG_BIT);
if(sc==-1) sc = sysconf(_SC_LONG_BIT);
if(sc!=-1) system.setWidth(sc);
system.setWidth(LONG_BIT);

pushd(PROC_SYS);

Expand Down
21 changes: 11 additions & 10 deletions src/core/sysfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mount.h>
#include <libgen.h>


__ID("@(#) $Id$");
Expand Down Expand Up @@ -103,7 +104,7 @@ static string sysfs_getbustype(const string & path)
{
string devname =
string(fs.path + "/bus/") + string(namelist[i]->d_name) +
"/devices/" + basename(path.c_str());
"/devices/" + basename(const_cast<char*>(path.c_str()));

if (samefile(devname, path))
{
Expand Down Expand Up @@ -151,7 +152,7 @@ static string sysfstobusinfo(const string & path)

if (bustype == "usb")
{
string name = basename(path.c_str());
string name = basename(const_cast<char*>(path.c_str()));
if (matches(name, "^[0-9]+-[0-9]+(\\.[0-9]+)*:[0-9]+\\.[0-9]+$"))
{
size_t colon = name.rfind(":");
Expand All @@ -162,18 +163,18 @@ static string sysfstobusinfo(const string & path)

if (bustype == "virtio")
{
string name = basename(path.c_str());
string name = basename(const_cast<char*>(path.c_str()));
if (name.compare(0, 6, "virtio") == 0)
return "virtio@" + name.substr(6);
else
return "virtio@" + name;
}

if (bustype == "vio")
return string("vio@") + basename(path.c_str());
return string("vio@") + basename(const_cast<char*>(path.c_str()));

if (bustype == "ccw")
return string("ccw@") + basename(path.c_str());
return string("ccw@") + basename(const_cast<char*>(path.c_str()));

if (bustype == "ccwgroup")
{
Expand Down Expand Up @@ -251,7 +252,7 @@ string entry::driver() const
string driverlink = This->devpath + "/driver";
if (!exists(driverlink))
return "";
return basename(readlink(driverlink).c_str());
return basename(const_cast<char*>(readlink(driverlink).c_str()));
}


Expand Down Expand Up @@ -339,7 +340,7 @@ string entry::name_in_class(const string & classname) const

string entry::name() const
{
return basename(This->devpath.c_str());
return basename(const_cast<char*>(This->devpath.c_str()));
}


Expand All @@ -351,17 +352,17 @@ entry entry::parent() const

string entry::classname() const
{
return basename(dirname(This->devpath).c_str());
return basename(const_cast<char*>(dirname(This->devpath).c_str()));
}

string entry::subsystem() const
{
return basename(realpath(This->devpath+"/subsystem").c_str());
return basename(const_cast<char*>(realpath(This->devpath+"/subsystem").c_str()));
}

bool entry::isvirtual() const
{
return string(basename(dirname(dirname(This->devpath)).c_str())) == "virtual";
return string(basename(const_cast<char*>(dirname(dirname(This->devpath)).c_str()))) == "virtual";
}

string entry::string_attr(const string & name, const string & def) const
Expand Down

0 comments on commit d3c66a6

Please sign in to comment.