]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
gnulib module 'strdup'.
authorBruno Haible <bruno@clisp.org>
Fri, 14 Jan 2005 12:22:26 +0000 (12:22 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:12:04 +0000 (12:12 +0200)
gettext-tools/libgrep/strdup.c [new file with mode: 0644]
gettext-tools/libgrep/strdup.h [new file with mode: 0644]
gettext-tools/m4/strdup.m4 [new file with mode: 0644]

diff --git a/gettext-tools/libgrep/strdup.c b/gettext-tools/libgrep/strdup.c
new file mode 100644 (file)
index 0000000..8c88e31
--- /dev/null
@@ -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 <config.h>
+#endif
+
+#ifndef _LIBC
+/* Get specification.  */
+# include "strdup.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#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 (file)
index 0000000..d58bd13
--- /dev/null
@@ -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 <string.h>
+
+#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 (file)
index 0000000..9964d15
--- /dev/null
@@ -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], [:])