From: Todd C. Miller Date: Mon, 3 May 2010 21:56:06 +0000 (-0400) Subject: No longer need strdup() or strndup() replacements. X-Git-Tag: SUDO_1_8_0~670 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9166c156e6ce70891efa3dc8318b584079886ade;p=sudo No longer need strdup() or strndup() replacements. --- diff --git a/compat/Makefile.in b/compat/Makefile.in index 402d27e0a..090d7fbe3 100644 --- a/compat/Makefile.in +++ b/compat/Makefile.in @@ -91,8 +91,6 @@ nanosleep.lo: $(compat)/nanosleep.c $(incdir)/compat.h $(top_builddir)/config.h sigaction.lo: $(compat)/sigaction.c $(incdir)/compat.h $(incdir)/compat.h snprintf.lo: $(compat)/snprintf.c $(incdir)/compat.h $(top_builddir)/config.h strcasecmp.lo: $(compat)/strcasecmp.c $(incdir)/compat.h $(top_builddir)/config.h -strdup.lo: $(compat)/strdup.c $(incdir)/compat.h $(top_builddir)/config.h -strndup.lo: $(compat)/strdup.c $(incdir)/compat.h $(top_builddir)/config.h strerror.lo: $(compat)/strerror.c $(incdir)/compat.h $(top_builddir)/config.h strlcat.lo: $(compat)/strlcat.c $(incdir)/compat.h $(top_builddir)/config.h strlcpy.lo: $(compat)/strlcpy.c $(incdir)/compat.h $(top_builddir)/config.h diff --git a/compat/strdup.c b/compat/strdup.c deleted file mode 100644 index 17e11f932..000000000 --- a/compat/strdup.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2010 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. - */ - -#include - -#include -#ifdef STDC_HEADERS -# include -# include -#else -# ifdef HAVE_STDLIB_H -# include -# endif -#endif /* STDC_HEADERS */ -#ifdef HAVE_STRING_H -# include -#else -# ifdef HAVE_STRINGS_H -# include -# endif -#endif /* HAVE_STRING_H */ -#if defined(HAVE_MALLOC_H) && !defined(STDC_HEADERS) -# include -#endif /* HAVE_MALLOC_H && !STDC_HEADERS */ - -#include - -char * -strdup(const char *src) -{ - char *dst = NULL; - size_t len = strlen(src); - - dst = (char *) malloc(len + 1); - (void) memcpy(dst, src, len); - dst[len] = '\0'; - - return dst; -} diff --git a/compat/strndup.c b/compat/strndup.c deleted file mode 100644 index d6a905d5b..000000000 --- a/compat/strndup.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2010 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. - */ - -#include - -#include -#ifdef STDC_HEADERS -# include -# include -#else -# ifdef HAVE_STDLIB_H -# include -# endif -#endif /* STDC_HEADERS */ -#ifdef HAVE_STRING_H -# include -#else -# ifdef HAVE_STRINGS_H -# include -# endif -#endif /* HAVE_STRING_H */ -#if defined(HAVE_MALLOC_H) && !defined(STDC_HEADERS) -# include -#endif /* HAVE_MALLOC_H && !STDC_HEADERS */ - -#include - -char * -strndup(const char *src, size_t maxlen) -{ - char *dst = NULL; - size_t len = strlen(src); - - if (len > maxlen) - len = maxlen; - dst = (char *) malloc(len + 1); - (void) memcpy(dst, src, len); - dst[len] = '\0'; - - return dst; -} -