Subject: error function re-factoring.
To: None <tech-userlevel@netbsd.org>
From: Christos Zoulas <christos@zoulas.com>
List: tech-userlevel
Date: 07/09/2006 18:11:36
Hello,

I just finished moving all the e* functions used in the code to libutil.
I am planning to commit this in the next couple of days, so speak up if
you have concerns.

christos

delete:
cvs diff: sbin/rcorder/ealloc.c was removed, no comparison available
cvs diff: sbin/rcorder/ealloc.h was removed, no comparison available
cvs diff: usr.sbin/netgroup_mkdb/util.c was removed, no comparison available
cvs diff: usr.sbin/netgroup_mkdb/util.h was removed, no comparison available

add:
--- /dev/null	2006-07-09 18:06:04.000000000 -0400
+++ lib/libutil/efun.c	2006-07-03 13:05:19.000000000 -0400
@@ -0,0 +1,135 @@
+/*	$NetBSD$	*/
+
+/*-
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD$");
+
+#include <err.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+size_t
+estrlcpy(char *dst, const char *src, size_t len)
+{
+	size_t rv;
+	if ((rv = strlcpy(dst, src, len)) >= len) {
+		errno = ENAMETOOLONG;
+		err(1, "Cannot copy `%s'", src);
+	}
+	return rv;
+}
+
+size_t
+estrlcat(char *dst, const char *src, size_t len)
+{
+	size_t rv;
+	if ((rv = strlcat(dst, src, len)) >= len) {
+		errno = ENAMETOOLONG;
+		err(1, "Cannot append `%s'", src);
+	}
+	return rv;
+}
+
+char *
+estrdup(const char *s)
+{
+	char *d = strdup(s);
+	if (d == NULL)
+		err(1, "Cannot copy `%s'", s);
+	return d;
+}
+
+void *
+emalloc(size_t n)
+{
+	void *p = malloc(n);
+	if (p == NULL)
+		err(1, "Cannot allocate %zu bytes", n);
+	return p;
+}
+
+void *
+ecalloc(size_t n, size_t s)
+{
+	void *p = malloc(n *= s);
+	if (p == NULL)
+		err(1, "Cannot allocate %zu bytes", n);
+	return memset(p, 0, n);
+}
+
+void *
+erealloc(void *p, size_t n)
+{
+	void *q = realloc(p, n);
+	if (q == NULL)
+		err(1, "Cannot re-allocate %zu bytes", n);
+	return q;
+}
+
+FILE *
+efopen(const char *p, const char *m)
+{
+	FILE *fp = fopen(p, m);
+	if (fp == NULL)
+		err(1, "Cannot open `%s'", p);
+	return fp;
+}
+
+int
+easprintf(char ** __restrict ret, const char * __restrict format, ...)
+{
+	int rv;
+	va_list ap;
+	va_start(ap, format);
+	if ((rv = vasprintf(ret, format, ap)) == -1)
+		err(1, "Cannot format string");
+	va_end(ap);
+	return rv;
+}
+
+int
+evasprintf(char ** __restrict ret, const char * __restrict format, va_list ap)
+{
+	int rv;
+	if ((rv = vasprintf(ret, format, ap)) == -1)
+		err(1, "Cannot format string");
+	return rv;
+}
--- /dev/null	2006-07-09 18:06:04.000000000 -0400
+++ lib/libutil/efun.3	2006-07-03 13:04:32.000000000 -0400
@@ -0,0 +1,98 @@
+.\"     $NetBSD$
+.\"
+.\" Copyright (c) 2006 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Christos Zoulas.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgement:
+.\"        This product includes software developed by the NetBSD
+.\"        Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\"    contributors may be used to endorse or promote products derived
+.\"    from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd July 3, 2006
+.Dt EFUN 3
+.Os
+.Sh NAME
+.Nm easprintf ,
+.Nm efopen ,
+.Nm emalloc ,
+.Nm ecalloc ,
+.Nm erealloc ,
+.Nm estrdup ,
+.Nm estrlcat ,
+.Nm estrlcpy ,
+.Nm evasprintf
+.Nd error-checked utility functions
+.Sh LIBRARY
+.Lb libutil
+.Sh SYNOPSIS
+.Ft int
+.Fn easprintf "char ** restrict str" "const char * restrict fmt" "..."
+.Ft FILE *
+.Fn efopen "const char *p" "const char *m"
+.Ft void *
+.Fn ecalloc "size_t n" "size_t c"
+.Ft void *
+.Fn emalloc "size_t n"
+.Ft void *
+.Fn erealloc "void *p" "size_t n"
+.Ft char *
+.Fn estrdup "const char *s"
+.Ft size_t
+.Fn estrlcat "char *dst" "const char *src" "size_t len"
+.Ft size_t
+.Fn estrlcpy "char *dst" "const char *src" "size_t len"
+.Ft int
+.Fn evasprintf "char ** restrict str" "const char * restrict fmt" "..."
+.Sh DESCRIPTION
+The
+.Nm easprintf ,
+.Nm efopen ,
+.Nm ecalloc ,
+.Nm emalloc ,
+.Nm erealloc ,
+.Nm estrdup ,
+.Nm estrlcat ,
+.Nm estrlcpy ,
+.Nm evasprintf
+operate exactly as the correspoding functions that do not start with an
+.Dq e
+except that they call
+.Xr err 3 
+on failure.
+.Sh SEE ALSO
+.Xr asprintf 3 ,
+.Xr err 3 ,
+.Xr fopen 3 ,
+.Xr calloc 3 ,
+.Xr malloc 3 ,
+.Xr realloc 3 ,
+.Xr strdup 3 ,
+.Xr strlcat 3 ,
+.Xr strlcpy 3 ,
+.Xr vasprintf 3 .

diff:
Index: include/err.h
===================================================================
RCS file: /cvsroot/src/include/err.h,v
retrieving revision 1.14
diff -u -u -r1.14 err.h
--- include/err.h	3 Feb 2005 04:39:32 -0000	1.14
+++ include/err.h	9 Jul 2006 22:01:50 -0000
@@ -61,6 +61,25 @@
 		    __attribute__((__format__(__printf__, 1, 2)));
 void		vwarnx(const char *, _BSD_VA_LIST_)
 		    __attribute__((__format__(__printf__, 1, 0)));
+
+#ifdef	_BSD_SIZE_T_
+typedef	_BSD_SIZE_T_	size_t;
+#undef	_BSD_SIZE_T_
+#endif
+
+size_t 		estrlcpy(char *, const char *src, size_t);
+size_t 		estrlcat(char *, const char *src, size_t);
+char 		*estrdup(const char *);
+void 		*ecalloc(size_t, size_t);
+void 		*emalloc(size_t);
+void 		*erealloc(void *, size_t);
+struct __sFILE	*efopen(const char *, const char *);
+int	 	easprintf(char ** __restrict, const char * __restrict, ...)
+    __attribute__((__format__(__printf__, 2, 3)));
+int		evasprintf(char ** __restrict, const char * __restrict,
+    _BSD_VA_LIST_)
+    __attribute__((__format__(__printf__, 2, 0)));
+
 __END_DECLS
 
 #endif /* !_ERR_H_ */
Index: lib/libasn1/asn1_compile/Makefile
===================================================================
RCS file: /cvsroot/src/lib/libasn1/asn1_compile/Makefile,v
retrieving revision 1.19
diff -u -u -r1.19 Makefile
--- lib/libasn1/asn1_compile/Makefile	10 Jan 2005 03:11:17 -0000	1.19
+++ lib/libasn1/asn1_compile/Makefile	9 Jul 2006 22:01:50 -0000
@@ -31,8 +31,7 @@
 	print_version.c				\
 	warnerr.c				\
 	strupr.c				\
-	get_window_size.c			\
-	emalloc.c
+	get_window_size.c
 
 SRCS=	$(asn1_compile_SRCS)			\
 	$(roken_SRCS)
Index: lib/libroken/Makefile
===================================================================
RCS file: /cvsroot/src/lib/libroken/Makefile,v
retrieving revision 1.13
diff -u -u -r1.13 Makefile
--- lib/libroken/Makefile	10 Jan 2005 03:11:17 -0000	1.13
+++ lib/libroken/Makefile	9 Jul 2006 22:01:55 -0000
@@ -11,16 +11,19 @@
 
 LIB=		roken
 
+.if ${OBJECT_FMT} == "ELF"
+LIBDPLIBS= util ${.CURDIR}/../libutil
+.else
+.PATH: ${NETBSDSRCDIR}/lib/libutil
+SRCS+=	efun.c
+.endif
+
 SRCS=						\
 	base64.c				\
 	concat.c				\
-	ecalloc.c				\
-	emalloc.c				\
 	environment.c				\
 	eread.c					\
-	erealloc.c				\
 	esetenv.c				\
-	estrdup.c				\
 	ewrite.c				\
 	get_default_username.c			\
 	get_window_size.c			\
Index: lib/libutil/Makefile
===================================================================
RCS file: /cvsroot/src/lib/libutil/Makefile,v
retrieving revision 1.49
diff -u -u -r1.49 Makefile
--- lib/libutil/Makefile	14 Sep 2005 18:45:40 -0000	1.49
+++ lib/libutil/Makefile	9 Jul 2006 22:01:55 -0000
@@ -8,7 +8,7 @@
 WARNS=3
 LIB=	util
 CPPFLAGS+=-DLIBC_SCCS
-SRCS=	getbootfile.c getlabelsector.c getmaxpartitions.c \
+SRCS=	efun.c getbootfile.c getlabelsector.c getmaxpartitions.c \
 	getmntopts.c getrawpartition.c \
 	disklabel_dkcksum.c disklabel_scan.c \
 	if_media.c \
