summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-10-11 12:51:15 -0400
committerNick Mathewson <nickm@torproject.org>2013-10-11 12:51:15 -0400
commit0546edde66b3ca3dfbbd51f95b906d9e8f4f1459 (patch)
tree87e24c4d904e173094d49e84242dfdaf0960ed11 /src/common
parent6f9584b3fd5346bfc7ee58dedee2f1c292bf0354 (diff)
parent7ef9ecf6b38041e38dd079c2d18b5c8813d1959a (diff)
downloadtor-0546edde66b3ca3dfbbd51f95b906d9e8f4f1459.tar.gz
tor-0546edde66b3ca3dfbbd51f95b906d9e8f4f1459.zip
Merge branch 'bug1376'
Diffstat (limited to 'src/common')
-rw-r--r--src/common/util.c14
-rw-r--r--src/common/util.h2
2 files changed, 12 insertions, 4 deletions
diff --git a/src/common/util.c b/src/common/util.c
index a4cdae04ee..f3a6c10621 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -2191,12 +2191,20 @@ write_chunks_to_file_impl(const char *fname, const smartlist_t *chunks,
return -1;
}
-/** Given a smartlist of sized_chunk_t, write them atomically to a file
- * <b>fname</b>, overwriting or creating the file as necessary. */
+/** Given a smartlist of sized_chunk_t, write them to a file
+ * <b>fname</b>, overwriting or creating the file as necessary.
+ * If <b>no_tempfile</b> is 0 then the file will be written
+ * atomically. */
int
-write_chunks_to_file(const char *fname, const smartlist_t *chunks, int bin)
+write_chunks_to_file(const char *fname, const smartlist_t *chunks, int bin,
+ int no_tempfile)
{
int flags = OPEN_FLAGS_REPLACE|(bin?O_BINARY:O_TEXT);
+
+ if (no_tempfile) {
+ /* O_APPEND stops write_chunks_to_file from using tempfiles */
+ flags |= O_APPEND;
+ }
return write_chunks_to_file_impl(fname, chunks, flags);
}
diff --git a/src/common/util.h b/src/common/util.h
index fdd8c135a9..dcf45942f0 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -365,7 +365,7 @@ typedef struct sized_chunk_t {
size_t len;
} sized_chunk_t;
int write_chunks_to_file(const char *fname, const struct smartlist_t *chunks,
- int bin);
+ int bin, int no_tempfile);
int append_bytes_to_file(const char *fname, const char *str, size_t len,
int bin);
int write_bytes_to_new_file(const char *fname, const char *str, size_t len,