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

Side by Side Diff: runtime/bin/file_win.cc

Issue 8437056: Implemented File create API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « runtime/bin/file_test.cc ('k') | runtime/bin/gen_snapshot.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 #include <fcntl.h> 5 #include <fcntl.h>
6 #include <io.h> 6 #include <io.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <string.h> 8 #include <string.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 10
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 if (position < 0) { 81 if (position < 0) {
82 // The file is not capable of seeking. Return an error. 82 // The file is not capable of seeking. Return an error.
83 return -1; 83 return -1;
84 } 84 }
85 off_t result = lseek(handle_->fd(), 0, SEEK_END); 85 off_t result = lseek(handle_->fd(), 0, SEEK_END);
86 lseek(handle_->fd(), position, SEEK_SET); 86 lseek(handle_->fd(), position, SEEK_SET);
87 return result; 87 return result;
88 } 88 }
89 89
90 90
91 File* File::OpenFile(const char* name, bool writable) { 91 File* File::Open(const char* name, bool writable) {
92 int flags = O_RDONLY | O_BINARY; 92 int flags = O_RDONLY | O_BINARY;
93 if (writable) { 93 if (writable) {
94 flags = (O_RDWR | O_CREAT | O_TRUNC | O_BINARY); 94 flags = (O_RDWR | O_CREAT | O_TRUNC | O_BINARY);
95 } 95 }
96 int fd = open(name, flags, 0666); 96 int fd = open(name, flags, 0666);
97 if (fd < 0) { 97 if (fd < 0) {
98 return NULL; 98 return NULL;
99 } 99 }
100 return new File(name, new FileHandle(fd)); 100 return new File(name, new FileHandle(fd));
101 } 101 }
102 102
103 103
104 bool File::FileExists(const char* name) { 104 bool File::Exists(const char* name) {
105 struct stat st; 105 struct stat st;
106 if (stat(name, &st) == 0) { 106 if (stat(name, &st) == 0) {
107 return ((st.st_mode & S_IFMT) == S_IFREG); 107 return ((st.st_mode & S_IFMT) == S_IFREG);
108 } else { 108 } else {
109 return false; 109 return false;
110 } 110 }
111 } 111 }
112 112
113 113
114 bool File::Create(const char* name) {
115 int fd = open(name, O_RDONLY | O_CREAT, 0666);
116 if (fd < 0) {
117 return false;
118 }
119 return (close(fd) == 0);
120 }
121
122
114 bool File::IsAbsolutePath(const char* pathname) { 123 bool File::IsAbsolutePath(const char* pathname) {
115 // Should we consider network paths? 124 // Should we consider network paths?
116 if (pathname == NULL) return false; 125 if (pathname == NULL) return false;
117 return (strlen(pathname) > 2) && 126 return (strlen(pathname) > 2) &&
118 (pathname[1] == ':') && 127 (pathname[1] == ':') &&
119 (pathname[2] == '\\'); 128 (pathname[2] == '\\');
120 } 129 }
121 130
122 131
123 char* File::GetCanonicalPath(const char* pathname) { 132 char* File::GetCanonicalPath(const char* pathname) {
124 int required_size = GetFullPathName(pathname, 0, NULL, NULL); 133 int required_size = GetFullPathName(pathname, 0, NULL, NULL);
125 char* path = static_cast<char*>(malloc(required_size)); 134 char* path = static_cast<char*>(malloc(required_size));
126 int written = GetFullPathName(pathname, required_size, path, NULL); 135 int written = GetFullPathName(pathname, required_size, path, NULL);
127 ASSERT(written == (required_size - 1)); 136 ASSERT(written == (required_size - 1));
128 return path; 137 return path;
129 } 138 }
130 139
131 140
132 const char* File::PathSeparator() { 141 const char* File::PathSeparator() {
133 return "\\"; 142 return "\\";
134 } 143 }
135 144
136 145
137 const char* File::StringEscapedPathSeparator() { 146 const char* File::StringEscapedPathSeparator() {
138 return "\\\\"; 147 return "\\\\";
139 } 148 }
OLDNEW
« no previous file with comments | « runtime/bin/file_test.cc ('k') | runtime/bin/gen_snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698