Merge "Fix <sys/sysmacros.h>."
diff --git a/libc/include/sys/sysmacros.h b/libc/include/sys/sysmacros.h
index 6f053a8..54e43dd 100644
--- a/libc/include/sys/sysmacros.h
+++ b/libc/include/sys/sysmacros.h
@@ -25,28 +25,20 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
#ifndef _SYS_SYSMACROS_H_
#define _SYS_SYSMACROS_H_
-/* some rogue code includes this file directly :-( */
-#ifndef _SYS_TYPES_H_
-# include <sys/types.h>
-#endif
+#define makedev(__major, __minor) \
+ ( \
+ (((__major) & 0xfffff000ULL) << 32) | (((__major) & 0xfffULL) << 8) | \
+ (((__minor) & 0xffffff00ULL) << 12) | (((__minor) & 0xffULL)) \
+ )
-static __inline__ int major(dev_t _dev)
-{
- return (_dev >> 8) & 0xfff;
-}
+#define major(__dev) \
+ ((unsigned) ((((unsigned long long) (__dev) >> 32) & 0xfffff000) | (((__dev) >> 8) & 0xfff)))
-static __inline__ int minor(dev_t _dev)
-{
- return (_dev & 0xff) | ((_dev >> 12) & 0xfff00);
-}
-
-static __inline__ dev_t makedev(int __ma, int __mi)
-{
- return ((__ma & 0xfff) << 8) | (__mi & 0xff) | ((__mi & 0xfff00) << 12);
-}
+#define minor(__dev) \
+ ((unsigned) ((((__dev) >> 12) & 0xffffff00) | ((__dev) & 0xff)))
#endif /* _SYS_SYSMACROS_H_ */
-
diff --git a/libc/include/sys/types.h b/libc/include/sys/types.h
index a6b0fd8..217fd60 100644
--- a/libc/include/sys/types.h
+++ b/libc/include/sys/types.h
@@ -139,19 +139,18 @@
typedef unsigned int uint_t;
typedef unsigned int uint;
-/* for some applications */
+#ifdef __BSD_VISIBLE
#include <sys/sysmacros.h>
-#ifdef __BSD_VISIBLE
-typedef unsigned char u_char;
-typedef unsigned short u_short;
-typedef unsigned int u_int;
-typedef unsigned long u_long;
+typedef unsigned char u_char;
+typedef unsigned short u_short;
+typedef unsigned int u_int;
+typedef unsigned long u_long;
-typedef uint32_t u_int32_t;
-typedef uint16_t u_int16_t;
-typedef uint8_t u_int8_t;
-typedef uint64_t u_int64_t;
+typedef uint32_t u_int32_t;
+typedef uint16_t u_int16_t;
+typedef uint8_t u_int8_t;
+typedef uint64_t u_int64_t;
#endif
#endif
diff --git a/tests/Android.mk b/tests/Android.mk
index 8e37a76..3a0d6ee 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -107,6 +107,7 @@
sys_statvfs_test.cpp \
sys_syscall_test.cpp \
sys_sysinfo_test.cpp \
+ sys_sysmacros_test.cpp \
sys_time_test.cpp \
sys_types_test.cpp \
sys_uio_test.cpp \
diff --git a/tests/sys_sysmacros_test.cpp b/tests/sys_sysmacros_test.cpp
new file mode 100644
index 0000000..f17fac5
--- /dev/null
+++ b/tests/sys_sysmacros_test.cpp
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sys/sysmacros.h>
+
+#include <gtest/gtest.h>
+
+TEST(sys_sysmacros, makedev) {
+ ASSERT_EQ(0x12345aabbcc678ddULL, makedev(0x12345678, 0xaabbccdd));
+}
+
+TEST(sys_sysmacros, major) {
+ ASSERT_EQ(0x12345678UL, major(0x12345aabbcc678dd));
+}
+
+TEST(sys_sysmacros, minor) {
+ ASSERT_EQ(0xaabbccddUL, minor(0x12345aabbcc678dd));
+}