FreeRDP
Loading...
Searching...
No Matches
uwac-utils.c
1/*
2 * Copyright © 2012 Collabora, Ltd.
3 * Copyright © 2008 Kristian Høgsberg
4 * Copyright © 2014 David FORT <contact@hardening-consulting.com>
5 *
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that copyright
9 * notice and this permission notice appear in supporting documentation, and
10 * that the name of the copyright holders not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. The copyright holders make no representations
13 * about the suitability of this software for any purpose. It is provided "as
14 * is" without express or implied warranty.
15 *
16 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 * OF THIS SOFTWARE.
23 */
24
25#include <uwac/config.h>
26
27#include <stdlib.h>
28#include <stdio.h>
29#include <string.h>
30#include <errno.h>
31#include <winpr/wtypes.h>
32
33#include "uwac-utils.h"
34
35/*
36 * This part is an adaptation of client/window.c from the weston project.
37 */
38
39static void* fail_on_null(void* p)
40{
41 if (p == nullptr)
42 {
43 (void)fprintf(stderr, "out of memory\n");
44 // NOLINTNEXTLINE(concurrency-mt-unsafe)
45 exit(EXIT_FAILURE);
46 }
47
48 return p;
49}
50
51void* xmalloc(size_t s)
52{
53 return fail_on_null(malloc(s));
54}
55
56void* xzalloc(size_t s)
57{
58 return fail_on_null(zalloc(s));
59}
60
61char* xstrdup(const char* s)
62{
63 return fail_on_null(strdup(s));
64}
65
66void* xrealloc(void* p, size_t s)
67{
68 return fail_on_null(realloc(p, s));
69}