mirror of https://github.com/ipxe/ipxe.git
[libc] Convert memcpy() from a macro to an inline function
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/598/head
parent
fc30b13b25
commit
61c6af3f0b
|
@ -28,6 +28,14 @@ FILE_LICENCE ( PUBLIC_DOMAIN );
|
||||||
extern void * __memcpy ( void *dest, const void *src, size_t len );
|
extern void * __memcpy ( void *dest, const void *src, size_t len );
|
||||||
extern void * __memcpy_reverse ( void *dest, const void *src, size_t len );
|
extern void * __memcpy_reverse ( void *dest, const void *src, size_t len );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy memory area (where length is a compile-time constant)
|
||||||
|
*
|
||||||
|
* @v dest Destination address
|
||||||
|
* @v src Source address
|
||||||
|
* @v len Length
|
||||||
|
* @ret dest Destination address
|
||||||
|
*/
|
||||||
static inline __attribute__ (( always_inline )) void *
|
static inline __attribute__ (( always_inline )) void *
|
||||||
__constant_memcpy ( void *dest, const void *src, size_t len ) {
|
__constant_memcpy ( void *dest, const void *src, size_t len ) {
|
||||||
union {
|
union {
|
||||||
|
@ -139,10 +147,22 @@ __constant_memcpy ( void *dest, const void *src, size_t len ) {
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define memcpy( dest, src, len ) \
|
/**
|
||||||
( __builtin_constant_p ( (len) ) ? \
|
* Copy memory area
|
||||||
__constant_memcpy ( (dest), (src), (len) ) : \
|
*
|
||||||
__memcpy ( (dest), (src), (len) ) )
|
* @v dest Destination address
|
||||||
|
* @v src Source address
|
||||||
|
* @v len Length
|
||||||
|
* @ret dest Destination address
|
||||||
|
*/
|
||||||
|
static inline __attribute__ (( always_inline )) void *
|
||||||
|
memcpy ( void *dest, const void *src, size_t len ) {
|
||||||
|
if ( __builtin_constant_p ( len ) ) {
|
||||||
|
return __constant_memcpy ( dest, src, len );
|
||||||
|
} else {
|
||||||
|
return __memcpy ( dest, src, len );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#define __HAVE_ARCH_MEMMOVE
|
#define __HAVE_ARCH_MEMMOVE
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ char * __pure strpbrk(const char * cs,const char * ct) __nonnull;
|
||||||
char * strtok(char * s,const char * ct) __nonnull;
|
char * strtok(char * s,const char * ct) __nonnull;
|
||||||
char * strsep(char **s, const char *ct) __nonnull;
|
char * strsep(char **s, const char *ct) __nonnull;
|
||||||
void * memset(void * s,int c,size_t count) __nonnull;
|
void * memset(void * s,int c,size_t count) __nonnull;
|
||||||
|
void * memcpy ( void *dest, const void *src, size_t len ) __nonnull;
|
||||||
void * memmove(void * dest,const void *src,size_t count) __nonnull;
|
void * memmove(void * dest,const void *src,size_t count) __nonnull;
|
||||||
int __pure memcmp(const void * cs,const void * ct,
|
int __pure memcmp(const void * cs,const void * ct,
|
||||||
size_t count) __nonnull;
|
size_t count) __nonnull;
|
||||||
|
|
Loading…
Reference in New Issue