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

Technical Reference: Base Operating System and Extensions, Volume 1


ldfhread Subroutine

Purpose

Reads the file header of an XCOFF file.

Library

Object File Access Routine Library (libld.a)

Syntax


#include <stdio.h>
#include <ldfcn.h>


int ldfhread ( ldPointer, FileHeader)
LDFILE *ldPointer;
void *FileHeader;

Description

The ldfhread subroutine reads the file header of the object file currently associated with the ldPointer parameter into the area of memory beginning at the FileHeader parameter. For AIX 4.3.2 and above, it is the responsibility of the calling routine to provide a pointer to a buffer large enough to contain the file header of the associated object file. Since the ldopen subroutine provides magic number information (via the HEADER(ldPointer).f_magic macro), the calling application can always determine whether the FileHeader pointer should refer to a 32-bit FILHDR or 64-bit FILHDR_64 structure.

Parameters


ldPointer Points to the LDFILE structure that was returned as the result of a successful call to ldopen or ldaopen subroutine.
FileHeader Points to a buffer large enough to accommodate a FILHDR structure, according to the object mode of the file being read.

Return Values

The ldfhread subroutine returns Success or Failure.

Error Codes

The ldfhread subroutine fails if it cannot read the file header.

Note: In most cases, the use of ldfhread can be avoided by using the HEADER (ldPointer) macro defined in the ldfcn.h file. The information in any field or fieldname of the header file may be accessed using the header (ldPointer) fieldname macro.

Examples

The following is an example of code that opens an object file, determines its mode, and uses the ldfhread subroutine to acquire the file header. This code would be compiled with both _XCOFF32_ and _XCOFF64_ defined:

#define __XCOFF32__
#define __XCOFF64__
 
#include <ldfcn.h>
 
 
/* for each FileName to be processed */
 
if ( (ldPointer = ldopen(fileName, ldPointer)) != NULL)
{
    FILHDR    FileHead32;
    FILHDR_64 FileHead64;
    void      *FileHeader;
 
    if ( HEADER(ldPointer).f_magic == U802TOCMAGIC )
        FileHeader = &FileHead32;
    else if ( HEADER(ldPointer).f_magic == U803XTOCMAGIC )
        FileHeader = &FileHead64;
    else
        FileHeader = NULL;
 
    if ( FileHeader && (ldfhread( ldPointer, &FileHeader ) == SUCCESS) )
    {
        /* ...successfully read header... */
        /* ...process according to magic number... */
    }
}

Implementation Specifics

This subroutine is part of Base Operating System (BOS) Runtime.

Related Information

The ldahread (ldahread Subroutine) subroutine, ldgetname (ldgetname Subroutine) subroutine, ldlread, ldlinit, or ldlitem (ldlread, ldlinit, or ldlitem Subroutine) subroutine, ldopen (ldopen or ldaopen Subroutine) subroutine, ldshread or ldnshread (ldshread or ldnshread Subroutine) subroutine, ldtbread (ldtbread Subroutine) subroutine.

Subroutines Overview in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.


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