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

Side by Side Diff: base/file_util_posix.cc

Issue 6005: Cross-platform equivalent of fopen, _wfopen_s etc.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 12 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_util.h" 5 #include "base/file_util.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <fnmatch.h> 9 #include <fnmatch.h>
10 #include <fts.h> 10 #include <fts.h>
11 #include <libgen.h> 11 #include <libgen.h>
12 #include <stdio.h>
12 #include <string.h> 13 #include <string.h>
13 #include <sys/errno.h> 14 #include <sys/errno.h>
14 #include <sys/stat.h> 15 #include <sys/stat.h>
15 #include <time.h> 16 #include <time.h>
16 17
17 #include <fstream> 18 #include <fstream>
18 19
19 #include "base/basictypes.h" 20 #include "base/basictypes.h"
20 #include "base/logging.h" 21 #include "base/logging.h"
21 #include "base/string_util.h" 22 #include "base/string_util.h"
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 303
303 bool GetFileInfo(const std::wstring& file_path, FileInfo* results) { 304 bool GetFileInfo(const std::wstring& file_path, FileInfo* results) {
304 struct stat64 file_info; 305 struct stat64 file_info;
305 if (stat64(WideToUTF8(file_path).c_str(), &file_info) != 0) 306 if (stat64(WideToUTF8(file_path).c_str(), &file_info) != 0)
306 return false; 307 return false;
307 results->is_directory = S_ISDIR(file_info.st_mode); 308 results->is_directory = S_ISDIR(file_info.st_mode);
308 results->size = file_info.st_size; 309 results->size = file_info.st_size;
309 return true; 310 return true;
310 } 311 }
311 312
313 FILE* OpenFile(const std::string& filename, const char* mode) {
314 return fopen(filename.c_str(), mode);
315 }
316
317 FILE* OpenFile(const std::wstring& filename, const char* mode) {
318 return fopen(WideToUTF8(filename).c_str(), mode);
319 }
320
312 int ReadFile(const std::wstring& filename, char* data, int size) { 321 int ReadFile(const std::wstring& filename, char* data, int size) {
313 int fd = open(WideToUTF8(filename).c_str(), O_RDONLY); 322 int fd = open(WideToUTF8(filename).c_str(), O_RDONLY);
314 if (fd < 0) 323 if (fd < 0)
315 return -1; 324 return -1;
316 325
317 int ret_value = read(fd, data, size); 326 int ret_value = read(fd, data, size);
318 close(fd); 327 close(fd);
319 return ret_value; 328 return ret_value;
320 } 329 }
321 330
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 return (file_type_ & FileEnumerator::DIRECTORIES) ? cur_file : Next(); 450 return (file_type_ & FileEnumerator::DIRECTORIES) ? cur_file : Next();
442 } else if (fts_ent->fts_info == FTS_F) { 451 } else if (fts_ent->fts_info == FTS_F) {
443 return (file_type_ & FileEnumerator::FILES) ? cur_file : Next(); 452 return (file_type_ & FileEnumerator::FILES) ? cur_file : Next();
444 } 453 }
445 // TODO(erikkay) - verify that the other fts_info types aren't interesting 454 // TODO(erikkay) - verify that the other fts_info types aren't interesting
446 return Next(); 455 return Next();
447 } 456 }
448 457
449 458
450 } // namespace file_util 459 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_util.cc ('k') | base/file_util_win.cc » ('j') | base/file_util_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698