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