Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: runtime/bin/file.h

Issue 1781883002: Fixes some memory leaks in //runtime/bin (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix tests on Windows Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/fdutils_android.cc ('k') | runtime/bin/file.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <sys/types.h> 11 #include <sys/types.h>
12 12
13 #include "bin/builtin.h" 13 #include "bin/builtin.h"
14 #include "bin/dartutils.h" 14 #include "bin/dartutils.h"
15 15
16
17 namespace dart { 16 namespace dart {
18 namespace bin { 17 namespace bin {
19 18
20 // Forward declaration. 19 // Forward declaration.
21 class FileHandle; 20 class FileHandle;
22 21
23 class File { 22 class File {
24 public: 23 public:
25 enum FileOpenMode { 24 enum FileOpenMode {
26 kRead = 0, 25 kRead = 0,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // Lock range of a file. 121 // Lock range of a file.
123 bool Lock(LockType lock, int64_t start, int64_t end); 122 bool Lock(LockType lock, int64_t start, int64_t end);
124 123
125 // Returns whether the file has been closed. 124 // Returns whether the file has been closed.
126 bool IsClosed(); 125 bool IsClosed();
127 126
128 // Open the file with the given path. The file is always opened for 127 // Open the file with the given path. The file is always opened for
129 // reading. If mode contains kWrite the file is opened for both 128 // reading. If mode contains kWrite the file is opened for both
130 // reading and writing. If mode contains kWrite and the file does 129 // reading and writing. If mode contains kWrite and the file does
131 // not exist the file is created. The file is truncated to length 0 if 130 // not exist the file is created. The file is truncated to length 0 if
132 // mode contains kTruncate. 131 // mode contains kTruncate. Assumes we are in an API scope.
132 static File* ScopedOpen(const char* path, FileOpenMode mode);
133
134 // Like ScopedOpen(), but no API scope is needed.
133 static File* Open(const char* path, FileOpenMode mode); 135 static File* Open(const char* path, FileOpenMode mode);
134 136
135 // Create a file object for the specified stdio file descriptor 137 // Create a file object for the specified stdio file descriptor
136 // (stdin, stout or stderr). 138 // (stdin, stout or stderr).
137 static File* OpenStdio(int fd); 139 static File* OpenStdio(int fd);
138 140
139 static bool Exists(const char* path); 141 static bool Exists(const char* path);
140 static bool Create(const char* path); 142 static bool Create(const char* path);
141 static bool CreateLink(const char* path, const char* target); 143 static bool CreateLink(const char* path, const char* target);
142 static bool Delete(const char* path); 144 static bool Delete(const char* path);
143 static bool DeleteLink(const char* path); 145 static bool DeleteLink(const char* path);
144 static bool Rename(const char* old_path, const char* new_path); 146 static bool Rename(const char* old_path, const char* new_path);
145 static bool RenameLink(const char* old_path, const char* new_path); 147 static bool RenameLink(const char* old_path, const char* new_path);
146 static bool Copy(const char* old_path, const char* new_path); 148 static bool Copy(const char* old_path, const char* new_path);
147 static int64_t LengthFromPath(const char* path); 149 static int64_t LengthFromPath(const char* path);
148 static void Stat(const char* path, int64_t* data); 150 static void Stat(const char* path, int64_t* data);
149 static time_t LastModified(const char* path); 151 static time_t LastModified(const char* path);
150 static char* LinkTarget(const char* pathname); 152 static const char* LinkTarget(const char* pathname);
151 static bool IsAbsolutePath(const char* path); 153 static bool IsAbsolutePath(const char* path);
152 static char* GetCanonicalPath(const char* path); 154 static const char* GetCanonicalPath(const char* path);
153 static const char* PathSeparator(); 155 static const char* PathSeparator();
154 static const char* StringEscapedPathSeparator(); 156 static const char* StringEscapedPathSeparator();
155 static Type GetType(const char* path, bool follow_links); 157 static Type GetType(const char* path, bool follow_links);
156 static Identical AreIdentical(const char* file_1, const char* file_2); 158 static Identical AreIdentical(const char* file_1, const char* file_2);
157 static StdioHandleType GetStdioHandleType(int fd); 159 static StdioHandleType GetStdioHandleType(int fd);
158 160
159 static FileOpenMode DartModeToFileMode(DartFileOpenMode mode); 161 static FileOpenMode DartModeToFileMode(DartFileOpenMode mode);
160 162
161 static CObject* ExistsRequest(const CObjectArray& request); 163 static CObject* ExistsRequest(const CObjectArray& request);
162 static CObject* CreateRequest(const CObjectArray& request); 164 static CObject* CreateRequest(const CObjectArray& request);
(...skipping 21 matching lines...) Expand all
184 static CObject* LinkTargetRequest(const CObjectArray& request); 186 static CObject* LinkTargetRequest(const CObjectArray& request);
185 static CObject* TypeRequest(const CObjectArray& request); 187 static CObject* TypeRequest(const CObjectArray& request);
186 static CObject* IdenticalRequest(const CObjectArray& request); 188 static CObject* IdenticalRequest(const CObjectArray& request);
187 static CObject* StatRequest(const CObjectArray& request); 189 static CObject* StatRequest(const CObjectArray& request);
188 static CObject* LockRequest(const CObjectArray& request); 190 static CObject* LockRequest(const CObjectArray& request);
189 191
190 private: 192 private:
191 explicit File(FileHandle* handle) : handle_(handle) { } 193 explicit File(FileHandle* handle) : handle_(handle) { }
192 void Close(); 194 void Close();
193 195
196 static File* FileOpenW(const wchar_t* system_name, FileOpenMode mode);
197
194 static const int kClosedFd = -1; 198 static const int kClosedFd = -1;
195 199
196 // FileHandle is an OS specific class which stores data about the file. 200 // FileHandle is an OS specific class which stores data about the file.
197 FileHandle* handle_; // OS specific handle for the file. 201 FileHandle* handle_; // OS specific handle for the file.
198 202
199 DISALLOW_COPY_AND_ASSIGN(File); 203 DISALLOW_COPY_AND_ASSIGN(File);
200 }; 204 };
201 205
202 } // namespace bin 206 } // namespace bin
203 } // namespace dart 207 } // namespace dart
204 208
205 #endif // BIN_FILE_H_ 209 #endif // BIN_FILE_H_
OLDNEW
« no previous file with comments | « runtime/bin/fdutils_android.cc ('k') | runtime/bin/file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698