@@ -17,7 +17,7 @@
 	passwd.c pw_scan.c pw_policy.c pidfile.c pidlock.c pty.c \
 	secure_path.c snprintb.c sockaddr_snprintf.c ttyaction.c ttymsg.c
 
-MAN=	getbootfile.3 getlabelsector.3 getmaxpartitions.3 \
+MAN=	efun.3 getbootfile.3 getlabelsector.3 getmaxpartitions.3 \
 	getmntopts.3 \
 	getrawpartition.3 \
 	login.3 login_cap.3 loginx.3 \
@@ -55,5 +55,13 @@
 MLINKS+=pw_lock.3 pw_setprefix.3
 MLINKS+=pidlock.3 ttylock.3
 MLINKS+=pidlock.3 ttyunlock.3
+MLINKS+=efun.3 easprintf.3
+MLINKS+=efun.3 estrlcpy.3
+MLINKS+=efun.3 estrlcat.3
+MLINKS+=efun.3 estrdup.3
+MLINKS+=efun.3 emalloc.3
+MLINKS+=efun.3 erealloc.3
+MLINKS+=efun.3 efopen.3
+MLINKS+=efun.3 evasprintf.3
 
 .include <bsd.lib.mk>
Index: lib/libutil/shlib_version
===================================================================
RCS file: /cvsroot/src/lib/libutil/shlib_version,v
retrieving revision 1.39
diff -u -u -r1.39 shlib_version
--- lib/libutil/shlib_version	18 Feb 2006 10:52:48 -0000	1.39
+++ lib/libutil/shlib_version	9 Jul 2006 22:01:55 -0000
@@ -2,4 +2,4 @@
 #	Remember to update distrib/sets/lists/base/shl.* when changing
 #
 major=7
-minor=9
+minor=10
Index: libexec/makewhatis/Makefile
===================================================================
RCS file: /cvsroot/src/libexec/makewhatis/Makefile,v
retrieving revision 1.17
diff -u -u -r1.17 Makefile
--- libexec/makewhatis/Makefile	18 May 2003 07:57:32 -0000	1.17
+++ libexec/makewhatis/Makefile	9 Jul 2006 22:01:56 -0000
@@ -10,8 +10,10 @@
 MAN=	${PROG}.8
 
 .ifndef HOSTPROG
-DPADD=	${LIBZ}
-LDADD=	-lz
+DPADD+=	${LIBZ}
+LDADD+=	-lz
 .endif
+DPADD+= ${LIBUTIL}
+LDADD+=	-lutil
 
 .include <bsd.prog.mk>
Index: libexec/makewhatis/makewhatis.c
===================================================================
RCS file: /cvsroot/src/libexec/makewhatis/makewhatis.c,v
retrieving revision 1.39
diff -u -u -r1.39 makewhatis.c
--- libexec/makewhatis/makewhatis.c	10 Apr 2006 14:39:06 -0000	1.39
+++ libexec/makewhatis/makewhatis.c	9 Jul 2006 22:01:56 -0000
@@ -110,8 +110,6 @@
 static char	*getwhatisdata(char *);
 static void	processmanpages(manpage **,whatis **);
 static void	dumpwhatis(FILE *, whatis *);
-static void	*emalloc(size_t);
-static char	*estrdup(const char *);
 static int	makewhatis(char * const *manpath);
 
 static char * const default_manpath[] = {
@@ -1091,21 +1089,3 @@
 		tree = tree->wi_right;
 	}
 }
-
-static void *
-emalloc(size_t len)
-{
-	void *ptr;
-	if ((ptr = malloc(len)) == NULL)
-		err(EXIT_FAILURE, "malloc %lu failed", (unsigned long)len);
-	return ptr;
-}
-
-static char *
-estrdup(const char *str)
-{
-	char *ptr;
-	if ((ptr = strdup(str)) == NULL)
-		err(EXIT_FAILURE, "strdup failed");
-	return ptr;
-}
Index: sbin/cgdconfig/pkcs5_pbkdf2.c
===================================================================
RCS file: /cvsroot/src/sbin/cgdconfig/pkcs5_pbkdf2.c,v
retrieving revision 1.8
diff -u -u -r1.8 pkcs5_pbkdf2.c
--- sbin/cgdconfig/pkcs5_pbkdf2.c	11 May 2006 00:40:54 -0000	1.8
+++ sbin/cgdconfig/pkcs5_pbkdf2.c	9 Jul 2006 22:01:58 -0000
@@ -61,6 +61,7 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
+#include <err.h>
 
 #include <openssl/hmac.h>
 
Index: sbin/cgdconfig/utils.c
===================================================================
RCS file: /cvsroot/src/sbin/cgdconfig/utils.c,v
retrieving revision 1.14
diff -u -u -r1.14 utils.c
--- sbin/cgdconfig/utils.c	11 May 2006 00:42:08 -0000	1.14
+++ sbin/cgdconfig/utils.c	9 Jul 2006 22:01:59 -0000
@@ -55,33 +55,6 @@
 #include "utils.h"
 
 
-void *
-emalloc(size_t len)
-{
-	void *ptr = malloc(len);
-	if (ptr == NULL)
-		err(1, NULL);
-	return ptr;
-}
-
-void *
-ecalloc(size_t nel, size_t len)
-{
-	void *ptr = calloc(nel, len);
-	if (ptr == NULL)
-		err(1, NULL);
-	return ptr;
-}
-
-char *
-estrdup(const char *str)
-{
-	char *ptr = strdup(str);
-	if (ptr == NULL)
-		err(1, NULL);
-	return ptr;
-}
-
 /* just strsep(3), but skips empty fields. */
 
 static char *
Index: sbin/cgdconfig/utils.h
===================================================================
RCS file: /cvsroot/src/sbin/cgdconfig/utils.h,v
retrieving revision 1.5
diff -u -u -r1.5 utils.h
--- sbin/cgdconfig/utils.h	30 Mar 2005 17:10:18 -0000	1.5
+++ sbin/cgdconfig/utils.h	9 Jul 2006 22:01:59 -0000
@@ -50,9 +50,6 @@
 typedef struct bits bits_t;
 
 __BEGIN_DECLS
-void		 *emalloc(size_t);
-void		 *ecalloc(size_t, size_t);
-char		 *estrdup(const char *);
 char		**words(const char *, int *);
 void	  	  words_free(char **, int);
 
Index: sbin/fsck/Makefile
===================================================================
RCS file: /cvsroot/src/sbin/fsck/Makefile,v
retrieving revision 1.16
diff -u -u -r1.16 Makefile
--- sbin/fsck/Makefile	19 Aug 2004 23:02:51 -0000	1.16
+++ sbin/fsck/Makefile	9 Jul 2006 22:01:59 -0000
@@ -4,4 +4,7 @@
 SRCS=	fsck.c fsutil.c preen.c
 MAN=	fsck.8
 
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
 .include <bsd.prog.mk>
Index: sbin/fsck/fsutil.c
===================================================================
RCS file: /cvsroot/src/sbin/fsck/fsutil.c,v
retrieving revision 1.15
diff -u -u -r1.15 fsutil.c
--- sbin/fsck/fsutil.c	5 Jun 2006 16:52:05 -0000	1.15
+++ sbin/fsck/fsutil.c	9 Jul 2006 22:01:59 -0000
@@ -242,39 +242,3 @@
 	 */
 	return (origname);
 }
-
-
-void *
-emalloc(size_t s)
-{
-	void *p;
-
-	p = malloc(s);
-	if (p == NULL)
-		err(1, "malloc failed");
-	return (p);
-}
-
-
-void *
-erealloc(void *p, size_t s)
-{
-	void *q;
-
-	q = realloc(p, s);
-	if (q == NULL)
-		err(1, "realloc failed");
-	return (q);
-}
-
-
-char *
-estrdup(const char *s)
-{
-	char *p;
-
-	p = strdup(s);
-	if (p == NULL)
-		err(1, "strdup failed");
-	return (p);
-}
Index: sbin/fsck/fsutil.h
===================================================================
RCS file: /cvsroot/src/sbin/fsck/fsutil.h,v
retrieving revision 1.11
diff -u -u -r1.11 fsutil.h
--- sbin/fsck/fsutil.h	5 Jun 2006 16:52:05 -0000	1.11
+++ sbin/fsck/fsutil.h	9 Jul 2006 22:01:59 -0000
@@ -49,9 +49,6 @@
 const char *cdevname(void);
 void setcdevname(const char *, int);
 int  hotroot(void);
-void *emalloc(size_t);
-void *erealloc(void *, size_t);
-char *estrdup(const char *);
 
 #define CHECK_PREEN	1
 #define	CHECK_VERBOSE	2
Index: sbin/fsck_ext2fs/Makefile
===================================================================
RCS file: /cvsroot/src/sbin/fsck_ext2fs/Makefile,v
retrieving revision 1.12
diff -u -u -r1.12 Makefile
--- sbin/fsck_ext2fs/Makefile	11 May 2006 23:16:29 -0000	1.12
+++ sbin/fsck_ext2fs/Makefile	9 Jul 2006 22:01:59 -0000
@@ -13,6 +13,9 @@
 
 .include <bsd.prog.mk>
 
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
 .if ${HAVE_GCC} == 4
 .for f in pass5 utilities
 COPTS.${f}.c+=  -Wno-pointer-sign
Index: sbin/fsck_ffs/Makefile
===================================================================
RCS file: /cvsroot/src/sbin/fsck_ffs/Makefile,v
retrieving revision 1.30
diff -u -u -r1.30 Makefile
--- sbin/fsck_ffs/Makefile	24 Jun 2006 05:21:11 -0000	1.30
+++ sbin/fsck_ffs/Makefile	9 Jul 2006 22:01:59 -0000
@@ -31,5 +31,8 @@
 SUBDIR+=SMM.doc
 .endif
 
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
 .include <bsd.prog.mk>
 .include <bsd.subdir.mk>
