diff options
| author | SkyperTHC | 2026-03-03 06:28:55 +0000 |
|---|---|---|
| committer | SkyperTHC | 2026-03-03 06:28:55 +0000 |
| commit | 5d3573ef7a109ee70416fe94db098fe6a769a798 (patch) | |
| tree | dc2d5b294c9db8ab2db7433511f94e1c4bb8b698 /other/openssh-reverse/xmalloc.c | |
| parent | c6c59dc73cc4586357f93ab38ecf459e98675cc5 (diff) | |
packetstorm sync
Diffstat (limited to 'other/openssh-reverse/xmalloc.c')
| -rw-r--r-- | other/openssh-reverse/xmalloc.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/other/openssh-reverse/xmalloc.c b/other/openssh-reverse/xmalloc.c new file mode 100644 index 0000000..ec62c58 --- /dev/null +++ b/other/openssh-reverse/xmalloc.c | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | /* | ||
| 2 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | ||
| 3 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | ||
| 4 | * All rights reserved | ||
| 5 | * Created: Mon Mar 20 21:23:10 1995 ylo | ||
| 6 | * Versions of malloc and friends that check their results, and never return | ||
| 7 | * failure (they call fatal if they encounter an error). | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include "includes.h" | ||
| 11 | RCSID("$OpenBSD: xmalloc.c,v 1.7 2000/06/20 01:39:45 markus Exp $"); | ||
| 12 | |||
| 13 | #include "ssh.h" | ||
| 14 | |||
| 15 | void * | ||
| 16 | xmalloc(size_t size) | ||
| 17 | { | ||
| 18 | void *ptr = malloc(size); | ||
| 19 | if (ptr == NULL) | ||
| 20 | fatal("xmalloc: out of memory (allocating %d bytes)", (int) size); | ||
| 21 | return ptr; | ||
| 22 | } | ||
| 23 | |||
| 24 | void * | ||
| 25 | xrealloc(void *ptr, size_t new_size) | ||
| 26 | { | ||
| 27 | void *new_ptr; | ||
| 28 | |||
| 29 | if (ptr == NULL) | ||
| 30 | fatal("xrealloc: NULL pointer given as argument"); | ||
| 31 | new_ptr = realloc(ptr, new_size); | ||
| 32 | if (new_ptr == NULL) | ||
| 33 | fatal("xrealloc: out of memory (new_size %d bytes)", (int) new_size); | ||
| 34 | return new_ptr; | ||
| 35 | } | ||
| 36 | |||
| 37 | void | ||
| 38 | xfree(void *ptr) | ||
| 39 | { | ||
| 40 | if (ptr == NULL) | ||
| 41 | fatal("xfree: NULL pointer given as argument"); | ||
| 42 | free(ptr); | ||
| 43 | } | ||
| 44 | |||
| 45 | char * | ||
| 46 | xstrdup(const char *str) | ||
| 47 | { | ||
| 48 | int len = strlen(str) + 1; | ||
| 49 | |||
| 50 | char *cp = xmalloc(len); | ||
| 51 | strlcpy(cp, str, len); | ||
| 52 | return cp; | ||
| 53 | } | ||
