[Toybox] [PATCH] include sys/sysmacros.h

Rob Landley rob at landley.net
Mon Feb 29 14:24:00 PST 2016


On 02/29/2016 12:36 PM, Mike Frysinger wrote:
> The major/minor macros are defined in sys/sysmacros.h.  This has
> historically been pulled in implicitly by sys/types.h,

http://man7.org/linux/man-pages/man3/major.3.html says sys/types.h, yes.

> but C libs
> are moving away from that as they aren't in POSIX.  Use the header
> directly as defined by BSD systems.

This adds a non-posix header to the posix header section of toys.h,
based on the premise that unspecified C libraries plan to break existing
programs at some unknown point in the future, for no obvious reason.

Details please? (Which libc(s) plan to do this? Is the plan to break
existing programs public? I assume you've checked the new non-standard
header is there on glibc, uClibc, musl, and bionic, and just forgot to
mention it?)

If we hit a system that doesn't include this (and I'd prefer to wait
until a libc upgrade does break existing programs), I can just add the
Linux transformation to lib/portability.h and bypass the whole mess.
linux/kdev_t.h has:

static inline u32 new_encode_dev(dev_t dev)
{
        unsigned major = MAJOR(dev);
        unsigned minor = MINOR(dev);
        return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
}

static inline dev_t new_decode_dev(u32 dev)
{
        unsigned major = (dev & 0xfff00) >> 8;
        unsigned minor = (dev & 0xff) | ((dev >> 12) & 0xfff00);
        return MKDEV(major, minor);
}

I note that I did those transformations by hand before switching to
using the libc versions. For ps, the switch was in commit:

https://github.com/landley/toybox/commit/26ec1c05b0eef896b59fe3c870f6885fa7edf4ae

I used the libc version because it seemed cleaner. If there isn't a
portable way to specify this, I prefer to do the known Linux thing
(fixed in the ABI for over a decade) by hand in my code rather than
switch from de-facto standard to de-facto standard for no reason.

Rob

 1456784640.0


More information about the Toybox mailing list