[or-cvs] Add a write_bytes_to_file so we can have files with NULs in...

Nick Mathewson nickm at seul.org
Wed Nov 3 19:02:52 UTC 2004


Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv14204/src/common

Modified Files:
	util.c util.h 
Log Message:
Add a write_bytes_to_file so we can have files with NULs in them.

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.164
retrieving revision 1.165
diff -u -d -r1.164 -r1.165
--- util.c	2 Nov 2004 19:25:52 -0000	1.164
+++ util.c	3 Nov 2004 19:02:47 -0000	1.165
@@ -757,6 +757,13 @@
 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 @@
         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));

Index: util.h
===================================================================
RCS file: /home/or/cvsroot/src/common/util.h,v
retrieving revision 1.112
retrieving revision 1.113
diff -u -d -r1.112 -r1.113
--- util.h	3 Nov 2004 07:29:03 -0000	1.112
+++ util.h	3 Nov 2004 19:02:48 -0000	1.113
@@ -88,6 +88,8 @@
 
 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);



More information about the tor-commits mailing list