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

Side by Side Diff: base/file_util.cc

Issue 19024: Reverting 8722,8721. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 11 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
« no previous file with comments | « base/file_util.h ('k') | chrome/browser/browser.scons » ('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) 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 #if defined(OS_WIN)
8 #include <io.h>
9 #endif
10 #include <stdio.h> 7 #include <stdio.h>
11 8
12 #include <fstream> 9 #include <fstream>
13 10
14 #include "base/file_path.h" 11 #include "base/file_path.h"
15 #include "base/logging.h" 12 #include "base/logging.h"
16 #include "base/string_util.h" 13 #include "base/string_util.h"
17 #include "unicode/uniset.h" 14 #include "unicode/uniset.h"
18 15
19 #include "base/string_piece.h" 16 #include "base/string_piece.h"
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 *file_size = info.size; 269 *file_size = info.size;
273 return true; 270 return true;
274 } 271 }
275 272
276 bool CloseFile(FILE* file) { 273 bool CloseFile(FILE* file) {
277 if (file == NULL) 274 if (file == NULL)
278 return true; 275 return true;
279 return fclose(file) == 0; 276 return fclose(file) == 0;
280 } 277 }
281 278
282 bool TruncateFile(FILE* file) {
283 if (file == NULL)
284 return false;
285 long current_offset = ftell(file);
286 if (current_offset == -1)
287 return false;
288 #if defined(OS_WIN)
289 int fd = _fileno(file);
290 if (_chsize(fd, current_offset) != 0)
291 return false;
292 #else
293 int fd = fileno(file);
294 if (ftruncate(fd, current_offset) != 0)
295 return false;
296 #endif
297 return true;
298 }
299
300 bool ContainsPath(const FilePath &parent, const FilePath& child) { 279 bool ContainsPath(const FilePath &parent, const FilePath& child) {
301 FilePath abs_parent = FilePath(parent); 280 FilePath abs_parent = FilePath(parent);
302 FilePath abs_child = FilePath(child); 281 FilePath abs_child = FilePath(child);
303 282
304 if (!file_util::AbsolutePath(&abs_parent) || 283 if (!file_util::AbsolutePath(&abs_parent) ||
305 !file_util::AbsolutePath(&abs_child)) 284 !file_util::AbsolutePath(&abs_child))
306 return false; 285 return false;
307 286
308 #if defined(OS_WIN) 287 #if defined(OS_WIN)
309 // file_util::AbsolutePath() does not flatten case on Windows, so we must do 288 // file_util::AbsolutePath() does not flatten case on Windows, so we must do
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 FilePath directory = path.DirName(); 466 FilePath directory = path.DirName();
488 // If there is no separator, we will get back kCurrentDirectory. 467 // If there is no separator, we will get back kCurrentDirectory.
489 // In this case, clear dir. 468 // In this case, clear dir.
490 if (directory == path || directory.value() == FilePath::kCurrentDirectory) 469 if (directory == path || directory.value() == FilePath::kCurrentDirectory)
491 dir->clear(); 470 dir->clear();
492 else 471 else
493 *dir = directory.ToWStringHack(); 472 *dir = directory.ToWStringHack();
494 } 473 }
495 } // namespace 474 } // namespace
496 475
OLDNEW
« no previous file with comments | « base/file_util.h ('k') | chrome/browser/browser.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698