It is time for a gripe.
Libc contains a lot of quite APIs. You probably know about the
gets dissaster, but there is a whole lot more.
- String-to-value conversions. Here is how you
convert from a string
scontaining a decimal integer
into an int
errno = 0;
l = strtol (s, &end, 10);
if (s != end && *end == 0 &&
errno != ERANGE &&
l >= INT_MIN && l
And that is before considering locales (which typically do not
affect integers, mind you).
- Time zones. The
is great, but having $TZ as as implicit and not explicit argument
makes it really, really hard to use for anything but the default
- ctype functions. At least two things are wrong:
(1) the encoding used is an implicit argument; and (2) they are defined obscurely such that
char c = 'a'; isdigit(c)may or may not
be valid, depending on the platform. Most commonly it is not valid,
i.e., it may core dump. The right way to do that is,
isdigit((unsigned char)c)which is enough to make a sane man crazy. (Alternatively one
unsigned charbut in
more practical code the type is often constrained by a parameter type.)
I have the feeling I might return to this subject later.