Ignore:
Timestamp:
28/03/2008 22:18:44 (4 years ago)
Author:
chris
Message:

Improve logging with macros that consistently output strerror(errno) and
errno, replacing almost all use of strerror() in the main code.

Log a more detailed error message before throwing an exception for some
more system call failures.

Make FileStream? store its filename on all platforms, not just Windows.

Wrap some long lines at less than 80 characters to improve readability.

Fix some minor violations of coding standard (white space) and a typo
in a comment.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/lib/common/FileStream.cpp

    r1369 r2115  
    3131        : mOSFileHandle(::open(Filename, flags, mode)), 
    3232#endif 
    33           mIsEOF(false) 
     33          mIsEOF(false), 
     34          mFileName(Filename) 
    3435{ 
    3536#ifdef WIN32 
     
    5051                } 
    5152        } 
    52 #ifdef WIN32 
    53         this->fileName = Filename; 
    54 #endif 
    5553} 
    5654 
     
    6664FileStream::FileStream(tOSFileHandle FileDescriptor) 
    6765        : mOSFileHandle(FileDescriptor), 
    68           mIsEOF(false) 
     66          mIsEOF(false), 
     67          mFileName("HANDLE") 
    6968{ 
    7069#ifdef WIN32 
     
    7877                THROW_EXCEPTION(CommonException, OSFileOpenError) 
    7978        } 
    80 #ifdef WIN32 
    81         this->fileName = "HANDLE"; 
    82 #endif 
    8379} 
    8480 
     
    151147                ); 
    152148 
    153         if ( valid ) 
     149        if(valid) 
    154150        { 
    155151                r = numBytesRead; 
    156152        } 
    157         else if (GetLastError() == ERROR_BROKEN_PIPE) 
     153        else if(GetLastError() == ERROR_BROKEN_PIPE) 
    158154        { 
    159155                r = 0; 
     
    161157        else 
    162158        { 
    163                 BOX_ERROR("Failed to read from file: " << 
    164                         GetErrorMessage(GetLastError())); 
     159                BOX_LOG_WIN_ERROR("Failed to read from file: " << mFileName); 
    165160                r = -1; 
    166161        } 
    167162#else 
    168163        int r = ::read(mOSFileHandle, pBuffer, NBytes); 
    169 #endif 
    170164        if(r == -1) 
    171165        { 
     166                BOX_LOG_SYS_ERROR("Failed to read from file: " << mFileName); 
     167        } 
     168#endif 
     169 
     170        if(r == -1) 
     171        { 
    172172                THROW_EXCEPTION(CommonException, OSFileReadError) 
    173173        } 
     174 
    174175        if(r == 0) 
    175176        { 
Note: See TracChangeset for help on using the changeset viewer.