1
0
Fork 0

added FileStat and FileExits to the drives

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@110
This commit is contained in:
Peter Veenstra 2002-08-06 09:19:56 +00:00
parent a4c775bff4
commit 1b31218f2b
3 changed files with 61 additions and 3 deletions

View file

@ -187,6 +187,7 @@ bool localDrive::RemoveDir(char * dir) {
char newdir[512];
strcpy(newdir,basedir);
strcat(newdir,dir);
CROSS_FILENAME(newdir);
int temp=rmdir(newdir);
return (temp==0);
}
@ -195,6 +196,7 @@ bool localDrive::TestDir(char * dir) {
char newdir[512];
strcpy(newdir,basedir);
strcat(newdir,dir);
CROSS_FILENAME(newdir);
int temp=access(newdir,F_OK);
return (temp==0);
}
@ -206,8 +208,8 @@ bool localDrive::Rename(char * oldname,char * newname) {
CROSS_FILENAME(newold);
char newnew[512];
strcpy(newnew,basedir);
strcat(newnew,newnew);
CROSS_FILENAME(newname);
strcat(newnew,newname);
CROSS_FILENAME(newnew);
int temp=rename(newold,newnew);
return (temp==0);
@ -223,6 +225,28 @@ bool localDrive::FreeSpace(Bit16u * bytes,Bit16u * sectors,Bit16u * clusters,Bit
return true;
};
bool localDrive::FileExists(const char* name) const {
char newname[512];
strcpy(newname,basedir);
strcat(newname,name);
CROSS_FILENAME(newname);
FILE* Temp=fopen(newname,"br");
if(Temp==NULL) return false;
fclose(Temp);
return true;
}
bool localDrive::FileStat(const char* name, struct stat* const stat_block) const {
char newname[512];
strcpy(newname,basedir);
strcat(newname,name);
CROSS_FILENAME(newname);
if(stat(newname,stat_block)!=0) return false;
return true;
}
localDrive::localDrive(char * startdir) {
strcpy(basedir,startdir);
@ -275,3 +299,4 @@ localFile::localFile(FILE * handle,Bit16u devinfo) {
info=devinfo;
}

View file

@ -19,10 +19,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "dosbox.h"
#include "dos_system.h"
#include "drives.h"
#include "support.h"
#include "cross.h"
struct VFILE_Block {
char * name;
@ -151,6 +153,32 @@ bool Virtual_Drive::TestDir(char * dir) {
return false;
}
bool Virtual_Drive::FileStat(const char* name, struct stat* const stat_block) const {
VFILE_Block * cur_file=first_file;
while (cur_file) {
if (strcasecmp(name,cur_file->name)==0) {
stat_block->st_size=cur_file->size;
struct tm tijd;
tijd.tm_hour=0;tijd.tm_min=0;tijd.tm_sec=0;
tijd.tm_year=80;tijd.tm_mday=6;tijd.tm_mon=0;
stat_block->st_mtime=mktime(&tijd);
/* more not needed at the moment (fcbopen.....)*/
return true;
}
cur_file=cur_file->next;
}
return false;
}
bool Virtual_Drive::FileExists(const char* name) const {
VFILE_Block * cur_file=first_file;
while (cur_file) {
if (strcasecmp(name,cur_file->name)==0) return true;
cur_file=cur_file->next;
}
return false;
}
static void FillDTABlock(DTA_FindBlock * dta,VFILE_Block * fill_file) {
strcpy(dta->name,fill_file->name);
dta->size=fill_file->size;

View file

@ -21,7 +21,7 @@
#include <sys/types.h>
#include <dirent.h>
#include "dos_system.h"
class localDrive : public DOS_Drive {
public:
@ -37,6 +37,8 @@ public:
bool GetFileAttr(char * name,Bit16u * attr);
bool Rename(char * oldname,char * newname);
bool FreeSpace(Bit16u * bytes,Bit16u * sectors,Bit16u * clusters,Bit16u * free);
bool FileExists(const char* name) const ;
bool FileStat(const char* name, struct stat* const stat_block) const;
private:
bool FillDTABlock(DTA_FindBlock * dta);
char basedir[512];
@ -63,6 +65,9 @@ public:
bool GetFileAttr(char * name,Bit16u * attr);
bool Rename(char * oldname,char * newname);
bool FreeSpace(Bit16u * bytes,Bit16u * sectors,Bit16u * clusters,Bit16u * free);
bool FileExists(const char* name) const ;
bool FileStat(const char* name, struct stat* const stat_block) const;
private:
VFILE_Block * search_file;
char search_string[255];