From patchwork Tue Sep 18 16:03:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 184756 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id CEE902C007D for ; Wed, 19 Sep 2012 02:03:31 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1348589012; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:From:To:Subject:Date:Message-ID:User-Agent: MIME-Version:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=+nn7vXzsO9tuTK4au/2jSFEvB9Y=; b=uOczqqF5h+xKdKy A42AdkbacHFomTGzHK3M9IWsY5h65SgUYvncMrmUjAn/hJbT+XgfssaNXLj5YWcN DHD8TezSthOYZDkz4OrpDinBrigZ1fWy59S1wnzR/HIasRK6BHyXNb/gHCRctAr1 v9ku8ox7nM+FE7mRJnzSBvgiGY+k= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:Received:Received:Received:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=NBRe47jN1s8QdSQZP42FCEc73J/aI1HdDquu10j1U6cLU7WGet32mCAYhXUd3M IBCMsbnOIAHh6Iw+4sHAM+zLIFSqP3fNYeWleO4a89y2zTB8YMxKKvFrRv1MpeHj Df0ZHvdCSWP2Hqqgct58qqixRVkhWFL851yZisDmdRwcU=; Received: (qmail 716 invoked by alias); 18 Sep 2012 16:03:26 -0000 Received: (qmail 697 invoked by uid 22791); 18 Sep 2012 16:03:23 -0000 X-SWARE-Spam-Status: No, hits=-4.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, TW_CP, TW_TR, TW_VF, TW_VP, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mail-pb0-f47.google.com (HELO mail-pb0-f47.google.com) (209.85.160.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 18 Sep 2012 16:03:08 +0000 Received: by pbcwy7 with SMTP id wy7so303671pbc.20 for ; Tue, 18 Sep 2012 09:03:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:date:message-id:user-agent:mime-version :content-type:x-gm-message-state; bh=15qEwfv67afMOEEKsJTOxgL20ngB1cVK8a/ORA+LX6I=; b=gWfv2PzzjekEQ52iQLenw8PfXftirqMiiApf7a4j38JxS3aqKoEDJzKH58xMZiy++P A03Ub6NzlR2rao2A8XVuZO9viXkqfH9GmUJRrOnauwuVW1sGFglxZjoJtxK3Ljm2l6Uc ewLd613azG6ID7puJpUpRD6KbK4F/v4y68f075vQUQvYTzOroPY8yF0CwDb+33bRUQTF aPKYqF1KgVDY/qqrFYWCXoAaQ9nVTLPNEIysuM7EJXbwFsFI6YhPj9Ao7h1fEeh0wftk mFo3MsZwjALQnjA+eIQy8/BSSbUxCwwEmEzfbi8chB+HVtzsN43liA2EiY/lBCW5CpW6 2iyw== Received: by 10.66.77.10 with SMTP id o10mr466894paw.6.1347984187886; Tue, 18 Sep 2012 09:03:07 -0700 (PDT) Received: by 10.66.77.10 with SMTP id o10mr466878paw.6.1347984187631; Tue, 18 Sep 2012 09:03:07 -0700 (PDT) Received: from coign.google.com ([2620:0:1000:2301:f2de:f1ff:fe40:72a8]) by mx.google.com with ESMTPS id pj10sm177515pbb.46.2012.09.18.09.03.04 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 18 Sep 2012 09:03:04 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org Subject: libiberty patch committed: Add strnlen Date: Tue, 18 Sep 2012 09:03:03 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-Gm-Message-State: ALoCoQlWXCixAZ3UOTgTo/Y4rlTyGv7DOX1Wz/lsQJ8Eo6PXKz2iY1lzBzPBDuW0KfDnMJR1miWKxaUsPCRubHbGIEBwDxbpLRjbdAb5E2whLAj93XL2usRcPraUHBylB05u1KsTFAtftCkz7f1ZVDa+ewAR8Am6l5OO34ePZdORNH5nf9YfQtdx2FXyV63T+GM3S/OY17WjMCXdUSur3C8oKuDS06l+pg== X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch to libiberty adds support for strnlen if it is not already present. I rebuilt the Makefile dependencies. This revealed that maint-tool wasn't recognizing that files that include dwarf2.h also depend on dwarf2.def, so I fixed maint-tool. I also rebuilt functions.texi, which had not been rebuilt for a while. Bootstrapped on x86_64-unknown-linux-gnu, where, as expected, the function was not compiled. Ian 2012-09-18 Ian Lance Taylor * strnlen.c: New file. * configure.ac: Check for strnlen, add it to AC_LIBOBJ if it's not present. * Makefile.in: Rebuild dependencies. (CFILES): Add strnlen.c. (CONFIGURED_OFILES): Add ./strnlen.$(objext). * configure, config.in, functions.texi: Rebuild. * maint-tool: Accept .def files in the include directory. Index: configure.ac =================================================================== --- configure.ac (revision 191430) +++ configure.ac (working copy) @@ -322,6 +322,7 @@ funcs="$funcs strchr" funcs="$funcs strdup" funcs="$funcs strncasecmp" funcs="$funcs strndup" +funcs="$funcs strnlen" funcs="$funcs strrchr" funcs="$funcs strstr" funcs="$funcs strtod" @@ -362,8 +363,8 @@ if test "x" = "y"; then random realpath rename rindex \ sbrk setenv setproctitle setrlimit sigsetmask snprintf spawnve spawnvpe \ stpcpy stpncpy strcasecmp strchr strdup \ - strerror strncasecmp strndup strrchr strsignal strstr strtod strtol \ - strtoul strverscmp sysconf sysctl sysmp \ + strerror strncasecmp strndup strnlen strrchr strsignal strstr strtod \ + strtol strtoul strverscmp sysconf sysctl sysmp \ table times tmpnam \ vasprintf vfprintf vprintf vsprintf \ wait3 wait4 waitpid) @@ -442,13 +443,14 @@ if test -n "${with_target_subdir}"; then AC_LIBOBJ([stpcpy]) AC_LIBOBJ([stpncpy]) AC_LIBOBJ([strndup]) + AC_LIBOBJ([strnlen]) AC_LIBOBJ([strverscmp]) AC_LIBOBJ([vasprintf]) AC_LIBOBJ([waitpid]) for f in $funcs; do case "$f" in - asprintf | basename | bcmp | bcopy | bzero | clock | ffs | getpagesize | index | insque | mempcpy | mkstemps | random | rindex | sigsetmask | stpcpy | stpncpy | strdup | strndup | strverscmp | vasprintf | waitpid) + asprintf | basename | bcmp | bcopy | bzero | clock | ffs | getpagesize | index | insque | mempcpy | mkstemps | random | rindex | sigsetmask | stpcpy | stpncpy | strdup | strndup | strnlen | strverscmp | vasprintf | waitpid) ;; *) n=HAVE_`echo $f | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'` Index: maint-tool =================================================================== --- maint-tool (revision 191430) +++ maint-tool (working copy) @@ -222,7 +222,7 @@ sub deps { opendir(INC, $incdir); while ($f = readdir INC) { - next unless $f =~ /\.h$/; + next unless $f =~ /\.h$/ || $f =~ /\.def$/; $mine{$f} = "\$(INCDIR)/$f"; $deps{$f} = join(' ', &deps_for("$incdir/$f")); } Index: strnlen.c =================================================================== --- strnlen.c (revision 0) +++ strnlen.c (revision 0) @@ -0,0 +1,28 @@ +/* Portable version of strnlen. + This function is in the public domain. */ + +/* + +@deftypefn Supplemental size_t strnlen (const char *@var{s}, size_t @var{maxlen}) + +Returns the length of @var{s}, as with @code{strlen}, but never looks +past the first @var{maxlen} characters in the string. If there is no +'\0' character in the first @var{maxlen} characters, returns +@var{maxlen}. + +@end deftypefn + +*/ + +#include "config.h" + +size_t +strnlen (const char *s, size_t maxlen) +{ + size_t i; + + for (i = 0; i < maxlen; ++i) + if (s[i] == '\0') + break; + return i; +} Index: Makefile.in =================================================================== --- Makefile.in (revision 191430) +++ Makefile.in (working copy) @@ -151,7 +151,7 @@ CFILES = alloca.c argv.c asprintf.c atex spaces.c splay-tree.c stack-limit.c stpcpy.c stpncpy.c \ strcasecmp.c strchr.c strdup.c strerror.c strncasecmp.c \ strncmp.c strrchr.c strsignal.c strstr.c strtod.c strtol.c \ - strtoul.c strndup.c strverscmp.c \ + strtoul.c strndup.c strnlen.c strverscmp.c \ timeval-utils.c tmpnam.c \ unlink-if-ordinary.c \ vasprintf.c vfork.c vfprintf.c vprintf.c vsnprintf.c vsprintf.c \ @@ -215,9 +215,9 @@ CONFIGURED_OFILES = ./asprintf.$(objext) ./sigsetmask.$(objext) ./snprintf.$(objext) \ ./stpcpy.$(objext) ./stpncpy.$(objext) ./strcasecmp.$(objext) \ ./strchr.$(objext) ./strdup.$(objext) ./strncasecmp.$(objext) \ - ./strncmp.$(objext) ./strndup.$(objext) ./strrchr.$(objext) \ - ./strstr.$(objext) ./strtod.$(objext) ./strtol.$(objext) \ - ./strtoul.$(objext) ./strverscmp.$(objext) \ + ./strncmp.$(objext) ./strndup.$(objext) ./strnlen.$(objext) \ + ./strrchr.$(objext) ./strstr.$(objext) ./strtod.$(objext) \ + ./strtol.$(objext) ./strtoul.$(objext) ./strverscmp.$(objext) \ ./tmpnam.$(objext) \ ./vasprintf.$(objext) ./vfork.$(objext) ./vfprintf.$(objext) \ ./vprintf.$(objext) ./vsnprintf.$(objext) ./vsprintf.$(objext) \ @@ -622,8 +622,8 @@ $(CONFIGURED_OFILES): stamp-picdir else true; fi $(COMPILE.c) $(srcdir)/crc32.c $(OUTPUT_OPTION) -./dwarfnames.$(objext): $(srcdir)/dwarfnames.c $(INCDIR)/dwarf2.h \ - $(INCDIR)/dwarf2.def +./dwarfnames.$(objext): $(srcdir)/dwarfnames.c $(INCDIR)/dwarf2.def \ + $(INCDIR)/dwarf2.h if [ x"$(PICFLAG)" != x ]; then \ $(COMPILE.c) $(PICFLAG) $(srcdir)/dwarfnames.c -o pic/$@; \ else true; fi @@ -656,7 +656,8 @@ $(CONFIGURED_OFILES): stamp-picdir else true; fi $(COMPILE.c) $(srcdir)/fibheap.c $(OUTPUT_OPTION) -./filename_cmp.$(objext): $(srcdir)/filename_cmp.c config.h $(INCDIR)/filenames.h \ +./filename_cmp.$(objext): $(srcdir)/filename_cmp.c config.h $(INCDIR)/ansidecl.h \ + $(INCDIR)/filenames.h $(INCDIR)/hashtab.h \ $(INCDIR)/safe-ctype.h if [ x"$(PICFLAG)" != x ]; then \ $(COMPILE.c) $(PICFLAG) $(srcdir)/filename_cmp.c -o pic/$@; \ @@ -757,7 +758,7 @@ $(CONFIGURED_OFILES): stamp-picdir $(COMPILE.c) $(srcdir)/insque.c $(OUTPUT_OPTION) ./lbasename.$(objext): $(srcdir)/lbasename.c config.h $(INCDIR)/ansidecl.h \ - $(INCDIR)/filenames.h $(INCDIR)/libiberty.h \ + $(INCDIR)/filenames.h $(INCDIR)/hashtab.h $(INCDIR)/libiberty.h \ $(INCDIR)/safe-ctype.h if [ x"$(PICFLAG)" != x ]; then \ $(COMPILE.c) $(PICFLAG) $(srcdir)/lbasename.c -o pic/$@; \ @@ -1043,7 +1044,7 @@ $(CONFIGURED_OFILES): stamp-picdir else true; fi $(COMPILE.c) $(srcdir)/splay-tree.c $(OUTPUT_OPTION) -./stack-limit.$(objext): $(srcdir)/stack-limit.c config.h +./stack-limit.$(objext): $(srcdir)/stack-limit.c config.h $(INCDIR)/ansidecl.h if [ x"$(PICFLAG)" != x ]; then \ $(COMPILE.c) $(PICFLAG) $(srcdir)/stack-limit.c -o pic/$@; \ else true; fi @@ -1104,6 +1105,12 @@ $(CONFIGURED_OFILES): stamp-picdir else true; fi $(COMPILE.c) $(srcdir)/strndup.c $(OUTPUT_OPTION) +./strnlen.$(objext): $(srcdir)/strnlen.c config.h + if [ x"$(PICFLAG)" != x ]; then \ + $(COMPILE.c) $(PICFLAG) $(srcdir)/strnlen.c -o pic/$@; \ + else true; fi + $(COMPILE.c) $(srcdir)/strnlen.c $(OUTPUT_OPTION) + ./strrchr.$(objext): $(srcdir)/strrchr.c $(INCDIR)/ansidecl.h if [ x"$(PICFLAG)" != x ]; then \ $(COMPILE.c) $(PICFLAG) $(srcdir)/strrchr.c -o pic/$@; \