diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-02-05 18:33:52 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-02-05 18:33:52 +0000 |
commit | f02be02356a6cedcec2b01d5046e5d5cba0797ad (patch) | |
tree | 1cb0b87b6d886fd4c5db5e8d14807d31b5a67828 /src/common/util.c | |
parent | 03ef2156c93523cb548ea20b41e554b939964c29 (diff) | |
download | tor-f02be02356a6cedcec2b01d5046e5d5cba0797ad.tar.gz tor-f02be02356a6cedcec2b01d5046e5d5cba0797ad.zip |
r11639@catbus: nickm | 2007-02-05 13:33:38 -0500
Add documentation to src/common/*.h; improve documentation for SMARTLIST_FOREACH; remove never-used options and corresponding tests from tor_strpartition.
svn:r9483
Diffstat (limited to 'src/common/util.c')
-rw-r--r-- | src/common/util.c | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/src/common/util.c b/src/common/util.c index 6ecb901eae..a5b87c4318 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -238,17 +238,12 @@ tor_strstrip(char *s, const char *strip) * string <b>s</b>, with the string <b>insert</b> inserted after every * <b>n</b> characters. Return 0 on success, -1 on failure. * - * If <b>rule</b> is ALWAYS_TERMINATE, then always end the string with - * <b>insert</b>, even if its length is not a multiple of <b>n</b>. If - * <b>rule</b> is NEVER_TERMINATE, then never end the string with - * <b>insert</b>, even if its length <i>is</i> a multiple of <b>n</b>. - * If <b>rule</b> is TERMINATE_IF_EVEN, then end the string with <b>insert</b> - * exactly when its length <i>is</i> a multiple of <b>n</b>. + * Never end the string with <b>insert</b>, even if its length <i>is</i> a + * multiple of <b>n</b>. */ int tor_strpartition(char *dest, size_t dest_len, - const char *s, const char *insert, size_t n, - part_finish_rule_t rule) + const char *s, const char *insert, size_t n) { char *destp; size_t len_in, len_out, len_ins; @@ -264,17 +259,8 @@ tor_strpartition(char *dest, size_t dest_len, tor_assert(len_in/n < SIZE_T_CEILING/len_ins); /* avoid overflow */ len_out = len_in + (len_in/n)*len_ins; is_even = (len_in%n) == 0; - switch (rule) - { - case ALWAYS_TERMINATE: - if (!is_even) len_out += len_ins; - break; - case NEVER_TERMINATE: - if (is_even && len_in) len_out -= len_ins; - break; - case TERMINATE_IF_EVEN: - break; - } + if (is_even && len_in) + len_out -= len_ins; if (dest_len < len_out+1) return -1; destp = dest; @@ -283,10 +269,8 @@ tor_strpartition(char *dest, size_t dest_len, strncpy(destp, s, n); remaining -= n; if (remaining < 0) { - if (rule == ALWAYS_TERMINATE) - strncpy(destp+n+remaining,insert,len_ins+1); break; - } else if (remaining == 0 && rule == NEVER_TERMINATE) { + } else if (remaining == 0) { *(destp+n) = '\0'; break; } |