xref: /freebsd/contrib/elftoolchain/libelf/elf_rand.3 (revision 2de3b87a120614a3b053be7dd845b72f1e9ce804)
1*2de3b87aSKai Wang.\" Copyright (c) 2006,2008 Joseph Koshy.  All rights reserved.
2*2de3b87aSKai Wang.\"
3*2de3b87aSKai Wang.\" Redistribution and use in source and binary forms, with or without
4*2de3b87aSKai Wang.\" modification, are permitted provided that the following conditions
5*2de3b87aSKai Wang.\" are met:
6*2de3b87aSKai Wang.\" 1. Redistributions of source code must retain the above copyright
7*2de3b87aSKai Wang.\"    notice, this list of conditions and the following disclaimer.
8*2de3b87aSKai Wang.\" 2. Redistributions in binary form must reproduce the above copyright
9*2de3b87aSKai Wang.\"    notice, this list of conditions and the following disclaimer in the
10*2de3b87aSKai Wang.\"    documentation and/or other materials provided with the distribution.
11*2de3b87aSKai Wang.\"
12*2de3b87aSKai Wang.\" This software is provided by Joseph Koshy ``as is'' and
13*2de3b87aSKai Wang.\" any express or implied warranties, including, but not limited to, the
14*2de3b87aSKai Wang.\" implied warranties of merchantability and fitness for a particular purpose
15*2de3b87aSKai Wang.\" are disclaimed.  in no event shall Joseph Koshy be liable
16*2de3b87aSKai Wang.\" for any direct, indirect, incidental, special, exemplary, or consequential
17*2de3b87aSKai Wang.\" damages (including, but not limited to, procurement of substitute goods
18*2de3b87aSKai Wang.\" or services; loss of use, data, or profits; or business interruption)
19*2de3b87aSKai Wang.\" however caused and on any theory of liability, whether in contract, strict
20*2de3b87aSKai Wang.\" liability, or tort (including negligence or otherwise) arising in any way
21*2de3b87aSKai Wang.\" out of the use of this software, even if advised of the possibility of
22*2de3b87aSKai Wang.\" such damage.
23*2de3b87aSKai Wang.\"
24*2de3b87aSKai Wang.\" $Id: elf_rand.3 189 2008-07-20 10:38:08Z jkoshy $
25*2de3b87aSKai Wang.\"
26*2de3b87aSKai Wang.Dd June 17, 2006
27*2de3b87aSKai Wang.Os
28*2de3b87aSKai Wang.Dt ELF_RAND 3
29*2de3b87aSKai Wang.Sh NAME
30*2de3b87aSKai Wang.Nm elf_rand
31*2de3b87aSKai Wang.Nd provide sequential access to the next archive member
32*2de3b87aSKai Wang.Sh LIBRARY
33*2de3b87aSKai Wang.Lb libelf
34*2de3b87aSKai Wang.Sh SYNOPSIS
35*2de3b87aSKai Wang.In libelf.h
36*2de3b87aSKai Wang.Ft off_t
37*2de3b87aSKai Wang.Fn elf_rand "Elf *archive" "off_t offset"
38*2de3b87aSKai Wang.Sh DESCRIPTION
39*2de3b87aSKai WangThe
40*2de3b87aSKai Wang.Fn elf_rand
41*2de3b87aSKai Wangfunction causes the ELF descriptor
42*2de3b87aSKai Wang.Ar archive
43*2de3b87aSKai Wangto be adjusted so that the next call to
44*2de3b87aSKai Wang.Xr elf_begin 3
45*2de3b87aSKai Wangwill provide access to the archive member at byte offset
46*2de3b87aSKai Wang.Ar offset
47*2de3b87aSKai Wangin the archive.
48*2de3b87aSKai WangArgument
49*2de3b87aSKai Wang.Ar offset
50*2de3b87aSKai Wangis the byte offset from the start of the archive to the beginning of
51*2de3b87aSKai Wangthe archive header for the desired member.
52*2de3b87aSKai Wang.Pp
53*2de3b87aSKai WangArchive member offsets may be retrieved using the
54*2de3b87aSKai Wang.Xr elf_getarsym 3
55*2de3b87aSKai Wangfunction.
56*2de3b87aSKai Wang.Sh RETURN VALUES
57*2de3b87aSKai WangFunction
58*2de3b87aSKai Wang.Fn elf_rand
59*2de3b87aSKai Wangreturns
60*2de3b87aSKai Wang.Ar offset
61*2de3b87aSKai Wangif successful or zero in case of an error.
62*2de3b87aSKai Wang.Sh EXAMPLES
63*2de3b87aSKai WangTo process all the members of an archive use:
64*2de3b87aSKai Wang.Bd -literal -offset indent
65*2de3b87aSKai Wangoff_t off;
66*2de3b87aSKai WangElf *archive, *e;
67*2de3b87aSKai Wang\&...
68*2de3b87aSKai Wangcmd = ELF_C_READ;
69*2de3b87aSKai Wangarchive = elf_begin(fd, cmd, NULL);
70*2de3b87aSKai Wangwhile ((e = elf_begin(fd, cmd, archive)) != (Elf *) 0)
71*2de3b87aSKai Wang{
72*2de3b87aSKai Wang	... process `e' here ...
73*2de3b87aSKai Wang	elf_end(e);
74*2de3b87aSKai Wang
75*2de3b87aSKai Wang	off = ...new value...;
76*2de3b87aSKai Wang	if (elf_rand(archive, off) != off) {
77*2de3b87aSKai Wang		... process error ...
78*2de3b87aSKai Wang	}
79*2de3b87aSKai Wang}
80*2de3b87aSKai Wangelf_end(archive);
81*2de3b87aSKai Wang.Ed
82*2de3b87aSKai Wang.Pp
83*2de3b87aSKai WangTo rewind an archive, use:
84*2de3b87aSKai Wang.Bd -literal -offset indent
85*2de3b87aSKai WangElf *archive;
86*2de3b87aSKai Wang\&...
87*2de3b87aSKai Wangif (elf_rand(archive, SARMAG) != SARMAG) {
88*2de3b87aSKai Wang	... error ...
89*2de3b87aSKai Wang}
90*2de3b87aSKai Wang.Ed
91*2de3b87aSKai Wang.Sh ERRORS
92*2de3b87aSKai WangFunction
93*2de3b87aSKai Wang.Fn elf_rand
94*2de3b87aSKai Wangmay fail with the following errors:
95*2de3b87aSKai Wang.Bl -tag -width "[ELF_E_RESOURCE]"
96*2de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT
97*2de3b87aSKai WangArgument
98*2de3b87aSKai Wang.Ar archive
99*2de3b87aSKai Wangwas null.
100*2de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT
101*2de3b87aSKai WangArgument
102*2de3b87aSKai Wang.Ar archive
103*2de3b87aSKai Wangwas not a descriptor for an
104*2de3b87aSKai Wang.Xr ar 1
105*2de3b87aSKai Wangarchive.
106*2de3b87aSKai Wang.It Bq Er ELF_E_ARCHIVE
107*2de3b87aSKai WangArgument
108*2de3b87aSKai Wang.Ar offset
109*2de3b87aSKai Wangdid not correspond to the start of an archive member header.
110*2de3b87aSKai Wang.El
111*2de3b87aSKai Wang.Sh SEE ALSO
112*2de3b87aSKai Wang.Xr ar 1 ,
113*2de3b87aSKai Wang.Xr elf 3 ,
114*2de3b87aSKai Wang.Xr elf_begin 3 ,
115*2de3b87aSKai Wang.Xr elf_end 3 ,
116*2de3b87aSKai Wang.Xr elf_getarsym 3 ,
117*2de3b87aSKai Wang.Xr elf_next 3 ,
118*2de3b87aSKai Wang.Xr gelf 3
119