⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ncbifile.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                } else {                    map_access = FILE_MAP_COPY;                }                map_protect = PAGE_READWRITE;                // So the file also must be open for reading and writing                file_access = GENERIC_READ | GENERIC_WRITE;                break;            default:                _TROUBLE;        }        if (share_attr == eMMS_Shared) {            file_share = FILE_SHARE_READ | FILE_SHARE_WRITE;        } else {            file_share = 0;        }        // If failed to attach to an existing file-mapping object then        // create a new one (based on the specified file)        m_Handle->hMap = OpenFileMapping(map_access, false, x_name.c_str());        if ( !m_Handle->hMap ) {             HANDLE hFile = CreateFile(x_name.c_str(), file_access,                                       file_share, NULL, OPEN_EXISTING,                                       FILE_ATTRIBUTE_NORMAL, NULL);            if (hFile == INVALID_HANDLE_VALUE)                break;            m_Handle->hMap = CreateFileMapping(hFile, NULL, map_protect,                                               0, 0, x_name.c_str());            CloseHandle(hFile);            if ( !m_Handle->hMap )                break;        }        m_DataPtr = MapViewOfFile(m_Handle->hMap, map_access,                                  0, 0, m_Size);        if ( !m_DataPtr ) {            CloseHandle(m_Handle->hMap);            break;        }#elif defined(NCBI_OS_UNIX)        // Translate attributes         int map_protect = 0, map_share = 0, file_access = 0;        switch (protect_attr) {            case eMMP_Read:                map_protect = PROT_READ;                file_access = O_RDONLY;                break;            case eMMP_Write:                map_protect = PROT_WRITE;                if  (share_attr == eMMS_Shared ) {                    // Must be read + write                    file_access = O_RDWR;                } else {                    file_access = O_RDONLY;                }                break;            case eMMP_ReadWrite:                map_protect = PROT_READ | PROT_WRITE;                if  (share_attr == eMMS_Shared ) {                    file_access = O_RDWR;                } else {                    file_access = O_RDONLY;                }                break;            default:                _TROUBLE;        }        switch (share_attr) {            case eMMS_Shared:                map_share = MAP_SHARED;                break;            case eMMS_Private:                map_share = MAP_PRIVATE;                break;            default:                _TROUBLE;        }        // Open file        int fd = open(file_name.c_str(), file_access);        if (fd < 0) {            break;        }        // Map file to memory        m_DataPtr = mmap(0, (size_t) m_Size, map_protect, map_share, fd, 0);        close(fd);        if (m_DataPtr == MAP_FAILED) {            break;        }#endif        // Success        return;    }    // Error; cleanup    delete m_Handle;    m_Handle = 0;    m_Size = -1;}bool CMemoryFile::Flush(void) const{    // If file is not mapped do nothing    if ( !m_Handle )        return false;    bool status = false;#if defined(NCBI_OS_MSWIN)    status = (FlushViewOfFile(m_DataPtr, 0) != 0);#elif defined(NCBI_OS_UNIX)    status = (msync((char*)m_DataPtr, (size_t) m_Size, MS_SYNC) == 0);#endif    return status;}bool CMemoryFile::Unmap(void){    // If file is not mapped do nothing    if ( !m_Handle )        return true;    bool status = false;#if defined(NCBI_OS_MSWIN)    status = (UnmapViewOfFile(m_DataPtr) != 0);    if ( status  &&  m_Handle->hMap )        status = (CloseHandle(m_Handle->hMap) != 0);#elif defined(NCBI_OS_UNIX)    status = (munmap((char*)m_DataPtr, (size_t) m_Size) == 0);#endif    delete m_Handle;    // Reinitialize members    m_Handle = 0;    m_DataPtr = 0;    m_Size = -1;    return status;}#if !defined(HAVE_MADVISE)bool CMemoryFile::MemMapAdviseAddr(void*, size_t, EMemMapAdvise) {    return true;}bool CMemoryFile::MemMapAdvise(EMemMapAdvise) {    return true;}#else  /* HAVE_MADVISE */bool CMemoryFile::MemMapAdviseAddr(void* addr, size_t len,                                   EMemMapAdvise advise){    int adv;    if (!addr || !len) {        return false;    }    switch (advise) {    case eMMA_Random:        adv = MADV_RANDOM;     break;    case eMMA_Sequential:        adv = MADV_SEQUENTIAL; break;    case eMMA_WillNeed:        adv = MADV_WILLNEED;   break;    case eMMA_DontNeed:        adv = MADV_DONTNEED;   break;    default:        adv = MADV_NORMAL;    }    // Conversion type of "addr" to char* -- Sun Solaris fix    return madvise((char*)addr, len, adv) == 0;}bool CMemoryFile::MemMapAdvise(EMemMapAdvise advise){    if (m_DataPtr  &&   m_Size > 0) {        return MemMapAdviseAddr(m_DataPtr, m_Size, advise);    } else {        return false;    }}#endif  /* HAVE_MADVISE */END_NCBI_SCOPE/* * =========================================================================== * $Log: ncbifile.cpp,v $ * Revision 1000.5  2004/06/01 19:09:09  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.78 * * Revision 1.78  2004/05/18 16:51:34  ivanov * Added CDir::GetTmpDir() * * Revision 1.77  2004/05/14 13:59:27  gorelenk * Added include of ncbi_pch.hpp * * Revision 1.76  2004/04/29 15:14:34  kuznets * + Generic FindFile algorithm capable of recursive searches * CDir::GetEntries received additional parameter to ignore self * recursive directory entries (".", "..") * * Revision 1.75  2004/04/28 19:04:29  ucko * Give GetType(), IsFile(), and IsDir() an optional EFollowLinks * parameter (currently only honored on Unix). * * Revision 1.74  2004/04/28 15:56:49  ivanov * CDirEntry::GetType(): fixed bug with incorrect entry type determination * on some platforms * * Revision 1.73  2004/04/21 11:24:53  ivanov * Define s_StdGetTmpName() for all platforms except NCBI_OS_UNIX * * Revision 1.72  2004/03/17 15:39:54  ivanov * CFile:: Fixed possible race condition concerned with temporary file name * generation. Added ETmpFileCreationMode enum. Fixed GetTmpName[Ex] and * CreateTmpFile[Ex] class methods. * * Revision 1.71  2004/03/05 12:26:43  ivanov * Moved CDirEntry::MatchesMask() to NStr class. * * Revision 1.70  2004/02/12 19:50:34  ivanov * Fixed CDirEntry::DeleteTrailingPathSeparator and CDir::CreatePath() * to avoid creating empty directories with disk name in the case if * specified path contains it. * * Revision 1.69  2004/02/11 20:49:57  gorelenk * Implemented case-insensitivity of CreateRelativePath on NCBI_OS_MSWIN. * * Revision 1.68  2004/02/11 20:30:21  gorelenk * Added case-insensitive test of root dirs inside CreateRelativePath. * * Revision 1.67  2004/01/07 13:58:28  ucko * Add missing first argument to string constructor in s_StripDir. * * Revision 1.66  2004/01/05 21:40:54  gorelenk * += Exception throwing in CDirEntry::CreateRelativePath() * * Revision 1.65  2004/01/05 20:04:05  gorelenk * + CDirEntry::CreateRelativePath() * * Revision 1.64  2003/11/28 16:51:48  ivanov * Fixed CDirEntry::SetTime() to set current time if parameter is empty * * Revision 1.63  2003/11/28 16:22:42  ivanov * + CDirEntry::SetTime() * * Revision 1.62  2003/11/05 15:36:23  kuznets * Implemented new variant of CDir::GetEntries() * * Revision 1.61  2003/10/23 12:10:51  ucko * Use AutoPtr with CDeleter rather than auto_ptr, which is *not* * guaranteed to be appropriate for malloc()ed memory. * * Revision 1.60  2003/10/22 13:25:47  ivanov * GetTmpName[Ex]:  replaced tempnam() with mkstemp() for UNIX * * Revision 1.59  2003/10/08 15:45:09  ivanov * Added CDirEntry::DeleteTrailingPathSeparator() * * Revision 1.58  2003/10/01 14:32:09  ucko * +EFollowLinks * * Revision 1.57  2003/09/30 15:08:51  ucko * Reworked CDirEntry::NormalizePath, which now handles .. correctly in * all cases and optionally resolves symlinks (on Unix). * * Revision 1.56  2003/09/17 20:55:02  ivanov * NormalizePath: added more processing for MS Windows paths * * Revision 1.55  2003/09/16 18:54:26  ivanov * NormalizePath(): added replacing double dir separators with single one * * Revision 1.54  2003/09/16 16:03:00  ivanov * MakePath():  don't add separator to directory name if it is an empty string * * Revision 1.53  2003/09/16 15:17:16  ivanov * + CDirEntry::NormalizePath() * * Revision 1.52  2003/08/29 16:54:28  ivanov * GetTmpName(): use tempname() instead tmpname() * * Revision 1.51  2003/08/21 20:32:48  ivanov * CDirEntry::GetType(): use lstat() instead stat() on UNIX * * Revision 1.50  2003/08/08 13:37:17  siyan * Changed GetTmpNameExt to GetTmpNameEx in CFile, as this is the more * appropriate name. * * Revision 1.49  2003/06/18 18:57:43  rsmith * alternate implementation of GetTmpNameExt replacing tempnam with mktemp for * library missing tempnam. * * Revision 1.48  2003/05/29 17:21:04  gouriano * added CreatePath() which creates directories recursively * * Revision 1.47  2003/04/11 14:04:49  ivanov * Fixed CDirEntry::GetMode (Mac OS) - store a mode only for a notzero pointers. * Fixed CDir::GetEntries -- do not try to close a dir handle if it was * not opened. * * Revision 1.46  2003/04/04 16:02:37  lavr * Lines wrapped at 79th column; some minor reformatting * * Revision 1.45  2003/04/03 14:15:48  rsmith * combine pp symbols NCBI_COMPILER_METROWERKS & _MSL_USING_MW_C_HEADERS * into NCBI_COMPILER_MW_MSL * * Revision 1.44  2003/04/02 16:22:34  rsmith * clean up metrowerks ifdefs. * * Revision 1.43  2003/04/02 13:29:29  rsmith * include ncbi_mslextras.h when compiling with MSL libs in Codewarrior. * * Revision 1.42  2003/03/10 18:57:08  kuznets * iterate->ITERATE * * Revision 1.41  2003/02/28 21:06:02  ivanov * Added close() call to CTmpStream destructor before the file deleting. * * Revision 1.40  2003/02/14 19:30:50  ivanov * Added mode ios::trunc by default for files creates in CFile::CreateTmpFile(). * Get read of some warnings - initialize variables in CMemoryFile::x_Map(). * * Revision 1.39  2003/02/06 16:14:28  ivanov * CMemomyFile::x_Map(): changed file access attribute from O_RDWR to * O_RDONLY in case of private sharing. * * Revision 1.38  2003/02/05 22:07:15  ivanov * Added protect and sharing parameters to the CMemoryFile constructor. * Added CMemoryFile::Flush() method. * * Revision 1.37  2003/01/16 13:27:56  dicuccio * Added CDir::GetCwd() * * Revision 1.36  2002/11/05 15:46:49  dicuccio * Changed CDir::GetEntries() to store fully qualified path names - this permits * CDirEntry::GetType() to work on files outside of the local directory. * * Revision 1.35  2002/10/01 17:23:57  gouriano * more fine-tuning of ConvertToOSPath * * Revision 1.34  2002/10/01 17:02:53  gouriano * minor modification of ConvertToOSPath * * Revision 1.33  2002/10/01 14:18:45  gouriano * "optimize" result of ConvertToOSPath * * Revision 1.32  2002/09/19 20:05:42  vasilche * Safe initialization of static mutexes * * Revision 1.31  2002/09/17 20:44:58  lavr * Add comment in unreachable return from CDirEntry::MatchesMask() * * Revision 1.30  2002/09/05 18:35:38  vakatov * Formal code rearrangement to get rid of comp.warnings;  some nice-ification * * Revision 1.29  2002/07/18 20:22:59  lebedev * NCBI_OS_MAC: fcntl.h added * * Revision 1.28  2002/07/15 18:17:24  gouriano * renamed CNcbiException and its descendents * * Revision 1.27  2002/07/11 19:28:30  ivanov * Removed test stuff from MemMapAdvise[Addr] * * Revision 1.26  2002/07/11 19:21:30  ivanov * Added CMemoryFile::MemMapAdvise[Addr]() * * Revision 1.25  2002/07/11 14:18:27  gouriano * exceptions replaced by CNcbiException-type ones * * Revision 1.24  2002/06/07 16:11:37  ivanov * Chenget GetTime() -- using CTime instead time_t, modification time * by default * * Revision 1.23  2002/06/07 15:21:06  ivanov * Added CDirEntry::GetTime() * * Revision 1.22  2002/05/01 22:59:00  vakatov * A couple of (size_t) type casts to avoid compiler warnings in 64-bit * * Revision 1.21  2002/04/11 21:08:02  ivanov * CVS log moved to end of the file * * Revision 1.20  2002/04/01 18:49:54  ivanov * Added class CMemoryFile. Added including <windows.h> under MS Windows * * Revision 1.19  2002/03/25 17:08:17  ucko * Centralize treatment of Cygwin as Unix rather than Windows in configure. * * Revision 1.18  2002/03/22 20:00:01  ucko * Tweak to work on Cygwin.  (Use Unix rather than MSWIN code). * * Revision 1.17  2002/02/07 21:05:47  kans * implemented GetHome (FindFolder kPreferencesFolderType) for Mac * * Revision 1.16  2002/01/24 22:18:02  ivanov * Changed CDirEntry::Remove() and CDir::Remove() * * Revision 1.15  2002/01/22 21:21:09  ivanov * Fixed typing error * * Revision 1.14  2002/01/22 19:27:39  ivanov * Added realization ConcatPathEx() * * Revision 1.13  2002/01/20 06:13:34  vakatov * Fixed warning;  formatted the source code * * Revision 1.12  2002/01/10 16:46:36  ivanov * Added CDir::GetHome() and some CDirEntry:: path processing functions * * Revision 1.11  2001/12/26 21:21:05  ucko * Conditionalize deletion of m_FSS on NCBI_OS_MAC. * * Revision 1.10  2001/12/26 20:58:22  juran * Use an FSSpec* member instead of an FSSpec, so a forward declaration can * be used. * Add copy constructor and assignment operator for CDirEntry on Mac OS, * thus avoiding memberwise copy which would blow up upon deleting the * pointer twice. * * Revision 1.9  2001/12/18 21:36:38  juran * Remove unneeded Mac headers. * (Required functions copied to ncbi_os_mac.cpp) * MoveRename PStr to PString in ncbi_os_mac.hpp. * Don't use MoreFiles xxxCompat functions.  They're for System 6. * Don't use global scope operator on functions copied into NCBI scope. * * Revision 1.8  2001/11/19 23:38:44  vakatov * Fix to compile with SUN WorkShop (and maybe other) compiler(s) * * Revision 1.7  2001/11/19 18:10:13  juran * Whitespace. * * Revision 1.6  2001/11/15 16:34:12  ivanov * Moved from util to corelib * * Revision 1.5  2001/11/06 14:34:11  ivanov * Fixed compile errors in CDir::Contents() under MS Windows * * Revision 1.4  2001/11/01 21:02:25  ucko * Fix to work on non-MacOS platforms again. * * Revision 1.3  2001/11/01 20:06:48  juran * Replace directory streams with Contents() method. * Implement and test Mac OS platform. * * Revision 1.2  2001/09/19 16:22:18  ucko * S_IFDOOR is nonportable; make sure it exists before using it. * Fix type of second argument to CTmpStream's constructor (caught by gcc 3). * * Revision 1.1  2001/09/19 13:06:09  ivanov * Initial revision * * =========================================================================== */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -