aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2016-01-12 14:43:27 -0800
committerElliott Hughes <enh@google.com>2016-01-12 14:43:27 -0800
commit9361ad3f80adc1e21ab97c8d684afed311788e00 (patch)
tree7fc6ab24e35aff54ffadb54267e71c19288f1e8b
parent906e67fdba54459983bfa6bc29e02253a6990144 (diff)
downloadbionic-9361ad3f80adc1e21ab97c8d684afed311788e00.tar.gz
Fix <sys/sysmacros.h>.
1. The definitions were wrong. 2. The definitions were inline functions. 3. The definitions were polluting the namespace even for code that doesn't want BSD cruft. Note that everybody will still get these by default, because you still get all the BSD stuff by default. Bug: http://b/12706131 Change-Id: I062ecd09feef7a6e8ba1922d465b96a9c4bf4f4e
-rw-r--r--libc/include/sys/sysmacros.h28
-rw-r--r--libc/include/sys/types.h21
-rw-r--r--tests/Android.mk1
-rw-r--r--tests/sys_sysmacros_test.cpp31
4 files changed, 52 insertions, 29 deletions
diff --git a/libc/include/sys/sysmacros.h b/libc/include/sys/sysmacros.h
index 6f053a838..54e43dd15 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
-
-static __inline__ int major(dev_t _dev)
-{
- return (_dev >> 8) & 0xfff;
-}
+#define makedev(__major, __minor) \
+ ( \
+ (((__major) & 0xfffff000ULL) << 32) | (((__major) & 0xfffULL) << 8) | \
+ (((__minor) & 0xffffff00ULL) << 12) | (((__minor) & 0xffULL)) \
+ )
-static __inline__ int minor(dev_t _dev)
-{
- return (_dev & 0xff) | ((_dev >> 12) & 0xfff00);
-}
+#define major(__dev) \
+ ((unsigned) ((((unsigned long long) (__dev) >> 32) & 0xfffff000) | (((__dev) >> 8) & 0xfff)))
-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 a6b0fd87f..217fd603b 100644
--- a/libc/include/sys/types.h
+++ b/libc/include/sys/types.h
@@ -139,19 +139,18 @@ typedef __kernel_ssize_t ssize_t;
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 uint32_t u_int32_t;
-typedef uint16_t u_int16_t;
-typedef uint8_t u_int8_t;
-typedef uint64_t u_int64_t;
+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;
#endif
#endif
diff --git a/tests/Android.mk b/tests/Android.mk
index 8e37a76d0..3a0d6ee42 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -107,6 +107,7 @@ libBionicStandardTests_src_files := \
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 000000000..f17fac53c
--- /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));
+}