xref: /titanic_51/usr/src/head/macros.h (revision ba3594ba9b5dd4c846c472a8d657edcb7c8109ac)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
22*ba3594baSGarrett D'Amore /*
23*ba3594baSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24*ba3594baSGarrett D'Amore  */
257c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
267c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef	_MACROS_H
307c478bd9Sstevel@tonic-gate #define	_MACROS_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/stat.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
367c478bd9Sstevel@tonic-gate extern "C" {
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  *	numeric() is useful in while's, if's, etc., but don't use *p++
417c478bd9Sstevel@tonic-gate  *	max() and min() depend on the types of the operands
427c478bd9Sstevel@tonic-gate  *	abs() is absolute value
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate #define	numeric(c)		((c) >= '0' && (c) <= '9')
457c478bd9Sstevel@tonic-gate #define	max(a, b) 		((a) < (b) ? (b) : (a))
467c478bd9Sstevel@tonic-gate #define	min(a, b) 		((a) > (b) ? (b) : (a))
477c478bd9Sstevel@tonic-gate #define	abs(x)			((x) >= 0 ? (x) : -(x))
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #define	compare(str1, str2)	strcmp((str1), (str2))
507c478bd9Sstevel@tonic-gate #define	equal(str1, str2)	(strcmp((str1), (str2)) == 0)
517c478bd9Sstevel@tonic-gate #define	length(str)		strlen(str)
527c478bd9Sstevel@tonic-gate #define	size(str)		(strlen(str) + 1)
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  *	The global variable Statbuf is available for use as a stat(II)
567c478bd9Sstevel@tonic-gate  *	structure.  Note that "stat.h" is included here and should
577c478bd9Sstevel@tonic-gate  *	not be included elsewhere.
587c478bd9Sstevel@tonic-gate  *	Exists(file) returns 0 if the file does not exist;
597c478bd9Sstevel@tonic-gate  *	the flags word if it does (the flags word is always non-zero).
607c478bd9Sstevel@tonic-gate  */
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate extern struct stat Statbuf;
637c478bd9Sstevel@tonic-gate #define	exists(file)		(stat(file, &Statbuf) < 0 ? 0 : Statbuf.st_mode)
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate /*
667c478bd9Sstevel@tonic-gate  *	SAVE() and RSTR() use local data in nested blocks.
677c478bd9Sstevel@tonic-gate  *	Make sure that they nest cleanly.
687c478bd9Sstevel@tonic-gate  */
697c478bd9Sstevel@tonic-gate #define	SAVE(name, place)	{ int place = name;
707c478bd9Sstevel@tonic-gate #define	RSTR(name, place)	name = place; }
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  *	Use: DEBUG(sum,d) which becomes fprintf(stderr,"sum = %d\n",sum)
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate #define	DEBUG(var, type)	fprintf(stderr, #var "= %" #type "\n", var)
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  *	Use of ERRABORT() will cause libS.a internal
797c478bd9Sstevel@tonic-gate  *	errors to cause aborts
807c478bd9Sstevel@tonic-gate  */
817c478bd9Sstevel@tonic-gate #define	ERRABORT()	_error() { abort(); }
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate  *	Use of USXALLOC() is required to force all calls to alloc()
857c478bd9Sstevel@tonic-gate  *	(e.g., from libS.a) to call xalloc().
867c478bd9Sstevel@tonic-gate  */
877c478bd9Sstevel@tonic-gate #define	NONBLANK(p)	while (*(p) == ' ' || *(p) == '\t') (p)++
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /*
907c478bd9Sstevel@tonic-gate  *	A global null string.
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate extern char	Null[1];
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /*
957c478bd9Sstevel@tonic-gate  *	A global error message string.
967c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate extern char	Error[128];
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1007c478bd9Sstevel@tonic-gate }
1017c478bd9Sstevel@tonic-gate #endif
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate #endif	/* _MACROS_H */
104