diff -ur lcdf-typetools-2.106.orig/liblcdf/filename.cc lcdf-typetools-2.106/liblcdf/filename.cc
--- lcdf-typetools-2.106.orig/liblcdf/filename.cc	Wed Jun 22 06:01:56 2016
+++ lcdf-typetools-2.106/liblcdf/filename.cc	Wed Jun 22 13:20:33 2016
@@ -126,5 +126,5 @@
     if (_actual || !_path)
 	return _actual;
     else
-	return fopen(_path.c_str(), binary ? "wb" : "w");
+	return fopen(_path.c_str(), "wb");
 }
diff -ur lcdf-typetools-2.106.orig/otftotfm/automatic.cc lcdf-typetools-2.106/otftotfm/automatic.cc
--- lcdf-typetools-2.106.orig/otftotfm/automatic.cc	Wed Jun 22 06:00:36 2016
+++ lcdf-typetools-2.106/otftotfm/automatic.cc	Wed Jun 22 13:43:40 2016
@@ -39,6 +39,10 @@
 #include <algorithm>
 
 #ifdef WIN32
+#ifdef _MSC_VER
+# include <io.h>
+# include <direct.h>
+#endif
 # define mkdir(dir, access) mkdir(dir)
 # define COPY_CMD "copy"
 # define CMD_SEP "&"
