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

Side by Side Diff: base/file_util_posix.cc

Issue 83001: ImportantFileWriter (Closed)
Patch Set: share more code Created 11 years, 7 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 | « base/file_util.cc ('k') | base/file_util_win.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) 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 <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <fnmatch.h> 10 #include <fnmatch.h>
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 FilePath directory; 362 FilePath directory;
363 if (!GetTempDir(&directory)) 363 if (!GetTempDir(&directory))
364 return false; 364 return false;
365 int fd = CreateAndOpenFdForTemporaryFile(directory, path); 365 int fd = CreateAndOpenFdForTemporaryFile(directory, path);
366 if (fd < 0) 366 if (fd < 0)
367 return false; 367 return false;
368 close(fd); 368 close(fd);
369 return true; 369 return true;
370 } 370 }
371 371
372 FILE* CreateAndOpenTemporaryFile(FilePath* path) {
373 FilePath directory;
374 if (!GetTempDir(&directory))
375 return false;
376
377 int fd = CreateAndOpenFdForTemporaryFile(directory, path);
378 if (fd < 0)
379 return NULL;
380
381 FILE *fp = fdopen(fd, "a+");
382 return fp;
383 }
384
385 FILE* CreateAndOpenTemporaryShmemFile(FilePath* path) { 372 FILE* CreateAndOpenTemporaryShmemFile(FilePath* path) {
386 FilePath directory; 373 FilePath directory;
387 if (!GetShmemTempDir(&directory)) 374 if (!GetShmemTempDir(&directory))
388 return false; 375 return false;
389 376
390 int fd = CreateAndOpenFdForTemporaryFile(directory, path); 377 return CreateAndOpenTemporaryFileInDir(directory, path);
378 }
379
380 FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir, FilePath* path) {
381 int fd = CreateAndOpenFdForTemporaryFile(dir, path);
391 if (fd < 0) 382 if (fd < 0)
392 return NULL; 383 return NULL;
393 384
394 FILE *fp = fdopen(fd, "a+"); 385 return fdopen(fd, "a+");
395 return fp;
396 } 386 }
397 387
398 bool CreateTemporaryFileNameInDir(const std::wstring& dir, 388 bool CreateTemporaryFileNameInDir(const std::wstring& dir,
399 std::wstring* temp_file) { 389 std::wstring* temp_file) {
400 // Not implemented yet. 390 // Not implemented yet.
401 NOTREACHED(); 391 NOTREACHED();
402 return false; 392 return false;
403 } 393 }
404 394
405 bool CreateNewTempDirectory(const FilePath::StringType& prefix, 395 bool CreateNewTempDirectory(const FilePath::StringType& prefix,
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 munmap(data_, length_); 632 munmap(data_, length_);
643 if (file_ != -1) 633 if (file_ != -1)
644 close(file_); 634 close(file_);
645 635
646 data_ = NULL; 636 data_ = NULL;
647 length_ = 0; 637 length_ = 0;
648 file_ = -1; 638 file_ = -1;
649 } 639 }
650 640
651 } // namespace file_util 641 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_util.cc ('k') | base/file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698