1 //----------------------------------------------------------------------
2 // This software is part of the OpenBeOS distribution and is covered
4 //---------------------------------------------------------------------
7 OffsetFile implementation.
12 #include "OffsetFile.h"
18 OffsetFile::OffsetFile()
26 OffsetFile::OffsetFile(BFile
*file
, off_t offset
)
35 OffsetFile::~OffsetFile()
41 OffsetFile::SetTo(BFile
*file
, off_t offset
)
46 return fFile
->InitCheck();
60 OffsetFile::InitCheck() const
62 return (fFile
? fFile
->InitCheck() : B_NO_INIT
);
67 OffsetFile::File() const
74 OffsetFile::ReadAt(off_t pos
, void *buffer
, size_t size
)
76 status_t error
= InitCheck();
79 result
= fFile
->ReadAt(pos
+ fOffset
, buffer
, size
);
80 return (error
== B_OK
? result
: error
);
85 OffsetFile::WriteAt(off_t pos
, const void *buffer
, size_t size
)
87 status_t error
= InitCheck();
90 result
= fFile
->WriteAt(pos
+ fOffset
, buffer
, size
);
91 return (error
== B_OK
? result
: error
);
96 OffsetFile::Seek(off_t position
, uint32 seekMode
)
98 off_t result
= B_BAD_VALUE
;
99 status_t error
= InitCheck();
104 result
= fCurrentPosition
= position
;
109 error
= GetSize(&size
);
111 if (size
+ position
>= 0)
112 result
= fCurrentPosition
= size
+ position
;
117 if (fCurrentPosition
+ position
>= 0)
118 result
= fCurrentPosition
+= position
;
124 return (error
== B_OK
? result
: error
);
129 OffsetFile::Position() const
131 return fCurrentPosition
;
136 OffsetFile::SetSize(off_t size
)
138 status_t error
= (size
>= 0 ? B_OK
: B_BAD_VALUE
);
142 error
= fFile
->SetSize(size
+ fOffset
);
148 OffsetFile::GetSize(off_t
*size
) const
150 status_t error
= (size
? B_OK
: B_BAD_VALUE
);
154 error
= fFile
->GetSize(size
);
165 OffsetFile::Offset() const
170 }; // namespace Storage
171 }; // namespace BPrivate