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

Side by Side Diff: runtime/bin/file_linux.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_impl.dart ('k') | runtime/bin/file_macos.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 <errno.h> 5 #include <errno.h>
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <sys/stat.h> 7 #include <sys/stat.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 #include <libgen.h> 9 #include <libgen.h>
10 10
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 if (position < 0) { 84 if (position < 0) {
85 // The file is not capable of seeking. Return an error. 85 // The file is not capable of seeking. Return an error.
86 return -1; 86 return -1;
87 } 87 }
88 off_t result = lseek(handle_->fd(), 0, SEEK_END); 88 off_t result = lseek(handle_->fd(), 0, SEEK_END);
89 lseek(handle_->fd(), position, SEEK_SET); 89 lseek(handle_->fd(), position, SEEK_SET);
90 return result; 90 return result;
91 } 91 }
92 92
93 93
94 File* File::OpenFile(const char* name, bool writable) { 94 File* File::Open(const char* name, bool writable) {
95 int flags = O_RDONLY; 95 int flags = O_RDONLY;
96 if (writable) { 96 if (writable) {
97 flags = (O_RDWR | O_CREAT | O_TRUNC); 97 flags = (O_RDWR | O_CREAT | O_TRUNC);
98 } 98 }
99 int fd = open(name, flags, 0666); 99 int fd = open(name, flags, 0666);
100 if (fd < 0) { 100 if (fd < 0) {
101 return NULL; 101 return NULL;
102 } 102 }
103 return new File(name, new FileHandle(fd)); 103 return new File(name, new FileHandle(fd));
104 } 104 }
105 105
106 106
107 bool File::FileExists(const char* name) { 107 bool File::Exists(const char* name) {
108 struct stat st; 108 struct stat st;
109 if (stat(name, &st) == 0) { 109 if (stat(name, &st) == 0) {
110 return S_ISREG(st.st_mode); // Deal with symlinks? 110 return S_ISREG(st.st_mode); // Deal with symlinks?
111 } else { 111 } else {
112 return false; 112 return false;
113 } 113 }
114 } 114 }
115 115
116 116
117 bool File::Create(const char* name) {
118 int fd = open(name, O_RDONLY | O_CREAT, 0666);
119 if (fd < 0) {
120 return false;
121 }
122 return (close(fd) == 0);
123 }
124
125
117 bool File::IsAbsolutePath(const char* pathname) { 126 bool File::IsAbsolutePath(const char* pathname) {
118 return (pathname != NULL && pathname[0] == '/'); 127 return (pathname != NULL && pathname[0] == '/');
119 } 128 }
120 129
121 130
122 char* File::GetCanonicalPath(const char* pathname) { 131 char* File::GetCanonicalPath(const char* pathname) {
123 char* abs_path = NULL; 132 char* abs_path = NULL;
124 if (pathname != NULL) { 133 if (pathname != NULL) {
125 abs_path = realpath(pathname, NULL); 134 abs_path = realpath(pathname, NULL);
126 assert(abs_path == NULL || IsAbsolutePath(abs_path)); 135 assert(abs_path == NULL || IsAbsolutePath(abs_path));
127 } 136 }
128 return abs_path; 137 return abs_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_impl.dart ('k') | runtime/bin/file_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698