Add FileIO::exists() function

This commit is contained in:
baldurk
2017-05-01 14:20:21 +01:00
parent f22d38bc63
commit 478f22559c
3 changed files with 20 additions and 0 deletions
+2
View File
@@ -252,6 +252,8 @@ FILE *fopen(const char *filename, const char *mode);
size_t fread(void *buf, size_t elementSize, size_t count, FILE *f);
size_t fwrite(const void *buf, size_t elementSize, size_t count, FILE *f);
bool exists(const char *filename);
std::string getline(FILE *f);
uint64_t ftell64(FILE *f);
+8
View File
@@ -373,6 +373,14 @@ int fclose(FILE *f)
return ::fclose(f);
}
bool exists(const char *filename)
{
struct ::stat st;
int res = stat(filename, &st);
return (res == 0);
}
void *logfile_open(const char *filename)
{
int fd = open(filename, O_APPEND | O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+10
View File
@@ -466,6 +466,16 @@ FILE *fopen(const char *filename, const char *mode)
return ret;
}
bool exists(const char *filename)
{
wstring wfn = StringFormat::UTF82Wide(filename);
struct _stat st;
int res = _wstat(wfn.c_str(), &st);
return (res == 0);
}
string getline(FILE *f)
{
string ret;