14484Sbinkertn@umich.edu/*-
24484Sbinkertn@umich.edu * Copyright (c) 2006 Joseph Koshy
34484Sbinkertn@umich.edu * All rights reserved.
44484Sbinkertn@umich.edu *
54484Sbinkertn@umich.edu * Redistribution and use in source and binary forms, with or without
64484Sbinkertn@umich.edu * modification, are permitted provided that the following conditions
74484Sbinkertn@umich.edu * are met:
84484Sbinkertn@umich.edu * 1. Redistributions of source code must retain the above copyright
94484Sbinkertn@umich.edu *    notice, this list of conditions and the following disclaimer.
104484Sbinkertn@umich.edu * 2. Redistributions in binary form must reproduce the above copyright
114484Sbinkertn@umich.edu *    notice, this list of conditions and the following disclaimer in the
124484Sbinkertn@umich.edu *    documentation and/or other materials provided with the distribution.
134484Sbinkertn@umich.edu *
144484Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
154484Sbinkertn@umich.edu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
164484Sbinkertn@umich.edu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
174484Sbinkertn@umich.edu * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
184484Sbinkertn@umich.edu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
194484Sbinkertn@umich.edu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
204484Sbinkertn@umich.edu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
214484Sbinkertn@umich.edu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
224484Sbinkertn@umich.edu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
234484Sbinkertn@umich.edu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
244484Sbinkertn@umich.edu * SUCH DAMAGE.
254484Sbinkertn@umich.edu */
264484Sbinkertn@umich.edu
274484Sbinkertn@umich.edu
284484Sbinkertn@umich.edu#include <ar.h>
294484Sbinkertn@umich.edu#include <assert.h>
304484Sbinkertn@umich.edu#include "libelf.h"
314484Sbinkertn@umich.edu
324484Sbinkertn@umich.edu#include "_libelf.h"
334484Sbinkertn@umich.edu
344484Sbinkertn@umich.eduElf_Cmd
354484Sbinkertn@umich.eduelf_next(Elf *e)
364484Sbinkertn@umich.edu{
374484Sbinkertn@umich.edu        off_t next;
384484Sbinkertn@umich.edu        Elf *parent;
394484Sbinkertn@umich.edu
404484Sbinkertn@umich.edu        if (e == NULL)
414484Sbinkertn@umich.edu                return (ELF_C_NULL);
424484Sbinkertn@umich.edu
434484Sbinkertn@umich.edu         if ((parent = e->e_parent) == NULL) {
444484Sbinkertn@umich.edu                 LIBELF_SET_ERROR(ARGUMENT, 0);
454484Sbinkertn@umich.edu                 return (ELF_C_NULL);
464484Sbinkertn@umich.edu         }
474484Sbinkertn@umich.edu
484484Sbinkertn@umich.edu        assert (parent->e_kind == ELF_K_AR);
494484Sbinkertn@umich.edu        assert (parent->e_cmd == ELF_C_READ);
504484Sbinkertn@umich.edu        assert((uintptr_t) e->e_rawfile % 2 == 0);
514484Sbinkertn@umich.edu        assert(e->e_rawfile > parent->e_rawfile);
524484Sbinkertn@umich.edu
534484Sbinkertn@umich.edu        next = e->e_rawfile - parent->e_rawfile + e->e_rawsize;
544484Sbinkertn@umich.edu        next = (next + 1) & ~1;	/* round up to an even boundary */
554484Sbinkertn@umich.edu
564484Sbinkertn@umich.edu        parent->e_u.e_ar.e_next = (next >= (off_t) parent->e_rawsize) ? (off_t) 0 : next;
574484Sbinkertn@umich.edu
584484Sbinkertn@umich.edu        return (ELF_C_READ);
594484Sbinkertn@umich.edu}
60