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: Bruno Haible
Subject: Re: [Bug-gnulib] xalloc: add xstrndup
Date: Sun, 17 Aug 2003 18:07:05 +0200
User-agent: KMail/1.5

Simon Josefsson wrote:
> 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.

Thanks, this was better. But you forgot to send the xstrndup.h file;
the xstrndup.c file doesn't need to check for <string.h>; size_t is
found in <stddef.h> which is more standard than <sys/types.h>; and
finally you didn't provide a function prototype for strndup() on
non-glibc systems.

To fix all this, I've added a strndup.h file to the module 'strndup',
and committed this patch.

Bruno


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

        * modules/xstrndup: New file.
        * MODULES.html.sh (func_all_modules): Add xstrndup.

2003-08-17  Bruno Haible  <address@hidden>

        * modules/strndup (Files, Include): Add lib/strndup.h.

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

        * xstrndup.m4: New file.

2003-08-17  Simon Josefsson  <address@hidden>
            Bruno Haible  <address@hidden>

        * xstrndup.h: New file.
        * xstrndup.c: New file.

2003-08-17  Bruno Haible  <address@hidden>

        * strndup.h: New file.

*** /dev/null   Thu Jan  1 01:00:00 1970
--- modules/xstrndup    Sun Aug 17 17:42:31 2003
***************
*** 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
+ 
*** MODULES.html.sh     11 Aug 2003 17:45:27 -0000      1.33
--- MODULES.html.sh     17 Aug 2003 16:01:31 -0000
***************
*** 1511,1516 ****
--- 1511,1517 ----
    func_module strnlen
    func_module strndup
    #func_module fstrcmp
+   func_module xstrndup
    func_end_table
  
    element="Numeric conversion functions <stdlib.h>"
*** modules/strndup     20 Jan 2003 10:02:38 -0000      1.3
--- modules/strndup     17 Aug 2003 16:02:04 -0000
***************
*** 2,7 ****
--- 2,8 ----
  strndup() function: duplicate a size-bounded string.
  
  Files:
+ lib/strndup.h
  lib/strndup.c
  m4/strndup.m4
  
***************
*** 14,19 ****
--- 15,21 ----
  Makefile.am:
  
  Include:
+ "strndup.h"
  
  Maintainer:
  glibc
*** /dev/null   Thu Jan  1 01:00:00 1970
--- m4/xstrndup.m4      Sun Aug 17 17:56:03 2003
***************
*** 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], [
+   :
+ ])
*** /dev/null   Thu Jan  1 01:00:00 1970
--- lib/xstrndup.h      Sun Aug 17 17:55:16 2003
***************
*** 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);
*** /dev/null   Thu Jan  1 01:00:00 1970
--- lib/xstrndup.c      Sun Aug 17 17:55:28 2003
***************
*** 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;
+ }
*** /dev/null   Thu Jan  1 01:00:00 1970
--- lib/strndup.h       Sun Aug 17 17:50:55 2003
***************
*** 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





reply via email to

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