1*0a6a1f1dSLionel Sambuc.\" $NetBSD: elf_errmsg.3,v 1.2 2014/03/09 16:58:04 christos Exp $ 2*0a6a1f1dSLionel Sambuc.\" 3*0a6a1f1dSLionel Sambuc.\" Copyright (c) 2006,2008 Joseph Koshy. All rights reserved. 4*0a6a1f1dSLionel Sambuc.\" 5*0a6a1f1dSLionel Sambuc.\" Redistribution and use in source and binary forms, with or without 6*0a6a1f1dSLionel Sambuc.\" modification, are permitted provided that the following conditions 7*0a6a1f1dSLionel Sambuc.\" are met: 8*0a6a1f1dSLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright 9*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer. 10*0a6a1f1dSLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright 11*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer in the 12*0a6a1f1dSLionel Sambuc.\" documentation and/or other materials provided with the distribution. 13*0a6a1f1dSLionel Sambuc.\" 14*0a6a1f1dSLionel Sambuc.\" This software is provided by Joseph Koshy ``as is'' and 15*0a6a1f1dSLionel Sambuc.\" any express or implied warranties, including, but not limited to, the 16*0a6a1f1dSLionel Sambuc.\" implied warranties of merchantability and fitness for a particular purpose 17*0a6a1f1dSLionel Sambuc.\" are disclaimed. in no event shall Joseph Koshy be liable 18*0a6a1f1dSLionel Sambuc.\" for any direct, indirect, incidental, special, exemplary, or consequential 19*0a6a1f1dSLionel Sambuc.\" damages (including, but not limited to, procurement of substitute goods 20*0a6a1f1dSLionel Sambuc.\" or services; loss of use, data, or profits; or business interruption) 21*0a6a1f1dSLionel Sambuc.\" however caused and on any theory of liability, whether in contract, strict 22*0a6a1f1dSLionel Sambuc.\" liability, or tort (including negligence or otherwise) arising in any way 23*0a6a1f1dSLionel Sambuc.\" out of the use of this software, even if advised of the possibility of 24*0a6a1f1dSLionel Sambuc.\" such damage. 25*0a6a1f1dSLionel Sambuc.\" 26*0a6a1f1dSLionel Sambuc.\" Id: elf_errmsg.3 189 2008-07-20 10:38:08Z jkoshy 27*0a6a1f1dSLionel Sambuc.\" 28*0a6a1f1dSLionel Sambuc.Dd June 11, 2006 29*0a6a1f1dSLionel Sambuc.Os 30*0a6a1f1dSLionel Sambuc.Dt ELF_ERRMSG 3 31*0a6a1f1dSLionel Sambuc.Sh NAME 32*0a6a1f1dSLionel Sambuc.Nm elf_errmsg , 33*0a6a1f1dSLionel Sambuc.Nm elf_errno 34*0a6a1f1dSLionel Sambuc.Nd ELF library error message handling 35*0a6a1f1dSLionel Sambuc.Sh LIBRARY 36*0a6a1f1dSLionel Sambuc.Lb libelf 37*0a6a1f1dSLionel Sambuc.Sh SYNOPSIS 38*0a6a1f1dSLionel Sambuc.In libelf.h 39*0a6a1f1dSLionel Sambuc.Ft int 40*0a6a1f1dSLionel Sambuc.Fn elf_errno "void" 41*0a6a1f1dSLionel Sambuc.Ft "const char *" 42*0a6a1f1dSLionel Sambuc.Fn elf_errmsg "int error" 43*0a6a1f1dSLionel Sambuc.Sh DESCRIPTION 44*0a6a1f1dSLionel SambucWhen an error occurs during an ELF library API call, the library 45*0a6a1f1dSLionel Sambucencodes the error using an error number and stores the error number 46*0a6a1f1dSLionel Sambucinternally for retrieval by the application at a later point of time. 47*0a6a1f1dSLionel SambucError numbers may contain an OS supplied error code in addition to 48*0a6a1f1dSLionel Sambucan ELF API specific error code. 49*0a6a1f1dSLionel SambucAn error number value of zero indicates no error. 50*0a6a1f1dSLionel Sambuc.Pp 51*0a6a1f1dSLionel SambucFunction 52*0a6a1f1dSLionel Sambuc.Fn elf_errno 53*0a6a1f1dSLionel Sambucis used to retrieve the last error recorded by the ELF library. 54*0a6a1f1dSLionel SambucInvoking this function has the side-effect of resetting the 55*0a6a1f1dSLionel SambucELF library's recorded error number to zero. 56*0a6a1f1dSLionel Sambuc.Pp 57*0a6a1f1dSLionel SambucThe function 58*0a6a1f1dSLionel Sambuc.Fn elf_errmsg 59*0a6a1f1dSLionel Sambucreturns a null-terminated string with a human readable 60*0a6a1f1dSLionel Sambucdescription of the error specified in argument 61*0a6a1f1dSLionel Sambuc.Ar error . 62*0a6a1f1dSLionel SambucA zero value for argument 63*0a6a1f1dSLionel Sambuc.Ar error 64*0a6a1f1dSLionel Sambucretrieves the most recent error encountered by the ELF 65*0a6a1f1dSLionel Sambuclibrary. 66*0a6a1f1dSLionel SambucAn argument value of -1 behaves identically, except that 67*0a6a1f1dSLionel Sambucit guarantees a non-NULL return from 68*0a6a1f1dSLionel Sambuc.Fn elf_errmsg . 69*0a6a1f1dSLionel Sambuc.Sh RETURN VALUES 70*0a6a1f1dSLionel SambucFunction 71*0a6a1f1dSLionel Sambuc.Fn elf_errno 72*0a6a1f1dSLionel Sambucreturns a non-zero value encoding the last error encountered 73*0a6a1f1dSLionel Sambucby the ELF library, or zero if no error was encountered. 74*0a6a1f1dSLionel Sambuc.Pp 75*0a6a1f1dSLionel SambucFunction 76*0a6a1f1dSLionel Sambuc.Fn elf_errmsg 77*0a6a1f1dSLionel Sambucreturns a pointer to library local storage for non-zero values 78*0a6a1f1dSLionel Sambucof argument 79*0a6a1f1dSLionel Sambuc.Ar error . 80*0a6a1f1dSLionel SambucWith a zero argument, the function will return a NULL pointer if no 81*0a6a1f1dSLionel Sambucerror had been encountered by the library, or will return a pointer to 82*0a6a1f1dSLionel Sambuclibrary local storage containing an appropriate message otherwise. 83*0a6a1f1dSLionel Sambuc.Sh EXAMPLES 84*0a6a1f1dSLionel SambucClearing the ELF library's recorded error number can be accomplished 85*0a6a1f1dSLionel Sambucby invoking 86*0a6a1f1dSLionel Sambuc.Fn elf_errno 87*0a6a1f1dSLionel Sambucand discarding its return value. 88*0a6a1f1dSLionel Sambuc.Bd -literal -offset indent 89*0a6a1f1dSLionel Sambuc/* clear error */ 90*0a6a1f1dSLionel Sambuc(void) elf_errno(); 91*0a6a1f1dSLionel Sambuc.Ed 92*0a6a1f1dSLionel Sambuc.Pp 93*0a6a1f1dSLionel SambucRetrieving a human-readable description of the current error number 94*0a6a1f1dSLionel Sambuccan be done with the following snippet: 95*0a6a1f1dSLionel Sambuc.Bd -literal -offset indent 96*0a6a1f1dSLionel Sambucint err; 97*0a6a1f1dSLionel Sambucconst char *errmsg; 98*0a6a1f1dSLionel Sambuc\&... 99*0a6a1f1dSLionel Sambucerr = elf_errno(); 100*0a6a1f1dSLionel Sambucif (err != 0) 101*0a6a1f1dSLionel Sambuc errmsg = elf_errmsg(err); 102*0a6a1f1dSLionel Sambuc.Ed 103*0a6a1f1dSLionel Sambuc.Sh SEE ALSO 104*0a6a1f1dSLionel Sambuc.Xr elf 3 , 105*0a6a1f1dSLionel Sambuc.Xr gelf 3 106*0a6a1f1dSLionel Sambuc.Sh BUGS 107*0a6a1f1dSLionel SambucFunction 108*0a6a1f1dSLionel Sambuc.Fn elf_errmsg 109*0a6a1f1dSLionel Sambucis not localized. 110