[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: strnlen.h needed?
From: |
Simon Josefsson |
Subject: |
Re: strnlen.h needed? |
Date: |
Wed, 10 Aug 2005 12:34:33 +0200 |
User-agent: |
Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux) |
(Old thread; I want to clean up my gnulib CVS tree...)
Simon Josefsson <address@hidden> writes:
> Dave Love <address@hidden> writes:
>
>> It looks as if gnulib needs a strnlen.h which declares rpl_strnlen
>> appropriately (conditional on HAVE_STRNLEN) and it should be used in
>> files where strnlen is called.
>
> I agree. Here's a patch for gnulib. Untested, but based on
> snprintf.h.
Ok to install? strnlen is a GNU extension, according to libc manual.
There were some discussion regarding strnlen.h, but the patch below
has worked for me for a while. Any problems can be fixed later on.
It seems correct to me.
The fix to make strndup use strnlen should go in too.
Thanks,
Simon
2005-08-10 Simon Josefsson <address@hidden>
* strndup.c: Use strnlen.h.
* strnlen.h: New file.
2005-08-10 Simon Josefsson <address@hidden>
* strnlen.m4: New file.
* strndup.m4: Don't check for strnlen declaration, done in
strnlen.m4.
2005-08-10 Simon Josefsson <address@hidden>
* modules/strnlen (Files): Add strnlen.h.
Index: m4/strnlen.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/strnlen.m4,v
retrieving revision 1.6
diff -u -p -r1.6 strnlen.m4
--- m4/strnlen.m4 23 Jan 2005 08:06:57 -0000 1.6
+++ m4/strnlen.m4 10 Aug 2005 10:31:34 -0000
@@ -1,5 +1,5 @@
-# strnlen.m4 serial 4
-dnl Copyright (C) 2002-2003 Free Software Foundation, Inc.
+# strnlen.m4 serial 5
+dnl Copyright (C) 2002-2003, 2005 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
@@ -22,4 +22,6 @@ AC_DEFUN([gl_FUNC_STRNLEN],
])
# Prerequisites of lib/strnlen.c.
-AC_DEFUN([gl_PREREQ_STRNLEN], [:])
+AC_DEFUN([gl_PREREQ_STRNLEN], [
+ AC_CHECK_DECLS_ONCE(strnlen)
+])
Index: m4/strndup.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/strndup.m4,v
retrieving revision 1.4
diff -u -p -r1.4 strndup.m4
--- m4/strndup.m4 21 Mar 2005 22:06:27 -0000 1.4
+++ m4/strndup.m4 10 Aug 2005 10:31:34 -0000
@@ -1,4 +1,4 @@
-# strndup.m4 serial 4
+# strndup.m4 serial 5
dnl Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -18,6 +18,4 @@ AC_DEFUN([gl_FUNC_STRNDUP],
])
# Prerequisites of lib/strndup.c.
-AC_DEFUN([gl_PREREQ_STRNDUP], [
- AC_CHECK_DECLS(strnlen)
-])
+AC_DEFUN([gl_PREREQ_STRNDUP], [:])
Index: modules/strnlen
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/strnlen,v
retrieving revision 1.4
diff -u -p -r1.4 strnlen
--- modules/strnlen 22 Sep 2004 15:11:04 -0000 1.4
+++ modules/strnlen 10 Aug 2005 10:31:34 -0000
@@ -2,6 +2,7 @@ Description:
strnlen() function: determine the length of a size-bounded string.
Files:
+lib/strnlen.h
lib/strnlen.c
m4/strnlen.m4
Index: lib/strnlen.h
===================================================================
RCS file: lib/strnlen.h
diff -N lib/strnlen.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/strnlen.h 10 Aug 2005 10:31:34 -0000
@@ -0,0 +1,29 @@
+/* Find the length of STRING, but scan at most MAXLEN characters.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+ Written by Simon Josefsson.
+
+ 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. */
+
+#ifndef STRNLEN_H
+#define STRNLEN_H
+
+/* Get strnlen declaration, if available. */
+#include <string.h>
+
+#if defined HAVE_DECL_STRNLEN && !HAVE_DECL_STRNLEN
+extern size_t strnlen(const char *s, size_t maxlen);
+#endif
+
+#endif /* STRNLEN_H */
Index: strndup.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/strndup.c,v
retrieving revision 1.11
diff -u -p -u -w -r1.11 strndup.c
--- strndup.c 14 May 2005 06:03:58 -0000 1.11
+++ strndup.c 10 Aug 2005 10:32:23 -0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 2000, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998, 2000, 2003, 2005 Free Software Foundation,
Inc.
NOTE: The canonical source of this file is maintained with the GNU C
Library.
Bugs can be reported to address@hidden
@@ -24,12 +24,8 @@
#include <stdlib.h>
#include <string.h>
-#ifndef HAVE_DECL_STRNLEN
-"this configure-time declaration test was not run"
-#endif
-#if !HAVE_DECL_STRNLEN
-size_t strnlen ();
-#endif
+/* Get strnlen. */
+#include "strnlen.h"
#undef __strndup
#undef strndup
- Re: strnlen.h needed?,
Simon Josefsson <=