| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BIN_FILE_H_ | 5 #ifndef BIN_FILE_H_ |
| 6 #define BIN_FILE_H_ | 6 #define BIN_FILE_H_ |
| 7 | 7 |
| 8 #if defined(_WIN32) | 8 #if defined(_WIN32) |
| 9 typedef signed __int64 int64_t; | 9 typedef signed __int64 int64_t; |
| 10 typedef unsigned __int8 uint8_t; | 10 typedef unsigned __int8 uint8_t; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 102 |
| 103 // Truncate (or extend) the file to the given length in bytes. | 103 // Truncate (or extend) the file to the given length in bytes. |
| 104 bool Truncate(int64_t length); | 104 bool Truncate(int64_t length); |
| 105 | 105 |
| 106 // Flush contents of file. | 106 // Flush contents of file. |
| 107 bool Flush(); | 107 bool Flush(); |
| 108 | 108 |
| 109 // Returns whether the file has been closed. | 109 // Returns whether the file has been closed. |
| 110 bool IsClosed(); | 110 bool IsClosed(); |
| 111 | 111 |
| 112 const char* name() const { return name_; } | |
| 113 | |
| 114 // Open the file with the given name. The file is always opened for | 112 // Open the file with the given name. The file is always opened for |
| 115 // reading. If mode contains kWrite the file is opened for both | 113 // reading. If mode contains kWrite the file is opened for both |
| 116 // reading and writing. If mode contains kWrite and the file does | 114 // reading and writing. If mode contains kWrite and the file does |
| 117 // not exist the file is created. The file is truncated to length 0 if | 115 // not exist the file is created. The file is truncated to length 0 if |
| 118 // mode contains kTruncate. | 116 // mode contains kTruncate. |
| 119 static File* Open(const char* name, FileOpenMode mode); | 117 static File* Open(const char* name, FileOpenMode mode); |
| 120 | 118 |
| 121 // Create a file object for the specified stdio file descriptor | 119 // Create a file object for the specified stdio file descriptor |
| 122 // (stdin, stout or stderr). | 120 // (stdin, stout or stderr). |
| 123 static File* OpenStdio(int fd); | 121 static File* OpenStdio(int fd); |
| 124 | 122 |
| 125 static bool Exists(const char* name); | 123 static bool Exists(const char* name); |
| 126 static bool Create(const char* name); | 124 static bool Create(const char* name); |
| 127 static bool Delete(const char* name); | 125 static bool Delete(const char* name); |
| 128 static off_t LengthFromName(const char* name); | 126 static off_t LengthFromName(const char* name); |
| 129 static time_t LastModified(const char* name); | 127 static time_t LastModified(const char* name); |
| 130 static bool IsAbsolutePath(const char* pathname); | 128 static bool IsAbsolutePath(const char* pathname); |
| 131 static char* GetCanonicalPath(const char* name); | 129 static char* GetCanonicalPath(const char* name); |
| 132 static char* GetContainingDirectory(char* name); | 130 static char* GetContainingDirectory(char* name); |
| 133 static const char* PathSeparator(); | 131 static const char* PathSeparator(); |
| 134 static const char* StringEscapedPathSeparator(); | 132 static const char* StringEscapedPathSeparator(); |
| 135 static StdioHandleType GetStdioHandleType(int fd); | 133 static StdioHandleType GetStdioHandleType(int fd); |
| 136 | 134 |
| 137 static FileOpenMode DartModeToFileMode(DartFileOpenMode mode); | 135 static FileOpenMode DartModeToFileMode(DartFileOpenMode mode); |
| 138 | 136 |
| 139 static Dart_Port GetServicePort(); | 137 static Dart_Port GetServicePort(); |
| 140 | 138 |
| 141 private: | 139 private: |
| 142 File(const char* name, FileHandle* handle) : name_(name), handle_(handle) { } | 140 explicit File(FileHandle* handle) : handle_(handle) { } |
| 143 void Close(); | 141 void Close(); |
| 144 | 142 |
| 145 static const int kClosedFd = -1; | 143 static const int kClosedFd = -1; |
| 146 | 144 |
| 147 const char* name_; | |
| 148 // FileHandle is an OS specific class which stores data about the file. | 145 // FileHandle is an OS specific class which stores data about the file. |
| 149 FileHandle* handle_; // OS specific handle for the file. | 146 FileHandle* handle_; // OS specific handle for the file. |
| 150 | 147 |
| 151 static dart::Mutex mutex_; | 148 static dart::Mutex mutex_; |
| 152 static int service_ports_size_; | 149 static int service_ports_size_; |
| 153 static Dart_Port* service_ports_; | 150 static Dart_Port* service_ports_; |
| 154 static int service_ports_index_; | 151 static int service_ports_index_; |
| 155 | 152 |
| 156 DISALLOW_COPY_AND_ASSIGN(File); | 153 DISALLOW_COPY_AND_ASSIGN(File); |
| 157 }; | 154 }; |
| 158 | 155 |
| 159 #endif // BIN_FILE_H_ | 156 #endif // BIN_FILE_H_ |
| OLD | NEW |