Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: third_party/minicrt/memory.cc

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/minicrt/memory.h ('k') | third_party/minicrt/misc.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 #include "libctiny.h"
3 #include <windows.h>
4 #include <errno.h>
5 #include "memory.h"
6
7 // memmove is defined first so it will use the intrinsic memcpy
8 void * __cdecl memmove(void * dst, const void * src, size_t count) {
9 void * ret = dst;
10
11 if (dst <= src || (char *)dst >= ((char *)src + count)) {
12 // Non-Overlapping Buffers - copy from lower addresses to higher addresses
13 // saves 500 bytes of 1.4MB in uncompressed setup.exe, worth it?
14 memcpy(dst, src, count);
15 // while (count--) {
16 // *(char *)dst = *(char *)src;
17 // dst = (char *)dst + 1;
18 // src = (char *)src + 1;
19 // }
20 }
21 else {
22 // Overlapping Buffers - copy from higher addresses to lower addresses
23 dst = (char *)dst + count - 1;
24 src = (char *)src + count - 1;
25
26 while (count--) {
27 *(char *)dst = *(char *)src;
28 dst = (char *)dst - 1;
29 src = (char *)src - 1;
30 }
31 }
32
33 return(ret);
34 }
35
36 // Turn off compiler intrinsics so that we can define these functions
37 #pragma function(memcmp, memcpy, memset)
38
39 int __cdecl memcmp(const void * buf1, const void * buf2, size_t count) {
40 if (!count)
41 return(0);
42 while (--count && *(char *)buf1 == *(char *)buf2) {
43 buf1 = (char *)buf1 + 1;
44 buf2 = (char *)buf2 + 1;
45 }
46 return( *((unsigned char *)buf1) - *((unsigned char *)buf2) );
47 }
48
49 void * __cdecl memcpy(void * dst, const void * src, size_t count) {
50 void * ret = dst;
51 // copy from lower addresses to higher addresses
52 while (count--) {
53 *(char *)dst = *(char *)src;
54 dst = (char *)dst + 1;
55 src = (char *)src + 1;
56 }
57 return(ret);
58 }
59
60 void * __cdecl memset(void *dst, int val, size_t count) {
61 void *start = dst;
62 while (count--) {
63 *(char *)dst = (char)val;
64 dst = (char *)dst + 1;
65 }
66 return(start);
67 }
68
69 errno_t __cdecl memmove_s(void* dst,
70 size_t size_in_bytes,
71 const void* src,
72 size_t count) {
73 if (count == 0) {
74 return 0;
75 }
76
77 if (!dst) return EINVAL;
78 if (!src) return EINVAL;
79 if (size_in_bytes < count) return ERANGE;
80
81 memmove(dst, src, count);
82 return 0;
83 }
84
85 errno_t __cdecl memcpy_s(void *dst,
86 size_t size_in_bytes,
87 const void *src,
88 size_t count) {
89 if (count == 0) {
90 return 0;
91 }
92
93 if (!dst) return EINVAL;
94 if (!src) return EINVAL;
95 if (size_in_bytes < count) return ERANGE;
96
97 memcpy(dst, src, count);
98 return 0;
99 }
100
OLDNEW
« no previous file with comments | « third_party/minicrt/memory.h ('k') | third_party/minicrt/misc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698