experimental-genesis 1
experimental-genesis 2
experimental-genesis 3
experimental-genesis 4
experimental-genesis 5
experimental-genesis 6
experimental-genesis 7
experimental-genesis 8
experimental-genesis 9
experimental-genesis 10
experimental-genesis 11
experimental-genesis 12
experimental-genesis 13
experimental-genesis 14
experimental-genesis 15
experimental-genesis 16
experimental-genesis 17
experimental-genesis 18
experimental-genesis 19
experimental-genesis 20
experimental-genesis 21
experimental-genesis 22
experimental-genesis 23
experimental-genesis 24
experimental-genesis 25
experimental-genesis 26
experimental-genesis 27
experimental-genesis 28
experimental-genesis 29
experimental-genesis 30
experimental-genesis 31
experimental-genesis 32
experimental-genesis 33 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
experimental-genesis 34 *
experimental-genesis 35 * Permission to use, copy, modify, and distribute this software for any
experimental-genesis 36 * purpose with or without fee is hereby granted, provided that the above
experimental-genesis 37 * copyright notice and this permission notice appear in all copies.
experimental-genesis 38 *
experimental-genesis 39 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
experimental-genesis 40 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
experimental-genesis 41 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
experimental-genesis 42 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
experimental-genesis 43 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
experimental-genesis 44 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
experimental-genesis 45 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
experimental-genesis 46 */
experimental-genesis 47 #ifndef BITCOIN_STRLCPY_H
experimental-genesis 48 #define BITCOIN_STRLCPY_H
experimental-genesis 49
experimental-genesis 50 * Copy src to string dst of size siz. At most siz-1 characters
experimental-genesis 51 * will be copied. Always NUL terminates (unless siz == 0).
experimental-genesis 52 * Returns strlen(src); if retval >= siz, truncation occurred.
experimental-genesis 53 */
experimental-genesis 54 inline size_t strlcpy(char *dst, const char *src, size_t siz)
experimental-genesis 55 {
experimental-genesis 56 char *d = dst;
experimental-genesis 57 const char *s = src;
experimental-genesis 58 size_t n = siz;
experimental-genesis 59
experimental-genesis 60
experimental-genesis 61 if (n != 0)
experimental-genesis 62 {
experimental-genesis 63 while (--n != 0)
experimental-genesis 64 {
experimental-genesis 65 if ((*d++ = *s++) == '\0')
experimental-genesis 66 break;
experimental-genesis 67 }
experimental-genesis 68 }
experimental-genesis 69
experimental-genesis 70
experimental-genesis 71 if (n == 0)
experimental-genesis 72 {
experimental-genesis 73 if (siz != 0)
experimental-genesis 74 *d = '\0';
experimental-genesis 75 while (*s++)
experimental-genesis 76 ;
experimental-genesis 77 }
experimental-genesis 78
experimental-genesis 79 return(s - src - 1);
experimental-genesis 80 }
experimental-genesis 81
experimental-genesis 82
experimental-genesis 83 * Appends src to string dst of size siz (unlike strncat, siz is the
experimental-genesis 84 * full size of dst, not space left). At most siz-1 characters
experimental-genesis 85 * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
experimental-genesis 86 * Returns strlen(src) + MIN(siz, strlen(initial dst)).
experimental-genesis 87 * If retval >= siz, truncation occurred.
experimental-genesis 88 */
experimental-genesis 89 inline size_t strlcat(char *dst, const char *src, size_t siz)
experimental-genesis 90 {
experimental-genesis 91 char *d = dst;
experimental-genesis 92 const char *s = src;
experimental-genesis 93 size_t n = siz;
experimental-genesis 94 size_t dlen;
experimental-genesis 95
experimental-genesis 96
experimental-genesis 97 while (n-- != 0 && *d != '\0')
experimental-genesis 98 d++;
experimental-genesis 99 dlen = d - dst;
experimental-genesis 100 n = siz - dlen;
experimental-genesis 101
experimental-genesis 102 if (n == 0)
experimental-genesis 103 return(dlen + strlen(s));
experimental-genesis 104 while (*s != '\0')
experimental-genesis 105 {
experimental-genesis 106 if (n != 1)
experimental-genesis 107 {
experimental-genesis 108 *d++ = *s;
experimental-genesis 109 n--;
experimental-genesis 110 }
experimental-genesis 111 s++;
experimental-genesis 112 }
experimental-genesis 113 *d = '\0';
experimental-genesis 114
experimental-genesis 115 return(dlen + (s - src));
experimental-genesis 116 }
experimental-genesis 117 #endif