Skip to content

Commit 9a9baa5

Browse files
Ian Lance TaylorIan Lance Taylor
Ian Lance Taylor
authored and
Ian Lance Taylor
committed
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
1 parent fb5e070 commit 9a9baa5

File tree

8 files changed

+141
-22
lines changed

8 files changed

+141
-22
lines changed

libiberty/ChangeLog

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2012-09-18 Ian Lance Taylor <[email protected]>
2+
3+
* strnlen.c: New file.
4+
* configure.ac: Check for strnlen, add it to AC_LIBOBJ if it's not
5+
present.
6+
* Makefile.in: Rebuild dependencies.
7+
(CFILES): Add strnlen.c.
8+
(CONFIGURED_OFILES): Add ./strnlen.$(objext).
9+
* configure, config.in, functions.texi: Rebuild.
10+
11+
* maint-tool: Accept .def files in the include directory.
12+
113
2012-09-18 Florian Weimer <[email protected]>
214

315
PR other/54411

libiberty/Makefile.in

+16-9
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ CFILES = alloca.c argv.c asprintf.c atexit.c \
151151
spaces.c splay-tree.c stack-limit.c stpcpy.c stpncpy.c \
152152
strcasecmp.c strchr.c strdup.c strerror.c strncasecmp.c \
153153
strncmp.c strrchr.c strsignal.c strstr.c strtod.c strtol.c \
154-
strtoul.c strndup.c strverscmp.c \
154+
strtoul.c strndup.c strnlen.c strverscmp.c \
155155
timeval-utils.c tmpnam.c \
156156
unlink-if-ordinary.c \
157157
vasprintf.c vfork.c vfprintf.c vprintf.c vsnprintf.c vsprintf.c \
@@ -215,9 +215,9 @@ CONFIGURED_OFILES = ./asprintf.$(objext) ./atexit.$(objext) \
215215
./sigsetmask.$(objext) ./snprintf.$(objext) \
216216
./stpcpy.$(objext) ./stpncpy.$(objext) ./strcasecmp.$(objext) \
217217
./strchr.$(objext) ./strdup.$(objext) ./strncasecmp.$(objext) \
218-
./strncmp.$(objext) ./strndup.$(objext) ./strrchr.$(objext) \
219-
./strstr.$(objext) ./strtod.$(objext) ./strtol.$(objext) \
220-
./strtoul.$(objext) ./strverscmp.$(objext) \
218+
./strncmp.$(objext) ./strndup.$(objext) ./strnlen.$(objext) \
219+
./strrchr.$(objext) ./strstr.$(objext) ./strtod.$(objext) \
220+
./strtol.$(objext) ./strtoul.$(objext) ./strverscmp.$(objext) \
221221
./tmpnam.$(objext) \
222222
./vasprintf.$(objext) ./vfork.$(objext) ./vfprintf.$(objext) \
223223
./vprintf.$(objext) ./vsnprintf.$(objext) ./vsprintf.$(objext) \
@@ -622,8 +622,8 @@ $(CONFIGURED_OFILES): stamp-picdir
622622
else true; fi
623623
$(COMPILE.c) $(srcdir)/crc32.c $(OUTPUT_OPTION)
624624

625-
./dwarfnames.$(objext): $(srcdir)/dwarfnames.c $(INCDIR)/dwarf2.h \
626-
$(INCDIR)/dwarf2.def
625+
./dwarfnames.$(objext): $(srcdir)/dwarfnames.c $(INCDIR)/dwarf2.def \
626+
$(INCDIR)/dwarf2.h
627627
if [ x"$(PICFLAG)" != x ]; then \
628628
$(COMPILE.c) $(PICFLAG) $(srcdir)/dwarfnames.c -o pic/$@; \
629629
else true; fi
@@ -656,7 +656,8 @@ $(CONFIGURED_OFILES): stamp-picdir
656656
else true; fi
657657
$(COMPILE.c) $(srcdir)/fibheap.c $(OUTPUT_OPTION)
658658

659-
./filename_cmp.$(objext): $(srcdir)/filename_cmp.c config.h $(INCDIR)/filenames.h \
659+
./filename_cmp.$(objext): $(srcdir)/filename_cmp.c config.h $(INCDIR)/ansidecl.h \
660+
$(INCDIR)/filenames.h $(INCDIR)/hashtab.h \
660661
$(INCDIR)/safe-ctype.h
661662
if [ x"$(PICFLAG)" != x ]; then \
662663
$(COMPILE.c) $(PICFLAG) $(srcdir)/filename_cmp.c -o pic/$@; \
@@ -757,7 +758,7 @@ $(CONFIGURED_OFILES): stamp-picdir
757758
$(COMPILE.c) $(srcdir)/insque.c $(OUTPUT_OPTION)
758759

