aboutsummaryrefslogtreecommitdiff
path: root/src/processor/minidump.cc
diff options
context:
space:
mode:
authormmentovai <mmentovai@4c0a9323-5329-0410-9bdc-e9ce6186880e>2006-09-08 16:41:17 +0000
committermmentovai <mmentovai@4c0a9323-5329-0410-9bdc-e9ce6186880e>2006-09-08 16:41:17 +0000
commit6dd21d3baf490a34af0b1b1f5a48f8443dcb1ea6 (patch)
treec17055e78b878f16e9773bcf3fe377bd4c700777 /src/processor/minidump.cc
parentaddressing follow-up review comments from mark (#17) (diff)
downloadbreakpad-6dd21d3baf490a34af0b1b1f5a48f8443dcb1ea6.tar.xz
Change interface for providing files to Minidump (#19). r=bryner
- Interface change: Minidump constructor now accepts a const string& path argument instead of int fd. Minidump will open the file on first Read and close it upon destruction. - Adapt callers to new interface, no longer leaking file descriptors. http://groups.google.com/group/airbag-dev/browse_thread/thread/ff24dbcde7db8ae3 git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@20 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/processor/minidump.cc')
-rw-r--r--src/processor/minidump.cc31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/processor/minidump.cc b/src/processor/minidump.cc
index 6c4226b3..1a82e0f0 100644
--- a/src/processor/minidump.cc
+++ b/src/processor/minidump.cc
@@ -19,14 +19,18 @@
// Author: Mark Mentovai
+#include <fcntl.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#ifdef _WIN32
#include <io.h>
typedef SSIZE_T ssize_t;
+#define open _open
#define read _read
#define lseek _lseek
+#else // _WIN32
+#define O_BINARY 0
#endif // _WIN32
#include <map>
@@ -1693,11 +1697,12 @@ void MinidumpMiscInfo::Print() {
//
-Minidump::Minidump(int fd)
+Minidump::Minidump(const string& path)
: header_(),
directory_(NULL),
stream_map_(NULL),
- fd_(fd),
+ path_(path),
+ fd_(-1),
swap_(false),
valid_(false) {
}
@@ -1706,6 +1711,25 @@ Minidump::Minidump(int fd)
Minidump::~Minidump() {
delete directory_;
delete stream_map_;
+ if (fd_ != -1)
+ close(fd_);
+}
+
+
+bool Minidump::Open() {
+ if (fd_ != -1) {
+ // The file is already open. Seek to the beginning, which is the position
+ // the file would be at if it were opened anew.
+ return SeekSet(0);
+ }
+
+ // O_BINARY is useful (and defined) on Windows. On other platforms, it's
+ // useless, and because it's defined as 0 above, harmless.
+ fd_ = open(path_.c_str(), O_RDONLY | O_BINARY);
+ if (fd_ == -1)
+ return false;
+
+ return true;
}
@@ -1718,6 +1742,9 @@ bool Minidump::Read() {
valid_ = false;
+ if (!Open())
+ return false;
+
if (!ReadBytes(&header_, sizeof(MDRawHeader)))
return false;