From: Bruno Haible Date: Sun, 17 Aug 2003 16:05:16 +0000 (+0000) Subject: Add an include file to module 'strndup'. X-Git-Tag: cvs-readonly~4598 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=2506f8959da247eeccb61bfd5ef8726a7aa4bcae;p=gnulib.git Add an include file to module 'strndup'. New module 'xstrndup'. --- diff --git a/ChangeLog b/ChangeLog index e2cbdb848..b501b5062 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2003-08-17 Simon Josefsson + + * modules/xstrndup: New file. + * MODULES.html.sh (func_all_modules): Add xstrndup. + +2003-08-17 Bruno Haible + + * modules/strndup (Files, Include): Add lib/strndup.h. + 2003-08-17 Bruno Haible * gnulib-tool (func_create_testdir): Handle gl_USE_SYSTEM_EXTENSIONS diff --git a/MODULES.html.sh b/MODULES.html.sh index 447506b13..82334f0a5 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -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 " diff --git a/lib/ChangeLog b/lib/ChangeLog index 0b7e058bf..f919fe735 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,13 @@ +2003-08-17 Simon Josefsson + Bruno Haible + + * xstrndup.h: New file. + * xstrndup.c: New file. + +2003-08-17 Bruno Haible + + * strndup.h: New file. + 2003-08-16 Paul Eggert * 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 index 000000000..318e79983 --- /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 + +#else + +#include + +/* 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 index 000000000..5addbf663 --- /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 +#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 index 000000000..b09a2fc0b --- /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 + +/* 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); diff --git a/m4/ChangeLog b/m4/ChangeLog index d4e2f01e8..7c569521f 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,7 @@ +2003-08-17 Simon Josefsson + + * xstrndup.m4: New file. + 2003-08-16 Jim Meyering * utimes.m4 (gl_FUNC_UTIMES): New file. diff --git a/m4/xstrndup.m4 b/m4/xstrndup.m4 new file mode 100644 index 000000000..87c0ab8cb --- /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], [ + : +]) diff --git a/modules/strndup b/modules/strndup index 90e599c2b..77d62f8c0 100644 --- a/modules/strndup +++ b/modules/strndup @@ -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 index 000000000..ab7f15621 --- /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 +