xref: /openbsd-src/usr.bin/tmux/xmalloc.h (revision ceb4a27f561382765ded17779619d067bd4d4639)
1*ceb4a27fSnicm /* $OpenBSD: xmalloc.h,v 1.4 2021/08/25 07:09:30 nicm Exp $ */
23baad57eSnicm 
33baad57eSnicm /*
43baad57eSnicm  * Author: Tatu Ylonen <ylo@cs.hut.fi>
53baad57eSnicm  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
63baad57eSnicm  *                    All rights reserved
73baad57eSnicm  * Created: Mon Mar 20 22:09:17 1995 ylo
83baad57eSnicm  *
93baad57eSnicm  * Versions of malloc and friends that check their results, and never return
103baad57eSnicm  * failure (they call fatal if they encounter an error).
113baad57eSnicm  *
123baad57eSnicm  * As far as I am concerned, the code I have written for this software
133baad57eSnicm  * can be used freely for any purpose.  Any derived versions of this
143baad57eSnicm  * software must be clearly marked as such, and if the derived work is
153baad57eSnicm  * incompatible with the protocol description in the RFC file, it must be
163baad57eSnicm  * called by a name other than "ssh" or "Secure Shell".
173baad57eSnicm  */
183baad57eSnicm 
193baad57eSnicm #ifndef XMALLOC_H
203baad57eSnicm #define XMALLOC_H
213baad57eSnicm 
223baad57eSnicm void	*xmalloc(size_t);
233baad57eSnicm void	*xcalloc(size_t, size_t);
243baad57eSnicm void	*xrealloc(void *, size_t);
253baad57eSnicm void	*xreallocarray(void *, size_t, size_t);
2618b1287eSnicm void	*xrecallocarray(void *, size_t, size_t, size_t);
273baad57eSnicm char	*xstrdup(const char *);
28700b11ffSnicm char	*xstrndup(const char *, size_t);
293baad57eSnicm int	 xasprintf(char **, const char *, ...)
303baad57eSnicm 		__attribute__((__format__ (printf, 2, 3)))
313baad57eSnicm 		__attribute__((__nonnull__ (2)));
323baad57eSnicm int	 xvasprintf(char **, const char *, va_list)
33*ceb4a27fSnicm 		__attribute__((__format__ (printf, 2, 0)))
343baad57eSnicm 		__attribute__((__nonnull__ (2)));
353baad57eSnicm int	 xsnprintf(char *, size_t, const char *, ...)
363baad57eSnicm 		__attribute__((__format__ (printf, 3, 4)))
373baad57eSnicm 		__attribute__((__nonnull__ (3)))
383baad57eSnicm 		__attribute__((__bounded__ (__string__, 1, 2)));
393baad57eSnicm int	 xvsnprintf(char *, size_t, const char *, va_list)
40*ceb4a27fSnicm 		__attribute__((__format__ (printf, 3, 0)))
413baad57eSnicm 		__attribute__((__nonnull__ (3)))
423baad57eSnicm 		__attribute__((__bounded__ (__string__, 1, 2)));
433baad57eSnicm 
443baad57eSnicm #endif	/* XMALLOC_H */
45