summaryrefslogtreecommitdiff
path: root/lib/sh
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sh')
-rw-r--r--lib/sh/Makefile.in2
-rw-r--r--lib/sh/itos.c12
-rw-r--r--lib/sh/strdup.c42
-rw-r--r--lib/sh/stringvec.c16
4 files changed, 71 insertions, 1 deletions
diff --git a/lib/sh/Makefile.in b/lib/sh/Makefile.in
index 938c3721..36a83052 100644
--- a/lib/sh/Makefile.in
+++ b/lib/sh/Makefile.in
@@ -92,7 +92,7 @@ CSOURCES = clktck.c clock.c getcwd.c getenv.c oslib.c setlinebuf.c \
mktime.c strftime.c mbschr.c zcatfd.c zmapfd.c winsize.c eaccess.c \
wcsdup.c fpurge.c zgetline.c mbscmp.c uconvert.c ufuncs.c \
casemod.c dprintf.c input_avail.c mbscasecmp.c fnxform.c \
- strchrnul.c unicode.c wcswidth.c wcsnwidth.c shmbchar.c
+ strchrnul.c unicode.c wcswidth.c wcsnwidth.c shmbchar.c strdup.c
# The header files for this library.
HSOURCES =
diff --git a/lib/sh/itos.c b/lib/sh/itos.c
index 12e9398d..cd36ef33 100644
--- a/lib/sh/itos.c
+++ b/lib/sh/itos.c
@@ -50,6 +50,18 @@ itos (i)
return (savestring (p));
}
+/* Integer to string conversion. This conses the string using strdup;
+ caller should free it and be prepared to deal with NULL return. */
+char *
+mitos (i)
+ intmax_t i;
+{
+ char *p, lbuf[INT_STRLEN_BOUND(intmax_t) + 1];
+
+ p = fmtumax (i, 10, lbuf, sizeof(lbuf), 0);
+ return (strdup (p));
+}
+
char *
uinttostr (i, buf, len)
uintmax_t i;
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 <http://www.gnu.org/licenses/>.
+*/
+
+
+#include <config.h>
+
+/* Get specification. */
+#include <string.h>
+#include <stdlib.h>
+
+/* 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);
+}
diff --git a/lib/sh/stringvec.c b/lib/sh/stringvec.c
index b0ed4164..3bb4ab70 100644
--- a/lib/sh/stringvec.c
+++ b/lib/sh/stringvec.c
@@ -40,6 +40,14 @@ strvec_create (n)
return ((char **)xmalloc ((n) * sizeof (char *)));
}
+/* Allocate an array of strings with room for N members. */
+char **
+strvec_mcreate (n)
+ int n;
+{
+ return ((char **)malloc ((n) * sizeof (char *)));
+}
+
char **
strvec_resize (array, nsize)
char **array;
@@ -48,6 +56,14 @@ strvec_resize (array, nsize)
return ((char **)xrealloc (array, nsize * sizeof (char *)));
}
+char **
+strvec_mresize (array, nsize)
+ char **array;
+ int nsize;
+{
+ return ((char **)realloc (array, nsize * sizeof (char *)));
+}
+
/* Return the length of ARRAY, a NULL terminated array of char *. */
int
strvec_len (array)