strnlen.c: New file.
* 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. From-SVN: r191432
This commit is contained in:
parent
fb5e0707d1
commit
9a9baa5254
@ -1,3 +1,15 @@
|
||||
2012-09-18 Ian Lance Taylor <iant@google.com>
|
||||
|
||||
* 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.
|
||||
|
||||
2012-09-18 Florian Weimer <fweimer@redhat.com>
|
||||
|
||||
PR other/54411
|
||||
|
@ -151,7 +151,7 @@ CFILES = alloca.c argv.c asprintf.c atexit.c \
|
||||
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) ./atexit.$(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/$@; \
|
||||
|
@ -262,6 +262,9 @@
|
||||
/* Define to 1 if you have the `strndup' function. */
|
||||
#undef HAVE_STRNDUP
|
||||
|
||||
/* Define to 1 if you have the `strnlen' function. */
|
||||
#undef HAVE_STRNLEN
|
||||
|
||||
/* Define to 1 if you have the `strrchr' function. */
|
||||
#undef HAVE_STRRCHR
|
||||
|
||||
|
13
libiberty/configure
vendored
13
libiberty/configure
vendored
@ -5340,6 +5340,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"
|
||||
@ -5380,8 +5381,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
|
||||
@ -5662,6 +5663,12 @@ esac
|
||||
;;
|
||||
esac
|
||||
|
||||
case " $LIBOBJS " in
|
||||
*" strnlen.$ac_objext "* ) ;;
|
||||
*) LIBOBJS="$LIBOBJS strnlen.$ac_objext"
|
||||
;;
|
||||
esac
|
||||
|
||||
case " $LIBOBJS " in
|
||||
*" strverscmp.$ac_objext "* ) ;;
|
||||
*) LIBOBJS="$LIBOBJS strverscmp.$ac_objext"
|
||||
@ -5683,7 +5690,7 @@ esac
|
||||
|
||||
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'`
|
||||
|
@ -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'`
|
||||
|
@ -84,7 +84,7 @@ is respectively less than, matching, or greater than the array member.
|
||||
|
||||
@end deftypefn
|
||||
|
||||
@c argv.c:142
|
||||
@c argv.c:135
|
||||
@deftypefn Extension char** buildargv (char *@var{sp})
|
||||
|
||||
Given a pointer to a string, parse the string extracting fields
|
||||
@ -95,7 +95,7 @@ remains unchanged. The last element of the vector is followed by a
|
||||
@code{NULL} element.
|
||||
|
||||
All of the memory for the pointer array and copies of the string
|
||||
is obtained from @code{malloc}. All of the memory can be returned to the
|
||||
is obtained from @code{xmalloc}. All of the memory can be returned to the
|
||||
system with the single function call @code{freeargv}, which takes the
|
||||
returned result of @code{buildargv}, as it's argument.
|
||||
|
||||
@ -166,6 +166,14 @@ pointer encountered. Pointers to empty strings are ignored.
|
||||
|
||||
@end deftypefn
|
||||
|
||||
@c argv.c:470
|
||||
@deftypefn Extension int countargv (char **@var{argv})
|
||||
|
||||
Return the number of elements in @var{argv}.
|
||||
Returns zero if @var{argv} is NULL.
|
||||
|
||||
@end deftypefn
|
||||
|
||||
@c crc32.c:141
|
||||
@deftypefn Extension {unsigned int} crc32 (const unsigned char *@var{buf}, @
|
||||
int @var{len}, unsigned int @var{init})
|
||||
@ -224,7 +232,7 @@ symbolic name or message.
|
||||
|
||||
@end deftypefn
|
||||
|
||||
@c argv.c:361
|
||||
@c argv.c:341
|
||||
@deftypefn Extension void expandargv (int *@var{argcp}, char ***@var{argvp})
|
||||
|
||||
The @var{argcp} and @code{argvp} arguments are pointers to the usual
|
||||
@ -296,7 +304,24 @@ and backward slashes are equal.
|
||||
|
||||
@end deftypefn
|
||||
|
||||
@c filename_cmp.c:81
|
||||
@c filename_cmp.c:178
|
||||
@deftypefn Extension int filename_eq (const void *@var{s1}, const void *@var{s2})
|
||||
|
||||
Return non-zero if file names @var{s1} and @var{s2} are equivalent.
|
||||
This function is for use with hashtab.c hash tables.
|
||||
|
||||
@end deftypefn
|
||||
|
||||
@c filename_cmp.c:147
|
||||
@deftypefn Extension hashval_t filename_hash (const void *@var{s})
|
||||
|
||||
Return the hash value for file name @var{s} that will be compared
|
||||
using filename_cmp.
|
||||
This function is for use with hashtab.c hash tables.
|
||||
|
||||
@end deftypefn
|
||||
|
||||
@c filename_cmp.c:89
|
||||
@deftypefn Extension int filename_ncmp (const char *@var{s1}, const char *@var{s2}, size_t @var{n})
|
||||
|
||||
Return zero if the two file names @var{s1} and @var{s2} are equivalent
|
||||
@ -376,7 +401,7 @@ unchanged.
|
||||
|
||||
@end deftypefn
|
||||
|
||||
@c argv.c:97
|
||||
@c argv.c:90
|
||||
@deftypefn Extension void freeargv (char **@var{vector})
|
||||
|
||||
Free an argument vector that was built using @code{buildargv}. Simply
|
||||
@ -1465,6 +1490,13 @@ deallocate values.
|
||||
|
||||
@end deftypefn
|
||||
|
||||
@c stack-limit.c:28
|
||||
@deftypefn Extension void stack_limit_increase (unsigned long @var{pref})
|
||||
|
||||
Attempt to increase stack size limit to @var{pref} bytes if possible.
|
||||
|
||||
@end deftypefn
|
||||
|
||||
@c stpcpy.c:23
|
||||
@deftypefn Supplemental char* stpcpy (char *@var{dst}, const char *@var{src})
|
||||
|
||||
@ -1574,6 +1606,16 @@ memory was available. The result is always NUL terminated.
|
||||
|
||||
@end deftypefn
|
||||
|
||||
@c strnlen.c:6
|
||||
@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
|
||||
|
||||
@c strrchr.c:6
|
||||
@deftypefn Supplemental char* strrchr (const char *@var{s}, int @var{c})
|
||||
|
||||
@ -1728,6 +1770,22 @@ This function is especially useful when dealing with filename sorting,
|
||||
because filenames frequently hold indices/version numbers.
|
||||
@end deftypefun
|
||||
|
||||
@c timeval-utils.c:43
|
||||
@deftypefn Extension void timeval_add (struct timeval *@var{a}, @
|
||||
struct timeval *@var{b}, struct timeval *@var{result})
|
||||
|
||||
Adds @var{a} to @var{b} and stores the result in @var{result}.
|
||||
|
||||
@end deftypefn
|
||||
|
||||
@c timeval-utils.c:67
|
||||
@deftypefn Extension void timeval_sub (struct timeval *@var{a}, @
|
||||
struct timeval *@var{b}, struct timeval *@var{result})
|
||||
|
||||
Subtracts @var{b} from @var{a} and stores the result in @var{result}.
|
||||
|
||||
@end deftypefn
|
||||
|
||||
@c tmpnam.c:3
|
||||
@deftypefn Supplemental char* tmpnam (char *@var{s})
|
||||
|
||||
@ -1829,7 +1887,7 @@ does the return value. The third argument is unused in @libib{}.
|
||||
|
||||
@end deftypefn
|
||||
|
||||
@c argv.c:306
|
||||
@c argv.c:286
|
||||
@deftypefn Extension int writeargv (const char **@var{argv}, FILE *@var{file})
|
||||
|
||||
Write each member of ARGV, handling all necessary quoting, to the file
|
||||
|
@ -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"));
|
||||
}
|
||||
|
30
libiberty/strnlen.c
Normal file
30
libiberty/strnlen.c
Normal file
@ -0,0 +1,30 @@
|
||||
/* 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"
|
||||
|
||||
#include <stddef.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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user