btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / debuganalyzer / util / DataSource.cpp
blob0ed98ae33b24f5f45ef695ec1defb5132872dc21
1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
6 #include "DataSource.h"
8 #include <new>
10 #include <String.h>
13 // #pragma mark - DataSource
16 DataSource::DataSource()
21 DataSource::~DataSource()
26 status_t
27 DataSource::GetName(BString& name)
29 return B_UNSUPPORTED;
33 // #pragma mark - FileDataSource
37 status_t
38 FileDataSource::CreateDataIO(BDataIO** _io)
40 BFile* file = new(std::nothrow) BFile;
41 if (file == NULL)
42 return B_NO_MEMORY;
44 status_t error = OpenFile(*file);
45 if (error != B_OK) {
46 delete file;
47 return error;
50 *_io = file;
51 return B_OK;
55 // #pragma mark - PathDataSource
58 status_t
59 PathDataSource::Init(const char* path)
61 return fPath.SetTo(path);
65 status_t
66 PathDataSource::GetName(BString& name)
68 if (fPath.Path() == NULL)
69 return B_NO_INIT;
71 name = fPath.Path();
72 return B_OK;
76 status_t
77 PathDataSource::OpenFile(BFile& file)
79 return file.SetTo(fPath.Path(), B_READ_ONLY);
83 // #pragma mark - EntryRefDataSource
86 status_t
87 EntryRefDataSource::Init(const entry_ref* ref)
89 if (ref->name == NULL)
90 return B_BAD_VALUE;
92 fRef = *ref;
93 if (fRef.name == NULL)
94 return B_NO_MEMORY;
96 return B_OK;
100 status_t
101 EntryRefDataSource::GetName(BString& name)
103 BEntry entry;
104 status_t error = entry.SetTo(&fRef);
105 if (error != B_OK)
106 return error;
108 BPath path;
109 error = entry.GetPath(&path);
110 if (error != B_OK)
111 return error;
113 name = path.Path();
114 return B_OK;
118 status_t
119 EntryRefDataSource::OpenFile(BFile& file)
121 return file.SetTo(&fRef, B_READ_ONLY);