40 Commits

Author SHA1 Message Date
Isaac Dunham
14f0272ea1 Add ABI compatability aliases.
GNU used several extensions that were incompatible with C99 and POSIX,
so they used alternate names for the standard functions.

The result is that we need these to run standards-conformant programs
that were linked with glibc.
2013-04-05 23:20:28 -07:00
Rich Felker
5afc74fbaa fix integer type issue in strverscmp
lenl-lenr is not a valid expression for a signed int return value from
strverscmp, since after implicit conversion from size_t to int this
difference could have the wrong sign or might even be zero. using the
difference for char values works since they're bounded well within the
range of differences representable by int, but it does not work for
size_t values.
2013-02-26 01:42:11 -05:00
Rich Felker
4853c1f7f7 implement non-stub strverscmp
patch by Isaac Dunham.
2013-02-26 01:36:47 -05:00
Rich Felker
e864ddc368 replace stub with working strcasestr 2013-02-21 23:54:25 -05:00
Rich Felker
330fd96213 fix wrong return value from wmemmove on forward copies 2013-02-21 23:19:18 -05:00
Rich Felker
820fccdefe fix alignment logic in strlcpy 2012-12-26 23:48:02 -05:00
Rich Felker
838951c97e simplify logic in stpcpy; avoid copying first aligned byte twice
gcc seems to be generating identical or near-identical code for both
versions, but the newer code is more expressive of what it's doing.
2012-10-22 15:17:09 -04:00
Rich Felker
c86f2974e2 add memmem function (gnu extension)
based on strstr. passes gnulib tests and a few quick checks of my own.
2012-10-15 23:02:57 -04:00
Rich Felker
68dbd05039 optimize strchrnul/strcspn not to scan string twice on no-match
when strchr fails, and important piece of information already
computed, the string length, is thrown away. have strchrnul (with
namespace protection) be the underlying function so this information
can be kept, and let strchr be a wrapper for it. this also allows
strcspn to be considerably faster in the case where the match set has
a single element that's not matched.
2012-09-27 17:19:09 -04:00
Rich Felker
3f9ff1514e slightly cleaner strlen, also seems to compile to better code
testing with gcc 4.6.3 on x86, -Os, the old version does a duplicate
null byte check after the first loop. this is purely the compiler
being stupid, but the old code was also stupid and unintuitive in how
it expressed the check.
2012-09-27 16:56:33 -04:00
Rich Felker
2bf469310d asm for memmove on i386 and x86_64
for the sake of simplicity, I've only used rep movsb rather than
breaking up the copy for using rep movsd/q. on all modern cpus, this
seems to be fine, but if there are performance problems, there might
be a need to go back and add support for rep movsd/q.
2012-09-10 19:04:24 -04:00
Rich Felker
1701e4f3d4 reenable word-at-at-time copying in memmove
before restrict was added, memove called memcpy for forward copies and
used a byte-at-a-time loop for reverse copies. this was changed to
avoid invoking UB now that memcpy has an undefined copying order,
making memmove considerably slower.

