1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate #ifndef _MACROS_H 27*7c478bd9Sstevel@tonic-gate #define _MACROS_H 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3.1.7 */ 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 32*7c478bd9Sstevel@tonic-gate #include <sys/stat.h> 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 35*7c478bd9Sstevel@tonic-gate extern "C" { 36*7c478bd9Sstevel@tonic-gate #endif 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate /* 39*7c478bd9Sstevel@tonic-gate * numeric() is useful in while's, if's, etc., but don't use *p++ 40*7c478bd9Sstevel@tonic-gate * max() and min() depend on the types of the operands 41*7c478bd9Sstevel@tonic-gate * abs() is absolute value 42*7c478bd9Sstevel@tonic-gate */ 43*7c478bd9Sstevel@tonic-gate #define numeric(c) ((c) >= '0' && (c) <= '9') 44*7c478bd9Sstevel@tonic-gate #define max(a, b) ((a) < (b) ? (b) : (a)) 45*7c478bd9Sstevel@tonic-gate #define min(a, b) ((a) > (b) ? (b) : (a)) 46*7c478bd9Sstevel@tonic-gate #define abs(x) ((x) >= 0 ? (x) : -(x)) 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate #define compare(str1, str2) strcmp((str1), (str2)) 49*7c478bd9Sstevel@tonic-gate #define equal(str1, str2) (strcmp((str1), (str2)) == 0) 50*7c478bd9Sstevel@tonic-gate #define length(str) strlen(str) 51*7c478bd9Sstevel@tonic-gate #define size(str) (strlen(str) + 1) 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate /* 54*7c478bd9Sstevel@tonic-gate * The global variable Statbuf is available for use as a stat(II) 55*7c478bd9Sstevel@tonic-gate * structure. Note that "stat.h" is included here and should 56*7c478bd9Sstevel@tonic-gate * not be included elsewhere. 57*7c478bd9Sstevel@tonic-gate * Exists(file) returns 0 if the file does not exist; 58*7c478bd9Sstevel@tonic-gate * the flags word if it does (the flags word is always non-zero). 59*7c478bd9Sstevel@tonic-gate */ 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate extern struct stat Statbuf; 62*7c478bd9Sstevel@tonic-gate #define exists(file) (stat(file, &Statbuf) < 0 ? 0 : Statbuf.st_mode) 63*7c478bd9Sstevel@tonic-gate 64*7c478bd9Sstevel@tonic-gate /* 65*7c478bd9Sstevel@tonic-gate * SAVE() and RSTR() use local data in nested blocks. 66*7c478bd9Sstevel@tonic-gate * Make sure that they nest cleanly. 67*7c478bd9Sstevel@tonic-gate */ 68*7c478bd9Sstevel@tonic-gate #define SAVE(name, place) { int place = name; 69*7c478bd9Sstevel@tonic-gate #define RSTR(name, place) name = place; } 70*7c478bd9Sstevel@tonic-gate 71*7c478bd9Sstevel@tonic-gate /* 72*7c478bd9Sstevel@tonic-gate * Use: DEBUG(sum,d) which becomes fprintf(stderr,"sum = %d\n",sum) 73*7c478bd9Sstevel@tonic-gate * 74*7c478bd9Sstevel@tonic-gate * Note: Sccsid[] strings are still supported but not the prefered 75*7c478bd9Sstevel@tonic-gate * method of labeling files. Use #ident. 76*7c478bd9Sstevel@tonic-gate */ 77*7c478bd9Sstevel@tonic-gate #ifdef __STDC__ 78*7c478bd9Sstevel@tonic-gate #define DEBUG(var, type) fprintf(stderr, #var "= %" #type "\n", var) 79*7c478bd9Sstevel@tonic-gate #define SCCSID(arg) static char Sccsid[] = #arg 80*7c478bd9Sstevel@tonic-gate #else 81*7c478bd9Sstevel@tonic-gate #define DEBUG(var, type) fprintf(stderr, "var = %type\n", var) 82*7c478bd9Sstevel@tonic-gate #define SCCSID(arg) static char Sccsid[] = "arg" 83*7c478bd9Sstevel@tonic-gate #endif 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate /* 86*7c478bd9Sstevel@tonic-gate * Use of ERRABORT() will cause libS.a internal 87*7c478bd9Sstevel@tonic-gate * errors to cause aborts 88*7c478bd9Sstevel@tonic-gate */ 89*7c478bd9Sstevel@tonic-gate #define ERRABORT() _error() { abort(); } 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate /* 92*7c478bd9Sstevel@tonic-gate * Use of USXALLOC() is required to force all calls to alloc() 93*7c478bd9Sstevel@tonic-gate * (e.g., from libS.a) to call xalloc(). 94*7c478bd9Sstevel@tonic-gate */ 95*7c478bd9Sstevel@tonic-gate #define NONBLANK(p) while (*(p) == ' ' || *(p) == '\t') (p)++ 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate /* 98*7c478bd9Sstevel@tonic-gate * A global null string. 99*7c478bd9Sstevel@tonic-gate */ 100*7c478bd9Sstevel@tonic-gate extern char Null[1]; 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate /* 103*7c478bd9Sstevel@tonic-gate * A global error message string. 104*7c478bd9Sstevel@tonic-gate */ 105*7c478bd9Sstevel@tonic-gate extern char Error[128]; 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 108*7c478bd9Sstevel@tonic-gate } 109*7c478bd9Sstevel@tonic-gate #endif 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate #endif /* _MACROS_H */ 112