diff --git a/changes/bug3607 b/changes/bug3607
new file mode 100644
index 0000000000000000000000000000000000000000..2e86253848b2daa6f8c61ce7eb86e37fb4084ea2
--- /dev/null
+++ b/changes/bug3607
@@ -0,0 +1,15 @@
+  o Minor bugfixes:
+
+    - Write several files (currently, buffer-stats, dirreq-stats, and
+      entry-stats on relays that collect those statistics, client_keys
+      and hostname files for hidden services that use authentication,
+      and (in the tor-gencert utility) newly generated identity and
+      signing keys) in text mode, on OSes that distinguish text mode
+      from binary mode (i.e. on Windows).  Previously, we wouldn't
+      specify text mode or binary mode, leading to an assertion
+      failure.  Fixes bug 3607.  Bugfix on 0.2.1.1-alpha (when the
+      DirRecordUsageByCountry option which would have triggered the
+      assertion failure was added), although this assertion failure
+      would have occurred in tor-gencert on Windows in 0.2.0.1-alpha.
+
+
diff --git a/src/or/geoip.c b/src/or/geoip.c
index c621ea81832db383e2c9604a9a010ac584d1b5a6..c51142c82e9e1bf3419a5956e273e1addc4d0c9d 100644
--- a/src/or/geoip.c
+++ b/src/or/geoip.c
@@ -976,7 +976,7 @@ geoip_dirreq_stats_write(time_t now)
   data_v2 = geoip_get_client_history(GEOIP_CLIENT_NETWORKSTATUS_V2);
   data_v3 = geoip_get_client_history(GEOIP_CLIENT_NETWORKSTATUS);
   format_iso_time(written, now);
-  out = start_writing_to_stdio_file(filename, OPEN_FLAGS_APPEND,
+  out = start_writing_to_stdio_file(filename, OPEN_FLAGS_APPEND | O_TEXT,
                                     0600, &open_file);
   if (!out)
     goto done;
@@ -1309,7 +1309,7 @@ geoip_entry_stats_write(time_t now)
   filename = get_datadir_fname2("stats", "entry-stats");
   data = geoip_get_client_history(GEOIP_CLIENT_CONNECT);
   format_iso_time(written, now);
-  out = start_writing_to_stdio_file(filename, OPEN_FLAGS_APPEND,
+  out = start_writing_to_stdio_file(filename, OPEN_FLAGS_APPEND | O_TEXT,
                                     0600, &open_file);
   if (!out)
     goto done;
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index d9a936471efa78af600930f1ce773027d41031e0..8a0171170cda4b0cd6e377cdec3edc961429d35c 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -635,13 +635,15 @@ rend_service_load_keys(void)
       }
 
       /* Prepare client_keys and hostname files. */
-      if (!(cfile = start_writing_to_stdio_file(cfname, OPEN_FLAGS_REPLACE,
+      if (!(cfile = start_writing_to_stdio_file(cfname,
+                                                OPEN_FLAGS_REPLACE | O_TEXT,
                                                 0600, &open_cfile))) {
         log_warn(LD_CONFIG, "Could not open client_keys file %s",
                  escaped(cfname));
         goto err;
       }
-      if (!(hfile = start_writing_to_stdio_file(fname, OPEN_FLAGS_REPLACE,
+      if (!(hfile = start_writing_to_stdio_file(fname,
+                                                OPEN_FLAGS_REPLACE | O_TEXT,
                                                 0600, &open_hfile))) {
         log_warn(LD_CONFIG, "Could not open hostname file %s", escaped(fname));
         goto err;
diff --git a/src/or/rephist.c b/src/or/rephist.c
index b7341f3c0d0a424d06fe952391965d058094a34e..24447004ef022608e76b64d50a022dabad7c34aa 100644
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@ -2500,7 +2500,7 @@ rep_hist_buffer_stats_write(time_t now)
   if (check_private_dir(statsdir, CPD_CREATE, get_options()->User) < 0)
     goto done;
   filename = get_datadir_fname2("stats", "buffer-stats");
-  out = start_writing_to_stdio_file(filename, OPEN_FLAGS_APPEND,
+  out = start_writing_to_stdio_file(filename, OPEN_FLAGS_APPEND | O_TEXT,
                                     0600, &open_file);
   if (!out)
     goto done;
diff --git a/src/tools/tor-gencert.c b/src/tools/tor-gencert.c
index a04eddafc7012df412fc75fe749ed365bfad5c75..7a516b45712ae5d994f8c5c53614c7897dd48266 100644
--- a/src/tools/tor-gencert.c
+++ b/src/tools/tor-gencert.c
@@ -264,7 +264,7 @@ load_identity_key(void)
     }
 
     if (!(f = start_writing_to_stdio_file(identity_key_file,
-                                          OPEN_FLAGS_REPLACE, 0400,
+                                          OPEN_FLAGS_REPLACE | O_TEXT, 0400,
                                           &open_file)))
       return 1;
 
@@ -349,7 +349,7 @@ generate_signing_key(void)
   }
 
   if (!(f = start_writing_to_stdio_file(signing_key_file,
-                                        OPEN_FLAGS_REPLACE, 0600,
+                                        OPEN_FLAGS_REPLACE | O_TEXT, 0600,
                                         &open_file)))
     return 1;