diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-10-19 00:45:47 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-10-19 00:45:47 -0400 |
commit | f6296870535ef3a37bbf5b5b92b393f9c6b7c0a2 (patch) | |
tree | 8b8d15888e150ead9dce30d637a55212277b5c64 /src/common/util.c | |
parent | 465d4e1cd10a995cff571b42b4f008811590c314 (diff) | |
parent | d40a814f4f6cceeb4af33f92372e6f5f00e7203d (diff) | |
download | tor-f6296870535ef3a37bbf5b5b92b393f9c6b7c0a2.tar.gz tor-f6296870535ef3a37bbf5b5b92b393f9c6b7c0a2.zip |
Merge branch 'microdesc'
Diffstat (limited to 'src/common/util.c')
-rw-r--r-- | src/common/util.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/common/util.c b/src/common/util.c index 8f10d2175c..989efd9581 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -684,6 +684,13 @@ tor_digest_is_zero(const char *digest) return tor_mem_is_zero(digest, DIGEST_LEN); } +/** Return true iff the DIGEST256_LEN bytes in digest are all zero. */ +int +tor_digest256_is_zero(const char *digest) +{ + return tor_mem_is_zero(digest, DIGEST256_LEN); +} + /* Helper: common code to check whether the result of a strtol or strtoul or * strtoll is correct. */ #define CHECK_STRTOX_RESULT() \ @@ -1729,7 +1736,8 @@ write_str_to_file(const char *fname, const char *str, int bin) struct open_file_t { char *tempname; /**< Name of the temporary file. */ char *filename; /**< Name of the original file. */ - int rename_on_close; /**< Are we using the temporary file or not? */ + unsigned rename_on_close:1; /**< Are we using the temporary file or not? */ + unsigned binary:1; /**< Did we open in binary mode? */ int fd; /**< fd for the open file. */ FILE *stdio_file; /**< stdio wrapper for <b>fd</b>. */ }; @@ -1785,6 +1793,8 @@ start_writing_to_file(const char *fname, int open_flags, int mode, open_flags &= ~O_EXCL; new_file->rename_on_close = 1; } + if (open_flags & O_BINARY) + new_file->binary = 1; if ((new_file->fd = open(open_name, open_flags, mode)) < 0) { log(LOG_WARN, LD_FS, "Couldn't open \"%s\" (%s) for writing: %s", @@ -1823,7 +1833,8 @@ fdopen_file(open_file_t *file_data) if (file_data->stdio_file) return file_data->stdio_file; tor_assert(file_data->fd >= 0); - if (!(file_data->stdio_file = fdopen(file_data->fd, "a"))) { + if (!(file_data->stdio_file = fdopen(file_data->fd, + file_data->binary?"ab":"a"))) { log_warn(LD_FS, "Couldn't fdopen \"%s\" [%d]: %s", file_data->filename, file_data->fd, strerror(errno)); } |