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

📄 mos.cpp

📁 跨平台C++基础库
💻 CPP
字号:

#include "MCRT/mos.h"

#ifdef WIN32
#   include <direct.h>
#else //! WIN32
#   include <sys/types.h>
#   include <sys/stat.h>
#   include <sys/select.h>  // for select time wait on Posix System
#   include <unistd.h>
#endif //end WIN32
#include <time.h>
#include <errno.h>

mInt32 MOS::mkdir( const char* pPath )
{
    if ( pPath == NULL )
    {
        return E_PARAM_POINTER_NULL;
    }

#ifdef WIN32
    int retVal  =   ::mkdir( pPath );
#else //! WIN32
    int retVal  =   ::mkdir( pPath, 0755 ); //use default
#endif //end WIN32

    if ( (retVal != 0) && (errno != EEXIST) )
    {
        return E_GENERAL;
    }

    return E_SUCCESS;
}

/**
 * @brief   unlink
 *
 * @param[in]   pPath   file path to be delete
 * @return      E_SUCCESS \n
 *              E_PARAM_POINTER_NULL
 */
mInt32 MOS::unlink( const char* pPath )
{
    if ( pPath == NULL )
    {
        return E_PARAM_POINTER_NULL;
    }

    ::unlink( pPath );

    return E_SUCCESS;
}

char* MOS::timestamp( char* bufDateTime, mUInt32 lenBuf )
{
    time_t  nowClock;
    tm*     nowTime =   NULL;

    ::time( &nowClock );
    nowTime =   ::localtime( &nowClock );
    ::strcpy( bufDateTime, ::asctime(nowTime) );

    return bufDateTime;
}

mInt32 MOS::sleep( mUInt32 nMilliSeconds )
{
#ifdef WIN32
    ::Sleep( nMilliSeconds );
#else //! WIN32
    timeval timeout;
    timeout.tv_sec  =   nMilliSeconds / 1000;
    timeout.tv_usec =   (nMilliSeconds % 1000) * 1000;

    ::select( 0, 0, 0, 0, &timeout );
#endif //end WIN32

    return E_SUCCESS;
}

⌨️ 快捷键说明

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