aboutsummaryrefslogtreecommitdiff
path: root/xmalloc.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2014-10-21 12:35:58 +0100
committerNicholas Marriott <nicholas.marriott@gmail.com>2014-10-21 12:35:58 +0100
commit201036ad80f2e51f7238db2adf05914a4a4f5819 (patch)
tree9ccaf6a087b551846b1c6e71a865cda3aac8c0f1 /xmalloc.c
parent65257b8e9b55d8d180265d714ba9b3637643c6dc (diff)
parent696b5a628f0f31f4c3566b5c0ab51fbd9f9f9880 (diff)
downloadrtmux-201036ad80f2e51f7238db2adf05914a4a4f5819.tar.gz
rtmux-201036ad80f2e51f7238db2adf05914a4a4f5819.tar.bz2
rtmux-201036ad80f2e51f7238db2adf05914a4a4f5819.zip
Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code
Diffstat (limited to 'xmalloc.c')
-rw-r--r--xmalloc.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/xmalloc.c b/xmalloc.c
index df583e55..4c24d0d8 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -16,10 +16,9 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/param.h>
+#include <sys/types.h>
-#include <errno.h>
-#include <libgen.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -67,7 +66,20 @@ xmalloc(size_t size)
}
void *
-xrealloc(void *oldptr, size_t nmemb, size_t size)
+xrealloc(void *oldptr, size_t newsize)
+{
+ void *newptr;
+
+ if (newsize == 0)
+ fatalx("zero size");
+ if ((newptr = realloc(oldptr, newsize)) == NULL)
+ fatal("xrealloc failed");
+
+ return (newptr);
+}
+
+void *
+xreallocarray(void *oldptr, size_t nmemb, size_t size)
{
size_t newsize = nmemb * size;
void *newptr;
@@ -77,12 +89,12 @@ xrealloc(void *oldptr, size_t nmemb, size_t size)
if (SIZE_MAX / nmemb < size)
fatalx("nmemb * size > SIZE_MAX");
if ((newptr = realloc(oldptr, newsize)) == NULL)
- fatal("xrealloc failed");
+ fatal("xreallocarray failed");
return (newptr);
}
-int printflike2
+int
xasprintf(char **ret, const char *fmt, ...)
{
va_list ap;
@@ -107,7 +119,7 @@ xvasprintf(char **ret, const char *fmt, va_list ap)
return (i);
}
-int printflike3
+int
xsnprintf(char *buf, size_t len, const char *fmt, ...)
{
va_list ap;