Index: sbin/fsck_lfs/Makefile
===================================================================
RCS file: /cvsroot/src/sbin/fsck_lfs/Makefile,v
retrieving revision 1.12
diff -u -u -r1.12 Makefile
--- sbin/fsck_lfs/Makefile	17 Apr 2006 19:05:16 -0000	1.12
+++ sbin/fsck_lfs/Makefile	9 Jul 2006 22:01:59 -0000
@@ -12,4 +12,7 @@
 .PATH:	${NETBSDSRCDIR}/sys/ufs/lfs ${FSCK}
 CPPFLAGS+=-I${.CURDIR} -I${FSCK} # -DVERBOSE_BLOCKMAP 
 
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
 .include <bsd.prog.mk>
Index: sbin/fsck_msdos/Makefile
===================================================================
RCS file: /cvsroot/src/sbin/fsck_msdos/Makefile,v
retrieving revision 1.10
diff -u -u -r1.10 Makefile
--- sbin/fsck_msdos/Makefile	20 Jan 2005 16:39:23 -0000	1.10
+++ sbin/fsck_msdos/Makefile	9 Jul 2006 22:01:59 -0000
@@ -10,4 +10,7 @@
 CPPFLAGS+= -I${FSCK}
 .PATH:	${FSCK}
 
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
 .include <bsd.prog.mk>
Index: sbin/ifconfig/extern.h
===================================================================
RCS file: /cvsroot/src/sbin/ifconfig/extern.h,v
retrieving revision 1.9
diff -u -u -r1.9 extern.h
--- sbin/ifconfig/extern.h	16 Jun 2006 23:48:35 -0000	1.9
+++ sbin/ifconfig/extern.h	9 Jul 2006 22:01:59 -0000
@@ -70,4 +70,3 @@
 const char *get_string(const char *, const char *, u_int8_t *, int *);
 void	print_string(const u_int8_t *, int);
 void    getsock(int);
-void estrlcpy(char *, char *, size_t);
Index: sbin/ifconfig/ifconfig.c
===================================================================
RCS file: /cvsroot/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.172
diff -u -u -r1.172 ifconfig.c
--- sbin/ifconfig/ifconfig.c	16 Jun 2006 23:48:35 -0000	1.172
+++ sbin/ifconfig/ifconfig.c	9 Jul 2006 22:02:00 -0000
@@ -1550,12 +1550,3 @@
 		progname, progname, progname, progname, progname, progname);
 	exit(1);
 }
-
-void
-estrlcpy(char *dst, char *src, size_t len)
-{
-	if (strlcpy(dst, src, len) >= len) { 
-		errno = ENAMETOOLONG; 
-		err(1, "Cannot copy `%s'", src);
-	}
-}
Index: sbin/rcorder/Makefile
===================================================================
RCS file: /cvsroot/src/sbin/rcorder/Makefile,v
retrieving revision 1.5
diff -u -u -r1.5 Makefile
--- sbin/rcorder/Makefile	27 Jun 2005 01:00:06 -0000	1.5
+++ sbin/rcorder/Makefile	9 Jul 2006 22:02:00 -0000
@@ -1,7 +1,10 @@
 #       $NetBSD: Makefile,v 1.5 2005/06/27 01:00:06 christos Exp $
 
 PROG=   rcorder
-SRCS=   ealloc.c hash.c rcorder.c
+SRCS=   hash.c rcorder.c
 MAN=	rcorder.8
 
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
 .include <bsd.prog.mk>
Index: sbin/rcorder/hash.c
===================================================================
RCS file: /cvsroot/src/sbin/rcorder/hash.c,v
retrieving revision 1.3
diff -u -u -r1.3 hash.c
--- sbin/rcorder/hash.c	7 Aug 2003 10:04:37 -0000	1.3
+++ sbin/rcorder/hash.c	9 Jul 2006 22:02:00 -0000
@@ -87,6 +87,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <err.h>
 
 /* hash.c --
  *
@@ -96,7 +97,6 @@
  * 	information increases.
  */
 #include "hash.h"
-#include "ealloc.h"
 
 /*
  * Forward references to local procedures that are used before they're
Index: sbin/rcorder/rcorder.c
===================================================================
RCS file: /cvsroot/src/sbin/rcorder/rcorder.c,v
retrieving revision 1.13
diff -u -u -r1.13 rcorder.c
--- sbin/rcorder/rcorder.c	21 Sep 2004 15:47:32 -0000	1.13
+++ sbin/rcorder/rcorder.c	9 Jul 2006 22:02:01 -0000
@@ -67,7 +67,6 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "ealloc.h"
 #include "hash.h"
 
 #ifdef DEBUG
Index: usr.bin/column/Makefile
===================================================================
RCS file: /cvsroot/src/usr.bin/column/Makefile,v
retrieving revision 1.5
diff -u -u -r1.5 Makefile
--- usr.bin/column/Makefile	16 Mar 2006 16:49:07 -0000	1.5
+++ usr.bin/column/Makefile	9 Jul 2006 22:02:27 -0000
@@ -4,4 +4,7 @@
 PROG=	column
 WARNS=	4
 
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
 .include <bsd.prog.mk>
Index: usr.bin/column/column.c
===================================================================
RCS file: /cvsroot/src/usr.bin/column/column.c,v
retrieving revision 1.14
diff -u -u -r1.14 column.c
--- usr.bin/column/column.c	9 Apr 2006 19:51:23 -0000	1.14
+++ usr.bin/column/column.c	9 Jul 2006 22:02:27 -0000
@@ -57,9 +57,6 @@
 #define	TAB	8
 
 static void  c_columnate(void);
-static void *emalloc(size_t);
-static void *erealloc(void *, size_t);
-static char *estrdup(const char *);
 static void  input(FILE *);
 static void  maketbl(void);
 static void  print(void);
@@ -291,37 +288,6 @@
 	}
 }
 
-static void *
-emalloc(size_t size)
-{
-	void *p;
-
-	if ((p = malloc(size)) == NULL)
-		err(1, "malloc");
-	(void)memset(p, 0, size);
-	return (p);
-}
-
-static void *
-erealloc(void *op, size_t size)
-{
-	void *p;
-
-	if ((p = realloc(op, size)) == NULL)
-		err(1, "realloc");
-	return p;
-}
-
-static char *
-estrdup(const char *str)
-{
-	char *p;
-
-	if ((p = strdup(str)) == NULL)
-		err(1, "strdup");
-	return p;
-}
-
 static void
 usage(void)
 {
Index: usr.bin/config/Makefile
===================================================================
RCS file: /cvsroot/src/usr.bin/config/Makefile,v
retrieving revision 1.3
diff -u -u -r1.3 Makefile
--- usr.bin/config/Makefile	4 Jun 2006 19:42:19 -0000	1.3
+++ usr.bin/config/Makefile	9 Jul 2006 22:02:27 -0000
@@ -9,6 +9,9 @@
 YHEADER=1
 CPPFLAGS+=-I${.CURDIR} -I.
 
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
 CWARNFLAGS+=-Wno-format-y2k
 
 .include <bsd.prog.mk>
Index: usr.bin/config/defs.h
===================================================================
RCS file: /cvsroot/src/usr.bin/config/defs.h,v
retrieving revision 1.11
diff -u -u -r1.11 defs.h
--- usr.bin/config/defs.h	4 Jun 2006 13:52:27 -0000	1.11
+++ usr.bin/config/defs.h	9 Jul 2006 22:02:28 -0000
@@ -60,6 +60,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <err.h>
 
 /* These are really for MAKE_BOOTSTRAP but harmless. */
 #ifndef __dead
@@ -534,10 +535,6 @@
 void	initsem(void);
 
 /* util.c */
-void	*ecalloc(size_t, size_t);
-void	*emalloc(size_t);
-void	*erealloc(void *, size_t);
-char	*estrdup(const char *);
 void	prefix_push(const char *);
 void	prefix_pop(void);
 char	*sourcepath(const char *);
Index: usr.bin/config/util.c
===================================================================
RCS file: /cvsroot/src/usr.bin/config/util.c,v
retrieving revision 1.2
diff -u -u -r1.2 util.c
--- usr.bin/config/util.c	4 Oct 2005 12:35:00 -0000	1.2
+++ usr.bin/config/util.c	9 Jul 2006 22:02:28 -0000
@@ -44,6 +44,7 @@
 #include "nbtool_config.h"
 #endif
 
+#include <err.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -52,7 +53,6 @@
 #include <sys/types.h>
 #include "defs.h"
 
-static void nomem(void);
 static void vxerror(const char *, int, const char *, va_list)
 	     __attribute__((__format__(__printf__, 3, 0)));
 static void vxwarn(const char *, int, const char *, va_list)
@@ -62,67 +62,6 @@
      __attribute__((__format__(__printf__, 4, 0)));
 
 /*
- * Calloc, with abort on error.
- */
-void *
-ecalloc(size_t nelem, size_t size)
-{
-	void *p;
-
-	if ((p = calloc(nelem, size)) == NULL)
-		nomem();
-	return (p);
-}
-
-/*
- * Malloc, with abort on error.
- */
-void *
-emalloc(size_t size)
-{
-	void *p;
-
-	if ((p = malloc(size)) == NULL)
-		nomem();
-	return (p);
-}
-
-/*
- * Realloc, with abort on error.
- */
-void *
-erealloc(void *p, size_t size)
-{
-	void *q;
-
-	if ((q = realloc(p, size)) == NULL)
-		nomem();
-	p = q;
-	return (p);
-}
-
-/*
- * Strdup, with abort on error.
- */
-char *
-estrdup(const char *p)
-{
-	char *cp;
-
-	if ((cp = strdup(p)) == NULL)
-		nomem();
-	return (cp);
-}
-
-static void
-nomem(void)
-{
-
-	(void)fprintf(stderr, "config: out of memory\n");
-	exit(1);
-}
-
-/*
  * Push a prefix onto the prefix stack.
  */
 void
Index: usr.bin/crunch/crunchgen/Makefile
===================================================================
RCS file: /cvsroot/src/usr.bin/crunch/crunchgen/Makefile,v
retrieving revision 1.13
diff -u -u -r1.13 Makefile
--- usr.bin/crunch/crunchgen/Makefile	3 Jan 2004 14:04:27 -0000	1.13
+++ usr.bin/crunch/crunchgen/Makefile	9 Jul 2006 22:02:28 -0000
@@ -8,6 +8,10 @@
 	${_MKTARGET_CREATE}
 	${HOST_SH} ${.ALLSRC} >${.TARGET}
 
+
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
 .include <bsd.prog.mk>
 
 .ifndef HOSTPROG
Index: usr.bin/crunch/crunchgen/crunchgen.c
===================================================================
RCS file: /cvsroot/src/usr.bin/crunch/crunchgen/crunchgen.c,v
retrieving revision 1.71
diff -u -u -r1.71 crunchgen.c
--- usr.bin/crunch/crunchgen/crunchgen.c	13 Jun 2006 17:18:56 -0000	1.71
+++ usr.bin/crunch/crunchgen/crunchgen.c	9 Jul 2006 22:02:29 -0000
@@ -115,8 +115,6 @@
 void add_string(strlst_t **listp, char *str);
 int is_dir(char *pathname);
 int is_nonempty_file(char *pathname);
-static void estrlcpy(char *, const char *, size_t);
-static void estrlcat(char *, const char *, size_t);
 
 /* helper routines for main() */
 
@@ -164,13 +162,13 @@
 	case 'O':	oneobj = 0; break;
 	case 'o':       useobjs = 1, oneobj = 0; break;
 
-	case 'm':	estrlcpy(outmkname, optarg, sizeof(outmkname)); break;
-	case 'c':	estrlcpy(outcfname, optarg, sizeof(outcfname)); break;
-	case 'e':	estrlcpy(execfname, optarg, sizeof(execfname)); break;
-	case 'd':       estrlcpy(dbg, optarg, sizeof(dbg)); break;
+	case 'm':	(void)estrlcpy(outmkname, optarg, sizeof(outmkname)); break;
+	case 'c':	(void)estrlcpy(outcfname, optarg, sizeof(outcfname)); break;
+	case 'e':	(void)estrlcpy(execfname, optarg, sizeof(execfname)); break;
+	case 'd':       (void)estrlcpy(dbg, optarg, sizeof(dbg)); break;
 
-	case 'D':	estrlcpy(topdir, optarg, sizeof(topdir)); break;
-	case 'L':	estrlcpy(libdir, optarg, sizeof(libdir)); break;
+	case 'D':	(void)estrlcpy(topdir, optarg, sizeof(topdir)); break;
+	case 'L':	(void)estrlcpy(libdir, optarg, sizeof(libdir)); break;
 	case 'v':	add_string(&vars, optarg); break;
 
 	case '?':
@@ -188,15 +186,15 @@
      * generate filenames
      */
 
-    estrlcpy(infilename, argv[0], sizeof(infilename));
+    (void)estrlcpy(infilename, argv[0], sizeof(infilename));
     getcwd(curdir, MAXPATHLEN);
 
     /* confname = `basename infilename .conf` */
 
     if ((p = strrchr(infilename, '/')) != NULL)
-	estrlcpy(confname, p + 1, sizeof(confname));
+	(void)estrlcpy(confname, p + 1, sizeof(confname));
     else
-	estrlcpy(confname, infilename, sizeof(confname));
+	(void)estrlcpy(confname, infilename, sizeof(confname));
     if ((p = strrchr(confname, '.')) != NULL && !strcmp(p, ".conf"))
 	*p = '\0';
 
@@ -273,7 +271,7 @@
 
     (void)snprintf(line, sizeof(line), "reading %s", filename);
     status(line);
-    estrlcpy(curfilename, filename, sizeof(curfilename));
+    (void)estrlcpy(curfilename, filename, sizeof(curfilename));
 
     if ((cf = fopen(curfilename, "r")) == NULL) {
 	perror(curfilename);
@@ -350,14 +348,14 @@
 
     for (i = 1; i < argc; i++) {
 	if (argv[i][0] == '/')
-		estrlcpy(tmppath, argv[i], sizeof(tmppath));
+		(void)estrlcpy(tmppath, argv[i], sizeof(tmppath));
 	else {
 		if (topdir[0] == '\0')
-		    estrlcpy(tmppath, curdir, sizeof(tmppath));
+		    (void)estrlcpy(tmppath, curdir, sizeof(tmppath));
 		else
-		    estrlcpy(tmppath, topdir, sizeof(tmppath));
-		estrlcat(tmppath, "/", sizeof(tmppath));
-		estrlcat(tmppath, argv[i], sizeof(tmppath));
+		    (void)estrlcpy(tmppath, topdir, sizeof(tmppath));
+		(void)estrlcat(tmppath, "/", sizeof(tmppath));
+		(void)estrlcat(tmppath, argv[i], sizeof(tmppath));
 	}
 	if (is_dir(tmppath))
 	    add_string(&srcdirs, tmppath);
@@ -470,11 +468,11 @@
 	} else {
 	    char tmppath[MAXPATHLEN];
 	    if (topdir[0] == '\0')
-	        estrlcpy(tmppath, curdir, sizeof(tmppath));
+	        (void)estrlcpy(tmppath, curdir, sizeof(tmppath));
 	    else
-	        estrlcpy(tmppath, topdir, sizeof(tmppath));
-	    estrlcat(tmppath, "/", sizeof(tmppath));
-	    estrlcat(tmppath, argv[3], sizeof(tmppath));
+	        (void)estrlcpy(tmppath, topdir, sizeof(tmppath));
+	    (void)estrlcat(tmppath, "/", sizeof(tmppath));
+	    (void)estrlcat(tmppath, argv[3], sizeof(tmppath));
 	    if ((p->srcdir = strdup(tmppath)) == NULL)
 		out_of_memory();
 	}
@@ -603,11 +601,11 @@
 		} else {
 		    char tmppath[MAXPATHLEN];
 		    if (topdir[0] == '\0')
-			estrlcpy(tmppath, curdir, sizeof(tmppath));
+			(void)estrlcpy(tmppath, curdir, sizeof(tmppath));
 		    else
-			estrlcpy(tmppath, topdir, sizeof(tmppath));
-		    estrlcat(tmppath, "/", sizeof(tmppath));
-		    estrlcat(tmppath, path, sizeof(tmppath));
+			(void)estrlcpy(tmppath, topdir, sizeof(tmppath));
+		    (void)estrlcat(tmppath, "/", sizeof(tmppath));
+		    (void)estrlcat(tmppath, path, sizeof(tmppath));
 		    if ((p->srcdir = strdup(tmppath)) == NULL)
 			out_of_memory();
 		}
@@ -1146,21 +1144,3 @@
 
     return S_ISREG(buf.st_mode) && buf.st_size > 0;
 }
-
-static void
-estrlcpy(char *dst, const char *src, size_t len)
-{
-	if (strlcpy(dst, src, len) >= len) {
-		errno = ENAMETOOLONG;
-		err(1, "Cannot copy `%s'", src);
-	}
-}
-
-static void
-estrlcat(char *dst, const char *src, size_t len)
-{
-	if (strlcat(dst, src, len) >= len) {
-		errno = ENAMETOOLONG;
-		err(1, "Cannot append `%s'", src);
-	}
-}
Index: usr.bin/find/Makefile
===================================================================
RCS file: /cvsroot/src/usr.bin/find/Makefile,v
retrieving revision 1.9
diff -u -u -r1.9 Makefile
--- usr.bin/find/Makefile	18 Sep 2002 14:00:36 -0000	1.9
+++ usr.bin/find/Makefile	9 Jul 2006 22:02:29 -0000
@@ -9,4 +9,7 @@
 CPPFLAGS+=	-I${NETBSDSRCDIR}/bin/ls
 .PATH:	${NETBSDSRCDIR}/bin/ls
 
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
 .include <bsd.prog.mk>
Index: usr.bin/find/extern.h
===================================================================
RCS file: /cvsroot/src/usr.bin/find/extern.h,v
retrieving revision 1.23
diff -u -u -r1.23 extern.h
--- usr.bin/find/extern.h	20 Feb 2006 16:31:02 -0000	1.23
+++ usr.bin/find/extern.h	9 Jul 2006 22:02:29 -0000
@@ -34,7 +34,6 @@
 #include <sys/cdefs.h>
 
 void	 brace_subst __P((char *, char **, char *, int *));
-void	*emalloc __P((unsigned int));
 PLAN	*find_create __P((char ***));
 int	 find_execute __P((PLAN *, char **));
 PLAN	*find_formplan __P((char **));
Index: usr.bin/find/misc.c
===================================================================
RCS file: /cvsroot/src/usr.bin/find/misc.c,v
retrieving revision 1.12
diff -u -u -r1.12 misc.c
--- usr.bin/find/misc.c	7 Aug 2003 11:13:42 -0000	1.12
+++ usr.bin/find/misc.c	9 Jul 2006 22:02:29 -0000
@@ -128,21 +128,6 @@
 }
  
 /*
- * emalloc --
- *	malloc with error checking.
- */
-void *
-emalloc(len)
-	u_int len;
-{
-	void *p;
-
-	if ((p = malloc(len)) == NULL)
-		err(1, "malloc");
-	return (p);
-}
-
-/*
  * show_path --
  *	called on SIGINFO
  */