759760
./lbasename.$(objext): $(srcdir)/lbasename.c config.h $(INCDIR)/ansidecl.h \
760-
$(INCDIR)/filenames.h $(INCDIR)/libiberty.h \
761+
$(INCDIR)/filenames.h $(INCDIR)/hashtab.h $(INCDIR)/libiberty.h \
761762
$(INCDIR)/safe-ctype.h
762763
if [ x"$(PICFLAG)" != x ]; then \
763764
$(COMPILE.c) $(PICFLAG) $(srcdir)/lbasename.c -o pic/$@; \
@@ -1043,7 +1044,7 @@ $(CONFIGURED_OFILES): stamp-picdir
10431044
else true; fi
10441045
$(COMPILE.c) $(srcdir)/splay-tree.c $(OUTPUT_OPTION)
10451046

1046-
./stack-limit.$(objext): $(srcdir)/stack-limit.c config.h
1047+
./stack-limit.$(objext): $(srcdir)/stack-limit.c config.h $(INCDIR)/ansidecl.h
10471048
if [ x"$(PICFLAG)" != x ]; then \
10481049
$(COMPILE.c) $(PICFLAG) $(srcdir)/stack-limit.c -o pic/$@; \
10491050
else true; fi
@@ -1104,6 +1105,12 @@ $(CONFIGURED_OFILES): stamp-picdir
11041105
else true; fi
11051106
$(COMPILE.c) $(srcdir)/strndup.c $(OUTPUT_OPTION)
11061107

1108+
./strnlen.$(objext): $(srcdir)/strnlen.c config.h
1109+
if [ x"$(PICFLAG)" != x ]; then \
1110+
$(COMPILE.c) $(PICFLAG) $(srcdir)/strnlen.c -o pic/$@; \
1111+
else true; fi
1112+
$(COMPILE.c) $(srcdir)/strnlen.c $(OUTPUT_OPTION)
1113+
11071114
./strrchr.$(objext): $(srcdir)/strrchr.c $(INCDIR)/ansidecl.h
11081115
if [ x"$(PICFLAG)" != x ]; then \
11091116
$(COMPILE.c) $(PICFLAG) $(srcdir)/strrchr.c -o pic/$@; \

libiberty/config.in

+3
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@
262262
/* Define to 1 if you have the `strndup' function. */
263263
#undef HAVE_STRNDUP
264264

265+
/* Define to 1 if you have the `strnlen' function. */
266+
#undef HAVE_STRNLEN
267+
265268
/* Define to 1 if you have the `strrchr' function. */
266269
#undef HAVE_STRRCHR
267270

libiberty/configure

+10-3
Original file line numberDiff line numberDiff line change
@@ -5340,6 +5340,7 @@ funcs="$funcs strchr"
53405340
funcs="$funcs strdup"
53415341
funcs="$funcs strncasecmp"
53425342
funcs="$funcs strndup"
5343+
funcs="$funcs strnlen"
53435344
funcs="$funcs strrchr"
53445345
funcs="$funcs strstr"
53455346
funcs="$funcs strtod"
@@ -5380,8 +5381,8 @@ if test "x" = "y"; then
53805381
random realpath rename rindex \
53815382
sbrk setenv setproctitle setrlimit sigsetmask snprintf spawnve spawnvpe \
53825383
stpcpy stpncpy strcasecmp strchr strdup \
5383-
strerror strncasecmp strndup strrchr strsignal strstr strtod strtol \
5384-
strtoul strverscmp sysconf sysctl sysmp \
5384+
strerror strncasecmp strndup strnlen strrchr strsignal strstr strtod \
5385+
strtol strtoul strverscmp sysconf sysctl sysmp \
53855386
table times tmpnam \
53865387
vasprintf vfprintf vprintf vsprintf \
53875388
wait3 wait4 waitpid
@@ -5662,6 +5663,12 @@ esac
56625663
;;
56635664
esac
56645665
5666+
case " $LIBOBJS " in
5667+
*" strnlen.$ac_objext "* ) ;;
5668+
*) LIBOBJS="$LIBOBJS strnlen.$ac_objext"
5669+
;;
5670+
esac
5671+
56655672
case " $LIBOBJS " in
56665673
*" strverscmp.$ac_objext "* ) ;;
56675674
*) LIBOBJS="$LIBOBJS strverscmp.$ac_objext"
@@ -5683,7 +5690,7 @@ esac
56835690
56845691
for f in $funcs; do
56855692
case "$f" in
5686-
asprintf | basename | bcmp | bcopy | bzero | clock | ffs | getpagesize | index | insque | mempcpy | mkstemps | random | rindex | sigsetmask | stpcpy | stpncpy | strdup | strndup | strverscmp | vasprintf | waitpid)
5693+
asprintf | basename | bcmp | bcopy | bzero | clock | ffs | getpagesize | index | insque | mempcpy | mkstemps | random | rindex | sigsetmask | stpcpy | stpncpy | strdup | strndup | strnlen | strverscmp | vasprintf | waitpid)
56875694
;;
56885695
*)
56895696
n=HAVE_`echo $f | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`

