| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 RUNTIME_BIN_FILE_H_ | 5 #ifndef RUNTIME_BIN_FILE_H_ |
| 6 #define RUNTIME_BIN_FILE_H_ | 6 #define RUNTIME_BIN_FILE_H_ |
| 7 | 7 |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // FileMode.READ, FileMode.WRITE, FileMode.APPEND, | 36 // FileMode.READ, FileMode.WRITE, FileMode.APPEND, |
| 37 // FileMode.WRITE_ONLY and FileMode.WRITE_ONLY_APPEND in file.dart. | 37 // FileMode.WRITE_ONLY and FileMode.WRITE_ONLY_APPEND in file.dart. |
| 38 enum DartFileOpenMode { | 38 enum DartFileOpenMode { |
| 39 kDartRead = 0, | 39 kDartRead = 0, |
| 40 kDartWrite = 1, | 40 kDartWrite = 1, |
| 41 kDartAppend = 2, | 41 kDartAppend = 2, |
| 42 kDartWriteOnly = 3, | 42 kDartWriteOnly = 3, |
| 43 kDartWriteOnlyAppend = 4 | 43 kDartWriteOnlyAppend = 4 |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 enum Type { | 46 enum Type { kIsFile = 0, kIsDirectory = 1, kIsLink = 2, kDoesNotExist = 3 }; |
| 47 kIsFile = 0, | |
| 48 kIsDirectory = 1, | |
| 49 kIsLink = 2, | |
| 50 kDoesNotExist = 3 | |
| 51 }; | |
| 52 | 47 |
| 53 enum Identical { | 48 enum Identical { kIdentical = 0, kDifferent = 1, kError = 2 }; |
| 54 kIdentical = 0, | |
| 55 kDifferent = 1, | |
| 56 kError = 2 | |
| 57 }; | |
| 58 | 49 |
| 59 enum StdioHandleType { | 50 enum StdioHandleType { |
| 60 kTerminal = 0, | 51 kTerminal = 0, |
| 61 kPipe = 1, | 52 kPipe = 1, |
| 62 kFile = 2, | 53 kFile = 2, |
| 63 kSocket = 3, | 54 kSocket = 3, |
| 64 kOther = 4 | 55 kOther = 4 |
| 65 }; | 56 }; |
| 66 | 57 |
| 67 enum FileStat { | 58 enum FileStat { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 98 // the number of bytes read/written. | 89 // the number of bytes read/written. |
| 99 int64_t Read(void* buffer, int64_t num_bytes); | 90 int64_t Read(void* buffer, int64_t num_bytes); |
| 100 int64_t Write(const void* buffer, int64_t num_bytes); | 91 int64_t Write(const void* buffer, int64_t num_bytes); |
| 101 | 92 |
| 102 // ReadFully and WriteFully do attempt to transfer num_bytes to/from | 93 // ReadFully and WriteFully do attempt to transfer num_bytes to/from |
| 103 // the buffer. In the event of short accesses they will loop internally until | 94 // the buffer. In the event of short accesses they will loop internally until |
| 104 // the whole buffer has been transferred or an error occurs. If an error | 95 // the whole buffer has been transferred or an error occurs. If an error |
| 105 // occurred the result will be set to false. | 96 // occurred the result will be set to false. |
| 106 bool ReadFully(void* buffer, int64_t num_bytes); | 97 bool ReadFully(void* buffer, int64_t num_bytes); |
| 107 bool WriteFully(const void* buffer, int64_t num_bytes); | 98 bool WriteFully(const void* buffer, int64_t num_bytes); |
| 108 bool WriteByte(uint8_t byte) { | 99 bool WriteByte(uint8_t byte) { return WriteFully(&byte, 1); } |
| 109 return WriteFully(&byte, 1); | |
| 110 } | |
| 111 | 100 |
| 112 // Get the length of the file. Returns a negative value if the length cannot | 101 // Get the length of the file. Returns a negative value if the length cannot |
| 113 // be determined (e.g. not seekable device). | 102 // be determined (e.g. not seekable device). |
| 114 int64_t Length(); | 103 int64_t Length(); |
| 115 | 104 |
| 116 // Get the current position in the file. | 105 // Get the current position in the file. |
| 117 // Returns a negative value if position cannot be determined. | 106 // Returns a negative value if position cannot be determined. |
| 118 int64_t Position(); | 107 int64_t Position(); |
| 119 | 108 |
| 120 // Set the byte position in the file. | 109 // Set the byte position in the file. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 static CObject* CreateLinkRequest(const CObjectArray& request); | 199 static CObject* CreateLinkRequest(const CObjectArray& request); |
| 211 static CObject* DeleteLinkRequest(const CObjectArray& request); | 200 static CObject* DeleteLinkRequest(const CObjectArray& request); |
| 212 static CObject* RenameLinkRequest(const CObjectArray& request); | 201 static CObject* RenameLinkRequest(const CObjectArray& request); |
| 213 static CObject* LinkTargetRequest(const CObjectArray& request); | 202 static CObject* LinkTargetRequest(const CObjectArray& request); |
| 214 static CObject* TypeRequest(const CObjectArray& request); | 203 static CObject* TypeRequest(const CObjectArray& request); |
| 215 static CObject* IdenticalRequest(const CObjectArray& request); | 204 static CObject* IdenticalRequest(const CObjectArray& request); |
| 216 static CObject* StatRequest(const CObjectArray& request); | 205 static CObject* StatRequest(const CObjectArray& request); |
| 217 static CObject* LockRequest(const CObjectArray& request); | 206 static CObject* LockRequest(const CObjectArray& request); |
| 218 | 207 |
| 219 private: | 208 private: |
| 220 explicit File(FileHandle* handle) : | 209 explicit File(FileHandle* handle) |
| 221 ReferenceCounted(), | 210 : ReferenceCounted(), handle_(handle), weak_handle_(NULL) {} |
| 222 handle_(handle), | |
| 223 weak_handle_(NULL) {} | |
| 224 | 211 |
| 225 ~File(); | 212 ~File(); |
| 226 | 213 |
| 227 static File* FileOpenW(const wchar_t* system_name, FileOpenMode mode); | 214 static File* FileOpenW(const wchar_t* system_name, FileOpenMode mode); |
| 228 | 215 |
| 229 static const int kClosedFd = -1; | 216 static const int kClosedFd = -1; |
| 230 | 217 |
| 231 // FileHandle is an OS specific class which stores data about the file. | 218 // FileHandle is an OS specific class which stores data about the file. |
| 232 FileHandle* handle_; // OS specific handle for the file. | 219 FileHandle* handle_; // OS specific handle for the file. |
| 233 | 220 |
| 234 // We retain the weak handle because we can do cleanup eagerly when Dart code | 221 // We retain the weak handle because we can do cleanup eagerly when Dart code |
| 235 // calls closeSync(). In that case, we delete the weak handle so that the | 222 // calls closeSync(). In that case, we delete the weak handle so that the |
| 236 // finalizer doesn't run. | 223 // finalizer doesn't run. |
| 237 Dart_WeakPersistentHandle weak_handle_; | 224 Dart_WeakPersistentHandle weak_handle_; |
| 238 | 225 |
| 239 friend class ReferenceCounted<File>; | 226 friend class ReferenceCounted<File>; |
| 240 DISALLOW_COPY_AND_ASSIGN(File); | 227 DISALLOW_COPY_AND_ASSIGN(File); |
| 241 }; | 228 }; |
| 242 | 229 |
| 243 } // namespace bin | 230 } // namespace bin |
| 244 } // namespace dart | 231 } // namespace dart |
| 245 | 232 |
| 246 #endif // RUNTIME_BIN_FILE_H_ | 233 #endif // RUNTIME_BIN_FILE_H_ |
| OLD | NEW |