aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-05-22 02:20:52 +0000
committerNick Mathewson <nickm@torproject.org>2007-05-22 02:20:52 +0000
commit4ec5e139c8442b321ef9b58684da547ea0388261 (patch)
tree70601b682cc85875f18891293e182770cab2fc95 /src/common
parentd23cb33a1a7c2fb8e16040826ec2bbda607468c5 (diff)
downloadtor-4ec5e139c8442b321ef9b58684da547ea0388261.tar
tor-4ec5e139c8442b321ef9b58684da547ea0388261.tar.gz
r12850@catbus: nickm | 2007-05-21 22:20:42 -0400
Partial backport candidate: do not rely on finding a \0 after an mmaped() router/extrainfo file. Also, set journal length correctly when starting up. svn:r10248
Diffstat (limited to 'src/common')
-rw-r--r--src/common/compat.h7
-rw-r--r--src/common/util.c29
-rw-r--r--src/common/util.h1
3 files changed, 37 insertions, 0 deletions
diff --git a/src/common/compat.h b/src/common/compat.h
index e5862f982..085af036d 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -161,6 +161,13 @@ int tor_vsnprintf(char *str, size_t size, const char *format, va_list args)
const void *tor_memmem(const void *haystack, size_t hlen, const void *needle,
size_t nlen) ATTR_PURE ATTR_NONNULL((1,3));
+static const void *tor_memstr(const void *haystack, size_t hlen,
+ const char *needle) ATTR_PURE ATTR_NONNULL((1,3));
+static INLINE const void *
+tor_memstr(const void *haystack, size_t hlen, const char *needle)
+{
+ return tor_memmem(haystack, hlen, needle, strlen(needle));
+}
#define TOR_ISALPHA(c) isalpha((int)(unsigned char)(c))
#define TOR_ISALNUM(c) isalnum((int)(unsigned char)(c))
diff --git a/src/common/util.c b/src/common/util.c
index 0c420f460..18d9fcba2 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -418,6 +418,35 @@ eat_whitespace(const char *s)
}
}
+/** 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.
+ */
+const char *
+eat_whitespace_eos(const char *s, const char *eos)
+{
+ tor_assert(s);
+ tor_assert(eos && s <= eos);
+
+ while (s < eos) {
+ switch (*s) {
+ case '\0':
+ default:
+ return s;
+ case ' ':
+ case '\t':
+ case '\n':
+ case '\r':
+ ++s;
+ break;
+ case '#':
+ ++s;
+ while (s < eos && *s && *s != '\n')
+ ++s;
+ }
+ }
+ return s;
+}
+
/** Return a pointer to the first char of s that is not a space or a tab,
* or to the terminating NUL if no such character exists. */
const char *
diff --git a/src/common/util.h b/src/common/util.h
index 7a0335935..6b32708c5 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -167,6 +167,7 @@ uint64_t tor_parse_uint64(const char *s, int base, uint64_t min,
uint64_t max, int *ok, char **next);
const char *hex_str(const char *from, size_t fromlen) ATTR_NONNULL((1));
const char *eat_whitespace(const char *s) ATTR_PURE;
+const char *eat_whitespace_eos(const char *s, const char *eos) ATTR_PURE;
const char *eat_whitespace_no_nl(const char *s) ATTR_PURE;
const char *find_whitespace(const char *s) ATTR_PURE;
int tor_mem_is_zero(const char *mem, size_t len) ATTR_PURE;