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