Windows 10
MS VS 2015
C++11
Boost 1.60
I create this symbolic link:
mklink /J "C:\T4 2.0\ApplicationSymlinks\T4" "C:\T4 2.0\Data"
This is a much simplified version of a program to check if the symbolic link is linked to the proper directory:
#include <boost/filesystem.hpp>
#include <iostream>
int main()
{
boost::filesystem::path directory = "c:\\T4 2.0\\Data";
boost::filesystem::path symlink = "c:\\T4 2.0\\ApplicationSymlinks\\T4";
boost::filesystem::path path_linked_to("");
path_linked_to = boost::filesystem::read_symlink(symlink); // Resolve symlink. path_linked_to is not absolute. L"\\T4 2.0\\Data"
path_linked_to = boost::filesystem::absolute(path_linked_to); // Absolute path. L"c:\\T4 2.0\\Data"
if (directory == path_linked_to)
std::cout << "paths are equal" << std::endl;
else
std::cout << "paths are not equal" << std::endl;
return 0;
}
The output is "paths are not equal". Shouldn't they be equal? In the autos window of the debugger I do see this:
directory size 14 capacity 15
where as
path_linked_to size 16 capacity 23 because it includes two trailing '\0's.
These two trailing '\0'
s are introduced in read_symlink
.
How do I resolve this? Why doesn't read_symlink
return an absolute? Why does read_symlink
add in two trailing '\0'
s (assuming that is the problem)? Why does operator==
not ignore the '\0'
s?
How I compiled and linked:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\CL.exe /c /IC:\Libraries\boost_1_60_0 /ZI /nologo /W3 /WX- /sdl /Od /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"x64\Debug\\" /Fd"x64\Debug\vc140.pdb" /Gd /TP /errorReport:prompt resolvesymlilnk.cpp stdafx.cpp
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\link.exe /ERRORREPORT:PROMPT /OUT:"c:\Users\Therefore\Documents\Visual Studio 2015\Projects\resolvesymlilnk\x64\Debug\resolvesymlilnk.exe" /INCREMENTAL /NOLOGO /LIBPATH:"C:\Libraries\boost_1_60_0\lib64-msvc-14.0" kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /Debug /PDB:"c:\Users\Therefore\Documents\Visual Studio 2015\Projects\resolvesymlilnk\x64\Debug\resolvesymlilnk.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"c:\Users\Therefore\Documents\Visual Studio 2015\Projects\resolvesymlilnk\x64\Debug\resolvesymlilnk.lib" /MACHINE:X64 x64\Debug\resolvesymlilnk.obj
Aucun commentaire:
Enregistrer un commentaire