diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-11-03 16:35:48 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-11-03 16:35:48 +0000 |
commit | 3f84ed3d46f52e3a147dfd205d3e76aa27254cf8 (patch) | |
tree | d6ff02d31c0fe236006f3357d60d018d0368fdec /src/common/util.c | |
parent | 7b45d530b09d52ebc5cf7b45c57d4f388e3f94ff (diff) | |
download | tor-3f84ed3d46f52e3a147dfd205d3e76aa27254cf8.tar.gz tor-3f84ed3d46f52e3a147dfd205d3e76aa27254cf8.zip |
Add a new memcmpstart to use instead of strcmpstart when the thing we are comparing is not nul-terminated.
svn:r17187
Diffstat (limited to 'src/common/util.c')
-rw-r--r-- | src/common/util.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c index cc94ccd00a..dc15c6b03a 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -484,6 +484,22 @@ strcasecmpend(const char *s1, const char *s2) return strncasecmp(s1+(n1-n2), s2, n2); } +/** Compare the value of the string <b>prefix</b> with the start of the + * <b>memlen</b>-byte memory chunk at <b>mem</b>. Return as for strcmp. + * + * [As memcmp(mem, prefix, strlen(prefix)) but returns -1 if memlen is less + * than strlen(prefix).] + */ +int +memcmpstart(const void *mem, size_t memlen, + const char *prefix) +{ + size_t plen = strlen(prefix); + if (memlen < plen) + return -1; + return memcmp(mem, prefix, plen); +} + /** Return a pointer to the first char of s that is not whitespace and * not a comment, or to the terminating NUL if no such character exists. */ |