2 * Copyright (C) 2004-2008 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file string.c Memory allocation and string handling functions. */
12 #include <sys/time.h> /* gettimeofday */
14 #include <sys/utsname.h> /* uname() */
20 * Paraslash's version of malloc().
22 * \param size The desired new size.
24 * A wrapper for malloc(3) which exits on errors.
26 * \return A pointer to the allocated memory, which is suitably aligned for any
31 __must_check __malloc void *para_malloc(size_t size)
34 void *p = malloc(size);
37 EMERG_LOG("malloc failed (size = %zu), aborting\n",
45 * Paraslash's version of calloc().
47 * \param size The desired new size.
49 * A wrapper for calloc(3) which exits on errors.
51 * \return A pointer to the allocated and zeroed-out memory, which is suitably
52 * aligned for any kind of variable.
56 __must_check __malloc void *para_calloc(size_t size)
58 void *ret = para_malloc(size);
65 * Paraslash's version of strdup().
67 * \param s The string to be duplicated.
69 * A wrapper for strdup(3). It calls \p exit(EXIT_FAILURE) on errors, i.e.
70 * there is no need to check the return value in the caller.
72 * \return A pointer to the duplicated string. If \p s was the NULL pointer,
73 * an pointer to an empty string is returned.
77 __must_check __malloc char *para_strdup(const char *s)
81 if ((ret = strdup(s? s: "")))
83 EMERG_LOG("strdup failed, aborting\n");