From: Bruno Haible Date: Fri, 14 Jan 2005 12:22:26 +0000 (+0000) Subject: gnulib module 'strdup'. X-Git-Tag: v0.14.2~138 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fbd4ee3b5e86fd2c4942777522ad4be5d0198616;p=thirdparty%2Fgettext.git gnulib module 'strdup'. --- diff --git a/gettext-tools/libgrep/strdup.c b/gettext-tools/libgrep/strdup.c new file mode 100644 index 000000000..8c88e310a --- /dev/null +++ b/gettext-tools/libgrep/strdup.c @@ -0,0 +1,56 @@ +/* Copyright (C) 1991, 1996, 1997, 1998, 2002, 2003, 2004 Free Software + Foundation, Inc. + + This file is part of the GNU C Library. + + 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifndef _LIBC +/* Get specification. */ +# include "strdup.h" +#endif + +#include +#include + +#undef __strdup +#undef strdup + +#ifndef weak_alias +# define __strdup strdup +#endif + +/* Duplicate S, returning an identical malloc'd string. */ +char * +__strdup (const char *s) +{ + size_t len = strlen (s) + 1; + void *new = malloc (len); + + if (new == NULL) + return NULL; + + return (char *) memcpy (new, s, len); +} +#ifdef libc_hidden_def +libc_hidden_def (__strdup) +#endif +#ifdef weak_alias +weak_alias (__strdup, strdup) +#endif diff --git a/gettext-tools/libgrep/strdup.h b/gettext-tools/libgrep/strdup.h new file mode 100644 index 000000000..d58bd13e2 --- /dev/null +++ b/gettext-tools/libgrep/strdup.h @@ -0,0 +1,29 @@ +/* strdup.h -- duplicate a string + Copyright (C) 2004 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#ifndef STRDUP_H_ +#define STRDUP_H_ + +/* Get strdup declaration, if available. */ +#include + +#if defined HAVE_DECL_STRDUP && !HAVE_DECL_STRDUP && !defined strdup +/* Duplicate S, returning an identical malloc'd string. */ +extern char *strdup (const char *s); +#endif + +#endif /* STRDUP_H_ */ diff --git a/gettext-tools/m4/strdup.m4 b/gettext-tools/m4/strdup.m4 new file mode 100644 index 000000000..9964d15b1 --- /dev/null +++ b/gettext-tools/m4/strdup.m4 @@ -0,0 +1,17 @@ +# strdup.m4 serial 4 +dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +AC_DEFUN([gl_FUNC_STRDUP], +[ + AC_REPLACE_FUNCS(strdup) + AC_CHECK_DECLS_ONCE(strdup) + gl_PREREQ_STRDUP +]) + +# Prerequisites of lib/strdup.c. +AC_DEFUN([gl_PREREQ_STRDUP], [:])