percent-encode the query parts of a request too, not only the path.
[Rockbox.git] / firmware / common / memcpy.c
blobe9b8e82bddf05db64d41cb76a80011a5eef324f3
1 /*
2 FUNCTION
3 <<memcpy>>---copy memory regions
5 ANSI_SYNOPSIS
6 #include <string.h>
7 void* memcpy(void *<[out]>, const void *<[in]>, size_t <[n]>);
9 TRAD_SYNOPSIS
10 void *memcpy(<[out]>, <[in]>, <[n]>
11 void *<[out]>;
12 void *<[in]>;
13 size_t <[n]>;
15 DESCRIPTION
16 This function copies <[n]> bytes from the memory region
17 pointed to by <[in]> to the memory region pointed to by
18 <[out]>.
20 If the regions overlap, the behavior is undefined.
22 RETURNS
23 <<memcpy>> returns a pointer to the first byte of the <[out]>
24 region.
26 PORTABILITY
27 <<memcpy>> is ANSI C.
29 <<memcpy>> requires no supporting OS subroutines.
31 QUICKREF
32 memcpy ansi pure
35 #include "config.h"
36 #include <_ansi.h>
37 #include <stddef.h>
38 #include <limits.h>
40 /* Nonzero if either X or Y is not aligned on a "long" boundary. */
41 #define UNALIGNED(X, Y) \
42 (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
44 /* How many bytes are copied each iteration of the 4X unrolled loop. */
45 #define BIGBLOCKSIZE (sizeof (long) << 2)
47 /* How many bytes are copied each iteration of the word copy loop. */
48 #define LITTLEBLOCKSIZE (sizeof (long))
50 /* Threshhold for punting to the byte copier. */
51 #define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE)
53 _PTR
54 _DEFUN (memcpy, (dst0, src0, len0),
55 _PTR dst0 _AND
56 _CONST _PTR src0 _AND
57 size_t len0) ICODE_ATTR;
59 _PTR
60 _DEFUN (memcpy, (dst0, src0, len0),
61 _PTR dst0 _AND
62 _CONST _PTR src0 _AND
63 size_t len0)
65 #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
66 char *dst = (char *) dst0;
67 char *src = (char *) src0;
69 _PTR save = dst0;
71 while (len0--)
73 *dst++ = *src++;
76 return save;
77 #else
78 char *dst = dst0;
79 _CONST char *src = src0;
80 long *aligned_dst;
81 _CONST long *aligned_src;
82 unsigned int len = len0;
84 /* If the size is small, or either SRC or DST is unaligned,
85 then punt into the byte copy loop. This should be rare. */
86 if (!TOO_SMALL(len) && !UNALIGNED (src, dst))
88 aligned_dst = (long*)dst;
89 aligned_src = (long*)src;
91 /* Copy 4X long words at a time if possible. */
92 while (len >= BIGBLOCKSIZE)
94 *aligned_dst++ = *aligned_src++;
95 *aligned_dst++ = *aligned_src++;
96 *aligned_dst++ = *aligned_src++;
97 *aligned_dst++ = *aligned_src++;
98 len -= (unsigned int)BIGBLOCKSIZE;
101 /* Copy one long word at a time if possible. */
102 while (len >= LITTLEBLOCKSIZE)
104 *aligned_dst++ = *aligned_src++;
105 len -= LITTLEBLOCKSIZE;
108 /* Pick up any residual with a byte copier. */
109 dst = (char*)aligned_dst;
110 src = (char*)aligned_src;
113 while (len--)
114 *dst++ = *src++;
116 return dst0;
117 #endif /* not PREFER_SIZE_OVER_SPEED */