Module Name: othersrc Committed By: dholland Date: Mon Feb 25 02:12:24 UTC 2013
Modified Files: othersrc/usr.bin/dholland-make2: Makefile make.h portable.h strlist.c othersrc/usr.bin/dholland-make2/lst.lib: lstInt.h Added Files: othersrc/usr.bin/dholland-make2: portable.c Removed Files: othersrc/usr.bin/dholland-make2: make_malloc.c make_malloc.h Log Message: Fold make_malloc stuff into portable.h. To generate a diff of this commit: cvs rdiff -u -r1.1.1.1 -r1.2 othersrc/usr.bin/dholland-make2/Makefile \ othersrc/usr.bin/dholland-make2/strlist.c cvs rdiff -u -r1.3 -r1.4 othersrc/usr.bin/dholland-make2/make.h cvs rdiff -u -r1.1.1.1 -r0 othersrc/usr.bin/dholland-make2/make_malloc.c \ othersrc/usr.bin/dholland-make2/make_malloc.h cvs rdiff -u -r0 -r1.1 othersrc/usr.bin/dholland-make2/portable.c cvs rdiff -u -r1.1 -r1.2 othersrc/usr.bin/dholland-make2/portable.h cvs rdiff -u -r1.1.1.1 -r1.2 othersrc/usr.bin/dholland-make2/lst.lib/lstInt.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: othersrc/usr.bin/dholland-make2/Makefile diff -u othersrc/usr.bin/dholland-make2/Makefile:1.1.1.1 othersrc/usr.bin/dholland-make2/Makefile:1.2 --- othersrc/usr.bin/dholland-make2/Makefile:1.1.1.1 Mon Feb 25 01:32:48 2013 +++ othersrc/usr.bin/dholland-make2/Makefile Mon Feb 25 02:12:23 2013 @@ -1,11 +1,11 @@ -# $NetBSD: Makefile,v 1.1.1.1 2013/02/25 01:32:48 dholland Exp $ +# $NetBSD: Makefile,v 1.2 2013/02/25 02:12:23 dholland Exp $ # @(#)Makefile 5.2 (Berkeley) 12/28/90 PROG= make SRCS= arch.c buf.c compat.c cond.c dir.c for.c hash.c job.c main.c \ make.c parse.c str.c suff.c targ.c trace.c var.c util.c SRCS+= strlist.c -SRCS+= make_malloc.c +SRCS+= portable.c SRCS+= lstAppend.c lstAtEnd.c lstAtFront.c lstClose.c lstConcat.c \ lstDatum.c lstDeQueue.c lstDestroy.c lstDupl.c lstEnQueue.c \ lstFind.c lstFindFrom.c lstFirst.c lstForEach.c lstForEachFrom.c \ Index: othersrc/usr.bin/dholland-make2/strlist.c diff -u othersrc/usr.bin/dholland-make2/strlist.c:1.1.1.1 othersrc/usr.bin/dholland-make2/strlist.c:1.2 --- othersrc/usr.bin/dholland-make2/strlist.c:1.1.1.1 Mon Feb 25 01:33:05 2013 +++ othersrc/usr.bin/dholland-make2/strlist.c Mon Feb 25 02:12:23 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: strlist.c,v 1.1.1.1 2013/02/25 01:33:05 dholland Exp $ */ +/* $NetBSD: strlist.c,v 1.2 2013/02/25 02:12:23 dholland Exp $ */ /*- * Copyright (c) 2008 - 2009 The NetBSD Foundation, Inc. @@ -33,18 +33,18 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: strlist.c,v 1.1.1.1 2013/02/25 01:33:05 dholland Exp $"; +static char rcsid[] = "$NetBSD: strlist.c,v 1.2 2013/02/25 02:12:23 dholland Exp $"; #else #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: strlist.c,v 1.1.1.1 2013/02/25 01:33:05 dholland Exp $"); +__RCSID("$NetBSD: strlist.c,v 1.2 2013/02/25 02:12:23 dholland Exp $"); #endif /* not lint */ #endif #include <stddef.h> #include <stdlib.h> +#include "portable.h" #include "strlist.h" -#include "make_malloc.h" void strlist_init(strlist_t *sl) Index: othersrc/usr.bin/dholland-make2/make.h diff -u othersrc/usr.bin/dholland-make2/make.h:1.3 othersrc/usr.bin/dholland-make2/make.h:1.4 --- othersrc/usr.bin/dholland-make2/make.h:1.3 Mon Feb 25 02:02:38 2013 +++ othersrc/usr.bin/dholland-make2/make.h Mon Feb 25 02:12:23 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: make.h,v 1.3 2013/02/25 02:02:38 dholland Exp $ */ +/* $NetBSD: make.h,v 1.4 2013/02/25 02:12:23 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -96,7 +96,6 @@ #include "hash.h" #include "config.h" #include "buf.h" -#include "make_malloc.h" /*- * The structure for an individual graph node. Each node has several Index: othersrc/usr.bin/dholland-make2/portable.h diff -u othersrc/usr.bin/dholland-make2/portable.h:1.1 othersrc/usr.bin/dholland-make2/portable.h:1.2 --- othersrc/usr.bin/dholland-make2/portable.h:1.1 Mon Feb 25 02:02:38 2013 +++ othersrc/usr.bin/dholland-make2/portable.h Mon Feb 25 02:12:23 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: portable.h,v 1.1 2013/02/25 02:02:38 dholland Exp $ */ +/* $NetBSD: portable.h,v 1.2 2013/02/25 02:12:23 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -72,6 +72,32 @@ * from: @(#)make.h 8.3 (Berkeley) 6/13/95 */ +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * 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. + * + * 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. + */ + /* * portable.h -- stuff for making make buildable anywhere * @@ -81,11 +107,19 @@ * MAKE_ATTR_PRINTFLIKE attribute for printf functions * UNCONST(p) macro for discarding const * MIN(a, b), MAX(a, b) + * bmake_malloc allocator functions that crash on error + * bmake_realloc allocator functions that crash on error + * bmake_strdup allocator functions that crash on error + * bmake_strndup allocator functions that crash on error + * + * External toggles that can be set: + * USE_EMALLOC use emalloc() from libutil */ #ifndef PORTABLE_H #define PORTABLE_H +#include <stddef.h> /* for size_t */ #ifdef BSD4_4 # include <sys/cdefs.h> @@ -138,5 +172,17 @@ #define MAX(a, b) ((a > b) ? a : b) #endif +#ifndef USE_EMALLOC +void *bmake_malloc(size_t); +void *bmake_realloc(void *, size_t); +char *bmake_strdup(const char *); +char *bmake_strndup(const char *, size_t); +#else +#include <util.h> +#define bmake_malloc(x) emalloc(x) +#define bmake_realloc(x,y) erealloc(x,y) +#define bmake_strdup(x) estrdup(x) +#define bmake_strndup(x,y) estrndup(x,y) +#endif #endif /* PORTABLE_H */ Index: othersrc/usr.bin/dholland-make2/lst.lib/lstInt.h diff -u othersrc/usr.bin/dholland-make2/lst.lib/lstInt.h:1.1.1.1 othersrc/usr.bin/dholland-make2/lst.lib/lstInt.h:1.2 --- othersrc/usr.bin/dholland-make2/lst.lib/lstInt.h:1.1.1.1 Mon Feb 25 01:33:22 2013 +++ othersrc/usr.bin/dholland-make2/lst.lib/lstInt.h Mon Feb 25 02:12:23 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: lstInt.h,v 1.1.1.1 2013/02/25 01:33:22 dholland Exp $ */ +/* $NetBSD: lstInt.h,v 1.2 2013/02/25 02:12:23 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -41,8 +41,8 @@ #ifndef _LSTINT_H_ #define _LSTINT_H_ +#include "../portable.h" #include "../lst.h" -#include "../make_malloc.h" typedef struct ListNode { struct ListNode *prevPtr; /* previous element in list */ Added files: Index: othersrc/usr.bin/dholland-make2/portable.c diff -u /dev/null othersrc/usr.bin/dholland-make2/portable.c:1.1 --- /dev/null Mon Feb 25 02:12:24 2013 +++ othersrc/usr.bin/dholland-make2/portable.c Mon Feb 25 02:12:23 2013 @@ -0,0 +1,120 @@ +/* $NetBSD: portable.c,v 1.1 2013/02/25 02:12:23 dholland Exp $ */ + +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * 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. + * + * 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. + */ + +#ifdef MAKE_NATIVE +#include <sys/cdefs.h> +__RCSID("$NetBSD: portable.c,v 1.1 2013/02/25 02:12:23 dholland Exp $"); +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "portable.h" +#include "make.h" + +#ifndef USE_EMALLOC +static void enomem(void) MAKE_ATTR_DEAD; + +/* + * enomem -- + * die when out of memory. + */ +static void +enomem(void) +{ + (void)fprintf(stderr, "%s: %s.\n", progname, strerror(ENOMEM)); + exit(2); +} + +/* + * bmake_malloc -- + * malloc, but die on error. + */ +void * +bmake_malloc(size_t len) +{ + void *p; + + if ((p = malloc(len)) == NULL) + enomem(); + return(p); +} + +/* + * bmake_strdup -- + * strdup, but die on error. + */ +char * +bmake_strdup(const char *str) +{ + size_t len; + char *p; + + len = strlen(str) + 1; + if ((p = malloc(len)) == NULL) + enomem(); + return memcpy(p, str, len); +} + +/* + * bmake_strndup -- + * strndup, but die on error. + */ +char * +bmake_strndup(const char *str, size_t max_len) +{ + size_t len; + char *p; + + if (str == NULL) + return NULL; + + len = strlen(str); + if (len > max_len) + len = max_len; + p = bmake_malloc(len + 1); + memcpy(p, str, len); + p[len] = '\0'; + + return(p); +} + +/* + * bmake_realloc -- + * realloc, but die on error. + */ +void * +bmake_realloc(void *ptr, size_t size) +{ + if ((ptr = realloc(ptr, size)) == NULL) + enomem(); + return(ptr); +} +#endif