OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 // A DirectoryIterator is created with a given directory. It originally points | 34 // A DirectoryIterator is created with a given directory. It originally points |
35 // to the first file in the directory, and can be advanecd with Next(). This | 35 // to the first file in the directory, and can be advanecd with Next(). This |
36 // allows you to get information about each file. | 36 // allows you to get information about each file. |
37 | 37 |
38 // Constructor | 38 // Constructor |
39 DirectoryIterator::DirectoryIterator() | 39 DirectoryIterator::DirectoryIterator() |
40 #ifdef WEBRTC_WIN | 40 #ifdef WEBRTC_WIN |
41 : handle_(INVALID_HANDLE_VALUE) { | 41 : handle_(INVALID_HANDLE_VALUE) { |
42 #else | 42 #else |
43 : dir_(NULL), dirent_(NULL) { | 43 : dir_(nullptr), dirent_(nullptr) { |
44 #endif | 44 #endif |
45 } | 45 } |
46 | 46 |
47 // Destructor | 47 // Destructor |
48 DirectoryIterator::~DirectoryIterator() { | 48 DirectoryIterator::~DirectoryIterator() { |
49 #if defined(WEBRTC_WIN) | 49 #if defined(WEBRTC_WIN) |
50 if (handle_ != INVALID_HANDLE_VALUE) | 50 if (handle_ != INVALID_HANDLE_VALUE) |
51 ::FindClose(handle_); | 51 ::FindClose(handle_); |
52 #else | 52 #else |
53 if (dir_) | 53 if (dir_) |
54 closedir(dir_); | 54 closedir(dir_); |
55 #endif | 55 #endif |
56 } | 56 } |
57 | 57 |
58 // Starts traversing a directory. | 58 // Starts traversing a directory. |
59 // dir is the directory to traverse | 59 // dir is the directory to traverse |
60 // returns true if the directory exists and is valid | 60 // returns true if the directory exists and is valid |
61 bool DirectoryIterator::Iterate(const Pathname &dir) { | 61 bool DirectoryIterator::Iterate(const Pathname &dir) { |
62 directory_ = dir.pathname(); | 62 directory_ = dir.pathname(); |
63 #if defined(WEBRTC_WIN) | 63 #if defined(WEBRTC_WIN) |
64 if (handle_ != INVALID_HANDLE_VALUE) | 64 if (handle_ != INVALID_HANDLE_VALUE) |
65 ::FindClose(handle_); | 65 ::FindClose(handle_); |
66 std::string d = dir.pathname() + '*'; | 66 std::string d = dir.pathname() + '*'; |
67 handle_ = ::FindFirstFile(ToUtf16(d).c_str(), &data_); | 67 handle_ = ::FindFirstFile(ToUtf16(d).c_str(), &data_); |
68 if (handle_ == INVALID_HANDLE_VALUE) | 68 if (handle_ == INVALID_HANDLE_VALUE) |
69 return false; | 69 return false; |
70 #else | 70 #else |
71 if (dir_ != NULL) | 71 if (dir_ != nullptr) |
72 closedir(dir_); | 72 closedir(dir_); |
73 dir_ = ::opendir(directory_.c_str()); | 73 dir_ = ::opendir(directory_.c_str()); |
74 if (dir_ == NULL) | 74 if (dir_ == nullptr) |
75 return false; | 75 return false; |
76 dirent_ = readdir(dir_); | 76 dirent_ = readdir(dir_); |
77 if (dirent_ == NULL) | 77 if (dirent_ == nullptr) |
78 return false; | 78 return false; |
79 | 79 |
80 if (::stat(std::string(directory_ + Name()).c_str(), &stat_) != 0) | 80 if (::stat(std::string(directory_ + Name()).c_str(), &stat_) != 0) |
81 return false; | 81 return false; |
82 #endif | 82 #endif |
83 return true; | 83 return true; |
84 } | 84 } |
85 | 85 |
86 // Advances to the next file | 86 // Advances to the next file |
87 // returns true if there were more files in the directory. | 87 // returns true if there were more files in the directory. |
88 bool DirectoryIterator::Next() { | 88 bool DirectoryIterator::Next() { |
89 #if defined(WEBRTC_WIN) | 89 #if defined(WEBRTC_WIN) |
90 return ::FindNextFile(handle_, &data_) == TRUE; | 90 return ::FindNextFile(handle_, &data_) == TRUE; |
91 #else | 91 #else |
92 dirent_ = ::readdir(dir_); | 92 dirent_ = ::readdir(dir_); |
93 if (dirent_ == NULL) | 93 if (dirent_ == nullptr) |
94 return false; | 94 return false; |
95 | 95 |
96 return ::stat(std::string(directory_ + Name()).c_str(), &stat_) == 0; | 96 return ::stat(std::string(directory_ + Name()).c_str(), &stat_) == 0; |
97 #endif | 97 #endif |
98 } | 98 } |
99 | 99 |
100 // returns true if the file currently pointed to is a directory | 100 // returns true if the file currently pointed to is a directory |
101 bool DirectoryIterator::IsDirectory() const { | 101 bool DirectoryIterator::IsDirectory() const { |
102 #if defined(WEBRTC_WIN) | 102 #if defined(WEBRTC_WIN) |
103 return (data_.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FALSE; | 103 return (data_.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FALSE; |
104 #else | 104 #else |
105 return S_ISDIR(stat_.st_mode); | 105 return S_ISDIR(stat_.st_mode); |
106 #endif | 106 #endif |
107 } | 107 } |
108 | 108 |
109 // returns the name of the file currently pointed to | 109 // returns the name of the file currently pointed to |
110 std::string DirectoryIterator::Name() const { | 110 std::string DirectoryIterator::Name() const { |
111 #if defined(WEBRTC_WIN) | 111 #if defined(WEBRTC_WIN) |
112 return ToUtf8(data_.cFileName); | 112 return ToUtf8(data_.cFileName); |
113 #else | 113 #else |
114 RTC_DCHECK(dirent_); | 114 RTC_DCHECK(dirent_); |
115 return dirent_->d_name; | 115 return dirent_->d_name; |
116 #endif | 116 #endif |
117 } | 117 } |
118 | 118 |
119 FilesystemInterface* Filesystem::default_filesystem_ = NULL; | 119 FilesystemInterface* Filesystem::default_filesystem_ = nullptr; |
120 | 120 |
121 FilesystemInterface *Filesystem::EnsureDefaultFilesystem() { | 121 FilesystemInterface *Filesystem::EnsureDefaultFilesystem() { |
122 if (!default_filesystem_) { | 122 if (!default_filesystem_) { |
123 #if defined(WEBRTC_WIN) | 123 #if defined(WEBRTC_WIN) |
124 default_filesystem_ = new Win32Filesystem(); | 124 default_filesystem_ = new Win32Filesystem(); |
125 #else | 125 #else |
126 default_filesystem_ = new UnixFilesystem(); | 126 default_filesystem_ = new UnixFilesystem(); |
127 #endif | 127 #endif |
128 } | 128 } |
129 return default_filesystem_; | 129 return default_filesystem_; |
(...skipping 30 matching lines...) Expand all Loading... |
160 } | 160 } |
161 delete di; | 161 delete di; |
162 return success; | 162 return success; |
163 } | 163 } |
164 | 164 |
165 bool FilesystemInterface::DeleteFolderAndContents(const Pathname& folder) { | 165 bool FilesystemInterface::DeleteFolderAndContents(const Pathname& folder) { |
166 return DeleteFolderContents(folder) && DeleteEmptyFolder(folder); | 166 return DeleteFolderContents(folder) && DeleteEmptyFolder(folder); |
167 } | 167 } |
168 | 168 |
169 } // namespace rtc | 169 } // namespace rtc |
OLD | NEW |