Index: usr.bin/hexdump/Makefile
===================================================================
RCS file: /cvsroot/src/usr.bin/hexdump/Makefile,v
retrieving revision 1.9
diff -u -u -r1.9 Makefile
--- usr.bin/hexdump/Makefile	18 May 2003 07:57:34 -0000	1.9
+++ usr.bin/hexdump/Makefile	9 Jul 2006 22:02:29 -0000
@@ -7,6 +7,9 @@
 WFORMAT=	1
 WARNS=		2
 
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
 .ifndef HOSTPROG
 LINKS=	${BINDIR}/hexdump ${BINDIR}/od
 .endif
Index: usr.bin/hexdump/display.c
===================================================================
RCS file: /cvsroot/src/usr.bin/hexdump/display.c,v
retrieving revision 1.19
diff -u -u -r1.19 display.c
--- usr.bin/hexdump/display.c	4 Jan 2006 01:30:21 -0000	1.19
+++ usr.bin/hexdump/display.c	9 Jul 2006 22:02:29 -0000
@@ -238,8 +238,8 @@
 	u_char *tmpp;
 
 	if (!curp) {
-		curp = emalloc(blocksize);
-		savp = emalloc(blocksize);
+		curp = ecalloc(blocksize, 1);
+		savp = ecalloc(blocksize, 1);
 	} else {
 		tmpp = curp;
 		curp = savp;
@@ -357,20 +357,3 @@
 		skip -= cnt;
 	}
 }
-
-void *
-emalloc(int allocsize)
-{
-	void *p;
-
-	if ((p = malloc((u_int)allocsize)) == NULL)
-		nomem();
-	memset(p, 0, allocsize);
-	return(p);
-}
-
-void
-nomem(void)
-{
-	err(1, NULL);
-}
Index: usr.bin/hexdump/hexdump.h
===================================================================
RCS file: /cvsroot/src/usr.bin/hexdump/hexdump.h,v
retrieving revision 1.9
diff -u -u -r1.9 hexdump.h
--- usr.bin/hexdump/hexdump.h	4 Jan 2006 01:30:21 -0000	1.9
+++ usr.bin/hexdump/hexdump.h	9 Jul 2006 22:02:30 -0000
@@ -91,12 +91,10 @@
 void	 display(void);
 void	 doskip(const char *, int);
 /*void	 err(const char *, ...);*/
-void	*emalloc(int);
 void	 escape(char *);
 u_char	*get(void);
 void	 newsyntax(int, char ***);
 int	 next(char **);
-void	 nomem(void);
 void	 oldsyntax(int, char ***);
 void	 rewrite(FS *);
 int	 size(FS *);
Index: usr.bin/hexdump/odsyntax.c
===================================================================
RCS file: /cvsroot/src/usr.bin/hexdump/odsyntax.c,v
retrieving revision 1.23
diff -u -u -r1.23 odsyntax.c
--- usr.bin/hexdump/odsyntax.c	4 Jan 2006 01:30:21 -0000	1.23
+++ usr.bin/hexdump/odsyntax.c	9 Jul 2006 22:02:30 -0000
@@ -284,10 +284,9 @@
 				break;
 		if (odf->type == 0)
 			errx(1, "%c%d: format not supported", type, nbytes);
-		asprintf(&fmt, "%d/%d  \"%*s%s \" \"\\n\"",
+		(void)easprintf(&fmt, "%d/%d  \"%*s%s \" \"\\n\"",
 		    16 / nbytes, nbytes,
 		    4 * nbytes - odf->minwidth, "", odf->format);
-		if (fmt == NULL) nomem();
 		add(fmt);
 	}
 }
Index: usr.bin/hexdump/parse.c
===================================================================
RCS file: /cvsroot/src/usr.bin/hexdump/parse.c,v
retrieving revision 1.19
diff -u -u -r1.19 parse.c
--- usr.bin/hexdump/parse.c	30 Mar 2006 19:53:58 -0000	1.19
+++ usr.bin/hexdump/parse.c	9 Jul 2006 22:02:30 -0000
@@ -145,8 +145,7 @@
 		for (savep = ++p; *p != '"';)
 			if (*p++ == 0)
 				badfmt(fmt);
-		if (!(tfu->fmt = malloc(p - savep + 1)))
-			nomem();
+		tfu->fmt = emalloc(p - savep + 1);
 		(void) strncpy(tfu->fmt, savep, p - savep);
 		tfu->fmt[p - savep] = '\0';
 		escape(tfu->fmt);
Index: usr.bin/iconv/Makefile
===================================================================
RCS file: /cvsroot/src/usr.bin/iconv/Makefile,v
retrieving revision 1.4
diff -u -u -r1.4 Makefile
--- usr.bin/iconv/Makefile	24 Apr 2005 17:46:06 -0000	1.4
+++ usr.bin/iconv/Makefile	9 Jul 2006 22:02:30 -0000
@@ -8,4 +8,7 @@
 CPPFLAGS+=	-I. -I${.CURDIR} -I${NETBSDSRCDIR}/lib/libc
 MAN=		iconv.1
 
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
 .include <bsd.prog.mk>
Index: usr.bin/iconv/iconv.c
===================================================================
RCS file: /cvsroot/src/usr.bin/iconv/iconv.c,v
retrieving revision 1.9
diff -u -u -r1.9 iconv.c
--- usr.bin/iconv/iconv.c	25 Apr 2005 13:57:34 -0000	1.9
+++ usr.bin/iconv/iconv.c	9 Jul 2006 22:02:30 -0000
@@ -40,7 +40,6 @@
 #include <err.h>
 
 static void usage(void) __attribute__((__unused__));
-static char *estrdup(const char *);
 static int scmp(const void *, const void *);
 static void show_codesets(void);
 static void do_conv(const char *, FILE *, const char *, const char *, int, int);
@@ -53,15 +52,6 @@
 	exit(1);
 }
 
-static char *
-estrdup(const char *str)
-{
-	char *ptr = strdup(str);
-	if (ptr == NULL)
-		err(EXIT_FAILURE, "Cannot copy string");
-	return ptr;
-}
-
 /*
  * qsort() helper function
  */
Index: usr.bin/make/Makefile
===================================================================
RCS file: /cvsroot/src/usr.bin/make/Makefile,v
retrieving revision 1.36
diff -u -u -r1.36 Makefile
--- usr.bin/make/Makefile	15 Jun 2006 10:55:02 -0000	1.36
+++ usr.bin/make/Makefile	9 Jul 2006 22:02:31 -0000
@@ -31,6 +31,9 @@
 main.o:	${OBJS:Nmain.o} ${MAKEFILE}
 COPTS.var.c+= -Wno-cast-qual
 
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
 # A simple unit-test driver to help catch regressions
 accept test:
 	cd ${.CURDIR}/unit-tests && ${.MAKE:S,^./,${.CURDIR}/,} TEST_MAKE=${TEST_MAKE:U${.OBJDIR}/${PROG:T}} ${.TARGET}
Index: usr.bin/make/main.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/main.c,v
retrieving revision 1.127
diff -u -u -r1.127 main.c
--- usr.bin/make/main.c	29 Jun 2006 22:02:06 -0000	1.127
+++ usr.bin/make/main.c	9 Jul 2006 22:02:32 -0000
@@ -1341,13 +1341,13 @@
  *
  * Results:
  *	A string containing the output of the command, or the empty string
- *	If err is not NULL, it contains the reason for the command failure
+ *	If errnum is not NULL, it contains the reason for the command failure
  *
  * Side Effects:
  *	The string must be freed by the caller.
  */
 char *
