Ralph Corderoy [Wed, 19 Oct 2016 17:13:10 +0000 (18:13 +0100)]
Add EndsWithC(char *s, int c) and call it in some initial places.
EndsWithC returns true if non-NULL string s ends with a c before the
terminating NUL.
Ralph Corderoy [Wed, 19 Oct 2016 16:52:44 +0000 (17:52 +0100)]
Add stdbool.h plus fallback to h/nmh.h.
Change h/mh.h's FALSE and TRUE to use stdbool.h's. In time, everything
can switch over and FALSE and TRUE can go. Delete some local
re-definitions of FALSE and TRUE.
Ralph Corderoy [Wed, 19 Oct 2016 14:43:12 +0000 (15:43 +0100)]
Alter ctype-checked to handle EOF and be hand-written.
Along the way, replace the code generation with code that punts the work
onto the stdlib's C functions, needing only a single `identity' array
for all the macros. A mkdir needed to be added in Makefile.am because
otherwise etc didn't exist in a distcheck and attempting to redirect
stdout to a file in etc failed. I'm not happy that's the best automake
way to achieve this, i.e. what if another rule attempts to create in etc
first?
Ralph Corderoy [Wed, 19 Oct 2016 12:04:12 +0000 (13:04 +0100)]
Don't recurse in advertise() on writev(2) error, just write(2).
Some errors, e.g. EPIPE, cause the advise()'s call to another
advertise() to fail again, ad segvinitum when stack busts. Instead,
snprintf(3) and write(2) that single string, ignoring any error.
Ralph Corderoy [Wed, 19 Oct 2016 09:09:47 +0000 (10:09 +0100)]
Replace strchr() condition with TrimSuffixC(), fixing assumptions.
A couple of the existing strchr()-based trims assumed fgets() returned a
string containing `\n' if it didn't return NULL.
Ralph Corderoy [Tue, 18 Oct 2016 16:05:24 +0000 (17:05 +0100)]
Add TrimSuffixC(char *s, int c).
TrimSuffixC deletes c from the end of non-NULL string s if it's present,
shortening s by 1. Only one instance of c is removed.
Ralph Corderoy [Tue, 18 Oct 2016 15:23:44 +0000 (16:23 +0100)]
Use concat() in m_putenv. Add FIXME about memory leaks.
POSIX defines setenv(3) and unsetenv(3). They seem like a good route,
just need to preserve the existing functions' behaviour.
Ralph Corderoy [Tue, 18 Oct 2016 00:18:24 +0000 (01:18 +0100)]
Replace a few calculations of string lengths with concat().
Saves the reader have to keep checking all the +1 are correct.
Passed the oauth tests; they weren't skipped.
Ralph Corderoy [Mon, 17 Oct 2016 22:52:00 +0000 (23:52 +0100)]
Close FILE pointer in anno for -append as well as -delete.
https://savannah.nongnu.org/bugs/?23465 has Peter Maydell pointing out
the assymetric open and close of a FILE pointer. He's right on that
AFAICS so change the test to be for a non-NULL pointer rather than the
more wordy and prone to error flag-testing.
Ralph Corderoy [Mon, 17 Oct 2016 19:35:51 +0000 (20:35 +0100)]
A-ha! automake has support for tests expected to fail; use that.
Backing out my recent addition of an `expectedfail` parameter to the
`check' function.
Ralph Corderoy [Mon, 17 Oct 2016 10:30:24 +0000 (11:30 +0100)]
Oops, fc31cece had a syntax error that gcc ignored, clang doesn't.
Two logical-or operators in a row don't upset gcc. Who said parsing was
a solved problem?
Ralph Corderoy [Mon, 17 Oct 2016 00:36:35 +0000 (01:36 +0100)]
Don't call strlen() twice; save result.
The second instance was attempting to write strlen(mmdlm2) bytes
and checking the return value against strlen(mmdlm1). I assumed
that was an error without digging.
Ralph Corderoy [Sun, 16 Oct 2016 22:16:26 +0000 (23:16 +0100)]
Rename local enum to avoid clashing with NEW() macro.
Even if it doesn't in practice due to the lack of parenthesis, it makes
things more clean if all the enumerates have a common abbreviation
prefix.
Ralph Corderoy [Sun, 16 Oct 2016 18:38:36 +0000 (19:38 +0100)]
Add NEW(p) that sets p to mh_xmalloc'd memory sized by *p.
Use it for the simple cases. Again, saves having to check the same
identifier is given, possibly far apart after a superfluous cast.
Ralph Corderoy [Sun, 16 Oct 2016 17:49:32 +0000 (18:49 +0100)]
Add macro NEW0(p) that callocs, and use it in simple calls.
p is a pointer, the size of the contents of the pointer is allocated
with calloc via mh_xcalloc. It saves having to check every calloc to
ensure the space requested matches the pointer to which it is assigned.
Ralph Corderoy [Sun, 16 Oct 2016 17:24:51 +0000 (18:24 +0100)]
Put parameter names in h/utils.h memory function prototypes.
It can be a problem if there is a system creeps in a clashing macro,
e.g. `size', but that's unlikely and I think the documentation benefits.