mirror of
https://github.com/1dot13/source.git
synced 2026-07-29 13:52:17 +02:00
libsmacker is an open reimplementation of the parts of smackw32.dll needed to get frames and audio out of an .smk file. Vendoring it here is the first step to dropping the proprietary SMACKW32.LIB/SMACKW32.DLL dependency. Nothing links against it yet. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
57 lines
1.3 KiB
C
57 lines
1.3 KiB
C
/**
|
|
libsmacker - A C library for decoding .smk Smacker Video files
|
|
Copyright (C) 2012-2017 Greg Kennedy
|
|
|
|
See smacker.h for more information.
|
|
|
|
smk_malloc.h
|
|
"Safe" implementations of malloc and free.
|
|
Verbose implementation of assert.
|
|
*/
|
|
|
|
#ifndef SMK_MALLOC_H
|
|
#define SMK_MALLOC_H
|
|
|
|
/* assert */
|
|
#include <assert.h>
|
|
/* calloc */
|
|
#include <stdlib.h>
|
|
/* fprintf */
|
|
#include <stdio.h>
|
|
|
|
/* Error messages from calloc */
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
|
|
/**
|
|
Safe free: attempts to prevent double-free by setting pointer to NULL.
|
|
Optionally warns on attempts to free a NULL pointer.
|
|
*/
|
|
#define smk_free(p) \
|
|
{ \
|
|
assert (p); \
|
|
free(p); \
|
|
p = NULL; \
|
|
}
|
|
|
|
/**
|
|
Safe malloc: exits if calloc() returns NULL.
|
|
Also initializes blocks to 0.
|
|
Optionally warns on attempts to malloc over an existing pointer.
|
|
Ideally, one should not exit() in a library. However, if you cannot
|
|
calloc(), you probably have bigger problems.
|
|
*/
|
|
#define smk_malloc(p, x) \
|
|
{ \
|
|
assert (p == NULL); \
|
|
p = calloc(1, x); \
|
|
if (!p) \
|
|
{ \
|
|
fprintf(stderr, "libsmacker::smk_malloc(" #p ", %lu) - ERROR: calloc() returned NULL (file: %s, line: %lu)\n\tReason: [%d] %s\n", \
|
|
(unsigned long) (x), __FILE__, (unsigned long)__LINE__, errno, strerror(errno)); \
|
|
exit(EXIT_FAILURE); \
|
|
} \
|
|
}
|
|
|
|
#endif
|