| OLD | NEW |
| 1 // Copyright (c) 2011, 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; |
| 11 #else | 11 #else |
| (...skipping 10 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 enum StdioHandleType { |
| 33 kTerminal = 0, |
| 34 kPipe = 1, |
| 35 kFile = 2, |
| 36 kOther = 3 |
| 37 }; |
| 38 |
| 32 ~File(); | 39 ~File(); |
| 33 | 40 |
| 34 // Read/Write attempt to transfer num_bytes to/from buffer. It returns | 41 // Read/Write attempt to transfer num_bytes to/from buffer. It returns |
| 35 // the number of bytes read/written. | 42 // the number of bytes read/written. |
| 36 int64_t Read(void* buffer, int64_t num_bytes); | 43 int64_t Read(void* buffer, int64_t num_bytes); |
| 37 int64_t Write(const void* buffer, int64_t num_bytes); | 44 int64_t Write(const void* buffer, int64_t num_bytes); |
| 38 | 45 |
| 39 // ReadFully and WriteFully do attempt to transfer num_bytes to/from | 46 // ReadFully and WriteFully do attempt to transfer num_bytes to/from |
| 40 // the buffer. In the event of short accesses they will loop internally until | 47 // the buffer. In the event of short accesses they will loop internally until |
| 41 // the whole buffer has been transferred or an error occurs. If an error | 48 // the whole buffer has been transferred or an error occurs. If an error |
| (...skipping 23 matching lines...) Expand all Loading... |
| 65 | 72 |
| 66 const char* name() const { return name_; } | 73 const char* name() const { return name_; } |
| 67 | 74 |
| 68 // Open the file with the given name. The file is always opened for | 75 // Open the file with the given name. The file is always opened for |
| 69 // reading. If mode contains kWrite the file is opened for both | 76 // reading. If mode contains kWrite the file is opened for both |
| 70 // reading and writing. If mode contains kWrite and the file does | 77 // reading and writing. If mode contains kWrite and the file does |
| 71 // not exist the file is created. The file is truncated to length 0 if | 78 // not exist the file is created. The file is truncated to length 0 if |
| 72 // mode contains kTruncate. | 79 // mode contains kTruncate. |
| 73 static File* Open(const char* name, FileOpenMode mode); | 80 static File* Open(const char* name, FileOpenMode mode); |
| 74 | 81 |
| 82 // Create a file object for the specified stdio file descriptor |
| 83 // (stdin, stout or stderr). |
| 84 static File* OpenStdio(int fd); |
| 85 |
| 75 static bool Exists(const char* name); | 86 static bool Exists(const char* name); |
| 76 static bool Create(const char* name); | 87 static bool Create(const char* name); |
| 77 static bool Delete(const char* name); | 88 static bool Delete(const char* name); |
| 78 static bool IsAbsolutePath(const char* pathname); | 89 static bool IsAbsolutePath(const char* pathname); |
| 79 static char* GetCanonicalPath(const char* name); | 90 static char* GetCanonicalPath(const char* name); |
| 80 static const char* PathSeparator(); | 91 static const char* PathSeparator(); |
| 81 static const char* StringEscapedPathSeparator(); | 92 static const char* StringEscapedPathSeparator(); |
| 93 static StdioHandleType GetStdioHandleType(int fd); |
| 82 | 94 |
| 83 private: | 95 private: |
| 84 File(const char* name, FileHandle* handle) : name_(name), handle_(handle) { } | 96 File(const char* name, FileHandle* handle) : name_(name), handle_(handle) { } |
| 85 void Close(); | 97 void Close(); |
| 86 bool IsClosed(); | 98 bool IsClosed(); |
| 87 | 99 |
| 88 static const int kClosedFd = -1; | 100 static const int kClosedFd = -1; |
| 89 | 101 |
| 90 const char* name_; | 102 const char* name_; |
| 91 // FileHandle is an OS specific class which stores data about the file. | 103 // FileHandle is an OS specific class which stores data about the file. |
| 92 FileHandle* handle_; // OS specific handle for the file. | 104 FileHandle* handle_; // OS specific handle for the file. |
| 93 | 105 |
| 94 // DISALLOW_COPY_AND_ASSIGN(File). | 106 // DISALLOW_COPY_AND_ASSIGN(File). |
| 95 File(const File&); | 107 File(const File&); |
| 96 void operator=(const File&); | 108 void operator=(const File&); |
| 97 }; | 109 }; |
| 98 | 110 |
| 99 #endif // BIN_FILE_H_ | 111 #endif // BIN_FILE_H_ |
| OLD | NEW |