changeset 4587:db90c263cc55

Add an include file to module 'strndup'. New module 'xstrndup'.
author Bruno Haible <bruno@clisp.org>
date Sun, 17 Aug 2003 16:05:16 +0000
parents eb1b4acf2e86
children c0c002593bca
files ChangeLog MODULES.html.sh lib/ChangeLog lib/strndup.h lib/xstrndup.c lib/xstrndup.h m4/ChangeLog m4/xstrndup.m4 modules/strndup modules/xstrndup
diffstat 10 files changed, 160 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -1511,6 +1511,7 @@
   func_module strnlen
   func_module strndup
   #func_module fstrcmp
+  func_module xstrndup
   func_end_table
 
   element="Numeric conversion functions <stdlib.h>"
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -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
new file mode 100644
--- /dev/null
+++ b/lib/strndup.h
@@ -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
new file mode 100644
--- /dev/null
+++ b/lib/xstrndup.c
@@ -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;
+}
new file mode 100644
--- /dev/null
+++ b/lib/xstrndup.h
@@ -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);
--- a/m4/ChangeLog
+++ b/m4/ChangeLog
@@ -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.
new file mode 100644
--- /dev/null
+++ b/m4/xstrndup.m4
@@ -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], [
+  :
+])
--- a/modules/strndup
+++ b/modules/strndup
@@ -2,6 +2,7 @@
 strndup() function: duplicate a size-bounded string.
 
 Files:
+lib/strndup.h
 lib/strndup.c
 m4/strndup.m4
 
@@ -14,6 +15,7 @@
 Makefile.am:
 
 Include:
+"strndup.h"
 
 Maintainer:
 glibc
new file mode 100644
--- /dev/null
+++ b/modules/xstrndup
@@ -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
+