OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/files/file_util.h" | 5 #include "base/files/file_util.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 <libgen.h> | 10 #include <libgen.h> |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 | 344 |
345 current = traversal.Next(); | 345 current = traversal.Next(); |
346 if (!current.empty()) | 346 if (!current.empty()) |
347 from_stat = traversal.GetInfo().stat(); | 347 from_stat = traversal.GetInfo().stat(); |
348 } | 348 } |
349 | 349 |
350 return success; | 350 return success; |
351 } | 351 } |
352 #endif // !defined(OS_NACL_NONSFI) | 352 #endif // !defined(OS_NACL_NONSFI) |
353 | 353 |
| 354 bool CreateLocalNonBlockingPipe(int fds[2]) { |
| 355 #if defined(OS_LINUX) |
| 356 return pipe2(fds, O_CLOEXEC | O_NONBLOCK) == 0; |
| 357 #else |
| 358 int raw_fds[2]; |
| 359 if (pipe(raw_fds) != 0) |
| 360 return false; |
| 361 ScopedFD fd_out(raw_fds[0]); |
| 362 ScopedFD fd_in(raw_fds[1]); |
| 363 if (!SetCloseOnExec(fd_out.get())) |
| 364 return false; |
| 365 if (!SetCloseOnExec(fd_in.get())) |
| 366 return false; |
| 367 if (!SetNonBlocking(fd_out.get())) |
| 368 return false; |
| 369 if (!SetNonBlocking(fd_in.get())) |
| 370 return false; |
| 371 fds[0] = fd_out.release(); |
| 372 fds[1] = fd_in.release(); |
| 373 return true; |
| 374 #endif |
| 375 } |
| 376 |
354 bool SetNonBlocking(int fd) { | 377 bool SetNonBlocking(int fd) { |
355 const int flags = fcntl(fd, F_GETFL); | 378 const int flags = fcntl(fd, F_GETFL); |
356 if (flags == -1) | 379 if (flags == -1) |
357 return false; | 380 return false; |
358 if (flags & O_NONBLOCK) | 381 if (flags & O_NONBLOCK) |
359 return true; | 382 return true; |
360 if (HANDLE_EINTR(fcntl(fd, F_SETFL, flags | O_NONBLOCK)) == -1) | 383 if (HANDLE_EINTR(fcntl(fd, F_SETFL, flags | O_NONBLOCK)) == -1) |
361 return false; | 384 return false; |
362 return true; | 385 return true; |
363 } | 386 } |
364 | 387 |
| 388 bool SetCloseOnExec(int fd) { |
| 389 const int flags = fcntl(fd, F_GETFD); |
| 390 if (flags == -1) |
| 391 return false; |
| 392 if (flags & FD_CLOEXEC) |
| 393 return true; |
| 394 if (HANDLE_EINTR(fcntl(fd, F_SETFD, flags | FD_CLOEXEC)) == -1) |
| 395 return false; |
| 396 return true; |
| 397 } |
| 398 |
365 bool PathExists(const FilePath& path) { | 399 bool PathExists(const FilePath& path) { |
366 ThreadRestrictions::AssertIOAllowed(); | 400 ThreadRestrictions::AssertIOAllowed(); |
367 #if defined(OS_ANDROID) | 401 #if defined(OS_ANDROID) |
368 if (path.IsContentUri()) { | 402 if (path.IsContentUri()) { |
369 return ContentUriExists(path); | 403 return ContentUriExists(path); |
370 } | 404 } |
371 #endif | 405 #endif |
372 return access(path.value().c_str(), F_OK) == 0; | 406 return access(path.value().c_str(), F_OK) == 0; |
373 } | 407 } |
374 | 408 |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 return false; | 981 return false; |
948 | 982 |
949 DeleteFile(from_path, true); | 983 DeleteFile(from_path, true); |
950 return true; | 984 return true; |
951 } | 985 } |
952 | 986 |
953 } // namespace internal | 987 } // namespace internal |
954 | 988 |
955 #endif // !defined(OS_NACL_NONSFI) | 989 #endif // !defined(OS_NACL_NONSFI) |
956 } // namespace base | 990 } // namespace base |
OLD | NEW |