From 2a83b111c40f44319efb0856f75c2d3f84d4c9ff Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Mon, 16 Jun 2003 13:33:40 +0000 Subject: [PATCH] Check if source and destination are identical before copying. git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@607 6ac86273-5f31-0410-b378-82cca8765d1b --- sys/sys.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/sys/sys.c b/sys/sys.c index 0538c06..9ffadca 100644 --- a/sys/sys.c +++ b/sys/sys.c @@ -35,7 +35,7 @@ #define DEBUG /* #define DDEBUG */ -#define SYS_VERSION "v2.5" +#define SYS_VERSION "v2.6" #include #include @@ -106,7 +106,9 @@ int stat(const char *file_name, struct stat *buf) return _dos_findfirst(file_name, _A_NORMAL | _A_HIDDEN | _A_SYSTEM, &find_tbuf); } -#endif + +/* WATCOM's getenv is case-insensitive which wastes a lot of space + for our purposes. So here's a simple case-sensitive one */ char *getenv(const char *name) { char **envp, *ep; @@ -127,6 +129,7 @@ char *getenv(const char *name) } return NULL; } +#endif BYTE pgm[] = "SYS"; @@ -314,7 +317,7 @@ int main(int argc, char **argv) } printf("\nCopying KERNEL.SYS...\n"); - if (!copy(drive, srcPath, rootPath, "kernel.sys")) + if (!copy(drive, srcPath, rootPath, "KERNEL.SYS")) { printf("\n%s: cannot copy \"KERNEL.SYS\"\n", pgm); exit(1); @@ -423,6 +426,11 @@ void reset_drive(int DosDrive); parm [dx] \ modify [ax bx]; +void truename(char far *dest, const char *src); +#pragma aux truename = \ + "mov ah,0x60" \ + "int 0x21" \ + parm [es di] [si]; #else #ifndef __TURBOC__ @@ -473,6 +481,19 @@ void reset_drive(int DosDrive) intdos(®s, ®s); } /* reset_drive */ +void truename(char *dest, const char *src) +{ + union REGS regs; + struct SREGS sregs; + + regs.h.ah = 0x60; + sregs.es = FP_SEG(dest); + regs.x.di = FP_OFF(dest); + sregs.ds = FP_SEG(src); + regs.x.si = FP_OFF(src); + intdosx(®s, ®s, &sregs); +} /* reset_drive */ + #endif int MyAbsReadWrite(int DosDrive, int count, ULONG sector, void *buffer, @@ -807,13 +828,12 @@ BYTE copybuffer[COPY_SIZE]; BOOL copy(COUNT drive, BYTE * srcPath, BYTE * rootPath, BYTE * file) { - BYTE dest[SYS_MAXPATH], source[SYS_MAXPATH]; + static BYTE dest[SYS_MAXPATH], source[SYS_MAXPATH]; unsigned ret; int fdin, fdout; ULONG copied = 0; struct stat fstatbuf; - sprintf(dest, "%c:\\%s", 'A' + drive, file); strcpy(source, srcPath); if (rootPath != NULL) /* trick for comspec */ strcat(source, file); @@ -836,6 +856,16 @@ BOOL copy(COUNT drive, BYTE * srcPath, BYTE * rootPath, BYTE * file) return FALSE; } + truename(dest, source); + strcpy(source, dest); + sprintf(dest, "%c:\\%s", 'A' + drive, file); + if (strcmp(source, dest) == 0) + { + printf("%s: source and destination are identical: skipping \"%s\"\n", + pgm, source); + return TRUE; + } + if ((fdin = open(source, O_RDONLY | O_BINARY)) < 0) { printf("%s: failed to open \"%s\"\n", pgm, source);