2008-04-27 06:10:09 +05:30
|
|
|
/*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-FileCopyrightText: 1990 - 1994, Julianne Frances Haugh
|
|
|
|
* SPDX-FileCopyrightText: 1996 - 1998, Marek Michałkiewicz
|
|
|
|
* SPDX-FileCopyrightText: 2003 - 2006, Tomasz Kłoczko
|
|
|
|
* SPDX-FileCopyrightText: 2008 , Nicolas François
|
2023-02-05 01:43:59 +05:30
|
|
|
* SPDX-FileCopyrightText: 2023 , Alejandro Colomar <alx@kernel.org>
|
2008-04-27 06:10:09 +05:30
|
|
|
*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2008-04-27 06:10:09 +05:30
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/* Replacements for malloc and strdup with error checking. Too trivial
|
|
|
|
to be worth copyrighting :-). I did that because a lot of code used
|
|
|
|
malloc and strdup without checking for NULL pointer, and I like some
|
|
|
|
message better than a core dump... --marekm
|
2023-02-05 01:43:59 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
Yeh, but. Remember that bailing out might leave the system in some
|
|
|
|
bizarre state. You really want to put in error checking, then add
|
|
|
|
some back-out failure recovery code. -- jfh */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2023-02-05 01:43:59 +05:30
|
|
|
#include "alloc.h"
|
|
|
|
|
2011-06-03 00:11:05 +05:30
|
|
|
#include <errno.h>
|
2023-02-05 01:43:59 +05:30
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "defines.h"
|
2008-01-05 18:53:22 +05:30
|
|
|
#include "prototypes.h"
|
2021-11-29 05:07:53 +05:30
|
|
|
#include "shadowlog.h"
|
2008-01-05 18:53:22 +05:30
|
|
|
|
2023-02-05 01:43:59 +05:30
|
|
|
|
|
|
|
extern inline void *xmalloc(size_t size);
|
|
|
|
extern inline void *xmallocarray(size_t nmemb, size_t size);
|
|
|
|
extern inline void *mallocarray(size_t nmemb, size_t size);
|
|
|
|
extern inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
|
|
|
|
extern inline char *xstrdup(const char *str);
|
|
|
|
|
|
|
|
|
|
|
|
void *
|
|
|
|
xcalloc(size_t nmemb, size_t size)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2023-02-05 01:43:59 +05:30
|
|
|
void *p;
|
|
|
|
|
|
|
|
p = calloc(nmemb, size);
|
|
|
|
if (p == NULL)
|
|
|
|
goto x;
|
|
|
|
|
|
|
|
return p;
|
|
|
|
|
|
|
|
x:
|
|
|
|
fprintf(log_get_logfd(), _("%s: %s\n"),
|
|
|
|
log_get_progname(), strerror(errno));
|
|
|
|
exit(13);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2023-02-05 01:43:59 +05:30
|
|
|
|
|
|
|
void *
|
|
|
|
xreallocarray(void *p, size_t nmemb, size_t size)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2023-02-05 01:43:59 +05:30
|
|
|
p = reallocarrayf(p, nmemb, size);
|
|
|
|
if (p == NULL)
|
|
|
|
goto x;
|
|
|
|
|
|
|
|
return p;
|
|
|
|
|
|
|
|
x:
|
|
|
|
fprintf(log_get_logfd(), _("%s: %s\n"),
|
|
|
|
log_get_progname(), strerror(errno));
|
|
|
|
exit(13);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|