[klibc] [klibc:master] sys/sysmacros.h: define major, minor, and makedev as macros

klibc-bot for H. Peter Anvin hpa at zytor.com
Thu May 24 17:06:02 PDT 2012


Commit-ID:  c96ae78fe9c8588732f19fd58c7bc1c7f45137f0
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=c96ae78fe9c8588732f19fd58c7bc1c7f45137f0
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Thu, 24 May 2012 17:02:02 -0700
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Thu, 24 May 2012 17:02:02 -0700

[klibc] sys/sysmacros.h: define major, minor, and makedev as macros

There seems to exist programs in the field that assume major(),
minor() and makedev() are argument-taking macros, resulting in
monstrosities like:

	int major, minor;

	major = major(st.st_rdev);
	minor = minor(st.st_rdev);

Although such code really should clean their house, in the interest of
minimizing porting friction define major, minor and makedev as macros.

While we are at it, clean up the type handling in the pure macro
versions.

Signed-off-by: H. Peter Anvin <hpa at zytor.com>

---
 usr/include/sys/sysmacros.h |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/usr/include/sys/sysmacros.h b/usr/include/sys/sysmacros.h
index ab2b2d4..efb476c 100644
--- a/usr/include/sys/sysmacros.h
+++ b/usr/include/sys/sysmacros.h
@@ -11,23 +11,27 @@
 #include <klibc/compiler.h>
 #include <sys/types.h>
 
-#define __major(__d) (((__d) >> 8) & 0xfff)
-__static_inline int major(dev_t __d)
+#define __major(__d) ((int)(((__d) >> 8) & 0xfffU))
+__static_inline int _major(dev_t __d)
 {
 	return __major(__d);
 }
+#define major(__d) _major(__d)
 
-#define __minor(__d) (((__d) & 0xff)|(((__d) >> 12) & 0xfff00))
-__static_inline int minor(dev_t __d)
+#define __minor(__d) ((int)(((__d) & 0xffU)|(((__d) >> 12) & 0xfff00U)))
+__static_inline int _minor(dev_t __d)
 {
 	return __minor(__d);
 }
+#define minor(__d) _minor(__d)
 
 #define __makedev(__ma, __mi) \
-	((((__ma) & 0xfff) << 8)|((__mi) & 0xff)|(((__mi) & 0xfff00) << 12))
-__static_inline dev_t makedev(int __ma, int __mi)
+	((dev_t)((((__ma) & 0xfffU) << 8)| \
+		 ((__mi) & 0xffU)|(((__mi) & 0xfff00U) << 12)))
+__static_inline dev_t _makedev(int __ma, int __mi)
 {
 	return __makedev(__ma, __mi);
 }
+#define makedev(__ma, __mi) _makedev(__ma, __mi)
 
 #endif				/* _SYS_SYSMACROS_H */


More information about the klibc mailing list