2022-03-22 23:04:29 +00:00
|
|
|
/* toolbox.c - replacement functions for Mac OS toolbox functions
|
|
|
|
|
|
|
|
This is used to run conversion tests on non-Mac OS systems to make
|
|
|
|
development easier. These are not intended to make it possible to port the
|
|
|
|
converter to non-Mac OS systems. */
|
2022-03-25 05:45:55 +00:00
|
|
|
#include "lib/defs.h"
|
2022-03-30 07:46:19 +00:00
|
|
|
#include "lib/util.h"
|
2022-03-22 23:04:29 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2022-03-23 05:26:25 +00:00
|
|
|
Handle NewHandle(Size byteCount)
|
|
|
|
{
|
2022-03-22 23:04:29 +00:00
|
|
|
Ptr p;
|
|
|
|
Handle h;
|
|
|
|
|
|
|
|
if (byteCount < 0) {
|
2022-03-30 07:46:19 +00:00
|
|
|
Fatalf("NewHandle: byteCount = %ld", byteCount);
|
2022-03-22 23:04:29 +00:00
|
|
|
}
|
|
|
|
p = malloc(byteCount);
|
|
|
|
if (byteCount > 0 && p == NULL) {
|
2022-03-25 17:33:24 +00:00
|
|
|
return NULL;
|
2022-03-22 23:04:29 +00:00
|
|
|
}
|
|
|
|
h = malloc(sizeof(Ptr));
|
|
|
|
if (h == NULL) {
|
2022-03-25 17:33:24 +00:00
|
|
|
free(p);
|
|
|
|
return NULL;
|
2022-03-22 23:04:29 +00:00
|
|
|
}
|
|
|
|
*h = p;
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2022-03-23 05:26:25 +00:00
|
|
|
void DisposeHandle(Handle h)
|
|
|
|
{
|
2022-03-22 23:04:29 +00:00
|
|
|
if (h != NULL) {
|
|
|
|
free(*h);
|
|
|
|
free(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-25 17:33:24 +00:00
|
|
|
Boolean ResizeHandle(Handle h, Size newSize)
|
2022-03-23 05:26:25 +00:00
|
|
|
{
|
2022-03-22 23:04:29 +00:00
|
|
|
Ptr p;
|
|
|
|
if (h == NULL) {
|
2022-03-30 07:46:19 +00:00
|
|
|
Fatalf("ResizeHandle: h = NULL");
|
2022-03-25 17:33:24 +00:00
|
|
|
}
|
|
|
|
if (newSize < 0) {
|
2022-03-30 07:46:19 +00:00
|
|
|
Fatalf("ResizeHandle: newSize = %ld", newSize);
|
2022-03-22 23:04:29 +00:00
|
|
|
}
|
|
|
|
p = realloc(*h, newSize);
|
|
|
|
if (newSize > 0 && p == NULL) {
|
2022-03-25 17:33:24 +00:00
|
|
|
return false;
|
2022-03-22 23:04:29 +00:00
|
|
|
}
|
|
|
|
*h = p;
|
2022-03-25 17:33:24 +00:00
|
|
|
return true;
|
2022-03-22 23:04:29 +00:00
|
|
|
}
|
|
|
|
|
2022-03-23 05:26:25 +00:00
|
|
|
void MemClear(void *ptr, Size size)
|
|
|
|
{
|
2022-03-22 23:04:29 +00:00
|
|
|
memset(ptr, 0, size);
|
|
|
|
}
|