[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [obfsproxy/master] obfsproxify tor_asprintf() and friends
commit dfbe3e36a516191a18fd55540d88dee344181ac4
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date: Wed Feb 22 11:39:55 2012 -0800
obfsproxify tor_asprintf() and friends
s/tor_snprintf/obfs_snprintf/g
s/tor_vasprintf/obfs_vasprintf/g
s/tor_asprintf/obfs_asprintf/g
s/tor_strdup/xstrdup/g
s/tor_free/free/g
s/tor_malloc/xmalloc/
Also, change 'log_err(); tor_assert()' to 'log_error()'.
Also, add prototypes for the functions.
---
src/util.c | 29 ++++++++++++++---------------
src/util.h | 3 +++
2 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/src/util.c b/src/util.c
index 1d78f1f..5c524b5 100644
--- a/src/util.c
+++ b/src/util.c
@@ -351,35 +351,34 @@ ascii_strlower(char *s)
* You can treat this function as if its implementation were something like
<pre>
char buf[_INFINITY_];
- tor_snprintf(buf, sizeof(buf), fmt, args);
- *strp = tor_strdup(buf);
+ obfs_snprintf(buf, sizeof(buf), fmt, args);
+ *strp = xstrdup(buf);
return strlen(*strp):
</pre>
* Where _INFINITY_ is an imaginary constant so big that any string can fit
* into it.
*/
int
-tor_asprintf(char **strp, const char *fmt, ...)
+obfs_asprintf(char **strp, const char *fmt, ...)
{
int r;
va_list args;
va_start(args, fmt);
- r = tor_vasprintf(strp, fmt, args);
+ r = obfs_vasprintf(strp, fmt, args);
va_end(args);
- if (!*strp || r < 0) {
- log_err(LD_BUG, "Internal error in asprintf");
- tor_assert(0);
- }
+ if (!*strp || r < 0)
+ log_error("Internal error in asprintf");
+
return r;
}
/**
* Portable vasprintf implementation. Does a printf() into a newly malloc'd
* string. Differs from regular vasprintf in the same ways that
- * tor_asprintf() differs from regular asprintf.
+ * obfs_asprintf() differs from regular asprintf.
*/
int
-tor_vasprintf(char **strp, const char *fmt, va_list args)
+obfs_vasprintf(char **strp, const char *fmt, va_list args)
{
/* use a temporary variable in case *strp is in args. */
char *strp_tmp=NULL;
@@ -401,10 +400,10 @@ tor_vasprintf(char **strp, const char *fmt, va_list args)
*strp = NULL;
return -1;
}
- strp_tmp = tor_malloc(len + 1);
+ strp_tmp = xmalloc(len + 1);
r = _vsnprintf(strp_tmp, len+1, fmt, args);
if (r != len) {
- tor_free(strp_tmp);
+ free(strp_tmp);
*strp = NULL;
return -1;
}
@@ -422,13 +421,13 @@ tor_vasprintf(char **strp, const char *fmt, va_list args)
len = vsnprintf(buf, sizeof(buf), fmt, tmp_args);
va_end(tmp_args);
if (len < (int)sizeof(buf)) {
- *strp = tor_strdup(buf);
+ *strp = xstrdup(buf);
return len;
}
- strp_tmp = tor_malloc(len+1);
+ strp_tmp = xmalloc(len+1);
r = vsnprintf(strp_tmp, len+1, fmt, args);
if (r != len) {
- tor_free(strp_tmp);
+ free(strp_tmp);
*strp = NULL;
return -1;
}
diff --git a/src/util.h b/src/util.h
index f8dfc7e..d879eba 100644
--- a/src/util.h
+++ b/src/util.h
@@ -138,6 +138,9 @@ int obfs_snprintf(char *str, size_t size,
const char *format, ...)
ATTR_PRINTF_3;
+int obfs_asprintf(char **strp, const char *fmt, ...);
+int obfs_vasprintf(char **strp, const char *fmt, va_list args);
+
/***** Logging. *****/
/** Log destinations */
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits