aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/compat.c6
-rw-r--r--src/common/container.c26
-rw-r--r--src/common/container.h2
-rw-r--r--src/common/crypto.c18
-rw-r--r--src/common/log.c16
-rw-r--r--src/common/log.h2
-rw-r--r--src/common/test.h14
-rw-r--r--src/common/torgzip.c2
-rw-r--r--src/common/tortls.c2
-rw-r--r--src/common/util.c42
-rw-r--r--src/common/util.h4
11 files changed, 67 insertions, 67 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index 49c8c3a7a..d46077485 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -158,7 +158,7 @@ int replace_file(const char *from, const char *to)
#ifndef MS_WINDOWS
return rename(from,to);
#else
- switch(file_status(to))
+ switch (file_status(to))
{
case FN_NOENT:
break;
@@ -318,11 +318,11 @@ int set_max_file_descriptors(unsigned int required_min) {
strerror(errno));
return -1;
}
- if(required_min > rlim.rlim_max) {
+ if (required_min > rlim.rlim_max) {
log_fn(LOG_WARN,"We need %u file descriptors available, and we're limited to %lu. Please change your ulimit.", required_min, (unsigned long int)rlim.rlim_max);
return -1;
}
- if(required_min > rlim.rlim_cur) {
+ if (required_min > rlim.rlim_cur) {
log_fn(LOG_INFO,"Raising max file descriptors from %lu to %lu.",
(unsigned long int)rlim.rlim_cur, (unsigned long int)rlim.rlim_max);
}
diff --git a/src/common/container.c b/src/common/container.c
index e26ec81c3..5ced2b6ff 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -104,10 +104,10 @@ void smartlist_add_all(smartlist_t *sl, const smartlist_t *s2)
*/
void smartlist_remove(smartlist_t *sl, void *element) {
int i;
- if(element == NULL)
+ if (element == NULL)
return;
- for(i=0; i < sl->num_used; i++)
- if(sl->list[i] == element) {
+ for (i=0; i < sl->num_used; i++)
+ if (sl->list[i] == element) {
sl->list[i] = sl->list[--sl->num_used]; /* swap with the end */
i--; /* so we process the new i'th element */
}
@@ -117,16 +117,16 @@ void smartlist_remove(smartlist_t *sl, void *element) {
*/
int smartlist_isin(const smartlist_t *sl, void *element) {
int i;
- for(i=0; i < sl->num_used; i++)
- if(sl->list[i] == element)
+ for (i=0; i < sl->num_used; i++)
+ if (sl->list[i] == element)
return 1;
return 0;
}
int smartlist_string_isin(const smartlist_t *sl, const char *element) {
int i;
- for(i=0; i < sl->num_used; i++)
- if(strcmp((const char*)sl->list[i],element)==0)
+ for (i=0; i < sl->num_used; i++)
+ if (strcmp((const char*)sl->list[i],element)==0)
return 1;
return 0;
}
@@ -135,8 +135,8 @@ int smartlist_string_isin(const smartlist_t *sl, const char *element) {
*/
int smartlist_overlap(const smartlist_t *sl1, const smartlist_t *sl2) {
int i;
- for(i=0; i < sl2->num_used; i++)
- if(smartlist_isin(sl1, sl2->list[i]))
+ for (i=0; i < sl2->num_used; i++)
+ if (smartlist_isin(sl1, sl2->list[i]))
return 1;
return 0;
}
@@ -146,8 +146,8 @@ int smartlist_overlap(const smartlist_t *sl1, const smartlist_t *sl2) {
*/
void smartlist_intersect(smartlist_t *sl1, const smartlist_t *sl2) {
int i;
- for(i=0; i < sl1->num_used; i++)
- if(!smartlist_isin(sl2, sl1->list[i])) {
+ for (i=0; i < sl1->num_used; i++)
+ if (!smartlist_isin(sl2, sl1->list[i])) {
sl1->list[i] = sl1->list[--sl1->num_used]; /* swap with the end */
i--; /* so we process the new i'th element */
}
@@ -158,7 +158,7 @@ void smartlist_intersect(smartlist_t *sl1, const smartlist_t *sl2) {
*/
void smartlist_subtract(smartlist_t *sl1, const smartlist_t *sl2) {
int i;
- for(i=0; i < sl2->num_used; i++)
+ for (i=0; i < sl2->num_used; i++)
smartlist_remove(sl1, sl2->list[i]);
}
@@ -544,7 +544,7 @@ void strmap_foreach(strmap_t *map,
* iter = strmap_iter_next_rmv(iter);
* free(val);
* } else {
- * for(;*cp;cp++) *cp = toupper(*cp);
+ * for (;*cp;cp++) *cp = toupper(*cp);
* iter = strmap_iter_next(iter);
* }
* }
diff --git a/src/common/container.h b/src/common/container.h
index 701af3295..dbe45a31e 100644
--- a/src/common/container.h
+++ b/src/common/container.h
@@ -60,7 +60,7 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join,
do { \
int var ## _sl_idx, var ## _sl_len=smartlist_len(sl); \
type var; \
- for(var ## _sl_idx = 0; var ## _sl_idx < var ## _sl_len; \
+ for (var ## _sl_idx = 0; var ## _sl_idx < var ## _sl_len; \
++var ## _sl_idx) { \
var = smartlist_get((sl),var ## _sl_idx); \
cmd; \
diff --git a/src/common/crypto.c b/src/common/crypto.c
index d7371fb76..650aad487 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -103,7 +103,7 @@ DH *_crypto_dh_env_get_dh(crypto_dh_env_t *dh);
*/
static INLINE int
crypto_get_rsa_padding_overhead(int padding) {
- switch(padding)
+ switch (padding)
{
case RSA_NO_PADDING: return 0;
case RSA_PKCS1_OAEP_PADDING: return 42;
@@ -116,7 +116,7 @@ crypto_get_rsa_padding_overhead(int padding) {
*/
static INLINE int
crypto_get_rsa_padding(int padding) {
- switch(padding)
+ switch (padding)
{
case PK_NO_PADDING: return RSA_NO_PADDING;
case PK_PKCS1_PADDING: return RSA_PKCS1_PADDING;
@@ -238,7 +238,7 @@ void crypto_free_pk_env(crypto_pk_env_t *env)
{
tor_assert(env);
- if(--env->refs > 0)
+ if (--env->refs > 0)
return;
if (env->key)
@@ -398,7 +398,7 @@ int crypto_pk_write_public_key_to_string(crypto_pk_env_t *env, char **dest, size
/* Now you can treat b as if it were a file. Just use the
* PEM_*_bio_* functions instead of the non-bio variants.
*/
- if(!PEM_write_bio_RSAPublicKey(b, env->key)) {
+ if (!PEM_write_bio_RSAPublicKey(b, env->key)) {
crypto_log_errors(LOG_WARN, "writing public key to string");
return -1;
}
@@ -435,7 +435,7 @@ int crypto_pk_read_public_key_from_string(crypto_pk_env_t *env, const char *src,
RSA_free(env->key);
env->key = PEM_read_bio_RSAPublicKey(b, NULL, NULL, NULL);
BIO_free(b);
- if(!env->key) {
+ if (!env->key) {
crypto_log_errors(LOG_WARN, "reading public key from string");
return -1;
}
@@ -1346,7 +1346,7 @@ int crypto_dh_compute_secret(crypto_dh_env_t *dh,
goto error;
secret_tmp = tor_malloc(crypto_dh_get_bytes(dh)+1);
result = DH_compute_key(secret_tmp, pubkey_bn, dh->dh);
- if(result < 0) {
+ if (result < 0) {
log_fn(LOG_WARN,"DH_compute_key() failed.");
goto error;
}
@@ -1368,7 +1368,7 @@ int crypto_dh_compute_secret(crypto_dh_env_t *dh,
if (pubkey_bn)
BN_free(pubkey_bn);
tor_free(secret_tmp);
- if(result < 0)
+ if (result < 0)
return result;
else
return secret_len;
@@ -1486,7 +1486,7 @@ int crypto_pseudo_rand_int(unsigned int max) {
* range.
*/
cutoff = UINT_MAX - (UINT_MAX%max);
- while(1) {
+ while (1) {
crypto_pseudo_rand((unsigned char*) &val, sizeof(val));
if (val < cutoff)
return val % max;
@@ -1498,7 +1498,7 @@ int crypto_pseudo_rand_int(unsigned int max) {
void *smartlist_choose(const smartlist_t *sl) {
size_t len;
len = smartlist_len(sl);
- if(len)
+ if (len)
return smartlist_get(sl,crypto_pseudo_rand_int(len));
return NULL; /* no elements to choose from */
}
diff --git a/src/common/log.c b/src/common/log.c
index c2639560f..f275d025f 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -34,7 +34,7 @@ typedef struct logfile_t {
/** Helper: map a log severity to descriptive string. */
static INLINE const char *sev_to_string(int severity) {
- switch(severity) {
+ switch (severity) {
case LOG_DEBUG: return "debug";
case LOG_INFO: return "info";
case LOG_NOTICE: return "notice";
@@ -136,7 +136,7 @@ static INLINE char *format_msg(char *buf, size_t buf_len,
}
r = tor_vsnprintf(buf+n,buf_len-n,format,ap);
- if(r < 0) {
+ if (r < 0) {
n = buf_len-2;
strlcpy(buf+buf_len-TRUNCATED_STR_LEN-1, TRUNCATED_STR,
buf_len-(buf_len-TRUNCATED_STR_LEN-1));
@@ -162,7 +162,7 @@ logv(int severity, const char *funcname, const char *format, va_list ap)
assert(format);
lf = logfiles;
- while(lf) {
+ while (lf) {
if (severity > lf->loglevel || severity < lf->max_loglevel) {
lf = lf->next;
continue;
@@ -188,7 +188,7 @@ logv(int severity, const char *funcname, const char *format, va_list ap)
lf = lf->next;
continue;
}
- if(fputs(buf, lf->file) == EOF ||
+ if (fputs(buf, lf->file) == EOF ||
fflush(lf->file) == EOF) { /* error */
/* don't log the error! Blow away this log entry and continue. */
logfile_t *victim = lf;
@@ -234,7 +234,7 @@ void _log_fn(int severity, const char *format, ...)
void close_logs()
{
logfile_t *victim;
- while(logfiles) {
+ while (logfiles) {
victim = logfiles;
logfiles = logfiles->next;
close_log(victim);
@@ -247,7 +247,7 @@ void close_logs()
void reset_logs()
{
logfile_t *lf = logfiles;
- while(lf) {
+ while (lf) {
if (reset_log(lf)) {
/* error. don't log it. delete the log entry and continue. */
logfile_t *victim = lf;
@@ -266,10 +266,10 @@ void reset_logs()
*/
static void delete_log(logfile_t *victim) {
logfile_t *tmpl;
- if(victim == logfiles)
+ if (victim == logfiles)
logfiles = victim->next;
else {
- for(tmpl = logfiles; tmpl && tmpl->next != victim; tmpl=tmpl->next) ;
+ for (tmpl = logfiles; tmpl && tmpl->next != victim; tmpl=tmpl->next) ;
tor_assert(tmpl);
tor_assert(tmpl->next == victim);
tmpl->next = victim->next;
diff --git a/src/common/log.h b/src/common/log.h
index 968686ef3..07e865e68 100644
--- a/src/common/log.h
+++ b/src/common/log.h
@@ -90,7 +90,7 @@ void _log_fn(int severity, const char *funcname, const char *format, ...)
extern const char *_log_fn_function_name;
void _log_fn(int severity, const char *format, ...);
/* We abuse the comma operator here, since we can't use the standard
- * do {...} while(0) trick to wrap this macro, since the macro can't take
+ * do {...} while (0) trick to wrap this macro, since the macro can't take
* arguments. */
#define log_fn (_log_fn_function_name=__FUNCTION__),_log_fn
#endif
diff --git a/src/common/test.h b/src/common/test.h
index 684968eaa..84ea1f912 100644
--- a/src/common/test.h
+++ b/src/common/test.h
@@ -36,7 +36,7 @@ extern int have_failed;
#define test_assert(expr) \
STMT_BEGIN \
- if(expr) { printf("."); fflush(stdout); } else { \
+ if (expr) { printf("."); fflush(stdout); } else { \
have_failed = 1; \
printf("\nFile %s: line %d (%s): assertion failed: (%s)\n", \
__FILE__, \
@@ -49,7 +49,7 @@ extern int have_failed;
#define test_eq(expr1, expr2) \
STMT_BEGIN \
long v1=(long)(expr1), v2=(long)(expr2); \
- if(v1==v2) { printf("."); fflush(stdout); } else { \
+ if (v1==v2) { printf("."); fflush(stdout); } else { \
have_failed = 1; \
printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\
" (%ld != %ld)\n", \
@@ -64,7 +64,7 @@ extern int have_failed;
#define test_neq(expr1, expr2) \
STMT_BEGIN \
long v1=(long)(expr1), v2=(long)(expr2); \
- if(v1!=v2) { printf("."); fflush(stdout); } else { \
+ if (v1!=v2) { printf("."); fflush(stdout); } else { \
have_failed = 1; \
printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n"\
" (%ld == %ld)\n", \
@@ -79,7 +79,7 @@ extern int have_failed;
#define test_streq(expr1, expr2) \
STMT_BEGIN \
const char *v1=(expr1), *v2=(expr2); \
- if(!strcmp(v1,v2)) { printf("."); fflush(stdout); } else { \
+ if (!strcmp(v1,v2)) { printf("."); fflush(stdout); } else { \
have_failed = 1; \
printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\
" (\"%s\" != \"%s\")\n", \
@@ -94,7 +94,7 @@ extern int have_failed;
#define test_strneq(expr1, expr2) \
STMT_BEGIN \
const char *v1=(expr1), *v2=(expr2); \
- if(strcmp(v1,v2)) { printf("."); fflush(stdout); } else { \
+ if (strcmp(v1,v2)) { printf("."); fflush(stdout); } else { \
have_failed = 1; \
printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n"\
" (\"%s\" == \"%s\")\n", \
@@ -109,7 +109,7 @@ extern int have_failed;
#define test_memeq(expr1, expr2, len) \
STMT_BEGIN \
const void *v1=(expr1), *v2=(expr2); \
- if(!memcmp(v1,v2,(len))) { printf("."); fflush(stdout); } else { \
+ if (!memcmp(v1,v2,(len))) { printf("."); fflush(stdout); } else {\
have_failed = 1; \
printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n", \
__FILE__, \
@@ -122,7 +122,7 @@ extern int have_failed;
#define test_memneq(expr1, expr2, len) \
STMT_BEGIN \
void *v1=(expr1), *v2=(expr2); \
- if(memcmp(v1,v2,(len))) { printf("."); fflush(stdout); } else { \
+ if (memcmp(v1,v2,(len))) { printf("."); fflush(stdout); } else {\
have_failed = 1; \
printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n", \
__FILE__, \
diff --git a/src/common/torgzip.c b/src/common/torgzip.c
index bffd81984..0e781cca6 100644
--- a/src/common/torgzip.c
+++ b/src/common/torgzip.c
@@ -176,7 +176,7 @@ tor_gzip_uncompress(char **out, size_t *out_len,
stream->avail_out = out_size;
while (1) {
- switch(inflate(stream, Z_FINISH))
+ switch (inflate(stream, Z_FINISH))
{
case Z_STREAM_END:
goto done;
diff --git a/src/common/tortls.c b/src/common/tortls.c
index 34c271219..4068805fd 100644
--- a/src/common/tortls.c
+++ b/src/common/tortls.c
@@ -466,7 +466,7 @@ tor_tls_write(tor_tls *tls, char *cp, size_t n)
tor_assert(tls->state == TOR_TLS_ST_OPEN);
if (n == 0)
return 0;
- if(tls->wantwrite_n) {
+ if (tls->wantwrite_n) {
/* if WANTWRITE last time, we must use the _same_ n as before */
tor_assert(n >= tls->wantwrite_n);
log_fn(LOG_DEBUG,"resuming pending-write, (%d to flush, reusing %d)",
diff --git a/src/common/util.c b/src/common/util.c
index a6a082a96..31ec0d5f4 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -108,7 +108,7 @@ void *tor_malloc(size_t size) {
}
result = malloc(size);
- if(!result) {
+ if (!result) {
log_fn(LOG_ERR, "Out of memory. Dying.");
exit(1);
}
@@ -150,7 +150,7 @@ char *tor_strdup(const char *s) {
tor_assert(s);
dup = strdup(s);
- if(!dup) {
+ if (!dup) {
log_fn(LOG_ERR,"Out of memory. Dying.");
exit(1);
}
@@ -221,7 +221,7 @@ int tor_strpartition(char *dest, size_t dest_len,
len_ins = strlen(insert);
len_out = len_in + (len_in/n)*len_ins;
is_even = (len_in%n) == 0;
- switch(rule)
+ switch (rule)
{
case ALWAYS_TERMINATE:
if (!is_even) len_out += len_ins;
@@ -236,7 +236,7 @@ int tor_strpartition(char *dest, size_t dest_len,
return -1;
destp = dest;
remaining = len_in;
- while(remaining) {
+ while (remaining) {
strncpy(destp, s, n);
remaining -= n;
if (remaining < 0) {
@@ -306,13 +306,13 @@ int strcmpend(const char *s1, const char *s2)
const char *eat_whitespace(const char *s) {
tor_assert(s);
- while(isspace((int)*s) || *s == '#') {
- while(isspace((int)*s))
+ while (isspace((int)*s) || *s == '#') {
+ while (isspace((int)*s))
s++;
- if(*s == '#') { /* read to a \n or \0 */
- while(*s && *s != '\n')
+ if (*s == '#') { /* read to a \n or \0 */
+ while (*s && *s != '\n')
s++;
- if(!*s)
+ if (!*s)
return s;
}
}
@@ -322,7 +322,7 @@ const char *eat_whitespace(const char *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 *eat_whitespace_no_nl(const char *s) {
- while(*s == ' ' || *s == '\t')
+ while (*s == ' ' || *s == '\t')
++s;
return s;
}
@@ -333,7 +333,7 @@ const char *eat_whitespace_no_nl(const char *s) {
const char *find_whitespace(const char *s) {
tor_assert(s);
- while(*s && !isspace((int)*s) && *s != '#')
+ while (*s && !isspace((int)*s) && *s != '#')
s++;
return s;
@@ -402,8 +402,8 @@ tor_parse_uint64(const char *s, int base, uint64_t min,
tor_assert(base <= 10);
r = (uint64_t)_atoi64(s);
endptr = (char*)s;
- while(isspace(*endptr)) endptr++;
- while(isdigit(*endptr)) endptr++;
+ while (isspace(*endptr)) endptr++;
+ while (isdigit(*endptr)) endptr++;
#else
r = (uint64_t)_strtoui64(s, &endptr, base);
#endif
@@ -461,7 +461,7 @@ int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen)
while (src<end) {
v1 = hex_decode_digit(*src);
v2 = hex_decode_digit(*(src+1));
- if(v1<0||v2<0)
+ if (v1<0||v2<0)
return -1;
*(uint8_t*)dest = (v1<<4)|v2;
++dest;
@@ -659,12 +659,12 @@ int write_all(int fd, const char *buf, size_t count, int isSocket) {
size_t written = 0;
int result;
- while(written != count) {
+ while (written != count) {
if (isSocket)
result = send(fd, buf+written, count-written, 0);
else
result = write(fd, buf+written, count-written);
- if(result<0)
+ if (result<0)
return -1;
written += result;
}
@@ -681,12 +681,12 @@ int read_all(int fd, char *buf, size_t count, int isSocket) {
size_t numread = 0;
int result;
- while(numread != count) {
+ while (numread != count) {
if (isSocket)
result = recv(fd, buf+numread, count-numread, 0);
else
result = read(fd, buf+numread, count-numread);
- if(result<0)
+ if (result<0)
return -1;
else if (result == 0)
break;
@@ -815,7 +815,7 @@ int write_bytes_to_file(const char *fname, const char *str, size_t len,
return -1;
}
result = write_all(fd, str, len, 0);
- if(result < 0 || (size_t)result != len) {
+ if (result < 0 || (size_t)result != len) {
log(LOG_WARN, "Error writing to %s: %s", tempname, strerror(errno));
close(fd);
return -1;
@@ -842,7 +842,7 @@ char *read_file_to_str(const char *filename, int bin) {
tor_assert(filename);
- if(stat(filename, &statbuf) < 0) {
+ if (stat(filename, &statbuf) < 0) {
log_fn(LOG_INFO,"Could not stat %s.",filename);
return NULL;
}
@@ -1260,7 +1260,7 @@ void start_daemon(const char *desired_cwd)
return;
start_daemon_called = 1;
- if(!desired_cwd)
+ if (!desired_cwd)
desired_cwd = "/";
/* Don't hold the wrong FS mounted */
if (chdir(desired_cwd) < 0) {
diff --git a/src/common/util.h b/src/common/util.h
index 4a627e549..e2a7546de 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -24,7 +24,7 @@
* calling assert() normally.
*/
#ifdef NDEBUG
-#define tor_assert(expr) do {} while(0)
+#define tor_assert(expr) do {} while (0)
#else
#define tor_assert(expr) do { \
if (!(expr)) { \
@@ -41,7 +41,7 @@ void *tor_malloc_zero(size_t size);
void *tor_realloc(void *ptr, size_t size);
char *tor_strdup(const char *s);
char *tor_strndup(const char *s, size_t n);
-#define tor_free(p) do {if(p) {free(p); (p)=NULL;}} while(0)
+#define tor_free(p) do { if (p) {free(p); (p)=NULL;} } while (0)
/* String manipulation */
#define HEX_CHARACTERS "0123456789ABCDEFabcdef"