aboutsummaryrefslogtreecommitdiff
path: root/xmalloc.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2014-10-21 07:11:44 +0100
committerThomas Adam <thomas@xteddy.org>2014-10-21 07:11:44 +0100
commit562af864bd8ab06c416075b5742ce3bbcf6d0610 (patch)
tree2c3900dd6b284aa52441c3fde9dfdf8383d87b54 /xmalloc.c
parentb6aef2490f086f3404f439308bb1746ec5134e9a (diff)
parent0a1a88d63caf3a0e8b4440686e73e1f0f690e03c (diff)
downloadrtmux-562af864bd8ab06c416075b5742ce3bbcf6d0610.tar.gz
rtmux-562af864bd8ab06c416075b5742ce3bbcf6d0610.tar.bz2
rtmux-562af864bd8ab06c416075b5742ce3bbcf6d0610.zip
Merge branch 'obsd-master'
Conflicts: Makefile cmd-list-commands.c cmd-suspend-client.c job.c tmux.h xmalloc.c
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;