Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 gcl (2.6.12-130) unstable; urgency=medium
 .
   * Version_2.6.13pre130
Author: Camm Maguire <camm@debian.org>

---
The information above should follow the Patch Tagging Guidelines, please
checkout https://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: (upstream|backport|vendor|other), (<patch-url>|commit:<commit-id>)
Bug: <upstream-bugtracker-url>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: (no|not-needed|<patch-forwarded-url>)
Applied-Upstream: <version>, (<commit-url>|commit:<commid-id>)
Reviewed-By: <name and email of someone who approved/reviewed the patch>
Last-Update: 2022-12-16

--- gcl-2.6.12.orig/cmpnew/gcl_cmpfun.lsp
+++ gcl-2.6.12/cmpnew/gcl_cmpfun.lsp
@@ -91,6 +91,7 @@
                        (cond ((char= char #\\) (wt "\\\\"))
                              ((char= char #\") (wt "\\\""))
                              ((char= char #\Newline) (wt "\\n"))
+			     ((char= char #\Return) (wt "\\r"))
                              (t (wt char)))))
                 (wt "\",")
                 (if (null vv-index) (wt "Cnil") (wt (vv-str vv-index)))
--- gcl-2.6.12.orig/cmpnew/gcl_cmpmain.lsp
+++ gcl-2.6.12/cmpnew/gcl_cmpmain.lsp
@@ -513,14 +513,14 @@ Cannot compile ~a.~%"
 			 na na na))	
 			    
 	     #+(or winnt bsd) ""; "-w"
-	     #-(or aix3 bsd winnt irix3) " 2> /dev/null ")
+	     #-(or aix3 bsd winnt irix3) "");" 2> /dev/null "
 		  
 		 
 	   )
    )
   )
 
-#+winnt (defun prep-win-path-acc ( s acc)
+#+(or cygwin winnt) (defun prep-win-path-acc ( s acc)
   (let ((pos (search "\~" s)))
     (if pos 
 	(let ((start (subseq s 0 (1+ pos)))
@@ -534,7 +534,7 @@ Cannot compile ~a.~%"
      nil
      #+vax "~a ~@[~*-O ~]-S -I. -w ~a ; as -J -W -o ~A ~A"
      #+(or system-v e15 dgux sgi ) "~a ~@[~*-O ~]-c -I. ~a 2> /dev/null"
-     #+winnt (prep-win-path-acc (compiler-command c-pathname o-pathname) "")
+     #+(or cygwin winnt) (prep-win-path-acc (compiler-command c-pathname o-pathname) "")
      #-(or vax system-v e15 dgux sgi) (compiler-command c-pathname o-pathname)
      *cc*
      (if (or (= *speed* 2) (= *speed* 3)) t nil)
--- gcl-2.6.12.orig/configure
+++ gcl-2.6.12/configure
@@ -3046,7 +3046,7 @@ case $canonical in
     powerpc-*-darwin*) use=powerpc-macosx;;
     *86*darwin*) use=386-macosx;;
     i*mingw*|i*msys*) use=mingw;;
-    i*cygwin*)
+    *cygwin*)
         if $CC -v 2>&1 | fgrep ming > /dev/null ;
         then use=mingw
         else use=gnuwin95
@@ -4648,11 +4648,22 @@ fi
 case $use in
     *mingw*)
 	assert_arg_to_cflags -fno-zero-initialized-in-bss
-	assert_arg_to_cflags -mms-bitfields;;
+	assert_arg_to_cflags -mms-bitfields
+	for i in makedefc windows/gcl.iss windows/sysdir.bat windows/install.lsp h/gclincl.h;  do
+	    cat $i.in | sed 's,^\r\n$,\r\n,g' >tmp && mv tmp $i.in;
+	done
+	OLD_LDFLAGS=$LDFLAGS
+	assert_arg_to_ldflags -pg
+	GPL_FLAG="-pg"
+	LDFLAGS=$OLD_LDFLAGS;;
     *gnuwin*)
 	assert_arg_to_cflags -fno-zero-initialized-in-bss
 	assert_arg_to_cflags -mms-bitfields
-        assert_arg_to_ldflags -Wl,--stack,8000000;;
+        assert_arg_to_ldflags -Wl,--stack,8000000
+	OLD_LDFLAGS=$LDFLAGS
+	assert_arg_to_ldflags -pg
+	GPL_FLAG="-pg"
+	LDFLAGS=$OLD_LDFLAGS;;
     386-macosx)
 #	assert_arg_to_cflags -Wno-error=implicit-function-declaration
 	add_arg_to_cflags -Wno-incomplete-setjmp-declaration
@@ -9779,7 +9790,7 @@ fi
 
 
 
-LDFLAGS="`echo $LDFLAGS | sed 's,gcl.script,../unixport/gcl.script,g'`"
+LDFLAGS="`echo $GPL_FLAG $LDFLAGS | sed 's,gcl.script,../unixport/gcl.script,g'`"
 
 LIBS="$X_PRE_LIBS $X_LIBS $X_EXTRA_LIBS $LIBS $TLIBS"
 
--- gcl-2.6.12.orig/configure.in
+++ gcl-2.6.12/configure.in
@@ -1,5 +1,5 @@
 AC_INIT
-AC_PREREQ([2.69])
+AC_PREREQ([2.68])
 AC_CONFIG_HEADERS([h/gclincl.h])
 
 VERSION=`cat majvers`.`cat minvers`
@@ -47,7 +47,7 @@ case $canonical in
     powerpc-*-darwin*) use=powerpc-macosx;;
     *86*darwin*) use=386-macosx;;
     i*mingw*|i*msys*) use=mingw;;
-    i*cygwin*)
+    *cygwin*)
         if $CC -v 2>&1 | fgrep ming > /dev/null ;
         then use=mingw
         else use=gnuwin95
@@ -312,11 +312,22 @@ AC_RUN_IFELSE(
 case $use in
     *mingw*)
 	assert_arg_to_cflags -fno-zero-initialized-in-bss
-	assert_arg_to_cflags -mms-bitfields;;
+	assert_arg_to_cflags -mms-bitfields
+	for i in makedefc windows/gcl.iss windows/sysdir.bat windows/install.lsp h/gclincl.h;  do
+	    cat $i.in | sed 's,[^\r]\n$,\r\n,g' >tmp && mv tmp $i.in;
+	done
+	OLD_LDFLAGS=$LDFLAGS
+	assert_arg_to_ldflags -pg
+	GPL_FLAG="-pg"
+	LDFLAGS=$OLD_LDFLAGS;;
     *gnuwin*)
 	assert_arg_to_cflags -fno-zero-initialized-in-bss
 	assert_arg_to_cflags -mms-bitfields
-        assert_arg_to_ldflags -Wl,--stack,8000000;;
+        assert_arg_to_ldflags -Wl,--stack,8000000
+	OLD_LDFLAGS=$LDFLAGS
+	assert_arg_to_ldflags -pg
+	GPL_FLAG="-pg"
+	LDFLAGS=$OLD_LDFLAGS;;
     386-macosx)
 #	assert_arg_to_cflags -Wno-error=implicit-function-declaration
 	add_arg_to_cflags -Wno-incomplete-setjmp-declaration
