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-23 21:51:55 +00:00
|
|
|
#include "convert/defs.h"
|
|
|
|
#include "convert/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
|
|
|
void DieErrorf(int errcode, const char *msg, ...)
|
|
|
|
{
|
2022-03-22 23:04:29 +00:00
|
|
|
va_list ap;
|
|
|
|
fputs("Error: ", stderr);
|
|
|
|
va_start(ap, msg);
|
|
|
|
vfprintf(stderr, msg, ap);
|
|
|
|
va_end(ap);
|
2022-03-23 05:26:25 +00:00
|
|
|
fputs(": ", stderr);
|
|
|
|
fputs(strerror(errcode), stderr);
|
2022-03-22 23:04:29 +00:00
|
|
|
fputc('\n', stderr);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
Dief("NewHandle: malloc failed");
|
|
|
|
}
|
|
|
|
h = malloc(sizeof(Ptr));
|
|
|
|
if (h == NULL) {
|
|
|
|
Dief("NewHandle: malloc failed");
|
|
|
|
}
|
|
|
|
*h = p;
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2022-03-23 05:26:25 +00:00
|
|
|
void HLock(Handle h)
|
|
|
|
{
|
2022-03-22 23:04:29 +00:00
|
|
|
(void)h;
|
|
|
|
}
|
|
|
|
|
2022-03-23 05:26:25 +00:00
|
|
|
void HUnlock(Handle h)
|
|
|
|
{
|
2022-03-22 23:04:29 +00:00
|
|
|
(void)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-23 05:26:25 +00:00
|
|
|
void SetHandleSize(Handle h, Size newSize)
|
|
|
|
{
|
2022-03-22 23:04:29 +00:00
|
|
|
Ptr p;
|
|
|
|
if (h == NULL) {
|
|
|
|
Dief("SetHandleSize: h = NULL");
|
|
|
|
}
|
|
|
|
p = realloc(*h, newSize);
|
|
|
|
if (newSize > 0 && p == NULL) {
|
|
|
|
Dief("SetHandleSize: realloc failed");
|
|
|
|
}
|
|
|
|
*h = p;
|
|
|
|
}
|
|
|
|
|
2022-03-23 05:26:25 +00:00
|
|
|
OSErr MemError(void)
|
|
|
|
{
|
2022-03-22 23:04:29 +00:00
|
|
|
/* Memory allocation failures abort the program. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|