#include #include #include #include using namespace std; // Uses the unicode version of argv[0] to generate an absolute (if necessary) // unicode path to a file in the directory this executable is in. inline wstring generatePath( const wchar_t* p, const wstring& file) { const wstring s( p ); if ( s.find(L"/") != wstring::npos) { return s.substr( 0, s.rfind( L"/" ) ) + L"/" + file; } else if ( s.find(L"\\") != wstring::npos ) { return s.substr( 0, s.rfind( L"\\" ) ) + L"\\" + file; } else { return file; } } int main() { int argc; wchar_t** argv = CommandLineToArgvW( GetCommandLineW(), &argc); const wstring file( generatePath( argv[0], L"file.txt") ); // Write the unicode path to the file specificed by that unicode path // so the path can be checked. File format is UTF-16LE FILE* out = _wfopen( file.c_str(), L"wb"); if (!out) { return 1; } fwprintf(out, L"%c", 0xFEFF); fwprintf(out, L"%s", file.c_str()); fclose(out); } // g++ -Wall -Wextra abspath.cpp -o abspath --define _UNICODE