tools/nolibc: move the logic of makedev() and friends into functions

Functions make it easier to keep the input and output types straight and
avoid duplicate evaluations of their arguments.

Also these functions will become a bit more complex to handle full
64-bit 'dev_t' which is easier to read in a function.

Still stay compatible with code which expects these to be macros.

Signed-off-by: Thomas Weißschuh <[email protected]>
Acked-by: Willy Tarreau <[email protected]>
Link: https://patch.msgid.link/[email protected]
This commit is contained in:
Thomas Weißschuh
2026-04-04 10:28:50 +02:00
parent 5afc7e9b90
commit 70091eada3
+20 -3
View File
@@ -13,8 +13,25 @@
#include "../std.h"
/* WARNING, it only deals with the 4096 first majors and 256 first minors */
#define makedev(major, minor) ((dev_t)((((major) & 0xfff) << 8) | ((minor) & 0xff)))
#define major(dev) ((unsigned int)(((dev) >> 8) & 0xfff))
#define minor(dev) ((unsigned int)((dev) & 0xff))
static __inline__ dev_t __nolibc_makedev(unsigned int maj, unsigned int min)
{
return ((maj & 0xfff) << 8) | (min & 0xff);
}
#define makedev(maj, min) __nolibc_makedev(maj, min)
static __inline__ unsigned int __nolibc_major(dev_t dev)
{
return (dev >> 8) & 0xfff;
}
#define major(dev) __nolibc_major(dev)
static __inline__ unsigned int __nolibc_minor(dev_t dev)
{
return dev & 0xff;
}
#define minor(dev) __nolibc_minor(dev)
#endif /* _NOLIBC_SYS_SYSMACROS_H */