vfs: check userland buffers before reading them.
[haiku.git] / src / kits / debugger / files / LocatableFile.cpp
blobab45947737a1bcd58801c39a43e4840a8f4728e8
1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2016, Rene Gollent, rene@gollent.com.
4 * Distributed under the terms of the MIT License.
5 */
7 #include "LocatableFile.h"
9 #include <AutoLocker.h>
11 #include "LocatableDirectory.h"
14 // #pragma mark - LocatableFile
17 LocatableFile::LocatableFile(LocatableEntryOwner* owner,
18 LocatableDirectory* directory, const BString& name)
20 LocatableEntry(owner, directory),
21 fName(name),
22 fLocatedPath(),
23 fListeners(8)
28 LocatableFile::~LocatableFile()
33 const char*
34 LocatableFile::Name() const
36 return fName.String();
40 void
41 LocatableFile::GetPath(BString& _path) const
43 fParent->GetPath(_path);
44 if (_path.Length() != 0)
45 _path << '/';
46 _path << fName;
50 bool
51 LocatableFile::GetLocatedPath(BString& _path) const
53 AutoLocker<LocatableEntryOwner> locker(fOwner);
55 if (fLocatedPath.Length() > 0) {
56 _path = fLocatedPath;
57 return true;
60 if (!fParent->GetLocatedPath(_path))
61 return false;
63 _path << '/' << fName;
64 return true;
68 void
69 LocatableFile::SetLocatedPath(const BString& path, bool implicit)
71 // called with owner already locked
73 if (implicit) {
74 fLocatedPath = (const char*)NULL;
75 fState = LOCATABLE_ENTRY_LOCATED_IMPLICITLY;
76 } else {
77 fLocatedPath = path;
78 fState = LOCATABLE_ENTRY_LOCATED_EXPLICITLY;
81 _NotifyListeners();
85 bool
86 LocatableFile::AddListener(Listener* listener)
88 AutoLocker<LocatableEntryOwner> locker(fOwner);
89 return fListeners.AddItem(listener);
93 void
94 LocatableFile::RemoveListener(Listener* listener)
96 AutoLocker<LocatableEntryOwner> locker(fOwner);
97 fListeners.RemoveItem(listener);
101 void
102 LocatableFile::_NotifyListeners()
104 for (int32 i = fListeners.CountItems() - 1; i >= 0; i--)
105 fListeners.ItemAt(i)->LocatableFileChanged(this);
109 // #pragma mark - Listener
112 LocatableFile::Listener::~Listener()