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 BIN_FILE_H_ | 5 #ifndef BIN_FILE_H_ |
6 #define BIN_FILE_H_ | 6 #define BIN_FILE_H_ |
7 | 7 |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // the whole buffer has been transferred or an error occurs. If an error | 83 // the whole buffer has been transferred or an error occurs. If an error |
84 // occurred the result will be set to false. | 84 // occurred the result will be set to false. |
85 bool ReadFully(void* buffer, int64_t num_bytes); | 85 bool ReadFully(void* buffer, int64_t num_bytes); |
86 bool WriteFully(const void* buffer, int64_t num_bytes); | 86 bool WriteFully(const void* buffer, int64_t num_bytes); |
87 bool WriteByte(uint8_t byte) { | 87 bool WriteByte(uint8_t byte) { |
88 return WriteFully(&byte, 1); | 88 return WriteFully(&byte, 1); |
89 } | 89 } |
90 | 90 |
91 // Get the length of the file. Returns a negative value if the length cannot | 91 // Get the length of the file. Returns a negative value if the length cannot |
92 // be determined (e.g. not seekable device). | 92 // be determined (e.g. not seekable device). |
93 off_t Length(); | 93 off64_t Length(); |
94 | 94 |
95 // Get the current position in the file. | 95 // Get the current position in the file. |
96 // Returns a negative value if position cannot be determined. | 96 // Returns a negative value if position cannot be determined. |
97 off_t Position(); | 97 off64_t Position(); |
98 | 98 |
99 // Set the byte position in the file. | 99 // Set the byte position in the file. |
100 bool SetPosition(int64_t position); | 100 bool SetPosition(off64_t position); |
101 | 101 |
102 // Truncate (or extend) the file to the given length in bytes. | 102 // Truncate (or extend) the file to the given length in bytes. |
103 bool Truncate(int64_t length); | 103 bool Truncate(off64_t length); |
104 | 104 |
105 // Flush contents of file. | 105 // Flush contents of file. |
106 bool Flush(); | 106 bool Flush(); |
107 | 107 |
108 // Returns whether the file has been closed. | 108 // Returns whether the file has been closed. |
109 bool IsClosed(); | 109 bool IsClosed(); |
110 | 110 |
111 // Open the file with the given path. The file is always opened for | 111 // Open the file with the given path. The file is always opened for |
112 // reading. If mode contains kWrite the file is opened for both | 112 // reading. If mode contains kWrite the file is opened for both |
113 // reading and writing. If mode contains kWrite and the file does | 113 // reading and writing. If mode contains kWrite and the file does |
114 // not exist the file is created. The file is truncated to length 0 if | 114 // not exist the file is created. The file is truncated to length 0 if |
115 // mode contains kTruncate. | 115 // mode contains kTruncate. |
116 static File* Open(const char* path, FileOpenMode mode); | 116 static File* Open(const char* path, FileOpenMode mode); |
117 | 117 |
118 // Create a file object for the specified stdio file descriptor | 118 // Create a file object for the specified stdio file descriptor |
119 // (stdin, stout or stderr). | 119 // (stdin, stout or stderr). |
120 static File* OpenStdio(int fd); | 120 static File* OpenStdio(int fd); |
121 | 121 |
122 static bool Exists(const char* path); | 122 static bool Exists(const char* path); |
123 static bool Create(const char* path); | 123 static bool Create(const char* path); |
124 static bool CreateLink(const char* path, const char* target); | 124 static bool CreateLink(const char* path, const char* target); |
125 static bool Delete(const char* path); | 125 static bool Delete(const char* path); |
126 static bool DeleteLink(const char* path); | 126 static bool DeleteLink(const char* path); |
127 static bool Rename(const char* old_path, const char* new_path); | 127 static bool Rename(const char* old_path, const char* new_path); |
128 static bool RenameLink(const char* old_path, const char* new_path); | 128 static bool RenameLink(const char* old_path, const char* new_path); |
129 static off_t LengthFromPath(const char* path); | 129 static off64_t LengthFromPath(const char* path); |
130 static void Stat(const char* path, int64_t* data); | 130 static void Stat(const char* path, int64_t* data); |
131 static time_t LastModified(const char* path); | 131 static time_t LastModified(const char* path); |
132 static char* LinkTarget(const char* pathname); | 132 static char* LinkTarget(const char* pathname); |
133 static bool IsAbsolutePath(const char* path); | 133 static bool IsAbsolutePath(const char* path); |
134 static char* GetCanonicalPath(const char* path); | 134 static char* GetCanonicalPath(const char* path); |
135 static const char* PathSeparator(); | 135 static const char* PathSeparator(); |
136 static const char* StringEscapedPathSeparator(); | 136 static const char* StringEscapedPathSeparator(); |
137 static Type GetType(const char* path, bool follow_links); | 137 static Type GetType(const char* path, bool follow_links); |
138 static Identical AreIdentical(const char* file_1, const char* file_2); | 138 static Identical AreIdentical(const char* file_1, const char* file_2); |
139 static StdioHandleType GetStdioHandleType(int fd); | 139 static StdioHandleType GetStdioHandleType(int fd); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 // FileHandle is an OS specific class which stores data about the file. | 176 // FileHandle is an OS specific class which stores data about the file. |
177 FileHandle* handle_; // OS specific handle for the file. | 177 FileHandle* handle_; // OS specific handle for the file. |
178 | 178 |
179 DISALLOW_COPY_AND_ASSIGN(File); | 179 DISALLOW_COPY_AND_ASSIGN(File); |
180 }; | 180 }; |
181 | 181 |
182 } // namespace bin | 182 } // namespace bin |
183 } // namespace dart | 183 } // namespace dart |
184 | 184 |
185 #endif // BIN_FILE_H_ | 185 #endif // BIN_FILE_H_ |
OLD | NEW |