Path: blob/main/crypto/krb5/src/clients/ksu/xmalloc.c
34890 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* clients/ksu/xmalloc.c - Exit-on-failure allocation wrappers */2/*3* Copyright 1999 by the Massachusetts Institute of Technology.4* All Rights Reserved.5*6* Export of this software from the United States of America may7* require a specific license from the United States Government.8* It is the responsibility of any person or organization contemplating9* export to obtain such a license before exporting.10*11* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and12* distribute this software and its documentation for any purpose and13* without fee is hereby granted, provided that the above copyright14* notice appear in all copies and that both that copyright notice and15* this permission notice appear in supporting documentation, and that16* the name of M.I.T. not be used in advertising or publicity pertaining17* to distribution of the software without specific, written prior18* permission. Furthermore if you modify this software you must label19* your software as modified software and not distribute it in such a20* fashion that it might be confused with the original M.I.T. software.21* M.I.T. makes no representations about the suitability of22* this software for any purpose. It is provided "as is" without express23* or implied warranty.24*/2526#include "k5-platform.h"27#include "ksu.h"2829void *xmalloc (size_t sz)30{31void *ret = malloc (sz);32if (ret == 0 && sz != 0) {33perror (prog_name);34exit (1);35}36return ret;37}3839void *xrealloc (void *old, size_t newsz)40{41void *ret = realloc (old, newsz);42if (ret == 0 && newsz != 0) {43perror (prog_name);44exit (1);45}46return ret;47}4849void *xcalloc (size_t nelts, size_t eltsz)50{51void *ret = calloc (nelts, eltsz);52if (ret == 0 && nelts != 0 && eltsz != 0) {53perror (prog_name);54exit (1);55}56return ret;57}5859char *xstrdup (const char *src)60{61size_t len = strlen (src) + 1;62char *dst = xmalloc (len);63memcpy (dst, src, len);64return dst;65}6667char *xasprintf (const char *format, ...)68{69char *out;70va_list args;7172va_start (args, format);73if (vasprintf(&out, format, args) < 0) {74perror (prog_name);75exit (1);76}77va_end(args);78return out;79}808182