From 2a4ec3b76c75c3d8f7fe0c87cd3b44a1e7dbe51c Mon Sep 17 00:00:00 2001 From: Iliyas Jorio Date: Mon, 22 Feb 2021 01:25:12 +0100 Subject: [PATCH] Implement PtrToHand --- src/Memory/Memory.cpp | 20 ++++++++++++++++++++ src/Pomme.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/src/Memory/Memory.cpp b/src/Memory/Memory.cpp index 2ed2538..354239a 100644 --- a/src/Memory/Memory.cpp +++ b/src/Memory/Memory.cpp @@ -97,6 +97,26 @@ void DisposeHandle(Handle h) blocks.Dispose(b); } +OSErr PtrToHand(const void* srcPtr, Handle* dstHndl, Size size) +{ + if (!dstHndl + || (!srcPtr && size > 0) + || size < 0) + { + return paramErr; + } + + Handle h = NewHandle(size); + if (!h) + return memFullErr; + + *dstHndl = h; + + memcpy(*h, srcPtr, size); + + return noErr; +} + //----------------------------------------------------------------------------- // Memory: Ptr diff --git a/src/Pomme.h b/src/Pomme.h index 2a7a33f..0844809 100644 --- a/src/Pomme.h +++ b/src/Pomme.h @@ -352,6 +352,9 @@ void SetHandleSize(Handle, Size); void DisposeHandle(Handle); +// Allocates a handle of the given size and copies the contents of srcPtr into it +OSErr PtrToHand(const void* srcPtr, Handle* dstHndl, Size size); + //----------------------------------------------------------------------------- // Memory: Ptr