コード例 #1
0
ファイル: time.c プロジェクト: Barrell/wine
static void test_wstrdate(void)
{
    wchar_t date[16], * result;
    int month, day, year, count, len;
    wchar_t format[] = { '%','0','2','d','/','%','0','2','d','/','%','0','2','d',0 };

    result = _wstrdate(date);
    ok(result == date, "Wrong return value\n");
    len = wcslen(date);
    ok(len == 8, "Wrong length: returned %d, should be 8\n", len);
    count = swscanf(date, format, &month, &day, &year);
    ok(count == 3, "Wrong format: count = %d, should be 3\n", count);
}
コード例 #2
0
ファイル: time.c プロジェクト: mikekap/wine
/**********************************************************************
 *              _wstrdate_s (MSVCRT.@)
 */
int CDECL _wstrdate_s(MSVCRT_wchar_t* date, MSVCRT_size_t size)
{
    if(date && size)
        date[0] = '\0';

    if(!date) {
        *MSVCRT__errno() = MSVCRT_EINVAL;
        return MSVCRT_EINVAL;
    }

    if(size < 9) {
        *MSVCRT__errno() = MSVCRT_ERANGE;
        return MSVCRT_ERANGE;
    }

    _wstrdate(date);
    return 0;
}
コード例 #3
0
ファイル: log.cpp プロジェクト: ffoxin/winmon
int __stdcall WriteLog( const TCHAR *msg, const int error, const TCHAR *location )
{
    static TCHAR        log_path[MAX_PATH]  = { };
    static bool         first_call          = FirstCall( log_file );

    std::wofstream      log;
    TCHAR               date[9];
    TCHAR               time[9];
    LPTSTR              err_buf;

    if( !*log_path )
    {
        if( !GetModuleFileName( 0, log_path, MAX_PATH ) )
            return -1;

        wcscpy( wcsrchr( log_path, L'.' ) + 1, L"log" );
    }

    log.open( log_path, std::ios::app );
    if( log.fail( ) )
        return -1;
    
    log.imbue( std::locale( "rus_rus" ) );

    if( first_call )
    {
        first_call = false;

        _wstrdate( date );
        if( log.rdbuf( )->pubseekoff( 0, std::ios_base::end ) > 0 )
            log << std :: endl;

        log << date << tab << L"log started" << std::endl;
    }

    _wstrtime( time );
    log << time << tab;
    
    if( error == 0 )
    {
        log << msg;
    }
    else
    {
        if( !FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_MAX_WIDTH_MASK, 
            0, error, MAKELANGID( LANG_NEUTRAL, SUBLANG_SYS_DEFAULT ), (LPTSTR) &err_buf, 0, 0 ) )
            return GetLastError( );
        log << L"Error: " << msg << tab << 
            L"(" << error << L") " << 
            err_buf << tab << location;
        LocalFree( err_buf );
    }

    if( log.fail( ) )
    {
        log.close( );
        log.open( log_path, std::ios::app );
    }
    
    log << std::endl;

    log.close( );

    return 0;
}