]> git.saurik.com Git - apple/bootx.git/blob - bootx.tproj/libclite.subproj/mem.c
BootX-36.tar.gz
[apple/bootx.git] / bootx.tproj / libclite.subproj / mem.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * mem.c - Standard memory functions.
24 *
25 * Copyright (c) 1998-2000 Apple Computer, Inc.
26 *
27 * DRI: Josh de Cesare
28 */
29
30 #import <libclite.h>
31 #import <ci.h>
32
33
34 void *memcpy(void *dst, const void *src, size_t len)
35 {
36 char *s = src, *d = dst;
37 int pos = 0, dir = 1;
38
39 if (d > s) {
40 dir = -1;
41 pos = len - 1;
42 }
43
44 while (len--) {
45 d[pos] = s[pos];
46 pos += dir;
47 }
48
49 return dst;
50 }
51
52
53 void *memset(void *dst, int ch, size_t len)
54 {
55 long tmp = 0x01010101 * (ch & 0x000000FF);
56
57 if (len < 32) while (len--) *(((char *)dst)++) = ch;
58 else {
59 // do the front chunk as chars
60 while ((long)dst & 3) {
61 len--;
62 *(((char *)dst)++) = ch;
63 }
64
65 // do the middle chunk as longs
66 while (len > 3) {
67 len -= 4;
68 *(((long *)dst)++) = tmp;
69 }
70
71 // do the last chunk as chars
72 while (len--) *(((char *)dst)++) = ch;
73 }
74
75 return dst;
76 }
77
78 void *bcopy(void *src, void *dst, int len)
79 {
80 return memcpy(dst, src, len);
81 }
82
83 void bzero(void *dst, int len)
84 {
85 memset(dst, 0, len);
86 }
87