xmalloc.h 1.5 KB

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