10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*12986SJohn.Zolnowsky@Sun.COM * Common Development and Distribution License (the "License"). 6*12986SJohn.Zolnowsky@Sun.COM * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*12986SJohn.Zolnowsky@Sun.COM * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate * 240Sstevel@tonic-gate * logadm/err.h -- public definitions for error module 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _LOGADM_ERR_H 280Sstevel@tonic-gate #define _LOGADM_ERR_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #include <setjmp.h> 310Sstevel@tonic-gate 320Sstevel@tonic-gate #ifdef __cplusplus 330Sstevel@tonic-gate extern "C" { 340Sstevel@tonic-gate #endif 350Sstevel@tonic-gate 360Sstevel@tonic-gate /* basic error handling routines */ 370Sstevel@tonic-gate void err_init(const char *myname); 380Sstevel@tonic-gate void err_fileline(const char *file, int line); 390Sstevel@tonic-gate void err(int flags, const char *fmt, ...); 400Sstevel@tonic-gate void out(const char *fmt, ...); 410Sstevel@tonic-gate void err_fromfd(int fd); 420Sstevel@tonic-gate void err_done(int exitcode); 430Sstevel@tonic-gate void err_exitcode(int exitcode); 440Sstevel@tonic-gate void err_mailto(const char *recipient); 450Sstevel@tonic-gate 460Sstevel@tonic-gate /* flags for err() */ 470Sstevel@tonic-gate #define EF_WARN 0x01 /* print warning and return */ 480Sstevel@tonic-gate #define EF_FILE 0x02 /* prepend file:line from last err_fileline() call */ 490Sstevel@tonic-gate #define EF_SYS 0x04 /* append errno text to message */ 500Sstevel@tonic-gate #define EF_JMP 0x08 /* longjmp through Error_env after printing error */ 510Sstevel@tonic-gate #define EF_RAW 0x10 /* don't prepend/append anything to message */ 520Sstevel@tonic-gate 530Sstevel@tonic-gate jmp_buf Err_env; 54*12986SJohn.Zolnowsky@Sun.COM extern jmp_buf *Err_env_ptr; 550Sstevel@tonic-gate 56*12986SJohn.Zolnowsky@Sun.COM #define SETJMP setjmp(*(Err_env_ptr = &Err_env)) 57*12986SJohn.Zolnowsky@Sun.COM #define LOCAL_ERR_BEGIN { jmp_buf Err_env, *Save_err_env_ptr = Err_env_ptr; { 58*12986SJohn.Zolnowsky@Sun.COM #define LOCAL_ERR_END } Err_env_break: Err_env_ptr = Save_err_env_ptr; } 59*12986SJohn.Zolnowsky@Sun.COM #define LOCAL_ERR_BREAK goto Err_env_break 600Sstevel@tonic-gate 610Sstevel@tonic-gate #define MALLOC(nbytes) err_malloc(nbytes, __FILE__, __LINE__) 620Sstevel@tonic-gate void *err_malloc(int nbytes, const char *fname, int line); 630Sstevel@tonic-gate 640Sstevel@tonic-gate #define REALLOC(ptr, nbytes) err_realloc(ptr, nbytes, __FILE__, __LINE__) 650Sstevel@tonic-gate void *err_realloc(void *ptr, int nbytes, const char *fname, int line); 660Sstevel@tonic-gate 670Sstevel@tonic-gate #define FREE(ptr) err_free(ptr, __FILE__, __LINE__) 680Sstevel@tonic-gate void err_free(void *ptr, const char *fname, int line); 690Sstevel@tonic-gate 700Sstevel@tonic-gate #define STRDUP(ptr) err_strdup(ptr, __FILE__, __LINE__) 710Sstevel@tonic-gate char *err_strdup(const char *ptr, const char *fname, int line); 720Sstevel@tonic-gate 730Sstevel@tonic-gate int Debug; /* replace with #define to zero to compile out Debug code */ 740Sstevel@tonic-gate 750Sstevel@tonic-gate #ifdef __cplusplus 760Sstevel@tonic-gate } 770Sstevel@tonic-gate #endif 780Sstevel@tonic-gate 790Sstevel@tonic-gate #endif /* _LOGADM_ERR_H */ 80