@@ -2181,7 +2192,7 @@ AC_CHECK_HEADERS(alloca.h)
 AC_FUNC_ALLOCA
 
 
-LDFLAGS="`echo $LDFLAGS | sed 's,gcl.script,../unixport/gcl.script,g'`"
+LDFLAGS="`echo $GPL_FLAG $LDFLAGS | sed 's,gcl.script,../unixport/gcl.script,g'`"
 AC_SUBST(LDFLAGS)
 LIBS="$X_PRE_LIBS $X_LIBS $X_EXTRA_LIBS $LIBS $TLIBS"
 AC_SUBST(LIBS)
--- gcl-2.6.12.orig/git.tag
+++ gcl-2.6.12/git.tag
@@ -1,2 +1,2 @@
-"Version_2_6_13pre129"
+"Version_2_6_13pre130"
 
--- gcl-2.6.12.orig/h/att.h
+++ gcl-2.6.12/h/att.h
@@ -72,7 +72,7 @@
 
 #define INIT_ALLOC \
      	heap_end = sbrk(0); \
-	({fixnum i;if ((i = ((int)heap_end & (PAGESIZE - 1))))	\
+	({fixnum i;if ((i = ((unsigned long)heap_end & (PAGESIZE - 1))))	\
 		     sbrk(PAGESIZE - i);});			\
 	heap_end = core_end = sbrk(0);
 
--- gcl-2.6.12.orig/h/gnuwin95.h
+++ gcl-2.6.12/h/gnuwin95.h
@@ -41,7 +41,6 @@ extern DBEGIN_TY _dbegin;
 
 #define HAVE_SIGACTION
 /* a noop */
-#define SA_ONSTACK 0
 
 #define brk(x) printf("not doing break\n");
 #include <stdarg.h>     
@@ -116,20 +115,11 @@ extern DBEGIN_TY _dbegin;
 
 #include <limits.h>
 #include <sys/stat.h>
-#define GET_FULL_PATH_SELF(a_) do {\
-  char b[20];\
-  static char q[PATH_MAX];\
-  struct stat ss;\
-  if (snprintf(b,sizeof(b),"/proc/%d/exe",getpid())<=0)\
-    error("Cannot write proc exe pathname");\
-  if (stat(b,&ss)) \
-    (a_)=argv[0];\
-  else {\
-    if (!realpath(b,q)) \
-      error("realpath error");\
-    (a_)=q;\
-  }\
-} while(0)
+#define GET_FULL_PATH_SELF(a_) do {				\
+    static char q[PATH_MAX];					\
+    massert(which("/proc/self/exe",q) || which(argv[0],q));	\
+    (a_)=q;							\
+  } while(0)
 
 /* Begin for cmpinclude */
 
@@ -138,7 +128,7 @@ extern DBEGIN_TY _dbegin;
 
 #define SF(a_) ((siginfo_t *)a_)
 
-#define FPE_CODE(i_,v_) make_fixnum(fSfpe_code(FFN(fSfnstsw)(),FFN(fSstmxcsr)()))
+#define FPE_CODE(i_,v_) make_fixnum((long)fSfpe_code((long)FFN(fSfnstsw)(),(long)FFN(fSstmxcsr)()))
 /* #define FPE_CODE(i_,v_) make_fixnum((fixnum)SF(i_)->si_code) */
 #define FPE_ADDR(i_,v_) make_fixnum((fixnum)SF(i_)->si_addr)
 #define FPE_CTXT(v_) Cnil
--- gcl-2.6.12.orig/h/mingw.h
+++ gcl-2.6.12/h/mingw.h
@@ -198,7 +198,7 @@ extern int mingwlisten(FILE *);
 
 #define NOFREE_ERR
 
-#define FPE_CODE(i_,v_) make_fixnum(fSfpe_code(FFN(fSfnstsw)(),FFN(fSstmxcsr)()))
+#define FPE_CODE(i_,v_) make_fixnum((long)fSfpe_code((long)FFN(fSfnstsw)(),(long)FFN(fSstmxcsr)()))
 #define FPE_ADDR(i_,v_) make_fixnum(0)
 #define FPE_CTXT(v_) Cnil
 
@@ -222,5 +222,3 @@ extern int mingwlisten(FILE *);
 
 
 #define NO_FILE_LOCKING /*FIXME*/
-
-#define sleep(n) Sleep(1000*n)
--- gcl-2.6.12.orig/h/notcomp.h
+++ gcl-2.6.12/h/notcomp.h
@@ -366,6 +366,7 @@ extern bool writable_malloc;
 
 #define psystem(x) prof_block(vsystem(x))
 #define pfork() prof_block(fork())
+#define pvfork() prof_block(vfork())
 
 #include "error.h"
 
--- gcl-2.6.12.orig/h/protoize.h
+++ gcl-2.6.12/h/protoize.h
@@ -1634,7 +1634,6 @@ void LlistA(void);
 void Lvalues_list(void);
 void Lequal(void);
 void Ldigit_char_p(void);
-void ERROR(void);
 void Lchar_neq(void);
 void Lpathname_directory(void);
 void Lcdaaar(void);
--- gcl-2.6.12.orig/h/wincoff.h
+++ gcl-2.6.12/h/wincoff.h
@@ -8,9 +8,7 @@
 
 /* prevent duplicate definition...  we wont be using varargs
    in this */
-#undef va_start
 
-#include "winsock2.h"
 #include "windows.h"
 #ifdef __MINGW32__
 #include "minglacks.h"
