34 #include <google/protobuf/testing/file.h>
37 #include <sys/types.h>
39 #define WIN32_LEAN_AND_MEAN // yeah, right
48 #include <google/protobuf/io/io_win32.h>
49 #include <google/protobuf/stubs/logging.h>
62 using google::protobuf::io::win32::access;
63 using google::protobuf::io::win32::chdir;
64 using google::protobuf::io::win32::fopen;
65 using google::protobuf::io::win32::mkdir;
76 FILE*
file = fopen(
name.c_str(), text_mode ?
"rt" :
"rb");
77 if (
file == NULL)
return false;
118 <<
"fopen(" <<
name <<
", \"wb\"): " << strerror(errno);
121 <<
"fwrite(" <<
name <<
"): " << strerror(errno);
123 <<
"fclose(" <<
name <<
"): " << strerror(errno);
130 return mkdir(
name.c_str(),
mode) == 0;
139 std::string::size_type slashpos =
path.find_last_of(
'/');
140 if (slashpos == std::string::npos) {
151 if (
name.empty())
return;
158 WIN32_FIND_DATAA find_data;
159 HANDLE find_handle = FindFirstFileA((
name +
"/*").
c_str(), &find_data);
162 DeleteFileA(
name.c_str());
163 RemoveDirectoryA(
name.c_str());
169 if (entry_name !=
"." && entry_name !=
"..") {
171 if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
173 RemoveDirectoryA(
path.c_str());
175 DeleteFileA(
path.c_str());
178 }
while(FindNextFileA(find_handle, &find_data));
179 FindClose(find_handle);
181 RemoveDirectoryA(
name.c_str());
186 if (lstat(
name.c_str(), &
stats) != 0)
return;
188 if (S_ISDIR(
stats.st_mode)) {
189 DIR* dir = opendir(
name.c_str());
192 struct dirent* entry = readdir(dir);
193 if (entry == NULL)
break;
195 if (entry_name !=
"." && entry_name !=
"..") {
204 }
else if (S_ISREG(
stats.st_mode)) {
205 remove(
name.c_str());
211 return chdir(new_working_directory.c_str()) == 0;