2022-03-29 19:34:27 +00:00
|
|
|
#ifndef lib_defs_h
|
|
|
|
#define lib_defs_h
|
2022-03-22 23:04:29 +00:00
|
|
|
/* defs.h - common definitions. */
|
|
|
|
|
2022-03-25 17:33:24 +00:00
|
|
|
/*==============================================================================
|
2022-03-29 19:34:27 +00:00
|
|
|
Target information
|
2022-03-25 17:33:24 +00:00
|
|
|
==============================================================================*/
|
|
|
|
|
2022-03-29 19:34:27 +00:00
|
|
|
/*
|
|
|
|
Note that this code does not need to be especially portable. It just runs on
|
|
|
|
Mac OS and development systems (for testing). We can assume that the
|
|
|
|
development system has GCC.
|
|
|
|
|
|
|
|
Macros we care about:
|
|
|
|
|
|
|
|
TARGET_OS_MAC OS is some Macintosh variant (broadly speaking)
|
|
|
|
TARGET_API_MAC_OS8 Targeting classic Mac OS (9.x and earlier)
|
|
|
|
|
|
|
|
TARGET_RT_LITTLE_ENDIAN Little-endian byte order
|
|
|
|
TARGET_RT_BIG_ENDIAN Big-endian byte order
|
|
|
|
*/
|
2022-03-22 23:04:29 +00:00
|
|
|
#if macintosh
|
|
|
|
|
2022-03-29 19:34:27 +00:00
|
|
|
/* Classic Mac OS. Header is part of Universal Interfaces & Carbon. */
|
|
|
|
#include <ConditionalMacros.h>
|
|
|
|
|
|
|
|
#elif __APPLE__
|
|
|
|
|
|
|
|
/* Newer apple systems, including macOS >= 10. Header is in /usr/include, or
|
|
|
|
within /usr/include inside the SDK. */
|
|
|
|
#include <TargetConditionals.h>
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#if __BYTE_ORDER__
|
|
|
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
|
|
|
#define TARGET_RT_LITTLE_ENDIAN 1
|
|
|
|
#define TARGET_RT_BIG_ENDIAN 0
|
|
|
|
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
|
|
|
#define TARGET_RT_LITTLE_ENDIAN 0
|
|
|
|
#define TARGET_RT_BIG_ENDIAN 1
|
|
|
|
#else
|
|
|
|
#error "unknown endian"
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#error "could not determine byte order"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*==============================================================================
|
|
|
|
Basic types
|
|
|
|
==============================================================================*/
|
|
|
|
|
|
|
|
#if TARGET_API_MAC_OS8
|
|
|
|
|
2022-03-22 23:04:29 +00:00
|
|
|
#include <MacTypes.h>
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* Include <stddef.h> for NULL */
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2022-03-25 17:33:24 +00:00
|
|
|
#if __STDC_VERSION__ >= 199901l
|
|
|
|
#include <stdbool.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __bool_true_false_are_defined
|
|
|
|
typedef bool Boolean;
|
|
|
|
#else
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
false,
|
|
|
|
true
|
|
|
|
};
|
|
|
|
typedef unsigned char Boolean;
|
|
|
|
#endif
|
|
|
|
|
2022-03-22 23:04:29 +00:00
|
|
|
typedef uint8_t UInt8;
|
|
|
|
typedef int8_t SInt8;
|
|
|
|
typedef uint16_t UInt16;
|
|
|
|
typedef int16_t SInt16;
|
|
|
|
typedef uint32_t UInt32;
|
|
|
|
typedef int32_t SInt32;
|
|
|
|
|
|
|
|
typedef char *Ptr;
|
|
|
|
typedef Ptr *Handle;
|
|
|
|
typedef long Size;
|
|
|
|
|
2022-03-25 17:33:24 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*==============================================================================
|
|
|
|
Error codes and error reporting
|
|
|
|
==============================================================================*/
|
|
|
|
|
|
|
|
/* Error codes. */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
/* No error. */
|
|
|
|
kErrorOK,
|
2022-03-22 23:04:29 +00:00
|
|
|
|
2022-03-25 17:33:24 +00:00
|
|
|
/* Memory allocation failed. */
|
|
|
|
kErrorNoMemory,
|
2022-03-22 23:04:29 +00:00
|
|
|
|
2022-03-25 17:33:24 +00:00
|
|
|
/* Invaild table data. */
|
2022-03-30 09:23:37 +00:00
|
|
|
kErrorBadData,
|
|
|
|
|
|
|
|
/* Too many files in one directory. */
|
|
|
|
kErrorDirectoryTooLarge
|
2022-03-25 17:33:24 +00:00
|
|
|
} ErrorCode;
|
|
|
|
|
|
|
|
/*==============================================================================
|
|
|
|
Memory allocation
|
|
|
|
==============================================================================*/
|
|
|
|
|
2022-03-29 19:34:27 +00:00
|
|
|
#if TARGET_API_MAC_OS8
|
2022-03-25 17:33:24 +00:00
|
|
|
|
|
|
|
#include <MacMemory.h>
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* Allocate a relocatable block of memory. */
|
|
|
|
Handle NewHandle(Size byteSize);
|
|
|
|
|
|
|
|
/* Free a relocatable block of memory. */
|
2022-03-22 23:04:29 +00:00
|
|
|
void DisposeHandle(Handle h);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2022-03-25 17:33:24 +00:00
|
|
|
/* Resize a relocatable block of memory. Return true on success. */
|
|
|
|
Boolean ResizeHandle(Handle h, Size newSize);
|
|
|
|
|
|
|
|
/* Fill memory with zeroes. */
|
2022-03-22 23:04:29 +00:00
|
|
|
void MemClear(void *ptr, Size size);
|
|
|
|
|
2022-03-30 09:23:37 +00:00
|
|
|
/*==============================================================================
|
|
|
|
Assertions
|
|
|
|
==============================================================================*/
|
|
|
|
|
|
|
|
#if NDEBUG
|
|
|
|
#define assert(x) ((void)0)
|
|
|
|
#else
|
|
|
|
#include <assert.h>
|
|
|
|
#endif
|
|
|
|
|
2022-03-22 23:04:29 +00:00
|
|
|
#endif
|