#include "nonstd_stdio.h" #if defined _WIN32 && !defined SHP //tu nie trzeba includów zeby dzialal unlink() #else #include #endif bool fileExists(const char* path) { //lepiej gdyby uzywalo stat bo mfopen mogloby cos niepotrzebnie wczytywac przy otwarciu pliku ale mfopen wiadomo ze zadziala wszedzie tak samo MFILE *f=mfopen(path,"r"); if (f==NULL) return false; mfclose(f); return true; } bool removeFile(const char* path) { return unlink(path)==0; //VS: "The POSIX name is deprecated. Instead, use the ISO C++ conformant name: _unlink" } #if defined SHP && defined BADA_API_1 MFILE *mfopen(const char*path, const char*mode) { Osp::Io::File *f = new Osp::Io::File(); result r = f->Construct(path, mode); if (IsFailed(r)) { delete f; f = NULL; } return f; } void mfclose(MFILE *f) { delete f; } int mfread(void *ptr, int size, int count, MFILE *f) { int bytes = size * count; int przeczytane = f->Read(ptr, bytes); return przeczytane != bytes ? przeczytane / size : count; } int mfwrite(const void *ptr, int size, int count, MFILE *f) { result r = f->Write(ptr, size * count); if (IsFailed(r)) return 0; //nie mozemy wykryc jesli udalo sie zapisac część else return count; } int mfputs(const char *txt, MFILE *f) { int len = strlen(txt); int res = mfwrite(txt, len, 1, f); return res == 1 ? 1 : EOF; } char* mfgets(char *str, int num, MFILE *f) { bool err = false; int przeczytane = 0; num--; //zeby zawsze zostalo miejsce na wpisanie konczącego NULL do { err = f->Read(str, 1) != 1; if (!err) { str++; przeczytane++; } } while (!err && przeczytaneTell(); int przeczytane = f->Read(&buf, 1); f->Seek(Osp::Io::FILESEEKPOSITION_BEGIN,pos); return przeczytane == 1 ? 0 : 1; } int mfseek(MFILE *f, long position, int type) { result r; if (type == SEEK_SET) r = f->Seek(Osp::Io::FILESEEKPOSITION_BEGIN, position); else if (type == SEEK_CUR) r = f->Seek(Osp::Io::FILESEEKPOSITION_CURRENT, position); else if (type == SEEK_END) r = f->Seek(Osp::Io::FILESEEKPOSITION_END, position); else return 1; return IsFailed(r) ? 1 : 0; } long mftell(MFILE *f) { return f->Tell(); } #endif