-
+ A243804709FA25F0D592AD67A62EB46D3DC0470B0D94D6E111F3DCAE5EFF15A7F6EE37352F3FD45A78E39A0E0BA54B4F7BE0EE15A7BB8FFFD3AB3CEA87A2F6EF
bitcoin/src/strlcpy.h
(0 . 0)(1 . 117)
22508 // /****************************\
22509 // * EXPERIMENTAL BRANCH. *
22510 // * FOR LABORATORY USE ONLY. *
22511 // ********************************
22512 // ************
22513 // **************
22514 // ****************
22515 // **** **** ****
22516 // *** *** ***
22517 // *** *** ***
22518 // *** * * **
22519 // ******** ********
22520 // ******* ******
22521 // *** **
22522 // * ******* **
22523 // ** * * * * *
22524 // ** * * ***
22525 // **** * * * * ****
22526 // **** *** * * ** ***
22527 // **** ********* ******
22528 // ******* ***** *******
22529 // ********* ****** **
22530 // ** ****** ******
22531 // ** ******* **
22532 // ** ******* ***
22533 // **** ******** ************
22534 // ************ ************
22535 // ******** *******
22536 // ****** ****
22537 // *** ***
22538 // ********************************
22539 /*
22540 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
22541 *
22542 * Permission to use, copy, modify, and distribute this software for any
22543 * purpose with or without fee is hereby granted, provided that the above
22544 * copyright notice and this permission notice appear in all copies.
22545 *
22546 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
22547 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
22548 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
22549 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22550 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
22551 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
22552 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22553 */
22554 #ifndef BITCOIN_STRLCPY_H
22555 #define BITCOIN_STRLCPY_H
22556 /*
22557 * Copy src to string dst of size siz. At most siz-1 characters
22558 * will be copied. Always NUL terminates (unless siz == 0).
22559 * Returns strlen(src); if retval >= siz, truncation occurred.
22560 */
22561 inline size_t strlcpy(char *dst, const char *src, size_t siz)
22562 {
22563 char *d = dst;
22564 const char *s = src;
22565 size_t n = siz;
22566
22567 /* Copy as many bytes as will fit */
22568 if (n != 0)
22569 {
22570 while (--n != 0)
22571 {
22572 if ((*d++ = *s++) == '\0')
22573 break;
22574 }
22575 }
22576
22577 /* Not enough room in dst, add NUL and traverse rest of src */
22578 if (n == 0)
22579 {
22580 if (siz != 0)
22581 *d = '\0'; /* NUL-terminate dst */
22582 while (*s++)
22583 ;
22584 }
22585
22586 return(s - src - 1); /* count does not include NUL */
22587 }
22588
22589 /*
22590 * Appends src to string dst of size siz (unlike strncat, siz is the
22591 * full size of dst, not space left). At most siz-1 characters
22592 * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
22593 * Returns strlen(src) + MIN(siz, strlen(initial dst)).
22594 * If retval >= siz, truncation occurred.
22595 */
22596 inline size_t strlcat(char *dst, const char *src, size_t siz)
22597 {
22598 char *d = dst;
22599 const char *s = src;
22600 size_t n = siz;
22601 size_t dlen;
22602
22603 /* Find the end of dst and adjust bytes left but don't go past end */
22604 while (n-- != 0 && *d != '\0')
22605 d++;
22606 dlen = d - dst;
22607 n = siz - dlen;
22608
22609 if (n == 0)
22610 return(dlen + strlen(s));
22611 while (*s != '\0')
22612 {
22613 if (n != 1)
22614 {
22615 *d++ = *s;
22616 n--;
22617 }
22618 s++;
22619 }
22620 *d = '\0';
22621
22622 return(dlen + (s - src)); /* count does not include NUL */
22623 }
22624 #endif