From 52c86e41bf92ae30a0ff4d882a15d633d3f4dfdb Mon Sep 17 00:00:00 2001 From: Simon Schubert Date: Sat, 3 Oct 2009 21:37:22 +0200 Subject: [PATCH] dma: add DragonFly compat files These are not used in DragonFly, but for compilation on other systems. --- libexec/dma/dfcompat.c | 121 +++++++++++++++++++++++++++++++++++++++++ libexec/dma/dfcompat.h | 22 ++++++++ libexec/dma/dma.h | 8 --- 3 files changed, 143 insertions(+), 8 deletions(-) create mode 100644 libexec/dma/dfcompat.c create mode 100644 libexec/dma/dfcompat.h diff --git a/libexec/dma/dfcompat.c b/libexec/dma/dfcompat.c new file mode 100644 index 0000000000..b5c9010002 --- /dev/null +++ b/libexec/dma/dfcompat.c @@ -0,0 +1,121 @@ +#ifdef NEED_STRLCPY + +/* + * Copyright (c) 1998 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ + * $FreeBSD: src/lib/libc/string/strlcpy.c,v 1.10 2008/10/19 10:11:35 delphij Exp $ + * $DragonFly: src/lib/libc/string/strlcpy.c,v 1.4 2005/09/18 16:32:34 asmodai Exp $ + */ + +#include +#include + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t +strlcpy(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0) { + while (--n != 0) { + if ((*d++ = *s++) == '\0') + break; + } + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} + +#endif /* NEED_STRLCPY */ + +#ifdef NEED_REALLOCF + +/*- + * Copyright (c) 1998, M. Warner Losh + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/libc/stdlib/reallocf.c,v 1.3 1999/08/28 00:01:37 peter Exp $ + * $DragonFly: src/lib/libc/stdlib/reallocf.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + */ +#include + +void * +reallocf(void *ptr, size_t size) +{ + void *nptr; + + nptr = realloc(ptr, size); + if (!nptr && ptr) + free(ptr); + return (nptr); +} + +#endif /* NEED_REALLOCF */ + +#ifdef NEED_GETPROGNAME + +#ifdef __GLIBC__ + +#define __USE_GNU +#include + +const char * +getprogname(void) +{ + return (program_invocation_short_name); +} + +#else /* __GLIBC__ */ +#error "no getprogname implementation available" +#endif + +#endif /* NEED_GETPROGNAME */ diff --git a/libexec/dma/dfcompat.h b/libexec/dma/dfcompat.h new file mode 100644 index 0000000000..fc962d15e6 --- /dev/null +++ b/libexec/dma/dfcompat.h @@ -0,0 +1,22 @@ +#ifndef DFCOMPAT_H +#define DFCOMPAT_H + +#include + +#ifndef __DECONST +#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) +#endif + +#ifdef NEED_STRLCPY +size_t strlcpy(char *, const char *, size_t); +#endif + +#ifdef NEED_REALLOCF +void *reallocf(void *, size_t); +#endif + +#ifdef NEED_GETPROGNAME +const char *getprogname(void); +#endif + +#endif /* DFCOMPAT_H */ diff --git a/libexec/dma/dma.h b/libexec/dma/dma.h index c96ae193cd..5d971c07ab 100644 --- a/libexec/dma/dma.h +++ b/libexec/dma/dma.h @@ -44,14 +44,6 @@ #include #include -#ifndef __unused -#ifdef __GNUC__ -#define __unused __attribute__((unused)) -#else -#define __unused -#endif /* __GNUC__ */ -#endif - #define VERSION "DragonFly Mail Agent" #define BUF_SIZE 2048 -- 2.41.0