Chromium Code Reviews| 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 // This file contains utility functions for dealing with the local | 5 // This file contains utility functions for dealing with the local |
| 6 // filesystem. | 6 // filesystem. |
| 7 | 7 |
| 8 #ifndef BASE_FILES_FILE_UTIL_H_ | 8 #ifndef BASE_FILES_FILE_UTIL_H_ |
| 9 #define BASE_FILES_FILE_UTIL_H_ | 9 #define BASE_FILES_FILE_UTIL_H_ |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 #include <sys/stat.h> | 28 #include <sys/stat.h> |
| 29 #include <unistd.h> | 29 #include <unistd.h> |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 #if defined(OS_POSIX) | 32 #if defined(OS_POSIX) |
| 33 #include "base/file_descriptor_posix.h" | 33 #include "base/file_descriptor_posix.h" |
| 34 #include "base/logging.h" | 34 #include "base/logging.h" |
| 35 #include "base/posix/eintr_wrapper.h" | 35 #include "base/posix/eintr_wrapper.h" |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 // fopen() takes a mode string that is typically something along the lines of | |
| 39 // "r" or "w+". By default, files opened via fopen() are opened such that they | |
| 40 // spill into child processes via the normal platform features (e.g., the file | |
| 41 // is opened with bInheritHandle=TRUE in its security descriptor on Windows). | |
| 42 // The character for a mode string to disable this spillage is not consistent | |
| 43 // across platforms. Define the macro FONE (i.e., "fopen 'N' or 'e'") for use in | |
|
gab
2017/02/06 21:13:19
Why "FONE"?
grt (UTC plus 2)
2017/02/06 21:51:21
FO -> fopen
N -> 'N' on Windows
E -> 'e' on glibc
gab
2017/02/07 19:42:59
That's very obscure to me. How about NOINHERITANCE
grt (UTC plus 2)
2017/02/07 20:36:06
How does PRIuS sit with you (https://cs.chromium.o
gab
2017/02/07 20:48:49
I don't like it either :)
| |
| 44 // cross platform code that calls base::OpenFile (or calls fopen directly). | |
| 45 #if defined(OS_WIN) | |
| 46 // "N" specifies that the underlying handle is not inherited by child processes | |
| 47 // (bInheritHandle=FALSE). | |
| 48 #define FONE "N" | |
| 49 #else // !defined(OS_WIN) | |
|
gab
2017/02/06 21:13:19
Just use // defined(OS_WIN) everywhere (i.e. here
grt (UTC plus 2)
2017/02/06 21:51:21
Done.
| |
| 50 // "e" specifies that the underlying descriptor is closed on exec (FD_CLOEXEC). | |
| 51 #define FONE "e" | |
| 52 #endif // OS_WIN | |
| 53 | |
| 38 namespace base { | 54 namespace base { |
| 39 | 55 |
| 40 class Environment; | 56 class Environment; |
| 41 class Time; | 57 class Time; |
| 42 | 58 |
| 43 //----------------------------------------------------------------------------- | 59 //----------------------------------------------------------------------------- |
| 44 // Functions that involve filesystem access or modification: | 60 // Functions that involve filesystem access or modification: |
| 45 | 61 |
| 46 // Returns an absolute version of a relative path. Returns an empty path on | 62 // Returns an absolute version of a relative path. Returns an empty path on |
| 47 // error. On POSIX, this function fails if the path does not exist. This | 63 // error. On POSIX, this function fails if the path does not exist. This |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 BASE_EXPORT bool IsLink(const FilePath& file_path); | 316 BASE_EXPORT bool IsLink(const FilePath& file_path); |
| 301 | 317 |
| 302 // Returns information about the given file path. | 318 // Returns information about the given file path. |
| 303 BASE_EXPORT bool GetFileInfo(const FilePath& file_path, File::Info* info); | 319 BASE_EXPORT bool GetFileInfo(const FilePath& file_path, File::Info* info); |
| 304 | 320 |
| 305 // Sets the time of the last access and the time of the last modification. | 321 // Sets the time of the last access and the time of the last modification. |
| 306 BASE_EXPORT bool TouchFile(const FilePath& path, | 322 BASE_EXPORT bool TouchFile(const FilePath& path, |
| 307 const Time& last_accessed, | 323 const Time& last_accessed, |
| 308 const Time& last_modified); | 324 const Time& last_modified); |
| 309 | 325 |
| 310 // Wrapper for fopen-like calls. Returns non-NULL FILE* on success. | 326 // Wrapper for fopen-like calls. Returns non-NULL FILE* on success. By default, |
| 327 // opened files will be inheritable by child processes. Append the FONE macro | |
| 328 // (defined above) when composing a |mode| string to disable this. | |
|
gab
2017/02/07 19:42:59
Mention that this is prefered for new callers and
| |
| 311 BASE_EXPORT FILE* OpenFile(const FilePath& filename, const char* mode); | 329 BASE_EXPORT FILE* OpenFile(const FilePath& filename, const char* mode); |
| 312 | 330 |
| 313 // Closes file opened by OpenFile. Returns true on success. | 331 // Closes file opened by OpenFile. Returns true on success. |
| 314 BASE_EXPORT bool CloseFile(FILE* file); | 332 BASE_EXPORT bool CloseFile(FILE* file); |
| 315 | 333 |
| 316 // Associates a standard FILE stream with an existing File. Note that this | 334 // Associates a standard FILE stream with an existing File. Note that this |
| 317 // functions take ownership of the existing File. | 335 // functions take ownership of the existing File. |
| 318 BASE_EXPORT FILE* FileToFILE(File file, const char* mode); | 336 BASE_EXPORT FILE* FileToFILE(File file, const char* mode); |
| 319 | 337 |
| 320 // Truncates an open file to end at the location of the current file pointer. | 338 // Truncates an open file to end at the location of the current file pointer. |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 // This function simulates Move(), but unlike Move() it works across volumes. | 466 // This function simulates Move(), but unlike Move() it works across volumes. |
| 449 // This function is not transactional. | 467 // This function is not transactional. |
| 450 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, | 468 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, |
| 451 const FilePath& to_path); | 469 const FilePath& to_path); |
| 452 #endif // defined(OS_WIN) | 470 #endif // defined(OS_WIN) |
| 453 | 471 |
| 454 } // namespace internal | 472 } // namespace internal |
| 455 } // namespace base | 473 } // namespace base |
| 456 | 474 |
| 457 #endif // BASE_FILES_FILE_UTIL_H_ | 475 #endif // BASE_FILES_FILE_UTIL_H_ |
| OLD | NEW |