aboutsummaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2003-12-08 23:45:37 +0000
committerNick Mathewson <nickm@torproject.org>2003-12-08 23:45:37 +0000
commitac552573dddbd661685382cdd89841a206dc0b00 (patch)
tree80ed7a762c4e939f8481820c1719be9351b7afa2 /src/common/util.c
parent8bd7c94bf6ca5ef0ece02b165ed0102eb39e0d78 (diff)
downloadtor-ac552573dddbd661685382cdd89841a206dc0b00.tar
tor-ac552573dddbd661685382cdd89841a206dc0b00.tar.gz
Make router/directory parsing nondestructive and more const-friendly
svn:r890
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/common/util.c b/src/common/util.c
index b28eb6d5e..c8ec2de23 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -54,12 +54,21 @@ char *tor_strdup(const char *s) {
return dup;
}
+char *tor_strndup(const char *s, size_t n) {
+ char *dup;
+ assert(s);
+ dup = tor_malloc(n+1);
+ strncpy(dup, s, n);
+ dup[n] = 0;
+ return dup;
+}
+
/*
* String manipulation
*/
/* return the first char of s that is not whitespace and not a comment */
-char *eat_whitespace(char *s) {
+const char *eat_whitespace(const char *s) {
assert(s);
while(isspace(*s) || *s == '#') {
@@ -75,14 +84,14 @@ char *eat_whitespace(char *s) {
return s;
}
-char *eat_whitespace_no_nl(char *s) {
+const char *eat_whitespace_no_nl(const char *s) {
while(*s == ' ' || *s == '\t')
++s;
return s;
}
/* return the first char of s that is whitespace or '#' or '\0 */
-char *find_whitespace(char *s) {
+const char *find_whitespace(const char *s) {
assert(s);
while(*s && !isspace(*s) && *s != '#')