libiberty/configure.ac

+5-3
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ funcs="$funcs strchr"
322322
funcs="$funcs strdup"
323323
funcs="$funcs strncasecmp"
324324
funcs="$funcs strndup"
325+
funcs="$funcs strnlen"
325326
funcs="$funcs strrchr"
326327
funcs="$funcs strstr"
327328
funcs="$funcs strtod"
@@ -362,8 +363,8 @@ if test "x" = "y"; then
362363
random realpath rename rindex \
363364
sbrk setenv setproctitle setrlimit sigsetmask snprintf spawnve spawnvpe \
364365
stpcpy stpncpy strcasecmp strchr strdup \
365-
strerror strncasecmp strndup strrchr strsignal strstr strtod strtol \
366-
strtoul strverscmp sysconf sysctl sysmp \
366+
strerror strncasecmp strndup strnlen strrchr strsignal strstr strtod \
367+
strtol strtoul strverscmp sysconf sysctl sysmp \
367368
table times tmpnam \
368369
vasprintf vfprintf vprintf vsprintf \
369370
wait3 wait4 waitpid)
@@ -442,13 +443,14 @@ if test -n "${with_target_subdir}"; then
442443
AC_LIBOBJ([stpcpy])
443444
AC_LIBOBJ([stpncpy])
444445
AC_LIBOBJ([strndup])
446+
AC_LIBOBJ([strnlen])
445447
AC_LIBOBJ([strverscmp])
446448
AC_LIBOBJ([vasprintf])
447449
AC_LIBOBJ([waitpid])
448450

449451
for f in $funcs; do
450452
case "$f" in
451-
asprintf | basename | bcmp | bcopy | bzero | clock | ffs | getpagesize | index | insque | mempcpy | mkstemps | random | rindex | sigsetmask | stpcpy | stpncpy | strdup | strndup | strverscmp | vasprintf | waitpid)
453+
asprintf | basename | bcmp | bcopy | bzero | clock | ffs | getpagesize | index | insque | mempcpy | mkstemps | random | rindex | sigsetmask | stpcpy | stpncpy | strdup | strndup | strnlen | strverscmp | vasprintf | waitpid)
452454
;;
453455
*)
454456
n=HAVE_`echo $f | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`

libiberty/functions.texi

+64-6
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ is respectively less than, matching, or greater than the array member.
8484

8585
@end deftypefn
8686

87-
@c argv.c:142
87+
@c argv.c:135
8888
@deftypefn Extension char** buildargv (char *@var{sp})
8989

9090
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
9595
@code{NULL} element.
9696

9797
All of the memory for the pointer array and copies of the string
98-
is obtained from @code{malloc}. All of the memory can be returned to the
98+
is obtained from @code{xmalloc}. All of the memory can be returned to the
9999
system with the single function call @code{freeargv}, which takes the
100100
returned result of @code{buildargv}, as it's argument.
101101

@@ -166,6 +166,14 @@ pointer encountered. Pointers to empty strings are ignored.
166166

167167
@end deftypefn
168168

169+
@c argv.c:470
170+
@deftypefn Extension int countargv (char **@var{argv})
171+
172+
Return the number of elements in @var{argv}.
173+
Returns zero if @var{argv} is NULL.
174+
175+
@end deftypefn
176+
169177
@c crc32.c:141
170178
@deftypefn Extension {unsigned int} crc32 (const unsigned char *@var{buf}, @
171179
int @var{len}, unsigned int @var{init})
@@ -224,7 +232,7 @@ symbolic name or message.
224232

225233
@end deftypefn
226234

227-
@c argv.c:361
235+
@c argv.c:341
228236
@deftypefn Extension void expandargv (int *@var{argcp}, char ***@var{argvp})
229237

230238
The @var{argcp} and @code{argvp} arguments are pointers to the usual
@@ -296,7 +304,24 @@ and backward slashes are equal.
296304

297305
@end deftypefn
298306

299-
@c filename_cmp.c:81
307+
@c filename_cmp.c:178
308+
@deftypefn Extension int filename_eq (const void *@var{s1}, const void *@var{s2})
309+
310+
Return non-zero if file names @var{s1} and @var{s2} are equivalent.
311+
This function is for use with hashtab.c hash tables.
312+
313+
@end deftypefn
314+
315+
@c filename_cmp.c:147
316+
@deftypefn Extension hashval_t filename_hash (const void *@var{s})
317+
318+
Return the hash value for file name @var{s} that will be compared
319+
using filename_cmp.
320+
This function is for use with hashtab.c hash tables.
321+
322+
@end deftypefn
323+
324+
@c filename_cmp.c:89
300325
@deftypefn Extension int filename_ncmp (const char *@var{s1}, const char *@var{s2}, size_t @var{n})
301326

