From 8b5c96da5292b1f934707c5267b551ccd2a3b9d5 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 17 Jun 2015 18:51:11 +0000 Subject: [PATCH] Use strdup in xstrdup from Fritjof Bornebusch. While here, remove xfree which is unused. --- usr.bin/file/xmalloc.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/usr.bin/file/xmalloc.c b/usr.bin/file/xmalloc.c index 857bcd91569..243da4c52dc 100644 --- a/usr.bin/file/xmalloc.c +++ b/usr.bin/file/xmalloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xmalloc.c,v 1.1 2015/04/24 16:24:11 nicm Exp $ */ +/* $OpenBSD: xmalloc.c,v 1.2 2015/06/17 18:51:11 nicm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -65,24 +65,13 @@ xreallocarray(void *ptr, size_t nmemb, size_t size) return new_ptr; } -void -xfree(void *ptr) -{ - if (ptr == NULL) - errx(1, "xfree: NULL pointer given as argument"); - free(ptr); -} - char * xstrdup(const char *str) { - size_t len; char *cp; - len = strlen(str) + 1; - cp = xmalloc(len); - if (strlcpy(cp, str, len) >= len) - errx(1, "xstrdup: string truncated"); + if ((cp = strdup(str)) == NULL) + err(1, "xstrdup"); return cp; } -- 2.20.1