4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * CDDL HEADER START
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * The contents of this file are subject to the terms of the
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Common Development and Distribution License (the "License").
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * You may not use this file except in compliance with the License.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * or http://www.opensolaris.org/os/licensing.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * See the License for the specific language governing permissions
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * and limitations under the License.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * When distributing Covered Code, include this CDDL HEADER in each
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * If applicable, add the following below this CDDL HEADER, with the
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * fields enclosed by brackets "[]" replaced with your own identifying
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * information: Portions Copyright [yyyy] [name of copyright owner]
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * CDDL HEADER END
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Use is subject to license terms.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai#pragma ident "%Z%%M% %I% %E% SMI"
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Utility functions
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai/* returns 1 if s1 == s2, 0 otherwise */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaifindelfsecidx(Elf *elf, const char *file, const char *tofind)
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai while ((scn = elf_nextscn(elf, scn)) != NULL) {
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai "Couldn't read header for section %d",
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai if ((name = elf_strptr(elf, ehdr.e_shstrndx,
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai "Couldn't get name for section %d",
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai terminate("failed to read ELF header: %s\n",
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai else if (ehdr.e_ident[EI_CLASS] == ELFCLASS64)
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai terminate("unknown ELF class %d\n", ehdr.e_ident[EI_CLASS]);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai /*NOTREACHED*/
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai/*PRINTFLIKE2*/
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaiwhine(char *type, char *format, va_list ap)
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai fprintf(stderr, "%s: %s: ", type, progname);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai fprintf(stderr, ": %s\n", strerror(error));
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai/*PRINTFLIKE1*/
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai if (getenv("CTF_ABORT_ON_TERMINATE") != NULL)
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai/*PRINTFLIKE1*/
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai/*PRINTFLIKE1*/
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai terminate("Termination due to warning\n");
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai/*PRINTFLIKE2*/
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaivadebug(int level, char *format, va_list ap)
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai (void) vfprintf(DEBUG_STREAM, format, ap);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai/*PRINTFLIKE2*/
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaimktmpname(const char *origname, const char *suffix)
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai newname = xmalloc(strlen(origname) + strlen(suffix) + 1);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai/*PRINTFLIKE2*/
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaielfterminate(const char *file, const char *fmt, ...)
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai vsnprintf(msgbuf, sizeof (msgbuf), fmt, ap);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai terminate("%s: %s: %s\n", file, msgbuf, elf_errmsg(-1));
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai return (tdp->t_name == NULL ? "(anon)" : tdp->t_name);