readLink() 函数在 Linux 中出现,并且在 unistd.h 中定义。请问在 Windows 中是否有类似的函数?如果没有,请提供一个类似功能的自定义函数。如果没有预定义的函数,则需要提供用于替换该函数的用户定义函数以使用与 readLink() 相同的功能。
以下是代码快照:
char buffer[2048];
readlink("/proc/self/exe", buffer, 2048);
std::stringstream ss;
ss << buffer;
std::string exeFile = ss.str();
std::string directory;
const size_t last_slash_idx = exeFile.rfind('/');
if (std::string::npos != last_slash_idx)
{
directory = exeFile.substr(0, last_slash_idx);
}
return directory;
#endif