Changeset 2275


Ignore:
Timestamp:
07/09/2008 14:20:14 (3 years ago)
Author:
chris
Message:

Fix test regression on Windows where a const char pointer was treated
as a file handle instead of as a string.

Location:
box/trunk/lib/common
Files:
2 edited

Legend:

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

    r2243 r2275  
    3333          mIsEOF(false), 
    3434          mFileName(rFilename) 
     35{ 
     36        AfterOpen(); 
     37} 
     38 
     39// -------------------------------------------------------------------------- 
     40// 
     41// Function 
     42//              Name:    FileStream::FileStream(const char *, int, int) 
     43//              Purpose: Alternative constructor, takes a const char *, 
     44//                       avoids const strings being interpreted as handles! 
     45//              Created: 2003/07/31 
     46// 
     47// -------------------------------------------------------------------------- 
     48FileStream::FileStream(const char *pFilename, int flags, int mode) 
     49#ifdef WIN32 
     50        : mOSFileHandle(::openfile(pFilename, flags, mode)), 
     51#else 
     52        : mOSFileHandle(::open(pFilename, flags, mode)), 
     53#endif 
     54          mIsEOF(false), 
     55          mFileName(pFilename) 
     56{ 
     57        AfterOpen(); 
     58} 
     59 
     60void FileStream::AfterOpen() 
    3561{ 
    3662#ifdef WIN32 
     
    4975                { 
    5076                        BOX_LOG_SYS_WARNING("Failed to open file: " << 
    51                                 rFilename); 
     77                                mFileName); 
    5278                        THROW_EXCEPTION(CommonException, OSFileOpenError) 
    5379                } 
  • box/trunk/lib/common/FileStream.h

    r2243 r2275  
    3939#endif 
    4040                int mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); 
     41 
     42        // Ensure that const char * name doesn't end up as a handle 
     43        // on Windows! 
     44 
     45        FileStream(const char *pFilename,  
     46#ifdef WIN32 
     47                int flags = (O_RDONLY | O_BINARY), 
     48#else 
     49                int flags = O_RDONLY, 
     50#endif 
     51                int mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); 
     52 
    4153        FileStream(tOSFileHandle FileDescriptor); 
    4254         
     
    5769        bool mIsEOF; 
    5870        FileStream(const FileStream &rToCopy) { /* do not call */ } 
     71        void AfterOpen(); 
    5972 
    6073        // for debugging.. 
Note: See TracChangeset for help on using the changeset viewer.