OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "services/files/directory_impl.h" | 5 #include "services/files/directory_impl.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 callback.Run(ErrnoToError(errno), Array<DirectoryEntryPtr>()); | 118 callback.Run(ErrnoToError(errno), Array<DirectoryEntryPtr>()); |
119 return; | 119 return; |
120 } | 120 } |
121 | 121 |
122 ScopedDIR dir(fdopendir(fd.release())); | 122 ScopedDIR dir(fdopendir(fd.release())); |
123 if (!dir) { | 123 if (!dir) { |
124 callback.Run(ErrnoToError(errno), Array<DirectoryEntryPtr>()); | 124 callback.Run(ErrnoToError(errno), Array<DirectoryEntryPtr>()); |
125 return; | 125 return; |
126 } | 126 } |
127 | 127 |
128 Array<DirectoryEntryPtr> result(0); | 128 auto result = Array<DirectoryEntryPtr>::New(0); |
129 | 129 |
130 // Warning: This is not portable (per POSIX.1 -- |buffer| may not be large | 130 // Warning: This is not portable (per POSIX.1 -- |buffer| may not be large |
131 // enough), but it's fine for Linux. | 131 // enough), but it's fine for Linux. |
132 #if !defined(OS_ANDROID) && !defined(OS_LINUX) | 132 #if !defined(OS_ANDROID) && !defined(OS_LINUX) |
133 #error "Use of struct dirent for readdir_r() buffer not portable; please check." | 133 #error "Use of struct dirent for readdir_r() buffer not portable; please check." |
134 #endif | 134 #endif |
135 struct dirent buffer; | 135 struct dirent buffer; |
136 for (size_t n = 0;;) { | 136 for (size_t n = 0;;) { |
137 struct dirent* entry = nullptr; | 137 struct dirent* entry = nullptr; |
138 if (int error = readdir_r(dir.get(), &buffer, &entry)) { | 138 if (int error = readdir_r(dir.get(), &buffer, &entry)) { |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 if (unlinkat(dir_fd_.get(), path.get().c_str(), AT_REMOVEDIR) == 0) { | 353 if (unlinkat(dir_fd_.get(), path.get().c_str(), AT_REMOVEDIR) == 0) { |
354 callback.Run(Error::OK); | 354 callback.Run(Error::OK); |
355 return; | 355 return; |
356 } | 356 } |
357 | 357 |
358 callback.Run(ErrnoToError(errno)); | 358 callback.Run(ErrnoToError(errno)); |
359 } | 359 } |
360 | 360 |
361 } // namespace files | 361 } // namespace files |
362 } // namespace mojo | 362 } // namespace mojo |
OLD | NEW |