Browse Source

[libc] Convert memcpy() from a macro to an inline function

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
61c6af3f0b
2 changed files with 25 additions and 4 deletions
  1. 24
    4
      src/arch/x86/include/bits/string.h
  2. 1
    0
      src/include/string.h

+ 24
- 4
src/arch/x86/include/bits/string.h View File

28
 extern void * __memcpy ( void *dest, const void *src, size_t len );
28
 extern void * __memcpy ( void *dest, const void *src, size_t len );
29
 extern void * __memcpy_reverse ( void *dest, const void *src, size_t len );
29
 extern void * __memcpy_reverse ( void *dest, const void *src, size_t len );
30
 
30
 
31
+/**
32
+ * Copy memory area (where length is a compile-time constant)
33
+ *
34
+ * @v dest		Destination address
35
+ * @v src		Source address
36
+ * @v len		Length
37
+ * @ret dest		Destination address
38
+ */
31
 static inline __attribute__ (( always_inline )) void *
39
 static inline __attribute__ (( always_inline )) void *
32
 __constant_memcpy ( void *dest, const void *src, size_t len ) {
40
 __constant_memcpy ( void *dest, const void *src, size_t len ) {
33
 	union {
41
 	union {
139
 	return dest;
147
 	return dest;
140
 }
148
 }
141
 
149
 
142
-#define memcpy( dest, src, len )			\
143
-	( __builtin_constant_p ( (len) ) ?		\
144
-	  __constant_memcpy ( (dest), (src), (len) ) :	\
145
-	  __memcpy ( (dest), (src), (len) ) )
150
+/**
151
+ * Copy memory area
152
+ *
153
+ * @v dest		Destination address
154
+ * @v src		Source address
155
+ * @v len		Length
156
+ * @ret dest		Destination address
157
+ */
158
+static inline __attribute__ (( always_inline )) void *
159
+memcpy ( void *dest, const void *src, size_t len ) {
160
+	if ( __builtin_constant_p ( len ) ) {
161
+		return __constant_memcpy ( dest, src, len );
162
+	} else {
163
+		return __memcpy ( dest, src, len );
164
+	}
165
+}
146
 
166
 
147
 #define __HAVE_ARCH_MEMMOVE
167
 #define __HAVE_ARCH_MEMMOVE
148
 
168
 

+ 1
- 0
src/include/string.h View File

37
 char * strtok(char * s,const char * ct) __nonnull;
37
 char * strtok(char * s,const char * ct) __nonnull;
38
 char * strsep(char **s, const char *ct) __nonnull;
38
 char * strsep(char **s, const char *ct) __nonnull;
39
 void * memset(void * s,int c,size_t count) __nonnull;
39
 void * memset(void * s,int c,size_t count) __nonnull;
40
+void * memcpy ( void *dest, const void *src, size_t len ) __nonnull;
40
 void * memmove(void * dest,const void *src,size_t count) __nonnull;
41
 void * memmove(void * dest,const void *src,size_t count) __nonnull;
41
 int __pure memcmp(const void * cs,const void * ct,
42
 int __pure memcmp(const void * cs,const void * ct,
42
 				    size_t count) __nonnull;
43
 				    size_t count) __nonnull;

Loading…
Cancel
Save