1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
// windows/platform.cpp (Windows)
// Copyright Michael Thomas Greer 2010
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt )
#ifndef PLATFORM_HPP
#error You need to include ../platform.cpp instead of this file!
#endif
#include <algorithm>
#include <windows.h>
namespace platform
{
//--------------------------------------------------------------------------
std::string find_executable( const std::string& argv0 )
{
WCHAR widename[ MAX_PATH ];
char ansiname[ MAX_PATH + MAX_PATH ];
if (GetModuleFileNameW( NULL, widename, MAX_PATH ) == 0)
{
GetModuleFileNameA( NULL, ansiname, sizeof( ansiname ) );
MultiByteToWideChar( CP_ACP, 0, ansiname, -1, widename, MAX_PATH );
}
WideCharToMultiByte( CP_UTF8, 0, widename, -1, ansiname, sizeof( ansiname ), NULL, NULL );
std::string name = ansiname;
std::replace( name.begin(), name.end(), '\\', '/' );
return name;
}
//--------------------------------------------------------------------------
bool isatty( unsigned fd )
{
static DWORD handles[] = {
STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE
};
DWORD foo;
if (fd > 2) return false;
return GetConsoleMode( GetStdHandle( handles[ fd ] ), &foo ) != 0;
}
}
// end platform.cpp
|