-Cmd_Exec(const char *cmd, const char **err)
+Cmd_Exec(const char *cmd, const char **errnum)
 {
     const char	*args[4];   	/* Args for invoking the shell */
     int 	fds[2];	    	/* Pipe streams */
@@ -1360,7 +1360,7 @@
     int		cc;
 
 
-    *err = NULL;
+    *errnum = NULL;
 
     if (!shellName)
 	Shell_Init();
@@ -1376,7 +1376,7 @@
      * Open a pipe for fetching its output
      */
     if (pipe(fds) == -1) {
-	*err = "Couldn't create pipe for \"%s\"";
+	*errnum = "Couldn't create pipe for \"%s\"";
 	goto bad;
     }
 
@@ -1403,7 +1403,7 @@
 	/*NOTREACHED*/
 
     case -1:
-	*err = "Couldn't exec \"%s\"";
+	*errnum = "Couldn't exec \"%s\"";
 	goto bad;
 
     default:
@@ -1437,10 +1437,10 @@
 	Buf_Destroy(buf, FALSE);
 
 	if (cc == 0)
-	    *err = "Couldn't read shell's output for \"%s\"";
+	    *errnum = "Couldn't read shell's output for \"%s\"";
 
 	if (status)
-	    *err = "\"%s\" returned non-zero status";
+	    *errnum = "\"%s\" returned non-zero status";
 
 	/*
 	 * Null-terminate the result, convert newlines to spaces and
@@ -1596,6 +1596,7 @@
 	Fatal("%d error%s", errors, errors == 1 ? "" : "s");
 }
 
+#ifndef __NetBSD__
 /*
  * emalloc --
  *	malloc, but die on error.
@@ -1646,6 +1647,7 @@
 	(void)fprintf(stderr, "%s: %s.\n", progname, strerror(errno));
 	exit(2);
 }
+#endif
 
 /*
  * enunlink --
Index: usr.bin/make/nonints.h
===================================================================
RCS file: /cvsroot/src/usr.bin/make/nonints.h,v
retrieving revision 1.36
diff -u -u -r1.36 nonints.h
--- usr.bin/make/nonints.h	31 Mar 2006 21:58:08 -0000	1.36
+++ usr.bin/make/nonints.h	9 Jul 2006 22:02:32 -0000
@@ -115,10 +115,14 @@
 void DieHorribly(void) __attribute__((__noreturn__));
 int PrintAddr(ClientData, ClientData);
 void Finish(int);
+#ifndef __NetBSD__
 char *estrdup(const char *);
 void *emalloc(size_t);
 void *erealloc(void *, size_t);
 void enomem(void);
+#else
+#include <err.h>
+#endif
 int eunlink(const char *);
 void execError(const char *, const char *);
 
Index: usr.bin/make/parse.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/parse.c,v
retrieving revision 1.114
diff -u -u -r1.114 parse.c
--- usr.bin/make/parse.c	31 Mar 2006 21:58:08 -0000	1.114
+++ usr.bin/make/parse.c	9 Jul 2006 22:02:34 -0000
@@ -1206,17 +1206,17 @@
 	 * allow on this line...
 	 */
 	if (specType != Not && specType != ExPath) {
-	    Boolean warn = FALSE;
+	    Boolean warning = FALSE;
 
 	    while (*cp && (ParseIsEscaped(lstart, cp) ||
 		((*cp != '!') && (*cp != ':')))) {
 		if (ParseIsEscaped(lstart, cp) ||
 		    (*cp != ' ' && *cp != '\t')) {
-		    warn = TRUE;
+		    warning = TRUE;
 		}
 		cp++;
 	    }
-	    if (warn) {
+	    if (warning) {
 		Parse_Error(PARSE_WARNING, "Extra target ignored");
 	    }
 	} else {
@@ -1734,7 +1734,7 @@
 	Var_Set(line, cp, ctxt, 0);
     } else if (type == VAR_SHELL) {
 	char *res;
-	const char *err;
+	const char *error;
 
 	if (strchr(cp, '$') != NULL) {
 	    /*
@@ -1746,12 +1746,12 @@
 	    freeCp = TRUE;
 	}
 
-	res = Cmd_Exec(cp, &err);
+	res = Cmd_Exec(cp, &error);
 	Var_Set(line, res, ctxt, 0);
 	free(res);
 
-	if (err)
-	    Parse_Error(PARSE_WARNING, err, cp);
+	if (error)
+	    Parse_Error(PARSE_WARNING, error, cp);
     } else {
 	/*
 	 * Normal assignment -- just do it.
Index: usr.bin/make/var.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/var.c,v
retrieving revision 1.111
diff -u -u -r1.111 var.c
--- usr.bin/make/var.c	29 Jun 2006 22:01:17 -0000	1.111
+++ usr.bin/make/var.c	9 Jul 2006 22:02:36 -0000
@@ -144,7 +144,7 @@
 char 	var_Error[] = "";
 
 /*
- * Similar to var_Error, but returned when the 'err' flag for Var_Parse is
+ * Similar to var_Error, but returned when the 'errnum' flag for Var_Parse is
  * set false. Why not just use a constant? Well, gcc likes to condense
  * identical string instances...
  */
@@ -232,7 +232,7 @@
     int		tvarLen;	
     char	*str;		/* string to expand */
     int		strLen;		
-    int		err;		/* err for not defined */
+    int		errnum;		/* errnum for not defined */
 } VarLoop_t;
 
 #ifndef NO_REGEX
@@ -1219,14 +1219,14 @@
  *-----------------------------------------------------------------------
  */
 static void
-VarREError(int err, regex_t *pat, const char *str)
+VarREError(int errnum, regex_t *pat, const char *str)
 {
     char *errbuf;
     int errlen;
 
-    errlen = regerror(err, pat, 0, 0);
+    errlen = regerror(errnum, pat, 0, 0);
     errbuf = emalloc(errlen);
-    regerror(err, pat, errbuf, errlen);
+    regerror(errnum, pat, errbuf, errlen);
     Error("%s: %s", str, errbuf);
     free(errbuf);
 }
@@ -1397,7 +1397,7 @@
 
     if (word && *word) {
         Var_Set(loop->tvar, word, loop->ctxt, VAR_NO_EXPORT);
-        s = Var_Subst(NULL, loop->str, loop->ctxt, loop->err);
+        s = Var_Subst(NULL, loop->str, loop->ctxt, loop->errnum);
         if (s != NULL && *s != '\0') {
             if (addSpace && *s != '\n')
                 Buf_AddByte(buf, ' ');
@@ -1716,7 +1716,7 @@
  */
 static char *
 VarGetPattern(GNode *ctxt, Var_Parse_State *vpstate __unused,
-	      int err, const char **tstr, int delim, int *flags,
+	      int errnum, const char **tstr, int delim, int *flags,
 	      int *length, VarPattern *pattern)
 {
     const char *cp;
@@ -1760,7 +1760,7 @@
 		     * delimiter, assume it's a variable
 		     * substitution and recurse.
 		     */
-		    cp2 = Var_Parse(cp, ctxt, err, &len, &freeIt);
+		    cp2 = Var_Parse(cp, ctxt, errnum, &len, &freeIt);
 		    Buf_AddBytes(buf, strlen(cp2), (Byte *)cp2);
 		    if (freeIt)
 			free(freeIt);
@@ -1978,7 +1978,7 @@
 static char *
 ApplyModifiers(char *nstr, const char *tstr,
 	       int startc, int endc,
-	       Var *v, GNode *ctxt, Boolean err,
+	       Var *v, GNode *ctxt, Boolean errnum,
 	       int *lengthPtr, void **freePtr)
 {
     const char 	   *start;
@@ -2007,7 +2007,7 @@
 	    char *rval;
 	    int rlen;
 
-	    rval = Var_Parse(tstr, ctxt, err, &rlen, &freeIt);
+	    rval = Var_Parse(tstr, ctxt, errnum, &rlen, &freeIt);
 
 	    if (DEBUG(VAR)) {
 		printf("Got '%s' from '%.*s'%.*s\n",
@@ -2021,9 +2021,9 @@
 
 		nstr = ApplyModifiers(nstr, rval,
 				      0, 0,
-				      v, ctxt, err, &used, freePtr);
+				      v, ctxt, errnum, &used, freePtr);
 		if (nstr == var_Error
-		    || (nstr == varNoError && err == 0)
+		    || (nstr == varNoError && errnum == 0)
 		    || strlen(rval) != (size_t) used) {
 		    if (freeIt)
 			free(freeIt);
@@ -2086,7 +2086,7 @@
 		    delim = BRCLOSE;
 		    pattern.flags = 0;
 
-		    pattern.rhs = VarGetPattern(ctxt, &parsestate, err,
+		    pattern.rhs = VarGetPattern(ctxt, &parsestate, errnum,
 						&cp, delim, NULL,
 						&pattern.rightLen,
 						NULL);
@@ -2135,13 +2135,13 @@
 
 		cp = ++tstr;
 		delim = '@';
-		if ((loop.tvar = VarGetPattern(ctxt, &parsestate, err,
+		if ((loop.tvar = VarGetPattern(ctxt, &parsestate, errnum,
 					       &cp, delim,
 					       &flags, &loop.tvarLen,
 					       NULL)) == NULL)
 		    goto cleanup;
 
-		if ((loop.str = VarGetPattern(ctxt, &parsestate, err,
+		if ((loop.str = VarGetPattern(ctxt, &parsestate, errnum,
 					      &cp, delim,
 					      &flags, &loop.strLen,
 					      NULL)) == NULL)
@@ -2150,7 +2150,7 @@
 		termc = *cp;
 		delim = '\0';
 
-		loop.err = err;
+		loop.errnum = errnum;
 		loop.ctxt = ctxt;
 		newStr = VarModify(ctxt, &parsestate, nstr, VarLoopExpand,
 				   (ClientData)&loop);
@@ -2192,7 +2192,7 @@
 			    int	    len;
 			    void    *freeIt;
 
-			    cp2 = Var_Parse(cp, ctxt, err, &len, &freeIt);
+			    cp2 = Var_Parse(cp, ctxt, errnum, &len, &freeIt);
 			    Buf_AddBytes(buf, strlen(cp2), (Byte *)cp2);
 			    if (freeIt)
 				free(freeIt);
@@ -2259,7 +2259,7 @@
 		delim = '!';
 
 		cp = ++tstr;
-		if ((pattern.rhs = VarGetPattern(ctxt, &parsestate, err,
+		if ((pattern.rhs = VarGetPattern(ctxt, &parsestate, errnum,
 						 &cp, delim,
 						 NULL, &pattern.rightLen,
 						 NULL)) == NULL)
@@ -2289,7 +2289,7 @@
 		cp = tstr+1; /* point to char after '[' */
 		delim = ']'; /* look for closing ']' */
 		estr = VarGetPattern(ctxt, &parsestate,
-				     err, &cp, delim,
+				     errnum, &cp, delim,
 				     NULL, NULL, NULL);
 		if (estr == NULL)
 		    goto cleanup; /* report missing ']' */
@@ -2580,7 +2580,7 @@
 		}
 		if ((cp2 = strchr(pattern, '$'))) {
 		    cp2 = pattern;
-		    pattern = Var_Subst(NULL, cp2, ctxt, err);
+		    pattern = Var_Subst(NULL, cp2, ctxt, errnum);
 		    if (copy)
 			free(cp2);
 		    copy = TRUE;
@@ -2617,14 +2617,14 @@
 		}
 
 		cp = tstr;
-		if ((pattern.lhs = VarGetPattern(ctxt, &parsestate, err,
+		if ((pattern.lhs = VarGetPattern(ctxt, &parsestate, errnum,
 						 &cp, delim,
 						 &pattern.flags,
 						 &pattern.leftLen,
 						 NULL)) == NULL)
 		    goto cleanup;
 
-		if ((pattern.rhs = VarGetPattern(ctxt, &parsestate, err,
+		if ((pattern.rhs = VarGetPattern(ctxt, &parsestate, errnum,
 						 &cp, delim, NULL,
 						 &pattern.rightLen,
 						 &pattern)) == NULL)
@@ -2674,7 +2674,7 @@
 
 		cp = ++tstr;
 		delim = ':';
-		if ((pattern.lhs = VarGetPattern(ctxt, &parsestate, err,
+		if ((pattern.lhs = VarGetPattern(ctxt, &parsestate, errnum,
 						 &cp, delim, NULL,
 						 &pattern.leftLen,
 						 NULL)) == NULL)
@@ -2682,7 +2682,7 @@
 
 		/* BROPEN or PROPEN */
 		delim = endc;
-		if ((pattern.rhs = VarGetPattern(ctxt, &parsestate, err,
+		if ((pattern.rhs = VarGetPattern(ctxt, &parsestate, errnum,
 						 &cp, delim, NULL,
 						 &pattern.rightLen,
 						 NULL)) == NULL)
@@ -2724,12 +2724,12 @@
 
 		cp = tstr;
 
-		if ((re = VarGetPattern(ctxt, &parsestate, err, &cp, delim,
+		if ((re = VarGetPattern(ctxt, &parsestate, errnum, &cp, delim,
 					NULL, NULL, NULL)) == NULL)
 		    goto cleanup;
 
 		if ((pattern.replace = VarGetPattern(ctxt, &parsestate,
-						     err, &cp, delim, NULL,
+						     errnum, &cp, delim, NULL,
 						     NULL, NULL)) == NULL){
 		    free(re);
 		    goto cleanup;
@@ -2903,12 +2903,12 @@
 		delim='=';
 		cp = tstr;
 		if ((pattern.lhs = VarGetPattern(ctxt, &parsestate, 
-						 err, &cp, delim, &pattern.flags,
+						 errnum, &cp, delim, &pattern.flags,
 						 &pattern.leftLen, NULL)) == NULL)
 		    goto cleanup;
 		delim = endc;
 		if ((pattern.rhs = VarGetPattern(ctxt, &parsestate,
-						 err, &cp, delim, NULL, &pattern.rightLen,
+						 errnum, &cp, delim, NULL, &pattern.rightLen,
 						 &pattern)) == NULL)
 		    goto cleanup;
 
@@ -2991,7 +2991,7 @@
  * Input:
  *	str		The string to parse
  *	ctxt		The context for the variable
- *	err		TRUE if undefined variables are an error
+ *	errnum		TRUE if undefined variables are an error
  *	lengthPtr	OUT: The length of the specification
  *	freePtr		OUT: TRUE if caller should free result
  *
@@ -3010,7 +3010,7 @@
  */
 /* coverity[+alloc : arg-*4] */
 char *
-Var_Parse(const char *str, GNode *ctxt, Boolean err, int *lengthPtr,
+Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr,
 	  void **freePtr)
 {
     const char	   *tstr;    	/* Pointer into str */
@@ -3074,7 +3074,7 @@
 	    /*
 	     * Error
 	     */
-	    return (err ? var_Error : varNoError);
+	    return (errnum ? var_Error : varNoError);
 	} else {
 	    haveModifier = FALSE;
 	    tstr = &str[1];
@@ -3082,7 +3082,7 @@
 	}
     } else if (str[1] == '\0') {
 	*lengthPtr = 1;
-	return (err ? var_Error : varNoError);
+	return (errnum ? var_Error : varNoError);
     } else { 
 	Buffer buf;	/* Holds the variable name */
 
@@ -3103,7 +3103,7 @@
 	    if (*tstr == '$') {
 		int rlen;
 		void *freeIt;
-		char *rval = Var_Parse(tstr, ctxt, err, &rlen, &freeIt);
+		char *rval = Var_Parse(tstr, ctxt, errnum, &rlen, &freeIt);
 		if (rval != NULL) {
 		    Buf_AddBytes(buf, strlen(rval), (Byte *)rval);
 		}
@@ -3245,7 +3245,7 @@
 		    return(pstr);
 		} else {
 		    Buf_Destroy(buf, TRUE);
-		    return (err ? var_Error : varNoError);
+		    return (errnum ? var_Error : varNoError);
 		}
 	    } else {
 		/*
@@ -3280,7 +3280,7 @@
      */
     nstr = (char *)Buf_GetAll(v->val, NULL);
     if (strchr(nstr, '$') != NULL) {
-	nstr = Var_Subst(NULL, nstr, ctxt, err);
+	nstr = Var_Subst(NULL, nstr, ctxt, errnum);
 	*freePtr = nstr;
     }
 
@@ -3295,7 +3295,7 @@
 	tstr++;
 
 	nstr = ApplyModifiers(nstr, tstr, startc, endc,
-			      v, ctxt, err, &used, freePtr);
+			      v, ctxt, errnum, &used, freePtr);
 	tstr += used;
 	*lengthPtr = tstr - start + 1;
     } else {
Index: usr.bin/shuffle/Makefile
===================================================================
RCS file: /cvsroot/src/usr.bin/shuffle/Makefile,v
retrieving revision 1.1
diff -u -u -r1.1 Makefile
--- usr.bin/shuffle/Makefile	23 Sep 1998 21:05:59 -0000	1.1
+++ usr.bin/shuffle/Makefile	9 Jul 2006 22:02:37 -0000
@@ -2,4 +2,7 @@
 
 PROG=	shuffle
 
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
 .include <bsd.prog.mk>
Index: usr.bin/shuffle/shuffle.c
===================================================================
RCS file: /cvsroot/src/usr.bin/shuffle/shuffle.c,v
retrieving revision 1.18
diff -u -u -r1.18 shuffle.c
--- usr.bin/shuffle/shuffle.c	1 Dec 2004 00:03:45 -0000	1.18
+++ usr.bin/shuffle/shuffle.c	9 Jul 2006 22:02:37 -0000
@@ -46,10 +46,6 @@
 #include <string.h>
 #include <unistd.h>
 
-static void enomem(void);
-static void *emalloc(size_t);
-static void *erealloc(void *, size_t);
-
 static size_t *get_shuffle(size_t);
 static void usage(void);
 static void get_lines(const char *, char ***, size_t *);
@@ -58,42 +54,6 @@
 int main(int, char *[]);
 
 /*
- * enomem --
- *	die when out of memory.
- */
-static void
-enomem(void)
-{
-	errx(2, "Cannot allocate memory.");
-}
-
-/*
- * emalloc --
- *	malloc, but die on error.
- */
-static void *
-emalloc(size_t len)
-{
-	void *p;
-
-	if ((p = malloc(len)) == NULL)
-		enomem();
-	return p;
-}
-
-/*
- * erealloc --
- *	realloc, but die on error.
- */
-void *
-erealloc(void *ptr, size_t size)
-{
-	if ((ptr = realloc(ptr, size)) == NULL)
-		enomem();
-	return ptr;
-}
-
-/*
  * get_shuffle --
  *	Construct a random shuffle array of t elements
  */
Index: usr.bin/spell/spellprog/Makefile
===================================================================
RCS file: /cvsroot/src/usr.bin/spell/spellprog/Makefile,v
retrieving revision 1.2
diff -u -u -r1.2 Makefile
--- usr.bin/spell/spellprog/Makefile	30 Jun 2005 16:25:05 -0000	1.2
+++ usr.bin/spell/spellprog/Makefile	9 Jul 2006 22:02:37 -0000
@@ -6,4 +6,7 @@
 SRCS=	spellprog.c look.c
 BINDIR=	/usr/libexec
 
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
 .include <bsd.prog.mk>
Index: usr.bin/spell/spellprog/spellprog.c
===================================================================
RCS file: /cvsroot/src/usr.bin/spell/spellprog/spellprog.c,v
retrieving revision 1.4
diff -u -u -r1.4 spellprog.c
--- usr.bin/spell/spellprog/spellprog.c	17 Jul 2005 17:08:25 -0000	1.4
+++ usr.bin/spell/spellprog/spellprog.c	9 Jul 2006 22:02:37 -0000
@@ -106,7 +106,6 @@
 static int	 vowel(int);
 static const char *lookuppref(char **, char *);
 static char	*skipv(char *);
-static char	*estrdup(const char *);
 static void	 ise(void);
 static void	 print_word(FILE *);
 static void	 ztos(char *);
@@ -789,16 +788,6 @@
 			*st = 's';
 }
 
-static char *
-estrdup(const char *st)
-{
-	char *d;
-
-	if ((d = strdup(st)) == NULL)
-		err(1, "strdup");
-	return d;
-}
-
 /*
  * Look up a word in the dictionary.
  * Returns 1 if found, 0 if not.
Index: usr.sbin/gspa/gspa/Makefile
===================================================================
RCS file: /cvsroot/src/usr.sbin/gspa/gspa/Makefile,v
retrieving revision 1.10
diff -u -u -r1.10 Makefile
--- usr.sbin/gspa/gspa/Makefile	1 Aug 2003 17:04:07 -0000	1.10
+++ usr.sbin/gspa/gspa/Makefile	9 Jul 2006 22:02:39 -0000
@@ -8,4 +8,7 @@
 	gsp_inst.c gsp_pseu.c gsp_gram.y
 YHEADER=1
 
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
 .include <bsd.prog.mk>
Index: usr.sbin/gspa/gspa/gsp_ass.h
===================================================================
RCS file: /cvsroot/src/usr.sbin/gspa/gspa/gsp_ass.h,v
retrieving revision 1.9
diff -u -u -r1.9 gsp_ass.h
--- usr.sbin/gspa/gspa/gsp_ass.h	13 May 2006 22:34:50 -0000	1.9
+++ usr.sbin/gspa/gspa/gsp_ass.h	9 Jul 2006 22:02:39 -0000
@@ -33,7 +33,7 @@
 
 #include <stddef.h>
 #include <sys/types.h>
-/*#include <alloca.h>*/
+#include <err.h>
 
 #define MAXLINE		133
 
@@ -127,7 +127,6 @@
 /* Prototypes */
 operand abs_adr(expr);
 operand add_operand(operand, operand);
-void *emalloc(size_t nbytes);
 expr bexpr(int, expr, expr);
 void do_asg(char *, expr, int flags);
 void do_list_pc(void);
Index: usr.sbin/gspa/gspa/gspa.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/gspa/gspa/gspa.c,v
retrieving revision 1.11
diff -u -u -r1.11 gspa.c
--- usr.sbin/gspa/gspa/gspa.c	13 May 2006 22:34:50 -0000	1.11
+++ usr.sbin/gspa/gspa/gspa.c	9 Jul 2006 22:02:39 -0000
@@ -290,18 +290,6 @@
 	longjmp(synerrjmp, 1);
 }
 
-void *
-emalloc(size_t nbytes)
-{
-	void *p;
-
-	if( (p = malloc(nbytes)) == NULL ){
-		fprintf(stderr, "Insufficient memory at line %d\n", lineno);
-		exit(1);
-	}
-	return p;
-}
-
 void
 usage()
 {
Index: usr.sbin/mountd/mountd.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/mountd/mountd.c,v
retrieving revision 1.106
diff -u -u -r1.106 mountd.c
--- usr.sbin/mountd/mountd.c	25 May 2006 00:37:03 -0000	1.106
+++ usr.sbin/mountd/mountd.c	9 Jul 2006 22:02:41 -0000
@@ -217,8 +217,6 @@
 static int xdr_explist __P((XDR *, caddr_t));
 static int xdr_fhs __P((XDR *, caddr_t));
 static int xdr_mlist __P((XDR *, caddr_t));
-static void *emalloc __P((size_t));
-static char *estrdup __P((const char *));
 static int bitcmp __P((void *, void *, int));
 static int netpartcmp __P((struct sockaddr *, struct sockaddr *, int));
 static int sacmp __P((struct sockaddr *, struct sockaddr *));
@@ -1942,35 +1940,6 @@
 #endif				/* ISO */
 
 /*
- * error checked malloc and strdup
- */
-static void *
-emalloc(n)
-	size_t n;
-{
-	void *ptr = malloc(n);
-
-	if (ptr == NULL) {
-		syslog(LOG_ERR, "%m");
-		exit(2);
-	}
-	return ptr;
-}
-
-static char *
-estrdup(s)
-	const char *s;
-{
-	char *n = strdup(s);
-
-	if (n == NULL) {
-		syslog(LOG_ERR, "%m");
-		exit(2);
-	}
-	return n;
-}
-
-/*
  * Do the nfssvc syscall to push the export info into the kernel.
  */
 static int
Index: usr.sbin/netgroup_mkdb/Makefile
===================================================================
RCS file: /cvsroot/src/usr.sbin/netgroup_mkdb/Makefile,v
retrieving revision 1.3
diff -u -u -r1.3 Makefile
--- usr.sbin/netgroup_mkdb/Makefile	4 Oct 1996 05:15:27 -0000	1.3
+++ usr.sbin/netgroup_mkdb/Makefile	9 Jul 2006 22:02:41 -0000
@@ -2,7 +2,10 @@
 #	$NetBSD: Makefile,v 1.3 1996/10/04 05:15:27 christos Exp $
 
 PROG=	netgroup_mkdb
-SRCS=	netgroup_mkdb.c util.c str.c
+SRCS=	netgroup_mkdb.c str.c
 MAN=	netgroup_mkdb.8
 
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
+
 .include <bsd.prog.mk>
Index: usr.sbin/netgroup_mkdb/netgroup_mkdb.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/netgroup_mkdb/netgroup_mkdb.c,v
retrieving revision 1.13
diff -u -u -r1.13 netgroup_mkdb.c
--- usr.sbin/netgroup_mkdb/netgroup_mkdb.c	25 May 2006 01:20:21 -0000	1.13
+++ usr.sbin/netgroup_mkdb/netgroup_mkdb.c	9 Jul 2006 22:02:42 -0000
@@ -222,7 +222,7 @@
 	if (db == NULL)
 		err(1, "dbopen");
 
-	while ((buf = getline(fp, &size)) != NULL) {
+	while ((buf = fparseln(fp, &size, NULL, NULL, 0)) != NULL) {
 		tail = head = NULL;
 		p = buf;
 
Index: usr.sbin/netgroup_mkdb/str.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/netgroup_mkdb/str.c,v
retrieving revision 1.4
diff -u -u -r1.4 str.c
--- usr.sbin/netgroup_mkdb/str.c	17 Oct 1997 11:49:10 -0000	1.4
+++ usr.sbin/netgroup_mkdb/str.c	9 Jul 2006 22:02:42 -0000
@@ -41,8 +41,8 @@
  */
 #include <stdlib.h>
 #include <string.h>
+#include <err.h>
 
-#include "util.h"
 #include "str.h"
 
 /*
Index: usr.sbin/ntp/libntp/Makefile
===================================================================
RCS file: /cvsroot/src/usr.sbin/ntp/libntp/Makefile,v
retrieving revision 1.8
diff -u -u -r1.8 Makefile
--- usr.sbin/ntp/libntp/Makefile	11 Jun 2006 19:34:22 -0000	1.8
+++ usr.sbin/ntp/libntp/Makefile	9 Jul 2006 22:02:42 -0000
@@ -7,7 +7,7 @@
 	audio.c authkeys.c authreadkeys.c authusekey.c \
 	buftvtots.c caljulian.c caltontp.c calyearstart.c \
 	clocktime.c clocktypes.c decodenetnum.c dofptoa.c dolfptoa.c \
-	emalloc.c findconfig.c fptoa.c fptoms.c getopt.c hextoint.c \
+	findconfig.c fptoa.c fptoms.c getopt.c hextoint.c \
 	hextolfp.c humandate.c icom.c inttoa.c iosignal.c lib_strbuf.c \
 	machines.c md5c.c \
 	memmove.c mfptoa.c mfptoms.c mktime.c modetoa.c mstolfp.c msutotsf.c \
Index: usr.sbin/ntp/ntpd/Makefile
===================================================================
RCS file: /cvsroot/src/usr.sbin/ntp/ntpd/Makefile,v
retrieving revision 1.13
diff -u -u -r1.13 Makefile
--- usr.sbin/ntp/ntpd/Makefile	11 Jun 2006 19:34:28 -0000	1.13
+++ usr.sbin/ntp/ntpd/Makefile	9 Jul 2006 22:02:42 -0000
@@ -31,7 +31,7 @@
 LDADD+=		-L${LIBPARSE} -lparse -L${LIBISC} -lisc
 DPADD+=		${LIBPARSE}/libparse.a ${LIBISC}/libisc.a
 
-LDADD+=	-lm
-DPADD+=	${LIBM}
+LDADD+=	-lutil -lm
+DPADD+=	${LIBUTIL} ${LIBM}
 
 .include <bsd.prog.mk>
Index: usr.sbin/ntp/ntpdate/Makefile
===================================================================
RCS file: /cvsroot/src/usr.sbin/ntp/ntpdate/Makefile,v
retrieving revision 1.4
diff -u -u -r1.4 Makefile
--- usr.sbin/ntp/ntpdate/Makefile	11 Jun 2006 19:34:28 -0000	1.4
+++ usr.sbin/ntp/ntpdate/Makefile	9 Jul 2006 22:02:42 -0000
@@ -13,7 +13,7 @@
 LDADD+=		-L${LIBISC} -lisc
 DPADD+=		${LIBISC}/libisc.a
 
-LDADD+=	-lm
-DPADD+=	${LIBM}
+LDADD+=	-lutil -lm
+DPADD+=	${LIBUTIL} ${LIBM}
 
 .include <bsd.prog.mk>
Index: usr.sbin/sup/Makefile.inc
===================================================================
RCS file: /cvsroot/src/usr.sbin/sup/Makefile.inc,v
retrieving revision 1.8
diff -u -u -r1.8 Makefile.inc
--- usr.sbin/sup/Makefile.inc	3 Apr 2003 17:56:52 -0000	1.8
+++ usr.sbin/sup/Makefile.inc	9 Jul 2006 22:02:42 -0000
@@ -10,6 +10,8 @@
 LIBSUPDIR != cd ${.CURDIR}/../lib && ${PRINTOBJDIR}
 LIBSUP=	${LIBSUPDIR}/libsup.a
 SUPLIB=	-L${LIBSUPDIR} -lsup
+LDADD+=-lutil
+DPADD+=${LIBUTIL}
 
 .if exists(${.CURDIR}/../../Makefile.inc)
 .include "${.CURDIR}/../../Makefile.inc"
Index: usr.sbin/sup/lib/Makefile
===================================================================
RCS file: /cvsroot/src/usr.sbin/sup/lib/Makefile,v
retrieving revision 1.11
diff -u -u -r1.11 Makefile
--- usr.sbin/sup/lib/Makefile	2 Apr 2006 01:39:48 -0000	1.11
+++ usr.sbin/sup/lib/Makefile	9 Jul 2006 22:02:42 -0000
@@ -6,7 +6,7 @@
 
 SRCS=	scm.c scmio.c stree.c log.c supmsg.c netcrypt.c
 SRCS+=	atoo.c errmsg.c expand.c ffilecopy.c filecopy.c \
-	nxtarg.c path.c quit.c run.c estrdup.c skipto.c
+	nxtarg.c path.c quit.c run.c skipto.c
 
 .PATH: ${.CURDIR}/../source