--- gcl-2.6.12.orig/lsp/gcl_iolib.lsp
+++ gcl-2.6.12/lsp/gcl_iolib.lsp
@@ -471,7 +471,7 @@
       (let* ((*load-pathname* pp)(*load-truename* epp))
 	(with-open-file
 	 (s epp :external-format external-format)
-	 (if (member (peek-char nil s nil 'eof) '#.(mapcar 'code-char (list 127 #xcf #xce #x4c)))
+	 (if (member (peek-char nil s nil 'eof) '#.(mapcar 'code-char (list 127 #xcf #xce #x4c #x64)))
 	     (load-fasl s print)
 	   (let ((*standard-input* s)) (load-stream s print)))))
     (when if-does-not-exist
--- gcl-2.6.12.orig/makefile
+++ gcl-2.6.12/makefile
@@ -267,7 +267,8 @@ $(HDIR)new_decl.h:
 	(cd o && $(MAKE) ../$@)
 
 $(HDIR)mcompdefs.h: $(HDIR)compdefs.h $(HDIR)new_decl.h
-	$(AWK) 'BEGIN {print "#include \"include.h\"";print "#include \"cmponly.h\"";print "---"} {a=$$1;gsub("\\.\\.\\.","",a);print "\"#define " $$1 "\" " a}' $< |\
+	cat $< |\
+	$(AWK) 'BEGIN {print "#include \"include.h\"";print "#include \"cmponly.h\"";print "---"} {a=$$1;gsub("\\.\\.\\.","",a);print "\"#define " $$1 "\" " a}' |\
 	$(CC) -E -P -I./$(HDIR) - |\
 	$(AWK) '/^\-\-\-$$/ {i=1;next} {if (!i) next} {gsub("\"","");print}' >$@
 
--- gcl-2.6.12.orig/o/cmpaux.c
+++ gcl-2.6.12/o/cmpaux.c
@@ -36,6 +36,17 @@ Foundation, 675 Mass Ave, Cambridge, MA
 
 #include "page.h"
 
+#ifdef HAVE_AOUT
+#undef ATT
+#undef BSD
+#ifndef HAVE_ELF
+#ifndef HAVE_FILEHDR
+#define BSD
+#endif
+#endif
+#include HAVE_AOUT
+#endif
+
 DEFUNO_NEW("SPECIALP",object,fSspecialp,SI
        ,1,1,NONE,OO,OO,OO,OO,void,siLspecialp,(object sym),"")
 {
@@ -468,6 +479,7 @@ gcl_init_or_load1(void (*fn)(void),const
     faslfile=open_stream(make_simple_string(file),smm_input,Cnil,sKerror);
     SEEK_TO_END_OFILE(faslfile->sm.sm_fp);
     call_init(0,memory,faslfile);
+    close_stream(faslfile);
 
   } else {
     printf("loading %s\n",file); 
--- gcl-2.6.12.orig/o/file.d
+++ gcl-2.6.12/o/file.d
@@ -516,6 +516,17 @@ DEFUN_NEW("OPEN-STREAM-P",object,fLopen_
 	Close_stream(strm) closes stream strm.
 	The abort_flag is not used now.
 */
+
+static int
+pipe_designator_p(object x) {
+
+  if (x==OBJNULL||x==Cnil)
+    return 0;
+  coerce_to_filename(x,FN1);
+  return FN1[0]=='|' ? 1 : 0;
+
+}
+
 void
 close_stream(object strm)  {
 
@@ -528,7 +539,10 @@ close_stream(object strm)  {
       FEerror("Cannot close the standard output.", 0);
     fflush(strm->sm.sm_fp);
     deallocate_stream_buffer(strm);
-    fclose(strm->sm.sm_fp);
+    if (pipe_designator_p(strm->sm.sm_object1))
+      pclose(strm->sm.sm_fp);
+    else
+      fclose(strm->sm.sm_fp);
     strm->sm.sm_fp = NULL;
     strm->sm.sm_fd = -1;
     break;
@@ -554,9 +568,7 @@ close_stream(object strm)  {
   case smm_io:
   case smm_probe:
     deallocate_stream_buffer(strm);
-    if (strm->sm.sm_object1 &&
-	type_of(strm->sm.sm_object1)==t_string &&
-	strm->sm.sm_object1->st.st_self[0] =='|')
+    if (pipe_designator_p(strm->sm.sm_object1))
       pclose(strm->sm.sm_fp);
     else
       fclose(strm->sm.sm_fp);
@@ -2110,7 +2122,7 @@ object x=Cnil;
 
     massert(!sigaction(SIGCHLD,&sa,&osa));
 
-    switch((pid=pfork())) {
+    switch((pid=pvfork())) {
     case -1:
       FEerror("Cannot fork", 0);
       break;
@@ -2119,7 +2131,7 @@ object x=Cnil;
       massert(setsid()>=0);
 
       if (daemon == sKpersistent)
-	switch(pfork()) {
+	switch(pvfork()) {
 	case -1:
 	  FEerror("daemon fork error", 0);
 	  break;
@@ -2162,7 +2174,7 @@ object x=Cnil;
 	  
 	  y=maccept(x);
 	  
-	  switch((pid=pfork())) {
+	  switch((pid=pvfork())) {
 	  case 0:
 	    massert(!sigaction(SIGCHLD,&osa,NULL));
 	    ifuncall1(server,y);
--- gcl-2.6.12.orig/o/main.c
+++ gcl-2.6.12/o/main.c
@@ -1163,6 +1163,10 @@ init_main(void) {
   ADD_FEATURE("WIN32");
 #endif
 
+#if defined(__CYGWIN__)
+  ADD_FEATURE("CYGWIN");
+#endif
+
 #ifdef IEEEFLOAT
   ADD_FEATURE("IEEE-FLOATING-POINT");
 #endif
--- gcl-2.6.12.orig/o/mingwin.c
+++ gcl-2.6.12/o/mingwin.c
@@ -942,23 +942,8 @@ vsystem(const char *command) {
   STARTUPINFO s={0};
   PROCESS_INFORMATION p={0};
   long unsigned int e;
-  char *cmd=NULL,*r;
 
-  if (!strpbrk(command,"\"'$<>")) {
-
-    cmd=FN1;
-    massert((r=strpbrk(command," \n\t"))-command<sizeof(FN1));
-    memcpy(FN1,command,r-command);
-    FN1[r-command]=0;
-
-  } else {
-
-    massert(snprintf(FN1,sizeof(FN1),"cmd /c %s",command)>=0);
-    command=FN1;
-
-  }
-
-  massert(CreateProcess(cmd,(void *)command,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW,NULL,NULL,&s,&p));
+  massert(CreateProcess(NULL,(void *)command,NULL,NULL,FALSE,0,NULL,NULL,&s,&p));
   massert(!WaitForSingleObject(p.hProcess,INFINITE));
   massert(GetExitCodeProcess(p.hProcess,&e));
   massert(CloseHandle(p.hProcess));
--- gcl-2.6.12.orig/o/num_log.c
+++ gcl-2.6.12/o/num_log.c
@@ -284,18 +284,18 @@ LFD(siLbit_array_op)(void)
 		xp = x->bv.bv_self;
 		xo = BV_OFFSET(x);
 		if (type_of(y) != t_bitvector)
-			goto ERROR;
+			goto ERROR1;
 		if (d != y->bv.bv_dim)
-			goto ERROR;
+			goto ERROR1;
 		yp = y->bv.bv_self;
 		yo = BV_OFFSET(y);
 		if (r == Ct)
 			r = x;
 		if (r != Cnil) {
 			if (type_of(r) != t_bitvector)
-				goto ERROR;
+				goto ERROR1;
 			if (r->bv.bv_dim != d)
-				goto ERROR;
+				goto ERROR1;
 			i = (r->bv.bv_self - xp)*8 + (BV_OFFSET(r) - xo);
 			if ((i > 0 && i < d) || (i < 0 && -i < d)) {
 				r0 = r;
@@ -325,35 +325,35 @@ LFD(siLbit_array_op)(void)
 		}
 	} else {
 		if (type_of(x) != t_array)
-			goto ERROR;
+			goto ERROR1;
 		if ((enum aelttype)x->a.a_elttype != aet_bit)
-			goto ERROR;
+			goto ERROR1;
 		d = x->a.a_dim;
 		xp = x->bv.bv_self;
 		xo = BV_OFFSET(x);
 		if (type_of(y) != t_array)
-			goto ERROR;
+			goto ERROR1;
 		if ((enum aelttype)y->a.a_elttype != aet_bit)
-			goto ERROR;
+			goto ERROR1;
 		if (x->a.a_rank != y->a.a_rank)
-			goto ERROR;
+			goto ERROR1;
 		yp = y->bv.bv_self;
 		yo = BV_OFFSET(y);
 		for (i = 0;  i < x->a.a_rank;  i++)
 			if (x->a.a_dims[i] != y->a.a_dims[i])
-				goto ERROR;
+				goto ERROR1;
 		if (r == Ct)
 			r = x;
 		if (r != Cnil) {
 			if (type_of(r) != t_array)
-				goto ERROR;
+				goto ERROR1;
 			if ((enum aelttype)r->a.a_elttype != aet_bit)
-				goto ERROR;
+				goto ERROR1;
 			if (r->a.a_rank != x->a.a_rank)
-				goto ERROR;
+				goto ERROR1;
 			for (i = 0;  i < x->a.a_rank;  i++)
 				if (r->a.a_dims[i] != x->a.a_dims[i])
-					goto ERROR;
+					goto ERROR1;
 			i = (r->bv.bv_self - xp)*8 + (BV_OFFSET(r) - xo);
 			if ((i > 0 && i < d) || (i < 0 && -i < d)) {
 				r0 = r;
@@ -487,7 +487,7 @@ LFD(siLbit_array_op)(void)
 	vs_push(r0);
 	return;
 
-ERROR:
+ERROR1:
 	FEerror("Illegal arguments for bit-array operation.", 0);
 }
 
--- gcl-2.6.12.orig/o/run_process.c
+++ gcl-2.6.12/o/run_process.c
@@ -21,6 +21,13 @@ License for more details.
 #define IN_RUN_PROCESS
 #include "include.h"
 
+#if defined(__CYGWIN__)
+#include <tchar.h>
+#include <time.h>
+#include <windows.h>
+#include <sys/cygwin.h>
+#endif
+
 #ifdef HAVE_SYS_SOCKIO_H
 #include <sys/sockio.h>
 #endif
@@ -30,10 +37,11 @@ License for more details.
 void setup_stream_buffer(object);
 object make_two_way_stream(object, object);
 
-#ifdef __MINGW32__
+#if defined(__MINGW32__) || defined(__CYGWIN__)
 
 #include<windows.h>
 #include <fcntl.h>
+#include <io.h>
 #define PIPE_BUFFER_SIZE 2048
 
 void DisplayError ( char *pszAPI );
@@ -65,7 +73,7 @@ void run_process ( char *name )
     CHAR chBuf[60] = "button .hello\npack .hello\n\0";
      /*CHAR chBuf[60] = "button .hello\n\0"; */
 #endif
-    
+
     /* Set up the security attributes struct. */
     sec_att.nLength= sizeof(SECURITY_ATTRIBUTES);
     sec_att.lpSecurityDescriptor = NULL;
@@ -156,11 +164,28 @@ void run_process ( char *name )
 #endif
 
     
+#if !defined (__CYGWIN__)
     /* Connect up the Lisp objects with the pipes. */
     ofd = _open_osfhandle ( (int)hChildStdoutRead, _O_RDONLY | _O_TEXT );
     ofp = _fdopen ( ofd, "r" );
     ifd = _open_osfhandle ( (int)hChildStdinWrite, _O_WRONLY | _O_TEXT );
     ifp = _fdopen ( ifd, "w" );
+#else
+    {
+      extern int cygwin_attach_handle_to_fd(char *,int,HANDLE,mode_t,DWORD);
+      static int rpn;
+
+      massert(snprintf(FN1,sizeof(FN1),"run_process_stdin_%d",rpn)>0);
+      ofd=cygwin_attach_handle_to_fd(FN1,-1,hChildStdoutRead,0,GENERIC_READ);
+      ofp=fdopen(ofd,"r");
+      massert(snprintf(FN1,sizeof(FN1),"run_process_stdout_%d",rpn)>0);
+      ifd=cygwin_attach_handle_to_fd(FN1,-1,hChildStdinWrite,0,GENERIC_WRITE);
+      ifp=fdopen(ifd,"w");
+      rpn++;
+
+    }
+
+#endif
 
 #if 0
     {
@@ -215,7 +240,7 @@ void PrepAndLaunchRedirectedChild (
                            NULL,
                            NULL,
                            TRUE,
-                           CREATE_NEW_CONSOLE,
+			   0,
                            NULL,
                            NULL,
                            &startup_info,
@@ -256,33 +281,35 @@ void DisplayError(char *pszAPI)
     FEerror ( "RUN-PROCESS encountered problems.", 0 );
 }
 
-void siLrun_process()
-{
-    char cmdline[20480];
-    int i, nargs;
-    int old = signals_allowed;
-    int argc = 0;
-
-    nargs = vs_top - vs_base;
-    for ( i = 0; i < nargs; i++ ) {
-      check_type_string ( &vs_base[i] );
-    }
+void
+siLrun_process() {
+
+  int i, j;
+  int old = signals_allowed;
+  object x;
+
+  if (vs_top-vs_base!=2)
+    FEwrong_no_args("RUN-PROCESS requires two arguments",make_fixnum(vs_top-vs_base));
+  check_type_string(&vs_base[0]);
+
+  massert(snprintf(FN1,sizeof(FN1),"%.*s%n",vs_base[0]->st.st_fillp,vs_base[0]->st.st_self,&i)>=0);
+
+#if defined(__CYGWIN__)
+    cygwin_conv_path(CCP_POSIX_TO_WIN_A,FN1,FN2,sizeof(FN2));
+    massert(snprintf(FN1,sizeof(FN1),"%s%n",FN2,&i)>=0);
+#endif
+
+  x=vs_base[1];
+  for (;x!=Cnil;x=x->c.c_cdr,i+=j) {
+    check_type_list(&x);
+    check_type_string(&x->c.c_car);
+    massert(snprintf(FN1+i,sizeof(FN1)-i," %.*s %n",x->c.c_car->st.st_fillp,x->c.c_car->st.st_self,&j)>=0);
+  }
+
+  signals_allowed = sig_at_read;
+  run_process(FN1);
+  signals_allowed = old;
 
-    cmdline[0]='\0';
-    for ( i = 0; i < nargs; i++ ) {
-      if ( strlen ( cmdline ) + vs_base[i]->st.st_fillp + 2 > 20480 ) {
-	FEerror ( "RUN-PROCESS command more than 20480 characters long.", 0 );
-      }
-      if ( i != 0 ) {
-        strcat ( cmdline, " ");
-      }
-      strcat ( cmdline,  vs_base[i]->st.st_self );
-      emsg("siLrun_process: cmdline=%s\n", cmdline );
-      argc++;
-    }
-    signals_allowed = sig_at_read;
-    run_process ( cmdline );
-    signals_allowed = old;
 }
 
 void
@@ -524,66 +551,82 @@ make_socket_pair()
  * with "C" type streams.
  */
 
-void
-spawn_process_with_streams(istream, ostream, pname, argv)
-object istream;
-object ostream;
-char *pname;
-char **argv;
-{
+static void
+spawn_process_with_streams(object istream,object ostream,char *pname,char **argv) {
 
   int fdin;
   int fdout;
+
   if (istream->sm.sm_fp == NULL || ostream->sm.sm_fp == NULL)
     FEerror("Cannot spawn process with given stream", 0);
+
   fdin = istream->sm.sm_int;
   fdout = ostream->sm.sm_int;
-  if (pfork() == 0)
-    { /* the child --- replace standard in and out with descriptors given */
-      close(0);
-      massert(dup(fdin)>=0);
-      close(1);
-      massert(dup(fdout)>=0);
-      emsg("\n***** Spawning process %s ", pname);
-      if (execvp(pname, argv) == -1)
-	{
-	  emsg("\n***** Error in process spawning *******");
-	  do_gcl_abort();
-	}
-    }
+
+  if (!pvfork()) {
+
+    /* the child --- replace standard in and out with descriptors given */
+    close(0);
+    massert(dup(fdin)>=0);
+    close(1);
+    massert(dup(fdout)>=0);
+
+    close(fileno(istream->sm.sm_fp));
+    close(fileno(ostream->sm.sm_fp));
+
+    emsg("\n***** Spawning process %s ", pname);
+
+    errno=0;
+    execvp(pname,argv);
+    _exit(128|(errno&0x7f));
+
+  } else {
+
+    close(fdin);
+    close(fdout);
+
+  }
 
 }
     
       
 void
-run_process(filename, argv)
-char *filename;
-char **argv;
-{
+run_process(char *filename,char **argv) {
+
   object stream = make_socket_pair();
-  spawn_process_with_streams(stream->sm.sm_object1,
-			    stream->sm.sm_object0,
-			    filename, argv);
+  spawn_process_with_streams(stream->sm.sm_object1,stream->sm.sm_object0,filename,argv);
+
   vs_base[0] = stream;
   vs_base[1] = Cnil;
   vs_top = vs_base + 2;
+
 }
     
 void
-FFN(siLrun_process)()
-{
-  int i;
-  object arglist;
-  char *argv[100];
-
-  arglist = vs_base[1];
-  argv[0] = "";
-  for(i = 1; arglist != Cnil; i++) {
-     argv[i] = lisp_to_string(arglist->c.c_car);
-     arglist = arglist->c.c_cdr;
+FFN(siLrun_process)() {
+
+  int i,j;
+  object x;
+  char **p1,**pp,*c,*spc=" \n\t";
+
+  if (vs_top-vs_base!=2)
+    FEwrong_no_args("RUN-PROCESS requires two arguments",make_fixnum(vs_top-vs_base));
+  check_type_string(&vs_base[0]);
+
+  massert(snprintf(FN1,sizeof(FN1),"%.*s%n",vs_base[0]->st.st_fillp,vs_base[0]->st.st_self,&i)>=0);
+
+  x=vs_base[1];
+  for (;x!=Cnil;x=x->c.c_cdr,i+=j) {
+    check_type_list(&x);
+    check_type_string(&x->c.c_car);
+    massert(snprintf(FN1+i,sizeof(FN1)-i," %.*s %n",x->c.c_car->st.st_fillp,x->c.c_car->st.st_self,&j)>=0);
   }
-  argv[i] = (char *)0;
-  run_process(object_to_string(vs_base[0]), argv);
+
+  for (pp=p1=(void *)FN2,c=FN1;(*pp=strtok(c,spc));c=NULL,pp++)
+    massert((void *)(pp+1)<(void *)FN2+sizeof(FN2));
+
+  run_process(FN1,(char **)FN2);
+
 }
 
 void
--- gcl-2.6.12.orig/o/sfaslcoff.c
+++ gcl-2.6.12/o/sfaslcoff.c
@@ -4,7 +4,7 @@
 
 typedef unsigned char  uc;
 typedef unsigned short us;
-typedef unsigned long  ul;
+typedef unsigned int  ul;
 
 struct filehdr {
   us f_magic;	/* magic number			*/
@@ -71,6 +71,10 @@ struct reloc {
 #define R_SECREL32    0x000B  /* Currently ignored, used only for debugging strings FIXME */
 #define R_PCRLONG     0x0014  /* 32-bit reference pc relative to the symbols virtual address */
 
+#define IMAGE_REL_AMD64_REL32  0x0004  /* 32-bit reference pc relative to the symbols virtual address */
+#define IMAGE_REL_AMD64_ADDR64 0x0001  /* The 64-bit VA of the relocation target */
+#define IMAGE_REL_AMD64_ADDR32NB 0x0003  /* The 32-bit address without an image base (RVA) */
+
 struct syment {
   union {
     char n_name[8];
@@ -115,10 +119,13 @@ add_val(ul *w,ul m,ul v) {
 }
 
 
+static unsigned long self_ibase;
+#define sym_lvalue(sym_) (!sym_->n_scnum ? self_ibase+sym_->n_value : (unsigned long)start+sym_->n_value)
+
 static void
-relocate(struct scnhdr *sec,struct reloc *rel,struct syment *sym) {
+relocate(struct scnhdr *sec,struct reloc *rel,struct syment *sym,void *start) {
 
-  ul *where=(void *)(sec->s_paddr+rel->r.r_vaddr);
+  ul *where=start+(sec->s_paddr+rel->r.r_vaddr);
 
   switch(rel->r_type) {
 
@@ -126,14 +133,24 @@ relocate(struct scnhdr *sec,struct reloc
   case R_SECREL32:
     break;
 
-  case R_DIR32:
+  case IMAGE_REL_AMD64_ADDR64:
+    add_val(where,~0L,sym_lvalue(sym));
+#if SIZEOF_LONG == 8
+    add_val(where+1,~0L,sym_lvalue(sym)>>32);
+#endif
+    break;
+
+  case IMAGE_REL_AMD64_ADDR32NB:
     add_val(where,~0L,sym->n_value);
-    /* *where+=sym->n_value; */
+    break;
+
+  case R_DIR32:
+    add_val(where,~0L,sym_lvalue(sym));
     break;
 
   case R_PCRLONG:
-    store_val(where,~0L,sym->n_value-(ul)(where+1));
-    /* *where=sym->n_value-(ul)(where+1); */
+  case IMAGE_REL_AMD64_REL32:
+    add_val(where,~0L,(ul)((void *)sym_lvalue(sym)-(void *)(where+1)));
     break;
 
   default:
@@ -150,9 +167,11 @@ find_init_address(struct syment *sym,str
 
   for(;sym<sye;sym++) {
 
-    if (*ptr==0 && sym->n_scnum == 1 && sym->n_value)
-      if (!strncmp(sym->n.n.n_zeroes ? sym->n.n_name : st1+sym->n.n.n_offset,"_init_",6))
+    if (*ptr==0 && sym->n_scnum == 1 && sym->n_value) {
+      char *s=sym->n.n.n_zeroes ? sym->n.n_name : st1+sym->n.n.n_offset;
+      if (!strncmp(s,"init_",5) || !strncmp(s,"_init_",6))
 	*ptr=sym->n_value;
+    }
 
     sym += (sym)->n_numaux;
 
@@ -161,11 +180,11 @@ find_init_address(struct syment *sym,str
 }    
 
 static ul
-get_sym_value(const char *name) {
+get_sym_svalue(const char *name) {
 
   struct node *answ;
 
-  return (answ=find_sym_ptable(name)) ? answ->address :
+  return (answ=find_sym_ptable(name)) ? answ->address-self_ibase :
     ({massert(!emsg("Unrelocated non-local symbol: %s\n",name));0;});
 
 }
@@ -182,7 +201,7 @@ relocate_symbols(struct syment *sym,stru
 
     else if (!sym->n_scnum) {
 
-      NM(sym,st1,s,value=get_sym_value(s));
+      NM(sym,st1,s,value=get_sym_svalue(s));
 
       sym->n_value=value;
 
@@ -195,26 +214,41 @@ relocate_symbols(struct syment *sym,stru
 }
 
 static object
-load_memory(struct scnhdr *sec1,struct scnhdr *sece,void *st) {
+load_memory(struct scnhdr *sec1,struct scnhdr *sece,void *st,ul *init_address) {
 
   object memory;
   struct scnhdr *sec;
-  ul sz;
+  ul sz,a,ma;
 
   BEGIN_NO_INTERRUPT;
 
-  for (sec=sec1,sz=0;sec<sece;sz+=sec->s_size,sec++)
-    if (ALLOC_SEC(sec))
+  for (sec=sec1,ma=sz=0;sec<sece;sec++)
+    if (ALLOC_SEC(sec)) {
+
+      a=1<<(((sec->s_flags>>20)&0xf)-1);
+      massert(a<=8192);
+      ma=ma ? ma : a;
+      sz=(sz+a-1)&~(a-1);
       sec->s_paddr=sz;
+      sz+=sec->s_size;
+
+    }
+
+  ma=ma>sizeof(struct contblock) ? ma-1 : 0;
+  sz+=ma;
 
   memory=new_cfdata();
   memory->cfd.cfd_size=sz;
   memory->cfd.cfd_start=alloc_code_space(sz,-1UL);
 
+  a=(((unsigned long)memory->cfd.cfd_start+ma)&~ma)-((unsigned long)memory->cfd.cfd_start);
+  *init_address+=a;
   for (sec=sec1;sec<sece;sec++) {
-    sec->s_paddr+=(ul)memory->cfd.cfd_start;
-    if (LOAD_SEC(sec))
-      memcpy((void *)sec->s_paddr,st+sec->s_scnptr,sec->s_size);
+    if (ALLOC_SEC(sec)) {
+      sec->s_paddr+=a;
+      if (LOAD_SEC(sec))
+	memcpy((void *)memory->cfd.cfd_start+sec->s_paddr,st+sec->s_scnptr,sec->s_size);
+    }
   }
 
   END_NO_INTERRUPT;
@@ -234,7 +268,8 @@ load_self_symbols() {
   struct opthdr *h;
   struct node *a;
   char *st1,*st;
-  ul ns,sl,jj;
+  ul ns,sl;
+  unsigned long jj;
 
   massert(f=fopen(kcl_self,"r"));
   massert(v1=get_mmap(f,&ve));
@@ -245,7 +280,11 @@ load_self_symbols() {
   fhp=v+4;
   h=(void *)(fhp+1);
   massert(h->h_magic==0x10b || h->h_magic==0x20b);
-  massert(h->h_magic==0x10b || !h->h_dbase); /*We cannot handle a 64bit load address*/
+  self_ibase=h->h_ibase;
+#if SIZEOF_LONG == 8
+  if (h->h_magic==0x20b)
+    self_ibase=(self_ibase<<32)+h->h_dbase;
+#endif
 
   sec1=(void *)(fhp+1)+fhp->f_opthdr;
   sece=sec1+fhp->f_nscns;
@@ -280,7 +319,7 @@ load_self_symbols() {
     NM(sym,st1,s,strcpy(st,s));
     
     sec=sec1+sym->n_scnum-1;
-    jj=sym->n_value+sec->s_vaddr+h->h_ibase;
+    jj=self_ibase+sym->n_value+sec->s_vaddr;
     
 #ifdef FIX_ADDRESS
     FIX_ADDRESS(jj);
@@ -305,7 +344,7 @@ load_self_symbols() {
     NM(sym,st1,s,strcpy(st,s));
 
     sec=sec1+sym->n_scnum-1;
-    jj=sym->n_value+sec->s_vaddr+h->h_ibase;
+    jj=self_ibase+sym->n_value+sec->s_vaddr;
 
 #ifdef FIX_ADDRESS
     FIX_ADDRESS(jj);
@@ -410,7 +449,7 @@ fasload(object faslfile) {
   struct scnhdr *sec1,*sec,*sece;
   struct syment *sy1,*sye;
   struct reloc *rel,*rele;
-  object memory, data;
+  object memory;
   FILE *fp;
   char *st1,*ste;
   int i;
@@ -431,14 +470,14 @@ fasload(object faslfile) {
 
   find_init_address(sy1,sye,&init_address,st1);
 	
-  memory=load_memory(sec1,sece,st);
+  memory=load_memory(sec1,sece,st,&init_address);
 
   relocate_symbols(sy1,sye,sec1,st1);  
 	
   for (sec=sec1;sec<sece;sec++)
     if (sec->s_flags&0xe0)
       for (rel=st+sec->s_relptr,rele=rel+(sec->s_flags&0x1000000 ? rel->r.r_count : sec->s_nreloc);rel<rele;rel++)
-	relocate(sec,rel,sy1+rel->r_symndx);
+	relocate(sec,rel,sy1+rel->r_symndx,memory->cfd.cfd_start);
   
   fseek(fp,(void *)ste-st,0);
   while ((i = getc(fp)) == 0);
--- gcl-2.6.12.orig/o/unexnt.c
+++ gcl-2.6.12/o/unexnt.c
@@ -208,18 +208,21 @@ _start (void)
 }
 #endif /* UNIXSAVE */
 
+#ifdef __CYGWIN__
+#include <sys/cygwin.h>
+#endif
+
 /* Dump out .data and .bss sections into a new executable.  */
 void
 unexec (char *new_name, char *old_name, void *start_data, void *start_bss,
 	void *entry_address)
 {
-#ifdef __CYGWIN32__
+#ifdef __CYGWIN__
   static file_data in_file, out_file;
   char out_filename[MAX_PATH], in_filename[MAX_PATH];
   char filename[MAX_PATH];
   unsigned long size;
   char *ptr;
-  extern void cygwin_conv_to_full_win32_path(char *,char *);
 
   fflush (stdin);
   /* copy_stdin = *stdin; */
@@ -238,11 +241,11 @@ unexec (char *new_name, char *old_name,
   ptr = old_name + strlen (old_name) - 4;
   strcpy(filename, old_name);
   strcat(filename, (strcmp (ptr, ".exe") && strcmp (ptr, ".EXE"))?".exe":"");
-  cygwin_conv_to_full_win32_path(filename,in_filename);
+  cygwin_conv_path(CCP_POSIX_TO_WIN_A,filename,in_filename,sizeof(in_filename));
   ptr = new_name + strlen (new_name) - 4;
   strcpy(filename, new_name);
   strcat(filename, (strcmp (ptr, ".exe") && strcmp (ptr, ".EXE"))?".exe":"");
-  cygwin_conv_to_full_win32_path(filename,out_filename);
+  cygwin_conv_path(CCP_POSIX_TO_WIN_A,filename,out_filename,sizeof(out_filename));
 #else 
   static file_data in_file, out_file;
   char out_filename[MAX_PATH], in_filename[MAX_PATH];
@@ -282,8 +285,8 @@ unexec (char *new_name, char *old_name,
   /* Open the undumped executable file.  */
   if (!open_input_file (&in_file, in_filename))
     {
-      printf ("Failed to open %s (%ld)...bailing.\n", 
-	      in_filename, GetLastError ());
+      printf ("Failed to open %s (%u)...bailing.\n",
+	      in_filename, (unsigned)GetLastError ());
       do_gcl_abort();
     }
 
@@ -303,8 +306,8 @@ unexec (char *new_name, char *old_name,
   size = heap_index_in_executable + get_committed_heap_size () + bss_size;
   if (!open_output_file (&out_file, out_filename, size))
     {
-      printf ("Failed to open %s (%ld)...bailing.\n", 
-	      out_filename, GetLastError ());
+      printf ("Failed to open %s (%u)...bailing.\n",
+	      out_filename, (unsigned)GetLastError ());
       do_gcl_abort();
     }
 
@@ -367,7 +370,7 @@ open_input_file (file_data *p_file, char
 
   file = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL,
 		     OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
-  if (file == INVALID_HANDLE_VALUE) 
+  if (file == INVALID_HANDLE_VALUE)
     return FALSE;
 
   size = GetFileSize (file, &upper_size);
@@ -548,8 +551,8 @@ get_section_info (file_data *p_infile)
   /* Check the NT header signature ...  */
   if (nt_header->Signature != IMAGE_NT_SIGNATURE) 
     {
-      printf ("Invalid IMAGE_NT_SIGNATURE 0x%lx in %s...bailing.\n",
-	      nt_header->Signature, p_infile->name);
+      printf ("Invalid IMAGE_NT_SIGNATURE 0x%x in %s...bailing.\n",
+	      (int)nt_header->Signature, p_infile->name);
     }
 
   /* Flip through the sections for .data and .bss ...  */
@@ -657,7 +660,7 @@ copy_executable_and_dump_data_section (f
   /* Get a pointer to the raw data in our address space.  */
   data_va = data_start_va;
     
-  size = (DWORD) data_file - (DWORD) p_outfile->file_base;
+  size = (unsigned long) data_file - (unsigned long) p_outfile->file_base;
   /* printf ("Copying executable up to data section...\n"); */
   /* printf ("\t0x%08x Offset in input file.\n", 0); */
   /* printf ("\t0x%08x Offset in output file.\n", 0); */
@@ -672,7 +675,7 @@ copy_executable_and_dump_data_section (f
   /* printf ("\t0x%08lx Size in bytes.\n", size); */
   memcpy (data_file, data_va, size);
   
-  index = (DWORD) data_file + size - (DWORD) p_outfile->file_base;
+  index = (unsigned long) data_file + size - (unsigned long) p_outfile->file_base;
   size = p_infile->size - index;
   /* printf ("Copying rest of executable...\n"); */
   /* printf ("\t0x%08lx Offset in input file.\n", index); */
@@ -780,7 +783,7 @@ map_in_heap (char *filename)
     }
     
   size = get_committed_heap_size ();
-  file_base = MapViewOfFileEx (file_mapping, FILE_MAP_COPY|FILE_MAP_EXECUTE, 0,
+  file_base = MapViewOfFileEx (file_mapping, FILE_MAP_ALL_ACCESS, 0,
 			       heap_index_in_executable, size,
 			       get_heap_start ());
   if (file_base != 0) 
@@ -794,7 +797,7 @@ map_in_heap (char *filename)
   CloseHandle (file_mapping);
 
   if (VirtualAlloc (get_heap_start (), get_committed_heap_size (),
-		    MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE) == NULL)
+		    MEM_COMMIT, PAGE_EXECUTE_READWRITE) == NULL)
     {
       i = GetLastError ();
       do_gcl_abort();
@@ -922,13 +925,22 @@ get_data_end (void)
   return data_region_end;
 }
 
+void *
+probe_base(void *base,unsigned long try,unsigned long inc,unsigned long c) {
+  void *r;
+  if (!(r=VirtualAlloc(base,try,MEM_RESERVE,PAGE_NOACCESS)))
+    return probe_base(base+inc,try,inc,c+1);
+  VirtualFree (r, 0, MEM_RELEASE);
+  return !c || inc<2 ? base : probe_base(base-inc,try,inc>>1,c+1);
+}
+
 unsigned long
-probe_heap_size(void *base,unsigned long try,unsigned long inc,unsigned long max) {
+probe_heap_size(void *base,unsigned long try,unsigned long inc) {
   void *r;
   if (!(r=VirtualAlloc(base,try,MEM_RESERVE,PAGE_NOACCESS)))
-    return try>inc ? probe_heap_size(base,try-inc,inc>>1,max) : 0;
+    return inc<2 ? try-inc : probe_heap_size(base,try-inc,inc>>1);
   VirtualFree (r, 0, MEM_RELEASE);
-  return (!inc || try >=max) ? try : probe_heap_size(base,try+inc,inc,max);
+  return probe_heap_size(base,try+inc,inc);
 }
 
 static char *
@@ -970,17 +982,16 @@ allocate_heap (void)
      the region below the 256MB line for our malloc arena - 229MB is
      still a pretty decent arena to play in!  */
 
+  void *base,*ptr;
+  unsigned long min=PAGESIZE,inc=(1UL<<31);
+
 #if defined(__CYGWIN__)
-#define PROBE_BASE NULL
-#elif defined(__MINGW32__)
-#define PROBE_BASE (void *)0x20000000
+  ptr=my_endbss;
 #else
-#error Need PROBE_BASE
+  ptr=(void *)0x5000000;
 #endif
-
-  void *base = PROBE_BASE,*ptr;/*FIXME, someday figure out how to let the heap start address default *//*(void *)0x10100000*/
-
-  reserved_heap_size=probe_heap_size(base,PAGESIZE,(1UL<<31),-1);
+  base=probe_base(ptr,min,(unsigned long)my_endbss,0);
+  reserved_heap_size=probe_heap_size(base,inc+min,inc);
   ptr = VirtualAlloc ((void *) base,get_reserved_heap_size (),MEM_RESERVE,PAGE_NOACCESS);
   /* printf("probe results: %lu at %p\n",reserved_heap_size,ptr); */
 
@@ -1085,8 +1096,8 @@ recreate_heap (char *executable_path) {
   /* First reserve the upper part of our heap.  (We reserve first
      because there have been problems in the past where doing the
      mapping first has loaded DLLs into the VA space of our heap.)  */
-  tmp = VirtualAlloc ((void *) get_heap_end (),
-		      get_reserved_heap_size () - get_committed_heap_size (),
+  tmp = VirtualAlloc ((void *) get_heap_start (),
+		      get_reserved_heap_size (),
 		      MEM_RESERVE,
 		      PAGE_NOACCESS);
   if (!tmp)
--- gcl-2.6.12.orig/o/unixfsys.c
+++ gcl-2.6.12/o/unixfsys.c
@@ -69,6 +69,7 @@ coerce_to_filename1(object spec, char *p
 
   object namestring=get_string(spec);
 
+  massert(type_of(namestring)==t_string);
   massert(namestring->st.st_fillp<sz);
   memcpy(p,namestring->st.st_self,namestring->st.st_fillp);
   p[namestring->st.st_fillp]=0;
@@ -76,7 +77,7 @@ coerce_to_filename1(object spec, char *p
 }
 
 #ifndef __MINGW32__
-static char GETPW_BUF[4096];
+static char GETPW_BUF[16384];
 #endif
 
 DEFUN_NEW("UID-TO-NAME",object,fSuid_to_name,SI,1,1,NONE,OI,OO,OO,OO,(fixnum uid),"") {
@@ -204,7 +205,7 @@ stat_internal(object x,struct stat *ssp)
     if (lstat(FN1,ssp))
       return 0;
   } else if ((x=file_stream(x))!=Cnil&&x->sm.sm_fp) {
-    if (fstat(fileno(x->sm.sm_fp),ssp))
+    if (fstat(fileno((FILE *)x->sm.sm_fp),ssp))
       return 0;
   } else
     return 0;
--- gcl-2.6.12.orig/o/unixsys.c
+++ gcl-2.6.12/o/unixsys.c
@@ -30,7 +30,7 @@ Foundation, 675 Mass Ave, Cambridge, MA
 
 #include "include.h"
 
-#ifndef __MINGW32__
+#if !defined(__MINGW32__) && !defined(__CYGWIN__)
 
 int
 vsystem(const char *command) {
@@ -58,7 +58,7 @@ vsystem(const char *command) {
 
   }
 
-  if (!(pid=vfork())) {
+  if (!(pid=pvfork())) {
     errno=0;
     execvp(*p1,(void *)p1);
     _exit(128|(errno&0x7f));
@@ -73,6 +73,40 @@ vsystem(const char *command) {
   return s;
 
 }
+#elif defined(__CYGWIN__)
+
+#include <tchar.h>
+#include <time.h>
+#include <windows.h>
+#include <sys/cygwin.h>
+
+int
+vsystem(const char *command) {
+
+  STARTUPINFO s={0};
+  PROCESS_INFORMATION p={0};
+  unsigned int e;
+  char *cmd=NULL,*r;
+
+  massert((r=strpbrk(command," \n\t"))-command<sizeof(FN2));
+  memcpy(FN2,command,r-command);
+  FN2[r-command]=0;
+  cygwin_conv_path(CCP_POSIX_TO_WIN_A,FN2,FN3,sizeof(FN3));
+  massert(snprintf(FN1,sizeof(FN1),"%s %s",FN3,r)>=0);
+  command=FN1;
+
+
+  s.cb=sizeof(s);
+  massert(CreateProcess(cmd,(void *)command,NULL,NULL,FALSE,0,NULL,NULL,&s,&p));
+  massert(!WaitForSingleObject(p.hProcess,INFINITE));
+  massert(GetExitCodeProcess(p.hProcess,&e));
+  massert(CloseHandle(p.hProcess));
+  massert(CloseHandle(p.hThread));
+
+  return e;
+
+}
+
 #endif
 
 
--- gcl-2.6.12.orig/o/unixtime.c
+++ gcl-2.6.12/o/unixtime.c
@@ -59,7 +59,9 @@ which is usually 60 maybe 100 or somethi
 #    include <sys/timeb.h>
 
 static struct timeb t0;
-int usleep ( unsigned int microseconds );
+int usleep1 ( unsigned int microseconds );
+#undef usleep
+#define usleep(x) usleep1(x)
 
 #  endif
 
@@ -252,7 +254,7 @@ gcl_init_unixtime(void) {
 }
 
 #ifdef __MINGW32__
-int usleep ( unsigned int microseconds )
+int usleep1 ( unsigned int microseconds )
 {
     unsigned int milliseconds = microseconds / 1000;
     return ( SleepEx ( milliseconds, TRUE ) );
@@ -280,7 +282,7 @@ DEFUN_NEW("CURRENT-TIMEZONE",object,fScu
   fixnum _t=time(0);
   gmtime_r(&_t, &gt);
   localtime_r(&_t, &lt);
-  return (object)(gt.tm_hour-lt.tm_hour+24*(gt.tm_yday!=lt.tm_yday ? (gt.tm_year>lt.tm_year||gt.tm_yday>lt.tm_yday ? 1 : -1) : 0));
+  return (object)(long)(gt.tm_hour-lt.tm_hour+24*(gt.tm_yday!=lt.tm_yday ? (gt.tm_year>lt.tm_year||gt.tm_yday>lt.tm_yday ? 1 : -1) : 0));
 #else
   time_t _t=time(0);
   return (object)(-localtime(&_t)->tm_gmtoff/3600);
--- gcl-2.6.12.orig/o/usig.c
+++ gcl-2.6.12/o/usig.c
@@ -224,14 +224,14 @@ DEFUN_NEW("FPE_CODE",object,fSfpe_code,S
 #if defined(__MINGW32__) || defined(__CYGWIN__)
 
 DEFUN_NEW("FNSTSW",object,fSfnstsw,SI,0,0,NONE,II,OO,OO,OO,(void),"") {
-  volatile unsigned short t;
+  volatile unsigned short t=0;
   ASM ("fnstsw %0" :: "m" (t));
-  RETURN1((object)t);
+  RETURN1((object)(long)t);
 }
 DEFUN_NEW("STMXCSR",object,fSstmxcsr,SI,0,0,NONE,II,OO,OO,OO,(void),"") {
-  volatile unsigned int t;
+  volatile unsigned int t=0;
   ASM ("stmxcsr %0" :: "m" (t));
-  RETURN1((object)t);
+  RETURN1((object)(long)t);
 }
 
 #endif
