xref: /freebsd/contrib/elftoolchain/libelf/elf_next.3 (revision c66ec88fed842fbaad62c30d510644ceb7bd2d71)
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_next.3 3698 2019-02-28 06:34:42Z jkoshy $
25.\"
26.Dd February 27, 2019
27.Dt ELF_NEXT 3
28.Os
29.Sh NAME
30.Nm elf_next
31.Nd provide sequential access to the next archive member
32.Sh LIBRARY
33.Lb libelf
34.Sh SYNOPSIS
35.In libelf.h
36.Ft Elf_Cmd
37.Fn elf_next "Elf *elf"
38.Sh DESCRIPTION
39The
40.Fn elf_next
41function causes the ELF archive descriptor corresponding to argument
42.Ar elf
43to be adjusted to provide access to the next member in
44the archive on a subsequent call to
45.Fn elf_begin .
46.Pp
47The return value of
48.Fn elf_next
49is suitable for use in a loop invoking
50.Fn elf_begin .
51.Sh RETURN VALUES
52If successful, function
53.Fn elf_next
54returns the value
55.Dv ELF_C_READ .
56Otherwise, if argument
57.Ar elf
58was not associated with an archive, or if it was
59.Dv NULL ,
60or if any other error occurred, the value
61.Dv ELF_C_NULL
62is returned.
63.Sh EXAMPLES
64To process all the members of an archive use:
65.Bd -literal -offset indent
66Elf_Cmd cmd;
67Elf *archive, *e;
68\&...
69cmd = ELF_C_READ;
70archive = elf_begin(fd, cmd, NULL);
71while ((e = elf_begin(fd, cmd, archive)) != (Elf *) 0)
72{
73	... process `e' here ...
74
75	cmd = elf_next(e);
76	elf_end(e);
77}
78elf_end(archive);
79.Ed
80.Sh ERRORS
81Function
82.Fn elf_next
83may fail with the following error:
84.Bl -tag -width "[ELF_E_RESOURCE]"
85.It Bq Er ELF_E_ARGUMENT
86Argument
87.Ar elf
88was not associated with a containing
89.Xr ar 1
90archive.
91.It Bq Er ELF_E_ARGUMENT
92An error was encountered while parsing the archive containing argument
93.Ar elf .
94.El
95.Sh SEE ALSO
96.Xr elf 3 ,
97.Xr elf_begin 3 ,
98.Xr elf_end 3 ,
99.Xr elf_rand 3
100