302327
Return zero if the two file names @var{s1} and @var{s2} are equivalent
@@ -376,7 +401,7 @@ unchanged.
376401

377402
@end deftypefn
378403

379-
@c argv.c:97
404+
@c argv.c:90
380405
@deftypefn Extension void freeargv (char **@var{vector})
381406

382407
Free an argument vector that was built using @code{buildargv}. Simply
@@ -1465,6 +1490,13 @@ deallocate values.
14651490

14661491
@end deftypefn
14671492

1493+
@c stack-limit.c:28
1494+
@deftypefn Extension void stack_limit_increase (unsigned long @var{pref})
1495+
1496+
Attempt to increase stack size limit to @var{pref} bytes if possible.
1497+
1498+
@end deftypefn
1499+
14681500
@c stpcpy.c:23
14691501
@deftypefn Supplemental char* stpcpy (char *@var{dst}, const char *@var{src})
14701502

@@ -1574,6 +1606,16 @@ memory was available. The result is always NUL terminated.
15741606

15751607
@end deftypefn
15761608

1609+
@c strnlen.c:6
1610+
@deftypefn Supplemental size_t strnlen (const char *@var{s}, size_t @var{maxlen})
1611+
1612+
Returns the length of @var{s}, as with @code{strlen}, but never looks
1613+
past the first @var{maxlen} characters in the string. If there is no
1614+
'\0' character in the first @var{maxlen} characters, returns
1615+
@var{maxlen}.
1616+
1617+
@end deftypefn
1618+
15771619
@c strrchr.c:6
15781620
@deftypefn Supplemental char* strrchr (const char *@var{s}, int @var{c})
15791621

@@ -1728,6 +1770,22 @@ This function is especially useful when dealing with filename sorting,
17281770
because filenames frequently hold indices/version numbers.
17291771
@end deftypefun
17301772

1773+
@c timeval-utils.c:43
1774+
@deftypefn Extension void timeval_add (struct timeval *@var{a}, @
1775+
struct timeval *@var{b}, struct timeval *@var{result})
1776+
1777+
Adds @var{a} to @var{b} and stores the result in @var{result}.
1778+
1779+
@end deftypefn
1780+
1781+
@c timeval-utils.c:67
1782+
@deftypefn Extension void timeval_sub (struct timeval *@var{a}, @
1783+
struct timeval *@var{b}, struct timeval *@var{result})
1784+
1785+
Subtracts @var{b} from @var{a} and stores the result in @var{result}.
1786+
1787+
@end deftypefn
1788+
17311789
@c tmpnam.c:3
17321790
@deftypefn Supplemental char* tmpnam (char *@var{s})
17331791

@@ -1829,7 +1887,7 @@ does the return value. The third argument is unused in @libib{}.
18291887

18301888
@end deftypefn
18311889

1832-
@c argv.c:306
1890+
@c argv.c:286
18331891
@deftypefn Extension int writeargv (const char **@var{argv}, FILE *@var{file})
18341892

18351893
Write each member of ARGV, handling all necessary quoting, to the file

libiberty/maint-tool

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ sub deps {
222222

223223
opendir(INC, $incdir);
224224
while ($f = readdir INC) {
225-
next unless $f =~ /\.h$/;
225+
next unless $f =~ /\.h$/ || $f =~ /\.def$/;
226226
$mine{$f} = "\$(INCDIR)/$f";
227227
$deps{$f} = join(' ', &deps_for("$incdir/$f"));
228228
}

libiberty/strnlen.c

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* Portable version of strnlen.
2+
This function is in the public domain. */
3+
4+
/*
5+
6+
@deftypefn Supplemental size_t strnlen (const char *@var{s}, size_t @var{maxlen})
7+
8+
Returns the length of @var{s}, as with @code{strlen}, but never looks
9+
past the first @var{maxlen} characters in the string. If there is no
10+
'\0' character in the first @var{maxlen} characters, returns
11+
@var{maxlen}.
12+
13+
@end deftypefn
14+
15+
*/
16+
17+
#include "config.h"
18+
19+
#include <stddef.h>
20+
21+
size_t
22+
strnlen (const char *s, size_t maxlen)
23+
{
24+
size_t i;
25+
26+
for (i = 0; i < maxlen; ++i)
27+
if (s[i] == '\0')
28+
break;
29+
return i;
30+
}

0 commit comments

Comments
 (0)