2022-04-10 08:22:58 +00:00
|
|
|
// Copyright 2022 Dietrich Epp.
|
|
|
|
// This file is part of SyncFiles. SyncFiles is licensed under the terms of the
|
|
|
|
// Mozilla Public License, version 2.0. See LICENSE.txt for details.
|
2022-03-22 23:04:29 +00:00
|
|
|
|
2022-04-21 17:57:17 +00:00
|
|
|
// toolbox.c - replacement functions for Mac OS toolbox functions
|
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);
|
|
|
|
}
|