Add an include file to module 'strndup'.
authorBruno Haible <bruno@clisp.org>
Sun, 17 Aug 2003 16:05:16 +0000 (16:05 +0000)
committerBruno Haible <bruno@clisp.org>
Sun, 17 Aug 2003 16:05:16 +0000 (16:05 +0000)
New module 'xstrndup'.

ChangeLog
MODULES.html.sh
lib/ChangeLog
lib/strndup.h [new file with mode: 0644]
lib/xstrndup.c [new file with mode: 0644]
lib/xstrndup.h [new file with mode: 0644]
m4/ChangeLog
m4/xstrndup.m4 [new file with mode: 0644]
modules/strndup
modules/xstrndup [new file with mode: 0644]

index e2cbdb8..b501b50 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2003-08-17  Simon Josefsson  <jas@extundo.com>
+
+       * modules/xstrndup: New file.
+       * MODULES.html.sh (func_all_modules): Add xstrndup.
+
+2003-08-17  Bruno Haible  <bruno@clisp.org>
+
+       * modules/strndup (Files, Include): Add lib/strndup.h.
+
 2003-08-17  Bruno Haible  <bruno@clisp.org>
 
        * gnulib-tool (func_create_testdir): Handle gl_USE_SYSTEM_EXTENSIONS
index 447506b..82334f0 100755 (executable)
@@ -1511,6 +1511,7 @@ func_all_modules ()
   func_module strnlen
   func_module strndup
   #func_module fstrcmp
+  func_module xstrndup
   func_end_table
 
   element="Numeric conversion functions <stdlib.h>"
index 0b7e058..f919fe7 100644 (file)
@@ -1,3 +1,13 @@
+2003-08-17  Simon Josefsson  <jas@extundo.com>
+            Bruno Haible  <bruno@clisp.org>
+
+       * xstrndup.h: New file.
+       * xstrndup.c: New file.
+
+2003-08-17  Bruno Haible  <bruno@clisp.org>
+
+       * strndup.h: New file.
+
 2003-08-16  Paul Eggert  <eggert@twinsun.com>
 
        * regex.h, strdup.c, strtoll.c, strtoul.c: Do not normalize white
diff --git a/lib/strndup.h b/lib/strndup.h
new file mode 100644 (file)
index 0000000..318e799
--- /dev/null
@@ -0,0 +1,30 @@
+/* Duplicate a size-bounded string.
+   Copyright (C) 2003 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.  */
+
+#if HAVE_STRNDUP
+
+/* Get strndup() declaration.  */
+#include <string.h>
+
+#else
+
+#include <stddef.h>
+
+/* Return a newly allocated copy of at most N bytes of STRING.  */
+extern char *strndup (const char *string, size_t n);
+
+#endif
diff --git a/lib/xstrndup.c b/lib/xstrndup.c
new file mode 100644 (file)
index 0000000..5addbf6
--- /dev/null
@@ -0,0 +1,39 @@
+/* Duplicate a bounded initial segment of a string, with out-of-memory
+   checking.
+   Copyright (C) 2003 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.  */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Specification.  */
+#include "xstrndup.h"
+
+#include "strndup.h"
+#include "xalloc.h"
+
+/* Return a newly allocated copy of at most N bytes of STRING.
+   In other words, return a copy of the initial segment of length N of
+   STRING.  */
+char *
+xstrndup (const char *string, size_t n)
+{
+  char *s = strndup (string, n);
+  if (! s)
+    xalloc_die ();
+  return s;
+}
diff --git a/lib/xstrndup.h b/lib/xstrndup.h
new file mode 100644 (file)
index 0000000..b09a2fc
--- /dev/null
@@ -0,0 +1,24 @@
+/* Duplicate a bounded initial segment of a string, with out-of-memory
+   checking.
+   Copyright (C) 2003 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.  */
+
+#include <stddef.h>
+
+/* Return a newly allocated copy of at most N bytes of STRING.
+   In other words, return a copy of the initial segment of length N of
+   STRING.  */
+extern char *xstrndup (const char *string, size_t n);
index d4e2f01..7c56952 100644 (file)
@@ -1,3 +1,7 @@
+2003-08-17  Simon Josefsson  <jas@extundo.com>
+
+       * xstrndup.m4: New file.
+
 2003-08-16  Jim Meyering  <jim@meyering.net>
 
        * utimes.m4 (gl_FUNC_UTIMES): New file.
diff --git a/m4/xstrndup.m4 b/m4/xstrndup.m4
new file mode 100644 (file)
index 0000000..87c0ab8
--- /dev/null
@@ -0,0 +1,17 @@
+# xstrndup.m4 serial 1
+dnl Copyright (C) 2003 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_XSTRNDUP],
+[
+  gl_PREREQ_XSTRNDUP
+])
+
+# Prerequisites of lib/xstrndup.c.
+AC_DEFUN([gl_PREREQ_XSTRNDUP], [
+  :
+])
index 90e599c..77d62f8 100644 (file)
@@ -2,6 +2,7 @@ Description:
 strndup() function: duplicate a size-bounded string.
 
 Files:
+lib/strndup.h
 lib/strndup.c
 m4/strndup.m4
 
@@ -14,6 +15,7 @@ gl_FUNC_STRNDUP
 Makefile.am:
 
 Include:
+"strndup.h"
 
 Maintainer:
 glibc
diff --git a/modules/xstrndup b/modules/xstrndup
new file mode 100644 (file)
index 0000000..ab7f156
--- /dev/null
@@ -0,0 +1,24 @@
+Description:
+Duplicate a bounded initial segment of a string, with out-of-memory checking.
+
+Files:
+lib/xstrndup.h
+lib/xstrndup.c
+m4/xstrndup.m4
+
+Depends-on:
+strndup
+xalloc
+
+configure.ac:
+gl_XSTRNDUP
+
+Makefile.am:
+lib_SOURCES += xstrndup.h xstrndup.c
+
+Include:
+"xstrndup.h"
+
+Maintainer:
+Simon Josefsson
+