From b6e23235f28b1c85e18e9a2b7ba8c6b6c46aecbc Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Wed, 29 Jan 2014 17:00:07 -0500 Subject: bash-4.3-rc2 overlay --- lib/sh/strdup.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lib/sh/strdup.c (limited to 'lib/sh/strdup.c') diff --git a/lib/sh/strdup.c b/lib/sh/strdup.c new file mode 100644 index 00000000..90fa3532 --- /dev/null +++ b/lib/sh/strdup.c @@ -0,0 +1,42 @@ +/* strdup - return a copy of a string in newly-allocated memory. */ + +/* Copyright (C) 2013 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see . +*/ + + +#include + +/* Get specification. */ +#include +#include + +/* Duplicate S, returning an identical malloc'd string. */ +char * +strdup (s) + const char *s; +{ + size_t len; + void *new; + + len = strlen (s) + 1; + if ((new = malloc (len)) == NULL) + return NULL; + + memcpy (new, s, len); + return ((char *)new); +} -- cgit v1.2.1