| 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 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 class File { | 23 class File { |
| 24 public: | 24 public: |
| 25 enum FileOpenMode { | 25 enum FileOpenMode { |
| 26 kRead = 0, | 26 kRead = 0, |
| 27 kWrite = 1, | 27 kWrite = 1, |
| 28 kTruncate = 1 << 2, | 28 kTruncate = 1 << 2, |
| 29 kWriteTruncate = kWrite | kTruncate | 29 kWriteTruncate = kWrite | kTruncate |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 // These values have to be kept in sync with the mode values of |
| 33 // FileMode.READ, FileMode.WRITE and FileMode.APPEND in file.dart. |
| 34 enum DartFileOpenMode { |
| 35 kDartRead = 0, |
| 36 kDartWrite = 1, |
| 37 kDartAppend = 2 |
| 38 }; |
| 39 |
| 32 enum StdioHandleType { | 40 enum StdioHandleType { |
| 33 kTerminal = 0, | 41 kTerminal = 0, |
| 34 kPipe = 1, | 42 kPipe = 1, |
| 35 kFile = 2, | 43 kFile = 2, |
| 36 kOther = 3 | 44 kOther = 3 |
| 37 }; | 45 }; |
| 38 | 46 |
| 47 enum FileRequest { |
| 48 kExistsRequest = 0, |
| 49 kCreateRequest = 1, |
| 50 kDeleteRequest = 2, |
| 51 kOpenRequest = 3, |
| 52 kFullPathRequest = 4, |
| 53 kDirectoryRequest = 5, |
| 54 kCloseRequest = 6, |
| 55 kPositionRequest = 7, |
| 56 kSetPositionRequest = 8, |
| 57 kTruncateRequest = 9, |
| 58 kLengthRequest = 10, |
| 59 kFlushRequest = 11, |
| 60 kReadByteRequest = 12, |
| 61 kWriteByteRequest = 13, |
| 62 kReadListRequest = 14, |
| 63 kWriteListRequest = 15, |
| 64 kWriteStringRequest = 16 |
| 65 }; |
| 66 |
| 39 ~File(); | 67 ~File(); |
| 40 | 68 |
| 41 // Read/Write attempt to transfer num_bytes to/from buffer. It returns | 69 // Read/Write attempt to transfer num_bytes to/from buffer. It returns |
| 42 // the number of bytes read/written. | 70 // the number of bytes read/written. |
| 43 int64_t Read(void* buffer, int64_t num_bytes); | 71 int64_t Read(void* buffer, int64_t num_bytes); |
| 44 int64_t Write(const void* buffer, int64_t num_bytes); | 72 int64_t Write(const void* buffer, int64_t num_bytes); |
| 45 | 73 |
| 46 // ReadFully and WriteFully do attempt to transfer num_bytes to/from | 74 // ReadFully and WriteFully do attempt to transfer num_bytes to/from |
| 47 // the buffer. In the event of short accesses they will loop internally until | 75 // the buffer. In the event of short accesses they will loop internally until |
| 48 // the whole buffer has been transferred or an error occurs. If an error | 76 // the whole buffer has been transferred or an error occurs. If an error |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 static bool Exists(const char* name); | 114 static bool Exists(const char* name); |
| 87 static bool Create(const char* name); | 115 static bool Create(const char* name); |
| 88 static bool Delete(const char* name); | 116 static bool Delete(const char* name); |
| 89 static bool IsAbsolutePath(const char* pathname); | 117 static bool IsAbsolutePath(const char* pathname); |
| 90 static char* GetCanonicalPath(const char* name); | 118 static char* GetCanonicalPath(const char* name); |
| 91 static char* GetContainingDirectory(char* name); | 119 static char* GetContainingDirectory(char* name); |
| 92 static const char* PathSeparator(); | 120 static const char* PathSeparator(); |
| 93 static const char* StringEscapedPathSeparator(); | 121 static const char* StringEscapedPathSeparator(); |
| 94 static StdioHandleType GetStdioHandleType(int fd); | 122 static StdioHandleType GetStdioHandleType(int fd); |
| 95 | 123 |
| 124 static FileOpenMode DartModeToFileMode(DartFileOpenMode mode); |
| 125 |
| 96 private: | 126 private: |
| 97 File(const char* name, FileHandle* handle) : name_(name), handle_(handle) { } | 127 File(const char* name, FileHandle* handle) : name_(name), handle_(handle) { } |
| 98 void Close(); | 128 void Close(); |
| 99 bool IsClosed(); | 129 bool IsClosed(); |
| 100 | 130 |
| 101 static const int kClosedFd = -1; | 131 static const int kClosedFd = -1; |
| 102 | 132 |
| 103 const char* name_; | 133 const char* name_; |
| 104 // FileHandle is an OS specific class which stores data about the file. | 134 // FileHandle is an OS specific class which stores data about the file. |
| 105 FileHandle* handle_; // OS specific handle for the file. | 135 FileHandle* handle_; // OS specific handle for the file. |
| 106 | 136 |
| 107 // DISALLOW_COPY_AND_ASSIGN(File). | 137 // DISALLOW_COPY_AND_ASSIGN(File). |
| 108 File(const File&); | 138 File(const File&); |
| 109 void operator=(const File&); | 139 void operator=(const File&); |
| 110 }; | 140 }; |
| 111 | 141 |
| 112 #endif // BIN_FILE_H_ | 142 #endif // BIN_FILE_H_ |
| OLD | NEW |