Mail archive
alpine-devel

Re: [alpine-devel] [PATCH] unmaintained/lshw: fix build

From: Natanael Copa <ncopa_at_alpinelinux.org>
Date: Mon, 15 Sep 2014 11:10:55 +0200

On Fri, 12 Sep 2014 21:58:34 -0700
Isaac Dunham <ibid.ag_at_gmail.com> wrote:

> s/__\(u*int\)/\1/g
> add headers
> replace sysconf(_SC_LONG_BITS) with 8*sizeof(long)
> make basename() usage conform to POSIX

...

> + bool scan_abi(hwNode & system)
> + {
> + // are we compiled as 32- or 64-bit process ?
> +- system.setWidth(sysconf(_SC_LONG_BIT));
> ++ system.setWidth(8*sizeof(long));

theoretically:

#ifdef _SC_LONG_BIT
  int longbit = sysconf(_SC_LONG_BIT);
  if (longbit < 0)
#endif
    longbit = 8*sizeof(long);
  system.setWidth(longbit);

But since it is a compile time value (as comment indicates) i think
what you do is good.

...


> +_at_@ -1127,10 +1129,16 @@ 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(drivername.c_str()));
> ++ char driver_c[PATH_MAX];
> ++ char module_c[PATH_MAX];
> ++ bzero(driver_c,PATH_MAX);
> ++ bzero(module_c,PATH_MAX);
> ++ strncpy(driver_c, drivername.c_str(),PATH_MAX);
> ++ strncpy(module_c, modulename.c_str(),PATH_MAX);
> ++
> ++ device->setConfig("driver", basename(driver_c));
> + if(exists(modulename))
> +- device->setConfig("module", basename(modulename.c_str()));
> ++ device->setConfig("module", basename(module_c));
> +
> + if(exists(string(devices[i]->d_name)+"/rom"))
> + {

You could have done #define _GNU_SOURCE before #include <string.h> to
get gnu basename. But what you do is ok too. Its more portable.

Applied as is and moved it back to testing.

Good job!

Thanks!

-nc


---
Unsubscribe:  alpine-devel+unsubscribe_at_lists.alpinelinux.org
Help:         alpine-devel+help_at_lists.alpinelinux.org
---
Received on Mon Sep 15 2014 - 11:10:55 UTC