X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=nucleus%2Flibrary%2Ffilesystem%2Fbyte_filer.cpp;h=e091996b2aed96f01bcd3be1574020f940f6727a;hb=ef338226ccf699c8d8a149d9b74e9888175c7099;hp=7aa05d78d2ce1b38440942007392bda4e39cbc2d;hpb=457b128b77b5b4a0b7dd3094de543de2ce1477ad;p=feisty_meow.git diff --git a/nucleus/library/filesystem/byte_filer.cpp b/nucleus/library/filesystem/byte_filer.cpp index 7aa05d78..e091996b 100644 --- a/nucleus/library/filesystem/byte_filer.cpp +++ b/nucleus/library/filesystem/byte_filer.cpp @@ -29,7 +29,7 @@ #include #endif -//#define DEBUG_BYTE_FILER +#define DEBUG_BYTE_FILER // uncomment for noisy version of class. using namespace basis; @@ -44,32 +44,32 @@ class file_hider public: FILE *fp; // the real file pointer. - file_hider() : fp(NIL) {} + file_hider() : fp(NULL_POINTER) {} }; ////////////// byte_filer::byte_filer() : _handle(new file_hider), - _filename(new astring), + _filename(new filename), _auto_close(true) {} -byte_filer::byte_filer(const astring &filename, const astring &perms) +byte_filer::byte_filer(const astring &fname, const astring &perms) : _handle(new file_hider), - _filename(new astring), + _filename(new filename), _auto_close(true) -{ open(filename, perms); } +{ open(fname, perms); } -byte_filer::byte_filer(const char *filename, const char *perms) +byte_filer::byte_filer(const char *fname, const char *perms) : _handle(new file_hider), - _filename(new astring), + _filename(new filename), _auto_close(true) -{ open(filename, perms); } +{ open(fname, perms); } byte_filer::byte_filer(bool auto_close, void *handle) : _handle(new file_hider), - _filename(new astring), + _filename(new filename), _auto_close(auto_close) { if (handle) { @@ -79,36 +79,25 @@ byte_filer::byte_filer(bool auto_close, void *handle) byte_filer::~byte_filer() { close(); WHACK(_handle); WHACK(_filename); } -astring byte_filer::filename() const { return *_filename; } +const astring &byte_filer::name() const { return _filename->raw(); } size_t byte_filer::file_size_limit() { return BTFL_FILE_TELL_LIMIT; } -bool byte_filer::open(const astring &filename, const astring &perms) +bool byte_filer::open(const astring &fname, const astring &perms) { close(); _auto_close = true; // reset since we know we're opening this. - *_filename = filename; -#ifndef __WIN32__ - _handle->fp = filename.t()? fopen(filename.s(), perms.s()) : NIL; -#else - _handle->fp = filename.t()? _wfopen((wchar_t *)(UTF16 *)transcode_to_utf16(filename), - (wchar_t *)(UTF16 *)transcode_to_utf16(perms)) : NIL; - -#ifdef DEBUG_BYTE_FILER - if (!_handle->fp) - wprintf((wchar_t *)(UTF16 *)transcode_to_utf16("could not open: %ls\n"), - (wchar_t *)(UTF16 *)transcode_to_utf16(filename)); -#endif - -#endif + _filename->reset(fname); + _handle->fp = _filename->raw().t()? fopen(_filename->raw().s(), perms.s()) : NULL_POINTER; + if (_handle->fp == NULL_POINTER) return false; return good(); } void byte_filer::close() { - *_filename = ""; + _filename->reset(""); if (_auto_close && _handle->fp) fclose(_handle->fp); - _handle->fp = NIL; + _handle->fp = NULL_POINTER; } bool byte_filer::good() { return !!_handle->fp; }