File: oom.c

package info (click to toggle)
libjodycode 4.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,676 kB
  • sloc: ansic: 2,820; makefile: 372; sh: 160; xml: 37
file content (27 lines) | stat: -rw-r--r-- 665 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* libjodycoe: out-of-memory and NULL pointer error exits
 *
 * Copyright (C) 2021-2026 by Jody Bruchon <jody@jodybruchon.com>
 * Released under The MIT License
 */

#include <stdio.h>
#include <stdlib.h>
#include "libjodycode.h"

static const char msg_unknown[] = "(unknown)";

/* Out of memory failure */
void jc_oom(const char * restrict msg)
{
	if (msg == NULL) msg = msg_unknown;
	fprintf(stderr, "\nout of memory: %s\n", msg);
	exit(EXIT_FAILURE);
}

/* Null pointer failure */
void jc_nullptr(const char * restrict func)
{
	if (func == NULL) func = msg_unknown;
	fprintf(stderr, "\ninternal error: NULL pointer caught at %s\n", func);
	exit(EXIT_FAILURE);
}