xref: /titanic_51/usr/src/cmd/logadm/err.h (revision e9a193fce9f1bf8520f55929577e0175e1e7625b)
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
5*e9a193fcSJohn.Zolnowsky@Sun.COM  * Common Development and Distribution License (the "License").
6*e9a193fcSJohn.Zolnowsky@Sun.COM  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*e9a193fcSJohn.Zolnowsky@Sun.COM  * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  *
247c478bd9Sstevel@tonic-gate  * logadm/err.h -- public definitions for error module
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_LOGADM_ERR_H
287c478bd9Sstevel@tonic-gate #define	_LOGADM_ERR_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <setjmp.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /* basic error handling routines */
377c478bd9Sstevel@tonic-gate void err_init(const char *myname);
387c478bd9Sstevel@tonic-gate void err_fileline(const char *file, int line);
397c478bd9Sstevel@tonic-gate void err(int flags, const char *fmt, ...);
407c478bd9Sstevel@tonic-gate void out(const char *fmt, ...);
417c478bd9Sstevel@tonic-gate void err_fromfd(int fd);
427c478bd9Sstevel@tonic-gate void err_done(int exitcode);
437c478bd9Sstevel@tonic-gate void err_exitcode(int exitcode);
447c478bd9Sstevel@tonic-gate void err_mailto(const char *recipient);
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate /* flags for err() */
477c478bd9Sstevel@tonic-gate #define	EF_WARN	0x01	/* print warning and return */
487c478bd9Sstevel@tonic-gate #define	EF_FILE	0x02	/* prepend file:line from last err_fileline() call */
497c478bd9Sstevel@tonic-gate #define	EF_SYS	0x04	/* append errno text to message */
507c478bd9Sstevel@tonic-gate #define	EF_JMP	0x08	/* longjmp through Error_env after printing error */
517c478bd9Sstevel@tonic-gate #define	EF_RAW	0x10	/* don't prepend/append anything to message */
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate jmp_buf Err_env;
54*e9a193fcSJohn.Zolnowsky@Sun.COM extern jmp_buf *Err_env_ptr;
557c478bd9Sstevel@tonic-gate 
56*e9a193fcSJohn.Zolnowsky@Sun.COM #define	SETJMP	setjmp(*(Err_env_ptr = &Err_env))
57*e9a193fcSJohn.Zolnowsky@Sun.COM #define	LOCAL_ERR_BEGIN	{ jmp_buf Err_env, *Save_err_env_ptr = Err_env_ptr; {
58*e9a193fcSJohn.Zolnowsky@Sun.COM #define	LOCAL_ERR_END	} Err_env_break: Err_env_ptr = Save_err_env_ptr; }
59*e9a193fcSJohn.Zolnowsky@Sun.COM #define	LOCAL_ERR_BREAK	goto Err_env_break
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate #define	MALLOC(nbytes) err_malloc(nbytes, __FILE__, __LINE__)
627c478bd9Sstevel@tonic-gate void *err_malloc(int nbytes, const char *fname, int line);
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #define	REALLOC(ptr, nbytes) err_realloc(ptr, nbytes, __FILE__, __LINE__)
657c478bd9Sstevel@tonic-gate void *err_realloc(void *ptr, int nbytes, const char *fname, int line);
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #define	FREE(ptr) err_free(ptr, __FILE__, __LINE__)
687c478bd9Sstevel@tonic-gate void err_free(void *ptr, const char *fname, int line);
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #define	STRDUP(ptr) err_strdup(ptr, __FILE__, __LINE__)
717c478bd9Sstevel@tonic-gate char *err_strdup(const char *ptr, const char *fname, int line);
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate int Debug;	/* replace with #define to zero to compile out Debug code */
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
767c478bd9Sstevel@tonic-gate }
777c478bd9Sstevel@tonic-gate #endif
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #endif	/* _LOGADM_ERR_H */
80