performance is still rather bad, so I'll be adding asm soon.
2012-09-10 18:16:11 -04:00
Rich Felker
400c5e5c83 use restrict everywhere it's required by c99 and/or posix 2008
to deal with the fact that the public headers may be used with pre-c99
compilers, __restrict is used in place of restrict, and defined
appropriately for any supported compiler. we also avoid the form
[restrict] since older versions of gcc rejected it due to a bug in the
original c99 standard, and instead use the form *restrict.
2012-09-06 22:44:55 -04:00
Rich Felker
bac03cdde1 remove dependency of wmemmove on wmemcpy direction
unlike the memmove commit, this one should be fine to leave in place.
wmemmove is not performance-critical, and even if it were, it's
already copying whole 32-bit words at a time instead of bytes.
2012-09-06 20:28:42 -04:00
Rich Felker
594318fd3d remove dependency of memmove on memcpy direction
this commit introduces a performance regression in many uses of
memmove, which will need to be addressed before the next release. i'm
making it as a temporary measure so that the restrict patch can be
committed without invoking undefined behavior when memmove calls
memcpy with overlapping regions.
2012-09-06 20:25:48 -04:00
Rich Felker
aaa9eb5101 memcpy asm for i386 and x86_64 2012-08-11 21:33:13 -04:00
Rich Felker
f997e224fc remove unused but buggy code from strstr.c 2012-08-11 18:40:33 -04:00
Rich Felker
35c16933f0 remove buggy short-string wcsstr implementation; always use twoway
since this interface is rarely used, it's probably best to lean
towards keeping code size down anyway. one-character needles will
still be found immediately by the initial wcschr call anyway.
2012-08-11 18:39:12 -04:00
Rich Felker
970ef6a124 optimize mempcpy to minimize need for data saved across the call 2012-07-31 21:18:17 -04:00
Rich Felker
f313a16224 make strerror_r behave nicer on failure
if the buffer is too short, at least return a partial string. this is
helpful if the caller is lazy and does not check for failure. care is
taken to avoid writing anything if the buffer length is zero, and to
always null-terminate when the buffer length is non-zero.
2012-06-20 12:07:18 -04:00
Rich Felker
054ba18599 fix overrun (n essentially ignored) in wcsncmp
bug report and solution by Richard Pennington
2012-05-26 18:04:17 -04:00
Rich Felker
aefd0f69bd fix failure of strrchr(str, 0)
bug report and solution by Richard Pennington
2012-05-26 18:01:34 -04:00
Rich Felker
e0614f7cd4 add all missing wchar functions except floating point parsers
these are mostly untested and adapted directly from corresponding byte
string functions and similar.
2012-03-01 23:24:45 -05:00
Rich Felker
a6540174be add dummied strverscmp (obnoxious GNU function)
programs that use this tend to horribly botch international text
support, so it's questionable whether we want to support it even in
the long term... for now, it's just a dummy that calls strcmp.
2011-09-11 22:45:56 -04:00
Rich Felker
73d2fde119 fix wrong type for wcsrchr argument 2 2011-06-13 14:06:04 -04:00
Rich Felker
86339bc4ba fix strncat and wcsncat (double null termination)
also modify wcsncpy to use the same loop logic
2011-05-22 21:58:43 -04:00
Rich Felker
e98136207a fix wcsncpy writing past end of buffer 2011-05-22 21:54:42 -04:00
Rich Felker
b5b41212a6 function signature fix: add const qualifier to mempcpy src arg 2011-04-26 12:28:41 -04:00
Rich Felker
6597f9ac13 implement memrchr (nonstandard) and optimize strrchr in terms of it 2011-04-13 08:36:29 -04:00
Rich Felker
cb8dff2149 fix misplaced *'s in string functions (harmless) 2011-04-07 16:19:30 -04:00
Rich Felker
1fee6186fe fix prototype for strsep 2011-04-06 14:28:29 -04:00
Rich Felker
16675df793 fix misaligned read on early string termination in strchr
this could actually cause rare crashes in the case where a short
string is located at the end of a page and the following page is not
readable, and in fact this was seen in gcc compiling certain files.
2011-04-05 09:27:41 -04:00
Rich Felker
c68b26369e fix serious bug in strchr - char signedness
search for bytes with high bit set was giving (potentially dangerous)
wrong results. i've tested, cleaned up, and hopefully sped up this
function now.
2011-04-03 18:16:11 -04:00
Rich Felker
9ae8d5fc71 fix all implicit conversion between signed/unsigned pointers
sadly the C language does not specify any such implicit conversion, so
this is not a matter of just fixing warnings (as gcc treats it) but
actual errors. i would like to revisit a number of these changes and
possibly revise the types used to reduce the number of casts required.
2011-03-25 16:34:03 -04:00
Rich Felker
a012aa879f fix broken wmemchr (unbounded search) 2011-03-17 22:38:45 -04:00
Rich Felker
2a195dd31c fix missing prototype for strsignal 2011-02-26 23:50:26 -05:00
Rich Felker
b8ff2aaabb add implementation of memccpy function 2011-02-24 12:35:42 -05:00
Rich Felker
9f19b3ec8d fix backwards conditional in stpncpy
this only made the function unnecessarily slow on systems with
unaligned access, but would of course crash on systems that can't do
unaligned accesses (none of which have ports yet).
2011-02-24 12:34:31 -05:00
Rich Felker
ca1aa5bae9 more header cleanup and conformance fixes - string.h 2011-02-14 20:53:15 -05:00
Rich Felker
0b44a0315b initial check-in, version 0.5.0 2011-02-12 00:22:29 -05:00