blob: ef6c7e6636c47bfa9622c8ec4b0c8a583690d391 [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <cutils/memory.h>
18
19void android_memset16(uint16_t* dst, uint16_t value, size_t size)
20{
21 size >>= 1;
22 while (size--) {
23 *dst++ = value;
24 }
25}
26
27void android_memset32(uint32_t* dst, uint32_t value, size_t size)
28{
29 size >>= 2;
30 while (size--) {
31 *dst++ = value;
32 }
33}
34
35#if !HAVE_STRLCPY
36/*
37 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
38 *
39 * Permission to use, copy, modify, and distribute this software for any
40 * purpose with or without fee is hereby granted, provided that the above
41 * copyright notice and this permission notice appear in all copies.
42 *
43 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
44 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
45 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
46 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
47 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
48 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
49 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
50 */
51
52#include <sys/types.h>
53#include <string.h>
54
55/* Implementation of strlcpy() for platforms that don't already have it. */
56
57/*
58 * Copy src to string dst of size siz. At most siz-1 characters
59 * will be copied. Always NUL terminates (unless siz == 0).
60 * Returns strlen(src); if retval >= siz, truncation occurred.
61 */
62size_t
63strlcpy(char *dst, const char *src, size_t siz)
64{
65 char *d = dst;
66 const char *s = src;
67 size_t n = siz;
68
69 /* Copy as many bytes as will fit */
70 if (n != 0) {
71 while (--n != 0) {
72 if ((*d++ = *s++) == '\0')
73 break;
74 }
75 }
76
77 /* Not enough room in dst, add NUL and traverse rest of src */
78 if (n == 0) {
79 if (siz != 0)
80 *d = '\0'; /* NUL-terminate dst */
81 while (*s++)
82 ;
83 }
84
85 return(s - src - 1); /* count does not include NUL */
86}
87#endif