[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 Base Operating System and Extensions Technical Reference, Volume 1

ldopen or ldaopen Subroutine

Purpose

Opens a common object file for reading.

Library

Object File Access Routine Library (libld.a)

Syntax

#include <stdio.h>
#include <filehdr.h>
#include <ldfcn.h>
ldfile *ldopen(FileName, ldPointer)
char *FileName;
LDFILE *ldPointer;
LDFILE *ldaopen(FileName, ldPointer)
char *FileName;
LDFILE *ldPointer;

Description

The ldopen and ldclose subroutines provide uniform access to both simple object files and object files that are members of archive files. Thus, an archive of common object files can be processed as if it were a series of simple common object files.

If the ldfcn.h file TYPE(ldPointer) macro has the a null value, the ldopen subroutine opens the FileName parameter and allocates and initializes the ldfile structure, and returns a pointer to the structure to the calling program.

If the ldPointer parameter is valid and if the TYPE(ldPointer) macro is the archive magic number, the ldopen subroutine reinitialized the ldfile structure for the next archive member of the FileName parameter.

The ldopen and ldclose subroutines are designed to work in concert. The ldclose subroutine returns a failure value only when the TYPE(ldPointer) macro is the archive magic number and another file in the archive is to be processed. Only then should the ldopen subroutine be called with the current value of the ldPointer parameter. In all other cases, in particular whenever a new FileName parameter is opened, the ldopen subroutine should be called with a null ldPointer argument.

Parameters

ldPointer Points to the LDFILE structure.
FileName Specifies the file name of an object file or archive of object files.

Error Codes

Both the ldopen and ldaopen subroutines open the FileName parameter for reading. Both functions return a null value if the FileName parameter cannot be opened, or if memory for the ldfile structure cannot be allocated. A successful open does not ensure that the given file is a common object file or an archived object file.

Examples

The following is an example of code that uses the ldopen and ldclose subroutines:

/* for each FileName to be processed */
 ldPointer = NULL;
 do
               
 if((ldPointer = ldopen(FileName, ldPointer)) != NULL)
                 
                      /* check magic number */
                      /* process the file */
                 "
                 " 
   while(ldclose(ldPointer) == FAILURE );

If the value of the ldPointer parameter is not a null value, the ldaopen subroutine opens the FileName parameter again and allocates and initializes a new ldfile structure, copying the TYPE , OFFSET , and HEADER fields from the ldPointer parameter. The ldaopen subroutine returns a pointer to the new ldfile structure. This new pointer is independent of the old pointer, ldPointer. The two pointers may be used concurrently to read separate parts of the object file. For example, one pointer may be used to step sequentially through the relocation information, while the other is used to read indexed symbol table entries.

Implementation Specifics

These subroutines are part of Base Operating System (BOS) Runtime.

Related Information

The ldclose or ldaclose subroutine.

Subroutines Overview in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.


[ Previous | Next | Contents | Glossary | Home | Search ]