1.\"	$NetBSD: elf_open.3,v 1.2 2014/03/09 16:58:04 christos Exp $
2.\"
3.\" Copyright (c) 2012 Joseph Koshy.  All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" This software is provided by Joseph Koshy ``as is'' and
15.\" any express or implied warranties, including, but not limited to, the
16.\" implied warranties of merchantability and fitness for a particular purpose
17.\" are disclaimed.  in no event shall Joseph Koshy be liable
18.\" for any direct, indirect, incidental, special, exemplary, or consequential
19.\" damages (including, but not limited to, procurement of substitute goods
20.\" or services; loss of use, data, or profits; or business interruption)
21.\" however caused and on any theory of liability, whether in contract, strict
22.\" liability, or tort (including negligence or otherwise) arising in any way
23.\" out of the use of this software, even if advised of the possibility of
24.\" such damage.
25.\"
26.\" Id: elf_open.3 2512 2012-05-31 06:15:57Z jkoshy
27.\"
28.Dd May 31, 2012
29.Os
30.Dt ELF_OPEN 3
31.Sh NAME
32.Nm elf_open
33.Nd open ELF objects and ar(1) archives
34.Sh LIBRARY
35.Lb libelf
36.Sh SYNOPSIS
37.In libelf.h
38.Ft "Elf *"
39.Fn elf_open "int fd"
40.Ft "Elf *"
41.Fn elf_openmemory "char *image" "size_t sz"
42.Sh DESCRIPTION
43.Em Important :
44The functions
45.Fn elf_open
46and
47.Fn elf_openmemory
48are extensions to the ELF(3) API, for the internal use of the
49Elftoolchain project.
50Portable applications should not use these functions.
51.Pp
52The function
53.Fn elf_open
54returns an Elf descriptor opened with mode
55.Dv ELF_C_READ
56for the ELF object or
57.Xr ar 1
58archive referenced by the file descriptor in argument
59.Ar fd .
60.Pp
61The function
62.Fn elf_openmemory
63returns an ELF descriptor opened with mode
64.Dv ELF_C_READ
65for the ELF object or
66.Xr ar 1
67archive contained in the memory area pointed to by the argument
68.Ar image .
69The argument
70.Ar sz
71specifies the size of the memory area in bytes.
72.Sh COMPATIBILITY
73These functions are non-standard extensions to the ELF(3) API set.
74.Pp
75The behavior of these functions differs from their counterparts
76.Xr elf_begin 3
77and
78.Xr elf_memory 3
79in that these functions will successfully open malformed ELF objects
80and
81.Xr ar 1
82archives, returning an Elf descriptor of type
83.Dv ELF_K_NONE .
84.Sh RETURN VALUES
85The function returns a pointer to a ELF descriptor if successful, or
86NULL if an error occurred.
87.Sh ERRORS
88These functions can fail with the following errors:
89.Bl -tag -width "[ELF_E_RESOURCE]"
90.It Bq Er ELF_E_ARGUMENT
91The argument
92.Ar fd
93was of an unsupported file type.
94.It Bq Er ELF_E_ARGUMENT
95The argument
96.Ar sz
97was zero, or the argument
98.Ar image
99was NULL.
100.It Bq Er ELF_E_IO
101The file descriptor in argument
102.Ar fd
103was invalid.
104.It Bq Er ELF_E_IO
105The file descriptor in argument
106.Ar fd
107could not be read.
108.It Bq Er ELF_E_RESOURCE
109An out of memory condition was encountered.
110.It Bq Er ELF_E_SEQUENCE
111Functions
112.Fn elf_open
113or
114.Fn elf_openmemory
115was called before a working version was established with
116.Xr elf_version 3 .
117.El
118.Sh SEE ALSO
119.Xr elf 3 ,
120.Xr elf_begin 3 ,
121.Xr elf_errno 3 ,
122.Xr elf_memory 3 ,
123.Xr gelf 3
124