From: Nick Mathewson Date: Wed, 3 Nov 2004 19:02:48 +0000 (+0000) Subject: Add a write_bytes_to_file so we can have files with NULs in them. X-Git-Tag: debian-version-0.0.8+0.0.9pre5-1~119 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d5244e3872ff3a6aa91eebdcb268ae7deccbf193;p=thirdparty%2Ftor.git Add a write_bytes_to_file so we can have files with NULs in them. svn:r2662 --- diff --git a/src/common/util.c b/src/common/util.c index ffe217c696..d118c4ae27 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -756,6 +756,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; @@ -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 6e674e4180..dba95e456d 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);