@@ -124,7 +128,18 @@
 static void
 find_writable_texdir(ErrorHandler *errh, const char *)
 {
+#if defined(W32TEX)
+// W32TeX does not have TEXMFVAR
+    char *p = kpsei_var_value("TEXMFVAR");
+    if (p == NULL) // W32TeX
+        look_for_writable_texdir("$TEXMFLOCAL", true);
+    else { // TeXLive
+        free (p);
+        look_for_writable_texdir("$TEXMFVAR", true);
+    }
+#else
     look_for_writable_texdir("$TEXMFVAR", true);
+#endif
     if (!writable_texdir)
 	look_for_writable_texdir("$VARTEXMF", false);
     if (!writable_texdir)
@@ -311,7 +326,7 @@
     String ls_r = writable_texdir + "ls-R";
     bool success = false;
     if (access(ls_r.c_str(), R_OK) >= 0) // make sure it already exists
-	if (FILE *f = fopen(ls_r.c_str(), "a")) {
+	if (FILE *f = fopen(ls_r.c_str(), "ab")) {
 	    fprintf(f, "./%s:\n%s\n", directory.c_str(), file.c_str());
 	    success = true;
 	    fclose(f);
@@ -321,7 +336,11 @@
     if (!success && writable_texdir.find_left('\'') < 0 && directory.find_left('\'') < 0 && file.find_left('\'') < 0) {
 	// look for mktexupd script
 	if (!mktexupd_tried) {
+#ifdef _WIN32
+	    mktexupd = "mktexupd";
+#else
 	    mktexupd = kpsei_string(kpsei_find_file("mktexupd", KPSEI_FMT_WEB2C));
+#endif
 	    mktexupd_tried = true;
 	}
 
@@ -675,7 +694,7 @@
 #endif
             {
                 fclose(f);
-                f = fopen(map_file.c_str(), "w");
+                f = fopen(map_file.c_str(), "wb");
                 fd = fileno(f);
             }
 
@@ -740,7 +759,16 @@
 	    if (slash >= 0)
 		filename = filename.substring(slash + 1);
             String redirect = verbose ? " 1>&2" : " >" DEV_NULL " 2>&1";
-	    String command = "updmap --nomkmap --enable Map " + shell_quote(filename) + redirect
+#if defined(W32TEX)
+// jtex_filetype is defined only in W32TeX
+	    char *p = kpsei_var_value("jtex_filetype");
+	    if (p != NULL) { // W32TeX
+		free(p);
+		String option = "--add ";
+	    } else // TeXLive
+#endif
+	    String option = "--enable Map ";
+	    String command = "updmap --nomkmap " + option  + shell_quote(filename) + redirect
                 + CMD_SEP " updmap" + redirect;
 	    int retval = mysystem(command.c_str(), errh);
 	    if (retval == 127)
diff -ur lcdf-typetools-2.106.orig/otftotfm/kpseinterface.c lcdf-typetools-2.106/otftotfm/kpseinterface.c
--- lcdf-typetools-2.106.orig/otftotfm/kpseinterface.c	Wed Jun 22 06:00:26 2016
+++ lcdf-typetools-2.106/otftotfm/kpseinterface.c	Wed Jun 22 13:45:39 2016
@@ -21,6 +21,9 @@
 #include <kpathsea/expand.h>
 #include <kpathsea/c-pathch.h>
 #include <kpathsea/tex-file.h>
+#ifdef W32TEX
+#include <kpathsea/variable.h>
+#endif
 #include "kpseinterface.h"
 
 int kpsei_env_sep_char = ENV_SEP;
@@ -86,3 +89,11 @@
 {
     kpathsea_debug = flags;
 }
+
+#ifdef W32TEX
+char*
+kpsei_var_value(const char *name)
+{
+  return kpse_var_value(name);
+}
+#endif
diff -ur lcdf-typetools-2.106.orig/otftotfm/kpseinterface.h lcdf-typetools-2.106/otftotfm/kpseinterface.h
--- lcdf-typetools-2.106.orig/otftotfm/kpseinterface.h	Wed Aug 14 05:12:16 2013
+++ lcdf-typetools-2.106/otftotfm/kpseinterface.h	Wed Jun 22 13:46:37 2016
@@ -13,6 +13,10 @@
 char* kpsei_find_file(const char* name, int format);
 void kpsei_set_debug_flags(unsigned flags);
 
+#ifdef W32TEX
+char* kpsei_var_value(const char *name);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff -ur lcdf-typetools-2.106.orig/otftotfm/otftotfm.cc lcdf-typetools-2.106/otftotfm/otftotfm.cc
--- lcdf-typetools-2.106.orig/otftotfm/otftotfm.cc	Wed Jun 22 06:06:05 2016
+++ lcdf-typetools-2.106/otftotfm/otftotfm.cc	Wed Jun 22 13:47:38 2016
@@ -63,6 +63,9 @@
 #ifdef HAVE_FCNTL_H
 # include <fcntl.h>
 #endif
+#ifdef _MSC_VER
+# include <io.h>
+#endif
 
 using namespace Efont;
 
@@ -582,7 +585,7 @@
 
     if (verbose)
 	errh->message("creating %s", filename.c_str());
-    FILE *f = fopen(filename.c_str(), "w");
+    FILE *f = fopen(filename.c_str(), "wb");
     if (!f) {
 	errh->error("%s: %s", filename.c_str(), strerror(errno));
 	return;
@@ -1028,7 +1031,7 @@
 #endif
     {
 	fclose(f);
-	f = fopen(filename.c_str(), "w");
+	f = fopen(filename.c_str(), "wb");
 	fd = fileno(f);
     }
 
diff -ur lcdf-typetools-2.106.orig/t1dotlessj/t1dotlessj.cc lcdf-typetools-2.106/t1dotlessj/t1dotlessj.cc
--- lcdf-typetools-2.106.orig/t1dotlessj/t1dotlessj.cc	Wed Jun 22 06:06:02 2016
+++ lcdf-typetools-2.106/t1dotlessj/t1dotlessj.cc	Wed Jun 22 13:27:55 2016
@@ -410,10 +410,10 @@
     // write it to output
     if (!outputf)
 	outputf = stdout;
-    if (binary) {
 #if defined(_MSDOS) || defined(_WIN32)
-	_setmode(_fileno(outputf), _O_BINARY);
+    _setmode(_fileno(outputf), _O_BINARY);
 #endif
+    if (binary) {
 	Type1PFBWriter w(outputf);
 	dotless_font->write(w);
     } else {
diff -ur lcdf-typetools-2.106.orig/t1rawafm/t1rawafm.cc lcdf-typetools-2.106/t1rawafm/t1rawafm.cc
--- lcdf-typetools-2.106.orig/t1rawafm/t1rawafm.cc	Wed Jun 22 06:05:55 2016
+++ lcdf-typetools-2.106/t1rawafm/t1rawafm.cc	Wed Jun 22 13:30:10 2016
@@ -359,6 +359,9 @@
         if (!outf)
             errh->fatal("%s: %s", output_file, strerror(errno));
     }
+#if defined(_MSDOS) || defined(_WIN32)
+    _setmode(_fileno(outf), _O_BINARY);
+#endif
 
     write_afm(outf, font);
 
diff -ur lcdf-typetools-2.106.orig/t1reencode/t1reencode.cc lcdf-typetools-2.106/t1reencode/t1reencode.cc
--- lcdf-typetools-2.106.orig/t1reencode/t1reencode.cc	Wed Jun 22 06:05:52 2016
+++ lcdf-typetools-2.106/t1reencode/t1reencode.cc	Wed Jun 22 13:31:29 2016
@@ -1094,10 +1094,10 @@
 	if (!outf)
 	    errh->fatal("%s: %s", output_file, strerror(errno));
     }
-    if (binary) {
 #if defined(_MSDOS) || defined(_WIN32)
-	_setmode(_fileno(outf), _O_BINARY);
+    _setmode(_fileno(outf), _O_BINARY);
 #endif
+    if (binary) {
 	Type1PFBWriter w(outf);
 	font->write(w);
     } else {
diff -ur lcdf-typetools-2.106.orig/t1testpage/t1testpage.cc lcdf-typetools-2.106/t1testpage/t1testpage.cc
--- lcdf-typetools-2.106.orig/t1testpage/t1testpage.cc	Wed Jun 22 06:05:45 2016
+++ lcdf-typetools-2.106/t1testpage/t1testpage.cc	Wed Jun 22 13:32:21 2016
@@ -665,6 +665,9 @@
 	if (!outf)
 	    errh->fatal("%s: %s", output_file, strerror(errno));
     }
+#if defined(_MSDOS) || defined(_WIN32)
+    _setmode(_fileno(outf), _O_BINARY);
+#endif
 
     //font->undo_synthetic();
