21 #if defined(__linux__) || \
22 defined(__FreeBSD_kernel__) || \
24 defined(__unix__) || \
25 defined(__CYGWIN__) || \
35 #include <util/pragma_push.def>
37 #pragma warning(disable:4668)
44 #include <util/pragma_pop.def>
52 char *wd=realpath(
".",
nullptr);
54 if(wd ==
nullptr || errno != 0)
56 std::string(
"realpath failed: ") + std::strerror(errno));
58 std::string working_directory=wd;
62 DWORD retval=GetCurrentDirectory(4096, buffer);
65 std::string working_directory(buffer);
68 return working_directory;
74 void delete_directory_utf16(
const std::wstring &path)
76 std::wstring pattern=path + L
"\\*";
78 struct _wfinddata_t info;
79 intptr_t hFile=_wfindfirst(pattern.c_str(), &info);
84 if(wcscmp(info.name, L
".")==0 || wcscmp(info.name, L
"..")==0)
86 std::wstring sub_path=path+L
"\\"+info.name;
87 if(info.attrib & _A_SUBDIR)
88 delete_directory_utf16(sub_path);
90 DeleteFileW(sub_path.c_str());
92 while(_wfindnext(hFile, &info)==0);
94 RemoveDirectoryW(path.c_str());
105 DIR *dir=opendir(path.c_str());
109 while((ent=readdir(dir))!=
nullptr)
112 if(strcmp(ent->d_name,
".")==0 || strcmp(ent->d_name,
"..")==0)
115 std::string sub_path=path+
"/"+ent->d_name;
118 int result=stat(sub_path.c_str(), &stbuf);
121 std::string(
"Stat failed: ") + std::strerror(errno));
123 if(S_ISDIR(stbuf.st_mode))
127 result=remove(sub_path.c_str());
130 std::string(
"Remove failed: ") + std::strerror(errno));
142 const std::string &directory,
143 const std::string &file_name)
146 return (file_name.size() > 1 && file_name[0] !=
'/' && file_name[1] ==
':') ?
147 file_name : directory +
"\\" + file_name;
149 return (!file_name.empty() && file_name[0]==
'/') ?
150 file_name : directory+
"/"+file_name;
161 auto attributes = ::GetFileAttributesW(
widen(path).c_str());
162 if (attributes == INVALID_FILE_ATTRIBUTES)
165 return (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
171 if(stat(path.c_str(), &buf)!=0)
174 return (buf.st_mode & S_IFDIR) != 0;