1 /* 2 * Copyright 2003, Axel Dörfler, axeld@pinc-software.de. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "Handle.h" 8 9 #include <SupportDefs.h> 10 11 #include <platform/openfirmware/openfirmware.h> 12 #include <util/kernel_cpp.h> 13 14 15 Handle::Handle(intptr_t handle, bool takeOwnership) 16 : 17 fHandle(handle), 18 fOwnHandle(takeOwnership) 19 { 20 } 21 22 23 Handle::Handle(void) 24 : 25 fHandle(0) 26 { 27 } 28 29 30 Handle::~Handle() 31 { 32 if (fOwnHandle) 33 of_close(fHandle); 34 } 35 36 37 void 38 Handle::SetHandle(intptr_t handle, bool takeOwnership) 39 { 40 if (fHandle && fOwnHandle) 41 of_close(fHandle); 42 43 fHandle = handle; 44 fOwnHandle = takeOwnership; 45 } 46 47 48 ssize_t 49 Handle::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) 50 { 51 if (pos == -1 || of_seek(fHandle, pos) != OF_FAILED) 52 return of_read(fHandle, buffer, bufferSize); 53 54 return B_ERROR; 55 } 56 57 58 ssize_t 59 Handle::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize) 60 { 61 if (pos == -1 || of_seek(fHandle, pos) != OF_FAILED) 62 return of_write(fHandle, buffer, bufferSize); 63 64 return B_ERROR; 65 } 66 67 68 off_t 69 Handle::Size() const 70 { 71 // ToDo: fix this! 72 return 1024LL * 1024 * 1024 * 1024; 73 // 1024 GB 74 } 75 76