aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/compat.c1
-rw-r--r--src/common/util.c24
-rw-r--r--src/common/util.h2
3 files changed, 22 insertions, 5 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index 7d3572e03f..cefba439fe 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -1730,7 +1730,6 @@ tor_threads_init(void)
}
#endif
-
/**
* On Windows, WSAEWOULDBLOCK is not always correct: when you see it,
* you need to ask the socket for its actual errno. Also, you need to
diff --git a/src/common/util.c b/src/common/util.c
index cfc06d4208..10c3cb8476 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -403,6 +403,21 @@ strcmpstart(const char *s1, const char *s2)
return strncmp(s1, s2, n);
}
+/** Compare the s1_len-byte string <b>s1</b> with <b>s2</b>,
+ * without depending on a terminating nul in s1. Sorting order is first by
+ * length, then lexically; return values are as for strcmp.
+ */
+int
+strcmp_len(const char *s1, const char *s2, size_t s1_len)
+{
+ size_t s2_len = strlen(s2);
+ if (s1_len < s2_len)
+ return -1;
+ if (s1_len > s2_len)
+ return 1;
+ return memcmp(s1, s2, s2_len);
+}
+
/** Compares the first strlen(s2) characters of s1 with s2. Returns as for
* strcasecmp.
*/
@@ -505,7 +520,8 @@ eat_whitespace_no_nl(const char *s)
return s;
}
-/** DOCDOC */
+/** As eat_whitespace_no_nl, but stop at <b>eos</b> whether we have
+ * found a non-whitespace character or not. */
const char *
eat_whitespace_eos_no_nl(const char *s, const char *eos)
{
@@ -537,7 +553,8 @@ find_whitespace(const char *s)
}
}
-/** DOCDOC */
+/** As find_whitespace, but stop at <b>eos</b> whether we have found a
+ * whitespace or not. */
const char *
find_whitespace_eos(const char *s, const char *eos)
{
@@ -556,10 +573,9 @@ find_whitespace_eos(const char *s, const char *eos)
++s;
}
}
- return NULL;
+ return s;
}
-
/** Return true iff the 'len' bytes at 'mem' are all zero. */
int
tor_mem_is_zero(const char *mem, size_t len)
diff --git a/src/common/util.h b/src/common/util.h
index 68d1333cba..de7245c259 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -155,6 +155,8 @@ void tor_strupper(char *s) ATTR_NONNULL((1));
int tor_strisprint(const char *s) ATTR_PURE ATTR_NONNULL((1));
int tor_strisnonupper(const char *s) ATTR_PURE ATTR_NONNULL((1));
int strcmpstart(const char *s1, const char *s2) ATTR_PURE ATTR_NONNULL((1,2));
+int strcmp_len(const char *s1, const char *s2, size_t len)
+ ATTR_PURE ATTR_NONNULL((1,2));
int strcasecmpstart(const char *s1, const char *s2)
ATTR_PURE ATTR_NONNULL((1,2));
int strcmpend(const char *s1, const char *s2) ATTR_PURE ATTR_NONNULL((1,2));