/ strGT(s1,s2)
strncmp(s1, s2, n) strnNE(s1, s2, n) / strnEQ(s1, s2, n)
+ memcmp(p1, p2, n) memNE(p1, p2, n)
+ !memcmp(p1, p2, n) memEQ(p1, p2, n)
+
Notice the different order of arguments to C<Copy> and C<Move> than used
in C<memcpy> and C<memmove>.
Instead Of: Use:
atof(s) Atof(s)
- atoi(s) grok_atou(s, &e)
- atol(s) grok_atou(s, &e)
+ atoi(s) grok_atoUV(s, &uv, &e)
+ atol(s) grok_atoUV(s, &uv, &e)
strtod(s, &p) Nothing. Just don't use it.
- strtol(s, &p, n) grok_atou(s, &e)
- strtoul(s, &p, n) grok_atou(s, &e)
+ strtol(s, &p, n) grok_atoUV(s, &uv, &e)
+ strtoul(s, &p, n) grok_atoUV(s, &uv, &e)
+
+Typical use is to do range checks on C<uv> before casting:
+
+ int i; UV uv; char* end_ptr;
+ if (grok_atoUV(input, &uv, &end_ptr)
+ && uv <= INT_MAX)
+ i = (int)uv;
+ ... /* continue parsing from end_ptr */
+ } else {
+ ... /* parse error: not a decimal integer in range 0 .. MAX_IV */
+ }
Notice also the C<grok_bin>, C<grok_hex>, and C<grok_oct> functions in
F<numeric.c> for converting strings representing numbers in the respective
-bases into C<NV>s. Note that grok_atou() doesn't handle negative inputs,
+bases into C<NV>s. Note that grok_atoUV() doesn't handle negative inputs,
or leading whitespace (being purposefully strict).
Note that strtol() and strtoul() may be disguised as Strtol(), Strtoul(),
system(s) Don't. Look at pp_system or use my_popen.
getenv(s) PerlEnv_getenv(s)
- setenv(s, val) my_putenv(s, val)
+ setenv(s, val) my_setenv(s, val)
=head2 Miscellaneous functions