diff options
author | Yves Orton <demerphq@gmail.com> | 2016-10-19 10:32:29 +0200 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2016-10-19 13:27:59 +0200 |
commit | 777fa2cb699b74cad6714d203572533dbd583976 (patch) | |
tree | b2fa85f3a66ae80b5310e3ac6dcefacf39d27b81 /handy.h | |
parent | 62946e08d24766c73755a22909c985cbf0a1b970 (diff) | |
download | perl-777fa2cb699b74cad6714d203572533dbd583976.tar.gz |
handy.h: add _memEQs() and _memNEs() for use with constant strings
memEQs() is already defined, and requires a length parameter for
the first pointer argument. However some times we do not have
this length handy and simply want to use the length of the constant
string instead.
In an ideal world, to be compatible with more s suffix macros,
IMO the existing memEQs() should have been called something like
memEQsl() maybe, and the ones I am adding would get the memEQs(
name, but it didnt work out like that.
Diffstat (limited to 'handy.h')
-rw-r--r-- | handy.h | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -505,9 +505,15 @@ Returns zero if non-equal, or non-zero if equal. /* memEQ and memNE where second comparand is a string constant */ #define memEQs(s1, l, s2) \ - (sizeof(s2)-1 == l && memEQ(s1, ("" s2 ""), (sizeof(s2)-1))) + (((sizeof(s2)-1) == (l)) && memEQ((s1), ("" s2 ""), (sizeof(s2)-1))) #define memNEs(s1, l, s2) !memEQs(s1, l, s2) +/* memEQ and memNE where second comparand is a string constant + * and we can assume the length of s1 is at least that of the string */ +#define _memEQs(s1, s2) \ + (memEQ((s1), ("" s2 ""), (sizeof(s2)-1))) +#define _memNEs(s1, s2) (memNE((s1),("" s2 ""),(sizeof(s2)-1))) + #define memLT(s1,s2,l) (memcmp(s1,s2,l) < 0) #define memLE(s1,s2,l) (memcmp(s1,s2,l) <= 0) #define memGT(s1,s2,l) (memcmp(s1,s2,l) > 0) |