17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57257d1b4Sraf * Common Development and Distribution License (the "License").
67257d1b4Sraf * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217257d1b4Sraf
227257d1b4Sraf /*
23*2a93c375SAli Bahrami * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
247257d1b4Sraf */
257257d1b4Sraf
267c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
277c478bd9Sstevel@tonic-gate /* All Rights Reserved */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #include "libelf.h"
307c478bd9Sstevel@tonic-gate #include "decl.h"
317c478bd9Sstevel@tonic-gate #include "msg.h"
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate size_t
elf_rand(Elf * elf,size_t off)347c478bd9Sstevel@tonic-gate elf_rand(Elf * elf, size_t off)
357c478bd9Sstevel@tonic-gate {
367c478bd9Sstevel@tonic-gate if (elf == 0)
377c478bd9Sstevel@tonic-gate return (0);
387c478bd9Sstevel@tonic-gate ELFWLOCK(elf)
397c478bd9Sstevel@tonic-gate if (elf->ed_kind != ELF_K_AR) {
407c478bd9Sstevel@tonic-gate _elf_seterr(EREQ_AR, 0);
417c478bd9Sstevel@tonic-gate ELFUNLOCK(elf)
427c478bd9Sstevel@tonic-gate return (0);
437c478bd9Sstevel@tonic-gate }
447c478bd9Sstevel@tonic-gate if ((off == 0) || (elf->ed_fsz < off)) {
457c478bd9Sstevel@tonic-gate _elf_seterr(EREQ_RAND, 0);
467c478bd9Sstevel@tonic-gate ELFUNLOCK(elf)
477c478bd9Sstevel@tonic-gate return (0);
487c478bd9Sstevel@tonic-gate }
497c478bd9Sstevel@tonic-gate elf->ed_nextoff = off;
507c478bd9Sstevel@tonic-gate ELFUNLOCK(elf)
517c478bd9Sstevel@tonic-gate return (off);
527c478bd9Sstevel@tonic-gate }
53*2a93c375SAli Bahrami
54*2a93c375SAli Bahrami /*
55*2a93c375SAli Bahrami * Private function used to obtain the current value of the next
56*2a93c375SAli Bahrami * offset field for an archive header. Returns 0 for error, and
57*2a93c375SAli Bahrami * the offset otherwise.
58*2a93c375SAli Bahrami */
59*2a93c375SAli Bahrami size_t
_elf_getnextoff(Elf * elf)60*2a93c375SAli Bahrami _elf_getnextoff(Elf *elf)
61*2a93c375SAli Bahrami {
62*2a93c375SAli Bahrami size_t off;
63*2a93c375SAli Bahrami
64*2a93c375SAli Bahrami if (elf == NULL)
65*2a93c375SAli Bahrami return (0);
66*2a93c375SAli Bahrami ELFWLOCK(elf)
67*2a93c375SAli Bahrami if (elf->ed_kind != ELF_K_AR) {
68*2a93c375SAli Bahrami _elf_seterr(EREQ_AR, 0);
69*2a93c375SAli Bahrami ELFUNLOCK(elf)
70*2a93c375SAli Bahrami return (0);
71*2a93c375SAli Bahrami }
72*2a93c375SAli Bahrami off = elf->ed_nextoff;
73*2a93c375SAli Bahrami ELFUNLOCK(elf)
74*2a93c375SAli Bahrami return (off);
75*2a93c375SAli Bahrami
76*2a93c375SAli Bahrami }
77