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