1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #include "common.h" 28 29 /*PRINTFLIKE1*/ 30 void 31 error(char *err, ...) 32 { 33 va_list ap; 34 va_start(ap, err); 35 36 (void) fprintf(stderr, gettext(ERR_ERROR)); 37 (void) vfprintf(stderr, err, ap); 38 va_end(ap); 39 exit(2); 40 } 41 42 /*PRINTFLIKE1*/ 43 void 44 warning(char *err, ...) 45 { 46 va_list ap; 47 va_start(ap, err); 48 49 (void) fprintf(stderr, gettext(WARN_WARNING)); 50 (void) vfprintf(stderr, err, ap); 51 va_end(ap); 52 } 53 54 /*PRINTFLIKE1*/ 55 void 56 diag(char *err, ...) 57 { 58 va_list ap; 59 va_start(ap, err); 60 61 (void) vfprintf(stderr, err, ap); 62 va_end(ap); 63 } 64 65 void * 66 Xmalloc(size_t size) 67 { 68 void *t; 69 70 t = malloc(size); 71 if (!t) { 72 error(gettext(ERR_MALLOC)); 73 /* NOTREACHED */ 74 } 75 return (t); 76 } 77 78 void * 79 Xcalloc(size_t nelem, size_t elsize) 80 { 81 void *t; 82 83 t = calloc(nelem, elsize); 84 if (!t) { 85 error(gettext(ERR_MALLOC)); 86 /* NOTREACHED */ 87 } 88 return (t); 89 } 90 91 void * 92 Xrealloc(void *ptr, size_t size) 93 { 94 void *t; 95 96 t = realloc(ptr, size); 97 if (!t) { 98 free(ptr); 99 error(gettext(ERR_MALLOC)); 100 /* NOTREACHED */ 101 } 102 return (t); 103 } 104 105 char * 106 Xstrdup(const char *str) 107 { 108 char *t; 109 110 t = strdup(str); 111 if (!t) { 112 error(gettext(ERR_MALLOC)); 113 /* NOTREACHED */ 114 } 115 return (t); 116 } 117