1
0

MallocAllocator.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #include "memory/MallocAllocator.h"
  16. #include <stdlib.h>
  17. static void* provideMemory(void* vNULL,
  18. struct Allocator_Allocation* original,
  19. unsigned long size,
  20. struct Allocator* group)
  21. {
  22. if (original == NULL) {
  23. if (size == 0) {
  24. return NULL;
  25. }
  26. return malloc(size);
  27. }
  28. if (size == 0) {
  29. free(original);
  30. return NULL;
  31. }
  32. return realloc(original, size);
  33. }
  34. struct Allocator* MallocAllocator__new(unsigned long sizeLimit, const char* file, int line)
  35. {
  36. return Allocator_new(sizeLimit, provideMemory, NULL, file, line);
  37. }