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,6 +28,14 @@ FILE_LICENCE ( PUBLIC_DOMAIN );
28 28
 extern void * __memcpy ( void *dest, const void *src, size_t len );
29 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 39
 static inline __attribute__ (( always_inline )) void *
32 40
 __constant_memcpy ( void *dest, const void *src, size_t len ) {
33 41
 	union {
@@ -139,10 +147,22 @@ __constant_memcpy ( void *dest, const void *src, size_t len ) {
139 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 167
 #define __HAVE_ARCH_MEMMOVE
148 168
 

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

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

Loading…
Cancel
Save