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"
|
|
|
|
#include "lib/test.h"
|
2022-03-22 23:04:29 +00:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2022-03-23 05:26:25 +00:00
|
|
|
void Dief(const char *msg, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
fputs("Error: ", stderr);
|
|
|
|
va_start(ap, msg);
|
|
|
|
vfprintf(stderr, msg, ap);
|
|
|
|
va_end(ap);
|
|
|
|
fputc('\n', stderr);
|
|
|
|
exit(1);
|
|
|
|
}
|
2022-03-22 23:04:29 +00:00
|
|
|
|
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) {
|
|
|
|
Dief("NewHandle: byteCount = %ld", byteCount);
|
|
|
|
}
|
|
|
|
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-25 17:33:24 +00:00
|
|
|
Dief("ResizeHandle: h = NULL");
|
|
|
|
}
|
|
|
|
if (newSize < 0) {
|
|
|
|
Dief("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);
|
|
|
|
}
|