소스 검색

[libc] Rewrite unrelicensable portions of stddef.h

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 년 전
부모
커밋
5d1f351278
1개의 변경된 파일29개의 추가작업 그리고 11개의 파일을 삭제
  1. 29
    11
      src/include/stddef.h

+ 29
- 11
src/include/stddef.h 파일 보기

@@ -1,25 +1,43 @@
1 1
 #ifndef STDDEF_H
2 2
 #define STDDEF_H
3 3
 
4
-FILE_LICENCE ( GPL2_ONLY );
4
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
5 5
 
6
-/* for size_t */
7 6
 #include <stdint.h>
8 7
 
8
+/** EFI headers also define NULL */
9 9
 #undef NULL
10
-#define NULL ((void *)0)
11 10
 
12
-#undef offsetof
13
-#if ( defined ( __GNUC__ ) && ( __GNUC__ > 3 ) )
14
-#define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)
11
+/** Null pointer */
12
+#define NULL ( ( void * ) 0 )
13
+
14
+/**
15
+ * Get offset of a field within a structure
16
+ *
17
+ * @v type		Structure type
18
+ * @v field		Field within structure
19
+ * @ret offset		Offset within structure
20
+ */
21
+#if defined ( __GNUC__ ) && ( __GNUC__ > 3 )
22
+#define offsetof( type, field ) __builtin_offsetof ( type, field )
15 23
 #else
16
-#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
24
+#define offsetof( type, field ) ( ( size_t ) &( ( ( type * ) NULL )->field ) )
17 25
 #endif
18 26
 
19
-#undef container_of
20
-#define container_of(ptr, type, member) ({                      \
21
-	const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
22
-	(type *)( (char *)__mptr - offsetof(type,member) );})
27
+/**
28
+ * Get containing structure
29
+ *
30
+ * @v ptr		Pointer to contained field
31
+ * @v type		Containing structure type
32
+ * @v field		Field within containing structure
33
+ * @ret container	Pointer to containing structure
34
+ */
35
+#define container_of( ptr, type, field ) ( {				\
36
+	type *__container;						\
37
+	const typeof ( __container->field ) *__field = (ptr);		\
38
+	__container = ( ( ( void * ) __field ) -			\
39
+			offsetof ( type, field ) );			\
40
+	__container; } )
23 41
 
24 42
 /* __WCHAR_TYPE__ is defined by gcc and will change if -fshort-wchar is used */
25 43
 #ifndef __WCHAR_TYPE__

Loading…
취소
저장