From: Christian Grothoff Date: Mon, 16 Nov 2009 14:10:10 +0000 (+0000) Subject: more X-Git-Tag: initial-import-from-subversion-38251~23059 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=c98085d62d4bebeb2be2517e3e0d896ff68fa0ed;p=oweals%2Fgnunet.git more --- diff --git a/src/util/Makefile.am b/src/util/Makefile.am index c85a2cd75..d4c35ccdb 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -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 \ diff --git a/src/util/program.c b/src/util/program.c index f74da8c7f..1a4c1175d 100644 --- a/src/util/program.c +++ b/src/util/program.c @@ -38,6 +38,9 @@ #if HAVE_ARGZ_H #include #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 index 000000000..1c702c7f4 --- /dev/null +++ b/src/util/program_lib_mempcpy.c @@ -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 + +/* Specification. */ +#include + +/* 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 index 000000000..3a1b0eae2 --- /dev/null +++ b/src/util/program_lib_strndup.c @@ -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 + +#include + +#include + +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 index 000000000..d346d3272 --- /dev/null +++ b/src/util/program_lib_strnlen.c @@ -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 + +#include + +/* 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; +}