[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1


elf_rand Subroutine

Purpose

Random archive member access

Library

cc [flag...] file... -lelf [library]...
#include <libelf.h>

Syntax


size_t elf_rand(Elf * elf, size_t offset);

Description

elf_rand, elf_next, and elf_begin manipulate simple object files and archives. elf is an ELF descriptor previously returned from elf_begin.

Parameters

elf_rand provides random archive processing, preparing elf to access an arbitrary archive member. elf must be a descriptor for the archive itself, not a member within the archive. offset gives the byte offset from the beginning of the archive to the archive header of the desired member. See the elf_getarsym subroutine for more information about archive member offsets. When elf_rand works, it returns offset. Otherwise it returns 0, because an error occurred, elf was null, or the file was not an archive (no archive member can have a zero offset). A program may mix random and sequential archive processing.

Examples

An archive starts with a magic string that has SARMAG bytes; the initial archive member follows immediately. An application could provide the following function to rewind an archive (the function returns -1 for errors and 0 otherwise).

   #include <ar.h>
   #include <libelf.h>
 
   int
   rewindelf(Elf *elf)
   {
        if (elf_rand(elf, (size_t)SARMAG) == SARMAG)
                return 0;
        return -1;
   }

Related Information

The ar file format.

The elf_begin (elf_begin Subroutine) subroutine, elf_getarsym (elf_getarsym Subroutine) subroutine, elf_next (elf_next Subroutine) subroutine.

Introduction to ELF Subroutines.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]