#ifndef HAVE_STRLCPY12/*3* Copyright (c) 1998 Todd C. Miller <[email protected]>4*5* Permission to use, copy, modify, and distribute this software for any6* purpose with or without fee is hereby granted, provided that the above7* copyright notice and this permission notice appear in all copies.8*9* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES10* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF11* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR12* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES13* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN14* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF15* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.16*17* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $18* $FreeBSD: src/lib/libc/string/strlcpy.c,v 1.10 2008/10/19 10:11:35 delphij Exp $19* $DragonFly: src/lib/libc/string/strlcpy.c,v 1.4 2005/09/18 16:32:34 asmodai Exp $20*/2122#include "dfcompat.h"2324#include <sys/types.h>25#include <string.h>2627/*28* Copy src to string dst of size siz. At most siz-1 characters29* will be copied. Always NUL terminates (unless siz == 0).30* Returns strlen(src); if retval >= siz, truncation occurred.31*/32size_t33strlcpy(char *dst, const char *src, size_t siz)34{35char *d = dst;36const char *s = src;37size_t n = siz;3839/* Copy as many bytes as will fit */40if (n != 0) {41while (--n != 0) {42if ((*d++ = *s++) == '\0')43break;44}45}4647/* Not enough room in dst, add NUL and traverse rest of src */48if (n == 0) {49if (siz != 0)50*d = '\0'; /* NUL-terminate dst */51while (*s++)52;53}5455return(s - src - 1); /* count does not include NUL */56}5758#endif /* !HAVE_STRLCPY */5960#ifndef HAVE_REALLOCF6162/*-63* Copyright (c) 1998, M. Warner Losh <[email protected]>64* All rights reserved.65*66* Redistribution and use in source and binary forms, with or without67* modification, are permitted provided that the following conditions68* are met:69* 1. Redistributions of source code must retain the above copyright70* notice, this list of conditions and the following disclaimer.71* 2. Redistributions in binary form must reproduce the above copyright72* notice, this list of conditions and the following disclaimer in the73* documentation and/or other materials provided with the distribution.74*75* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND76* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE77* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE78* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE79* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL80* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS81* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)82* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT83* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY84* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF85* SUCH DAMAGE.86*87* $FreeBSD: src/lib/libc/stdlib/reallocf.c,v 1.3 1999/08/28 00:01:37 peter Exp $88* $DragonFly: src/lib/libc/stdlib/reallocf.c,v 1.2 2003/06/17 04:26:46 dillon Exp $89*/90#include <stdlib.h>9192void *93reallocf(void *ptr, size_t size)94{95void *nptr;9697nptr = realloc(ptr, size);98if (!nptr && ptr && size != 0)99free(ptr);100return (nptr);101}102103#endif /* !HAVE_REALLOCF */104105#ifndef HAVE_GETPROGNAME106107#ifdef __GLIBC__108109#include <errno.h>110111const char *112getprogname(void)113{114return (program_invocation_short_name);115}116117#else /* __GLIBC__ */118#error "no getprogname implementation available"119#endif120121#endif /* !HAVE_GETPROGNAME */122123124