To: [email protected]
Subject: patch 5.4o.9
Fcc: outbox
From: Bram Moolenaar <[email protected]>
------------

This patch only applies to the DOS and Windows versions.  And then only to the
installation program.


Patch 5.4o.9
Problem:    The DOS install.exe program used the "move" program.  That doesn't
           work on Windows NT, where "move" is internal to cmd.exe.
Solution:   Don't use an external program for moving the executables.  Use C
           functions to copy the file and delete the original.
Files:      src/dosinst.c


*** ../vim-5.4o/src/dosinst.c   Sun Jul 11 20:10:44 1999
--- src/dosinst.c       Fri Jul 16 16:06:19 1999
***************
*** 12,23 ****
--- 12,25 ----
  * Compile with Makefile.bcc or Makefile.djg.
  */

+ #include <io.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
 #include <string.h>
 #include <direct.h>
 #include <sys/stat.h>
+ #include <fcntl.h>
 #ifdef WIN32
 # include <windows.h>
 #else
***************
*** 32,38 ****
 #define NUL 0

 /*
!  * Return TRUE if the the user types a 'y' or 'Y', FALSE otherwise.
  */
     int
 confirm(void)
--- 34,50 ----
 #define NUL 0

 /*
!  * EMX doesn't have a global way of making open() use binary I/O.
!  * Use O_BINARY for all open() calls.
!  */
! #if defined(__EMX__) || defined(__CYGWIN32__)
! # define O_EXTRA    O_BINARY
! #else
! # define O_EXTRA    0
! #endif
!
! /*
!  * Return TRUE if the user types a 'y' or 'Y', FALSE otherwise.
  */
     int
 confirm(void)
***************
*** 291,313 ****
 #endif

 /*
!  * Move a file to another directory.
  */
     void
 move_file(char *fname, char *dir)
 {
     struct stat       st;
!     char      cmd[1000];

     /* if the file doesn't exist, silently skip it */
     if (stat(fname, &st) < 0)
       return;

!     sprintf(cmd, "move %s %s", fname, dir);
!     system(cmd);

!     if (stat(fname, &st) >= 0)
       printf("ERROR: Moving \"%s\" to \"%s\" failed\n", fname, dir);
 }

 /*
--- 303,366 ----
 #endif

 /*
!  * Move file "fname" to directory "dir".
!  * We actually copy the file and then delete the original, to avoid depending
!  * on an external program.
  */
     void
 move_file(char *fname, char *dir)
 {
     struct stat       st;
!     char      new_name[256];
! #define COPYBUFSIZE 4096
!     char      *buf;
!     long      len;
!     int               fdr, fdw;
! #ifndef __MINGW32__
!     extern int        _fmode;
! #endif

     /* if the file doesn't exist, silently skip it */
     if (stat(fname, &st) < 0)
       return;

!     buf = malloc(COPYBUFSIZE);
!     if (buf == NULL)
!     {
!       printf("ERROR: Out of memory!\n");
!       return;
!     }
!
!     _fmode = O_BINARY;            /* Use binary I/O */
!
!     /* make the destination file name: "dir\fname" */
!     strcpy(new_name, dir);
!     if (dir[strlen(dir) - 1] != '\\' && dir[strlen(dir) - 1] != '/')
!       strcat(new_name, "\\");
!     strcat(new_name, fname);

!     fdr = open(fname, O_RDONLY | O_EXTRA, 0);
!     if (fdr >= 0)
!     {
!       fdw = open(new_name, O_WRONLY|O_CREAT|O_TRUNC|O_EXTRA, 0777);
!       if (fdw >= 0)
!       {
!           /* copy the file. */
!           while ((len = read(fdr, buf, COPYBUFSIZE)) > 0)
!               if (write(fdw, buf, len) != len)
!                   break;
!           close(fdw);
!       }
!       close(fdr);
!     }
!     if (fdr < 0 || fdw < 0 || len > 0 || len < 0)
       printf("ERROR: Moving \"%s\" to \"%s\" failed\n", fname, dir);
+     else
+     {
+       printf("%s moved to %s\n", fname, new_name);
+       unlink(fname);
+     }
+     free(buf);
 }

 /*
***************
*** 422,427 ****
--- 475,488 ----
     int               i;
     char      *p;
     int               vimdirend;
+
+ #ifdef DJGPP
+     /*
+      * Use Long File Names by default, if $LFN not set.
+      */
+     if (getenv("LFN") == NULL)
+       putenv("LFN=y");
+ #endif

     printf("This program sets up the installation of Vim %s\n\n",
           VIM_VERSION_MEDIUM);

--
hundred-and-one symptoms of being an internet addict:
127. You bring your laptop and cellular phone to church.

--/-/---- Bram Moolenaar ---- [email protected] ---- [email protected] ---\-\--
 \ \    www.vim.org/iccf      www.moolenaar.net       www.vim.org    / /