]> andersk Git - openssh.git/blame - xmalloc.c
- (bal) uuencode.c resync w/ OpenBSD tree, plus whitespace.
[openssh.git] / xmalloc.c
CommitLineData
8efc0c15 1/*
5260325f 2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
5260325f 5 * Versions of malloc and friends that check their results, and never return
6 * failure (they call fatal if they encounter an error).
2b87da3b 7 *
bcbf86ec 8 * As far as I am concerned, the code I have written for this software
9 * can be used freely for any purpose. Any derived versions of this
10 * software must be clearly marked as such, and if the derived work is
11 * incompatible with the protocol description in the RFC file, it must be
12 * called by a name other than "ssh" or "Secure Shell".
5260325f 13 */
8efc0c15 14
15#include "includes.h"
b705bea0 16RCSID("$OpenBSD: xmalloc.c,v 1.11 2001/02/04 15:32:27 stevesk Exp $");
8efc0c15 17
42f11eb2 18#include "xmalloc.h"
19#include "log.h"
8efc0c15 20
5260325f 21void *
22xmalloc(size_t size)
8efc0c15 23{
5260325f 24 void *ptr = malloc(size);
25 if (ptr == NULL)
26 fatal("xmalloc: out of memory (allocating %d bytes)", (int) size);
27 return ptr;
8efc0c15 28}
29
5260325f 30void *
31xrealloc(void *ptr, size_t new_size)
8efc0c15 32{
5260325f 33 void *new_ptr;
34
35 if (ptr == NULL)
36 fatal("xrealloc: NULL pointer given as argument");
37 new_ptr = realloc(ptr, new_size);
38 if (new_ptr == NULL)
39 fatal("xrealloc: out of memory (new_size %d bytes)", (int) new_size);
40 return new_ptr;
8efc0c15 41}
42
6ae2364d 43void
5260325f 44xfree(void *ptr)
8efc0c15 45{
5260325f 46 if (ptr == NULL)
47 fatal("xfree: NULL pointer given as argument");
48 free(ptr);
8efc0c15 49}
50
5260325f 51char *
52xstrdup(const char *str)
8efc0c15 53{
95f4ccfb 54 size_t len = strlen(str) + 1;
8efc0c15 55
5260325f 56 char *cp = xmalloc(len);
57 strlcpy(cp, str, len);
58 return cp;
8efc0c15 59}
This page took 0.6433 seconds and 5 git commands to generate.