Blame


1 2a00e21c 2021-09-28 thomas /* $OpenBSD$ */
2 2a00e21c 2021-09-28 thomas
3 2a00e21c 2021-09-28 thomas /*
4 2a00e21c 2021-09-28 thomas * Author: Tatu Ylonen <ylo@cs.hut.fi>
5 2a00e21c 2021-09-28 thomas * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
6 2a00e21c 2021-09-28 thomas * All rights reserved
7 2a00e21c 2021-09-28 thomas * Created: Mon Mar 20 22:09:17 1995 ylo
8 2a00e21c 2021-09-28 thomas *
9 2a00e21c 2021-09-28 thomas * Versions of malloc and friends that check their results, and never return
10 2a00e21c 2021-09-28 thomas * failure (they call fatal if they encounter an error).
11 2a00e21c 2021-09-28 thomas *
12 2a00e21c 2021-09-28 thomas * As far as I am concerned, the code I have written for this software
13 2a00e21c 2021-09-28 thomas * can be used freely for any purpose. Any derived versions of this
14 2a00e21c 2021-09-28 thomas * software must be clearly marked as such, and if the derived work is
15 2a00e21c 2021-09-28 thomas * incompatible with the protocol description in the RFC file, it must be
16 2a00e21c 2021-09-28 thomas * called by a name other than "ssh" or "Secure Shell".
17 2a00e21c 2021-09-28 thomas */
18 2a00e21c 2021-09-28 thomas
19 2a00e21c 2021-09-28 thomas #ifndef XMALLOC_H
20 2a00e21c 2021-09-28 thomas #define XMALLOC_H
21 2a00e21c 2021-09-28 thomas
22 2a00e21c 2021-09-28 thomas #include <stdarg.h>
23 2a00e21c 2021-09-28 thomas
24 2a00e21c 2021-09-28 thomas #if !defined(__bounded__)
25 2a00e21c 2021-09-28 thomas #define __bounded__(x, y, z)
26 2a00e21c 2021-09-28 thomas #endif
27 2a00e21c 2021-09-28 thomas
28 2a00e21c 2021-09-28 thomas void *xmalloc(size_t);
29 2a00e21c 2021-09-28 thomas void *xcalloc(size_t, size_t);
30 2a00e21c 2021-09-28 thomas void *xrealloc(void *, size_t);
31 2a00e21c 2021-09-28 thomas void *xreallocarray(void *, size_t, size_t);
32 2a00e21c 2021-09-28 thomas void *xrecallocarray(void *, size_t, size_t, size_t);
33 2a00e21c 2021-09-28 thomas char *xstrdup(const char *);
34 2a00e21c 2021-09-28 thomas char *xstrndup(const char *, size_t);
35 2a00e21c 2021-09-28 thomas int xasprintf(char **, const char *, ...)
36 2a00e21c 2021-09-28 thomas __attribute__((__format__ (printf, 2, 3)))
37 2a00e21c 2021-09-28 thomas __attribute__((__nonnull__ (2)));
38 2a00e21c 2021-09-28 thomas int xvasprintf(char **, const char *, va_list)
39 2a00e21c 2021-09-28 thomas __attribute__((__nonnull__ (2)));
40 2a00e21c 2021-09-28 thomas int xsnprintf(char *, size_t, const char *, ...)
41 2a00e21c 2021-09-28 thomas __attribute__((__format__ (printf, 3, 4)))
42 2a00e21c 2021-09-28 thomas __attribute__((__nonnull__ (3)))
43 2a00e21c 2021-09-28 thomas __attribute__((__bounded__ (__string__, 1, 2)));
44 2a00e21c 2021-09-28 thomas int xvsnprintf(char *, size_t, const char *, va_list)
45 2a00e21c 2021-09-28 thomas __attribute__((__nonnull__ (3)))
46 2a00e21c 2021-09-28 thomas __attribute__((__bounded__ (__string__, 1, 2)));
47 2a00e21c 2021-09-28 thomas
48 2a00e21c 2021-09-28 thomas #endif /* XMALLOC_H */