/* * Created by yuuta on 7/19/22. */ #ifndef LIBAC_HELPERS_H #define LIBAC_HELPERS_H #include #define SALLOC(s, out) alloc(NULL, 1, sizeof(s), true, (void **) out) /** * Allocate or reallocate a range of memory on heap. * @param existing The existing range to extend. NULL-able. * @param count The number of bytes. Final size = count * bytes. * @param bytes The size. Final size = count * bytes. * @param zero_out Whether to zero out the newly-allocated memory. Ignored when existing != NULL. * @param out Output memory range. Not NULL if the return value is AC_E_OK. * @return AC_E_OK or an error code. When failed, *out is untouched. * MT-Safe */ int alloc(void *existing, unsigned int count, unsigned int bytes, bool zero_out, void **out); /** * Duplicate a string. * @param str String to duplicate. * @param out Output string. Not NULL if the return value is AC_E_OK. * @return AC_E_OK or an error code. When failed, *out is untouched. * MT-Safe */ int strdup2(const char *str, char **out); /** * Cross-platform thread-safe wrapper of strerror(3). * @param errnum errno * @return Always non-NULL error message. * MT-Safe */ char *strerror2(int errnum); /** * Cleanup any necessary memory during exit of the current thread. */ void helpers_cleanup(void); #endif /* LIBAC_HELPERS_H */