bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gnulib] xalloc: add xstrndup


From: Simon Josefsson
Subject: Re: [Bug-gnulib] xalloc: add xstrndup
Date: Sat, 16 Aug 2003 00:55:11 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

Paul Eggert <address@hidden> writes:

> I like all of Bruno's suggestions, except for the one about taking
> Bison's implementation.  Bison's doesn't assume strndup, but we can
> assume it, so our code can be cleaner.
>
> Simon, can you please draft a revised patch taking all these
> suggestions into account?

Sounds better to me too.  Here goes:

ChangeLog:

2003-08-16  Simon Josefsson  <address@hidden>

        * MODULES.html.sh (func_all_modules): Add xstrndup.

        * modules/xstrndup: New file.

m4/ChangeLog:

2003-08-16  Simon Josefsson  <address@hidden>

        * xstrndup.m4: New file.

lib/ChangeLog:

2003-08-16  Simon Josefsson  <address@hidden>

        * xstrndup.h: New file.

Index: MODULES.html.sh
===================================================================
RCS file: /cvsroot/gnulib/gnulib/MODULES.html.sh,v
retrieving revision 1.33
diff -u -p -r1.33 MODULES.html.sh
--- MODULES.html.sh     11 Aug 2003 17:45:27 -0000      1.33
+++ MODULES.html.sh     15 Aug 2003 22:51:16 -0000
@@ -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: lib/xstrndup.c
===================================================================
RCS file: lib/xstrndup.c
diff -N lib/xstrndup.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/xstrndup.c      15 Aug 2003 22:51:16 -0000
@@ -0,0 +1,41 @@
+/* xstrndup.c -- copy at most n bytes 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
+
+#if STDC_HEADERS || HAVE_STRING_H
+# include <string.h>
+#else
+# include <strings.h>
+#endif
+
+#include <sys/types.h>
+
+#include "xstrndup.h"
+#include "xalloc.h"
+
+/* Return a newly allocated copy of at most n bytes of STRING.  */
+char *
+xstrndup (const char *string, size_t n)
+{
+  char *s = strndup (string, n);
+  if (! s)
+    xalloc_die ();
+  return s;
+}
Index: m4/xstrndup.m4
===================================================================
RCS file: m4/xstrndup.m4
diff -N m4/xstrndup.m4
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ m4/xstrndup.m4      15 Aug 2003 22:51:16 -0000
@@ -0,0 +1,18 @@
+# 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], [
+  AC_REQUIRE([AC_HEADER_STDC])
+  AC_CHECK_HEADERS_ONCE(string.h)
+])
Index: modules/xstrndup
===================================================================
RCS file: modules/xstrndup
diff -N modules/xstrndup
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ modules/xstrndup    15 Aug 2003 22:51:16 -0000
@@ -0,0 +1,22 @@
+Description:
+Copy at most n bytes of a string with out of memory checking.
+
+Files:
+lib/xstrndup.h
+lib/xstrndup.c
+m4/xstrndup.m4
+
+Depends-on:
+xalloc
+
+configure.ac:
+gl_XSTRNDUP
+
+Makefile.am:
+lib_SOURCES += xstrndup.h xstrndup.c
+
+Include:
+"xstrndup.h"
+
+Maintainer:
+Simon Josefsson





reply via email to

[Prev in Thread] Current Thread [Next in Thread]