Reads the file header of an XCOFF file.
Object File Access Routine Library (libld.a)
#include <stdio.h>
#include <ldfcn.h>
int ldfhread ( ldPointer, FileHeader)
LDFILE *ldPointer;
void *FileHeader;
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.
Item | Description |
---|---|
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. |
The ldfhread subroutine returns Success or Failure.
The ldfhread subroutine fails if it cannot read the file header.
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... */
}
}