aboutsummaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-06-30 11:18:00 -0400
committerNick Mathewson <nickm@torproject.org>2016-06-30 11:18:00 -0400
commitc6846d7bf0d8a382bea17304ea29a51c3a895f90 (patch)
tree9a19d14b30659e2e7b1cf47be683bc9da2abc677 /src/common/util.c
parenta31f55b16ba26c5c3720640bf27157fd7ab45c40 (diff)
parent13a16e001164581b687dae2d3377f77eedb701ff (diff)
downloadtor-c6846d7bf0d8a382bea17304ea29a51c3a895f90.tar.gz
tor-c6846d7bf0d8a382bea17304ea29a51c3a895f90.zip
Merge remote-tracking branch 'andrea/bug18322_v3_squashed'
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/common/util.c b/src/common/util.c
index fce99ee3f4..8a4fa1d710 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -2103,6 +2103,16 @@ clean_name_for_stat(char *name)
#endif
}
+/** Wrapper for unlink() to make it mockable for the test suite; returns 0
+ * if unlinking the file succeeded, -1 and sets errno if unlinking fails.
+ */
+
+MOCK_IMPL(int,
+tor_unlink,(const char *pathname))
+{
+ return unlink(pathname);
+}
+
/** Return:
* FN_ERROR if filename can't be read, is NULL, or is zero-length,
* FN_NOENT if it doesn't exist,
@@ -2166,9 +2176,9 @@ file_status(const char *fname)
* When effective_user is not NULL, check permissions against the given user
* and its primary group.
*/
-int
-check_private_dir(const char *dirname, cpd_check_t check,
- const char *effective_user)
+MOCK_IMPL(int,
+check_private_dir,(const char *dirname, cpd_check_t check,
+ const char *effective_user))
{
int r;
struct stat st;
@@ -2396,8 +2406,8 @@ check_private_dir(const char *dirname, cpd_check_t check,
* function, and all other functions in util.c that create files, create them
* with mode 0600.
*/
-int
-write_str_to_file(const char *fname, const char *str, int bin)
+MOCK_IMPL(int,
+write_str_to_file,(const char *fname, const char *str, int bin))
{
#ifdef _WIN32
if (!bin && strchr(str, '\r')) {
@@ -2756,8 +2766,8 @@ read_file_to_str_until_eof(int fd, size_t max_bytes_to_read, size_t *sz_out)
* the call to stat and the call to read_all: the resulting string will
* be truncated.
*/
-char *
-read_file_to_str(const char *filename, int flags, struct stat *stat_out)
+MOCK_IMPL(char *,
+read_file_to_str, (const char *filename, int flags, struct stat *stat_out))
{
int fd; /* router file */
struct stat statbuf;
@@ -3492,8 +3502,8 @@ smartlist_add_vasprintf(struct smartlist_t *sl, const char *pattern,
/** Return a new list containing the filenames in the directory <b>dirname</b>.
* Return NULL on error or if <b>dirname</b> is not a directory.
*/
-smartlist_t *
-tor_listdir(const char *dirname)
+MOCK_IMPL(smartlist_t *,
+tor_listdir, (const char *dirname))
{
smartlist_t *result;
#ifdef _WIN32