error.c revision 3dbfc80346c4b24f1337e411111b9521c729cf9e
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <thread.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <libelf.h>
#include <libintl.h>
#include "msg.h"
#include "decl.h"
#define ELFERRSHIFT 16
#define SYSERRMASK 0xffff
/*
* _elf_err has two values encoded in it, both the _elf_err # and
* the system errno value (if relevant). These values are encoded
* in the upper & lower 16 bits of the 4 byte integer.
*/
static int _elf_err = 0;
const char *
{
}
void
{
/*LINTED*/
(sys_err & SYSERRMASK);
#ifndef __lock_lint
if (thr_main()) {
return;
}
#endif
(void) thr_keycreate_once(&errkey, 0);
}
int
_elf_geterr() {
#ifndef __lock_lint
if (thr_main())
return (_elf_err);
#endif
}
const char *
elf_errmsg(int err)
{
char *errno_str;
char *elferr_str;
char *buffer = 0;
int syserr;
int elferr;
if (err == 0) {
if ((err = _elf_geterr()) == 0)
return (0);
} else if (err == -1) {
if ((err = _elf_geterr()) == 0)
/*LINTED*/ /* MSG_INTL(EINF_NULLERROR) */
}
if (thr_main())
else {
/*
* If this is a threaded APP then we store the
* errmsg buffer in Thread Specific Storage.
*
* Each thread has its own private buffer.
*/
return (MSG_INTL(EBUG_THRDKEY));
if (!buffer) {
return (MSG_INTL(EMEM_ERRMSG));
return (MSG_INTL(EBUG_THRDSET));
}
}
}
/*LINTED*/
else {
}
return (buffer);
}
int
{
int rc = _elf_geterr();
_elf_seterr(0, 0);
return (rc);
}