From c26a547cde8953f85f7aba770c8d2200762a8e05 Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Mon, 29 Dec 2003 22:42:23 +0000 Subject: [PATCH] Added Some warning concerning writeprotection Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@1504 --- src/dos/drive_local.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/dos/drive_local.cpp b/src/dos/drive_local.cpp index b2c14279..5e312116 100644 --- a/src/dos/drive_local.cpp +++ b/src/dos/drive_local.cpp @@ -16,6 +16,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* $Id: drive_local.cpp,v 1.41 2003-12-29 22:42:23 qbix79 Exp $ */ + #include #include #include @@ -51,7 +53,11 @@ bool localDrive::FileCreate(DOS_File * * file,char * name,Bit16u attributes) { strcat(newname,name); CROSS_FILENAME(newname); FILE * hand=fopen(dirCache.GetExpandName(newname),"wb+"); - if (!hand) return false; + if (!hand){ + LOG_MSG("Warning: file creation failed: %s",newname); + return false; + } + dirCache.AddEntry(newname, true); /* Make the 16 bit device information */ *file=new localFile(name,hand,0x202); @@ -79,7 +85,17 @@ bool localDrive::FileOpen(DOS_File * * file,char * name,Bit32u flags) { FILE * hand=fopen(newname,type); // Bit32u err=errno; - if (!hand) return false; + if (!hand) { + if((flags&3) != OPEN_READ) { + FILE * hmm=fopen(newname,"rb"); + if (hmm) { + fclose(hmm); + LOG_MSG("Warning: file %s exists and failed to open in write mode.\nPlease Remove write-protection",newname); + } + } + return false; + } + *file=new localFile(name,hand,0x202); (*file)->flags=flags; //for the inheritance flag and maybe check for others. // (*file)->SetFileName(newname); @@ -100,7 +116,7 @@ bool localDrive::FileUnlink(char * name) { bool localDrive::FindFirst(char * _dir,DOS_DTA & dta) { - + char tempDir[CROSS_LEN]; strcpy(tempDir,basedir); strcat(tempDir,_dir); @@ -132,7 +148,7 @@ bool localDrive::FindFirst(char * _dir,DOS_DTA & dta) { } bool localDrive::FindNext(DOS_DTA & dta) { - + char * dir_ent; struct stat stat_block; char full_name[CROSS_LEN]; @@ -376,7 +392,6 @@ bool localFile::Seek(Bit32u * pos,Bit32u type) { } bool localFile::Close() { - // only close if one reference left if (refCtr==1) { fclose(fhandle);