// memutil.c // PUBLIC DOMAIN // http:///www.purposeful.co.uk/software/yabaplib /* I, Tom Vajzovic, am the author of this software and its documentation. I permanently abandon all intellectual property rights in them, including copyright, trademarks, design rights, database right, patents, and the right to be identified as the author. I am fairly certain that the software does what the documentation says it does, but I do not guarantee that it does, or that it does what you think it should. I do not guarantee that it will not have undesirable side effects. You are free to use, modify and distribute this software as you please, but you do so at your own risk. If you do not pass on this warning then you may be responsible for any problems encountered by those who obtain the software through you. */ #include #include #include "memutil.h" void *malloc_or_die(size_t size) { void *mem = malloc(size); if (!mem) { abort(); } return mem; } void *realloc_or_free(void *old_ptr, size_t size) { void *new_ptr = realloc(old_ptr, size); if (!new_ptr) { free(old_ptr); } return new_ptr; } void *realloc_or_die(void *old_ptr, size_t size) { void *new_ptr = realloc(old_ptr, size); if (!new_ptr) { abort(); } return new_ptr; } void free_preserving_errno(void *ptr) { int save_errno = errno; free(ptr); errno = save_errno; }