diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-11-03 19:02:48 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-11-03 19:02:48 +0000 |
commit | d5244e3872ff3a6aa91eebdcb268ae7deccbf193 (patch) | |
tree | c3d06aec5ff38c9206e25b82ef2151be0ae0e525 /src | |
parent | 451f8b50452ae44c4319cfe55c666a45b9994e9f (diff) | |
download | tor-d5244e3872ff3a6aa91eebdcb268ae7deccbf193.tar tor-d5244e3872ff3a6aa91eebdcb268ae7deccbf193.tar.gz |
Add a write_bytes_to_file so we can have files with NULs in them.
svn:r2662
Diffstat (limited to 'src')
-rw-r--r-- | src/common/util.c | 8 | ||||
-rw-r--r-- | src/common/util.h | 2 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/common/util.c b/src/common/util.c index ffe217c69..d118c4ae2 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -757,6 +757,13 @@ int check_private_dir(const char *dirname, int create) int write_str_to_file(const char *fname, const char *str, int bin) { + return write_bytes_to_file(fname, str, strlen(str), bin); +} + +/* DOCDOC */ +int write_bytes_to_file(const char *fname, const char *str, size_t len, + int bin) +{ char tempname[1024]; int fd; size_t len; @@ -772,7 +779,6 @@ write_str_to_file(const char *fname, const char *str, int bin) strerror(errno)); return -1; } - len = strlen(str); result = write_all(fd, str, len, 0); if(result < 0 || (size_t)result != len) { log(LOG_WARN, "Error writing to %s: %s", tempname, strerror(errno)); diff --git a/src/common/util.h b/src/common/util.h index 6e674e418..dba95e456 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -88,6 +88,8 @@ file_status_t file_status(const char *filename); int check_private_dir(const char *dirname, int create); int write_str_to_file(const char *fname, const char *str, int bin); +int write_bytes_to_file(const char *fname, const char *str, size_t len, + int bin); char *read_file_to_str(const char *filename, int bin); int parse_line_from_file(char *line, size_t maxlen, FILE *f, char **key_out, char **value_out); char *expand_filename(const char *filename); |