more
authorChristian Grothoff <christian@grothoff.org>
Mon, 16 Nov 2009 14:10:10 +0000 (14:10 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 16 Nov 2009 14:10:10 +0000 (14:10 +0000)
src/util/Makefile.am
src/util/program.c
src/util/program_lib_mempcpy.c [new file with mode: 0644]
src/util/program_lib_strndup.c [new file with mode: 0644]
src/util/program_lib_strnlen.c [new file with mode: 0644]

index c85a2cd758811a1dac8aa5f2b56811fa3038d14e..d4c35ccdb4de4e73ab6bd6a401c8b1ac60b3fb7d 100644 (file)
@@ -363,6 +363,9 @@ perf_crypto_hash_LDADD = \
 
 EXTRA_DIST = \
   program_lib_argz.c \
+  program_lib_strndup.c \
+  program_lib_strnlen.c \
+  program_lib_mempcpy.c \
   test_configuration_data.conf \
   test_container_meta_data_image.jpg \
   test_program_data.conf \
index f74da8c7f5dba0ea2803a704668a1fe4d63b937f..1a4c1175dd524680e3026b8719bba1ca79472af6 100644 (file)
@@ -38,6 +38,9 @@
 #if HAVE_ARGZ_H
 #include <argz.h>
 #else
+#include "program_lib_strndup.c"
+#include "program_lib_strnlen.c"
+#include "program_lib_mempcpy.c"
 #include "program_lib_argz.c"
 #endif
 
diff --git a/src/util/program_lib_mempcpy.c b/src/util/program_lib_mempcpy.c
new file mode 100644 (file)
index 0000000..1c702c7
--- /dev/null
@@ -0,0 +1,29 @@
+/* Copy memory area and return pointer after last written byte.
+   Copyright (C) 2003, 2007 Free Software Foundation, Inc.
+
+   This program 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 2, or (at your option)
+   any later version.
+
+   This program 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 this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <string.h>
+
+/* Copy N bytes of SRC to DEST, return pointer to bytes after the
+   last written byte.  */
+void *
+mempcpy (void *dest, const void *src, size_t n)
+{
+  return (char *) memcpy (dest, src, n) + n;
+}
diff --git a/src/util/program_lib_strndup.c b/src/util/program_lib_strndup.c
new file mode 100644 (file)
index 0000000..3a1b0ea
--- /dev/null
@@ -0,0 +1,37 @@
+/* A replacement function, for systems that lack strndup.
+
+   Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006, 2007
+   Free Software Foundation, Inc.
+
+   This program 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 2, or (at your option) any
+   later version.
+
+   This program 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 this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+#include <string.h>
+
+#include <stdlib.h>
+
+char *
+strndup (char const *s, size_t n)
+{
+  size_t len = strnlen (s, n);
+  char *new = malloc (len + 1);
+
+  if (new == NULL)
+    return NULL;
+
+  new[len] = '\0';
+  return memcpy (new, s, len);
+}
diff --git a/src/util/program_lib_strnlen.c b/src/util/program_lib_strnlen.c
new file mode 100644 (file)
index 0000000..d346d32
--- /dev/null
@@ -0,0 +1,31 @@
+/* Find the length of STRING, but scan at most MAXLEN characters.
+   Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
+   Written by Simon Josefsson.
+
+   This program 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 2, or (at your option)
+   any later version.
+
+   This program 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 this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+#include <string.h>
+
+/* Find the length of STRING, but scan at most MAXLEN characters.
+   If no '\0' terminator is found in that many characters, return MAXLEN.  */
+
+size_t
+strnlen (const char *string, size_t maxlen)
+{
+  const char *end = memchr (string, '\0', maxlen);
+  return end ? (size_t) (end - string) : maxlen;
+}