OBJECT(3)

NAME
wr_open, wr_close, wr_ohead, wr_sect, wr_outsect, wr_emit, wr_putc, wr_relo, wr_name, wr_string, wr_arhdr, wr_ranlib, wr_int2, wr_long, wr_bytes, rd_open, rd_fdopen, rd_close, rd_ohead, rd_sect, rd_outsect, rd_emit, rd_relo, rd_rew_relo, rd_name, rd_string, rd_arhdr, rd_ranlib, rd_int2, rd_unsigned2, rd_long, rd_bytes, rd_fd - routines to read and write ACK-object files and libraries

SYNOPSIS
#include <out.h>
#include <arch.h>
#include <ranlib.h>
#include <object.h>

int wr_open(filename)
char *filename;

void wr_close()

void wr_ohead(head)
struct outhead *head;

void wr_sect(sect, cnt)
struct outsect *sect;
unsigned int cnt;

void wr_outsect(sectionnr)
int sectionnr;

void wr_emit(emit, cnt)
char *emit;
long cnt;

void wr_putc(ch)

void wr_relo(relo, cnt)
struct outrelo *relo;
unsigned int cnt;

void wr_name(name, cnt)
struct outname *name;
unsigned int cnt;

void wr_string(stringaddr, cnt)
char *stringaddr;
long cnt;

void wr_arhdr(fd, arhdr)
struct ar_hdr *arhdr;

void wr_ranlib(fd, ran, cnt)
struct ranlib *ran;
long cnt;

void wr_int2(fd, i)

void wr_long(fd, l)
long l;

void wr_bytes(fd, buf, l)
char *buf;
long l;

int rd_open(filename)
char *filename;

int rd_fdopen(fd)

void rd_close()

void rd_ohead(head)
struct outhead *head;

void rd_sect(sect, cnt)
struct outsect *sect;
unsigned int cnt;

void rd_outsect(sectionnr)
int sectionnr;

void rd_emit(emit, cnt)
char *emit;
long cnt;

void rd_relo(relo, cnt)
struct outrelo *relo;
unsigned int cnt;

void rd_rew_relo(head)
struct outhead *head;

void rd_name(name, cnt)
struct outname *name;
unsigned int cnt;

void rd_string(stringaddr, cnt)
char *stringaddr;
long cnt;

int rd_arhdr(fd, arhdr)
struct ar_hdr *arhdr;

void rd_ranlib(fd, ran, cnt)
struct ranlib *ran;
long cnt;

int rd_int2(fd)

unsigned int rd_unsigned2(fd)

long rd_long(fd)

void rd_bytes(fd, buf, l)
char *buf;
long l;

int rd_fd()

DESCRIPTION
These routines come in handy when reading or writing ACK-object files or libraries. No checking is performed.

Wr_open opens the file filename for writing and initializes some of this modules local variables. It must be called before writing parts of the object file. It returns 1 if it succeeds, 0 if it fails.

Wr_close closes the object file. Don't forget to call it, because it might flush internal buffers.

Wr_ohead writes the head header structure. This routine must be called before the routines to write the other parts.

Wr_sect writes cnt section headers, starting at sect. Before writing a section, its section header must be written.

Wr_outsect indicates that the next section to be written is sectionnr. This routine can be used to switch between sections.

Wr_emit writes cnt bytes, starting at emit, of the current section.

Wr_putc adds character ch to the current section.

Wr_relo writes cnt outrelo structures, indicated by relo, in the relocation information part of the object file.

Wr_name writes cnt outname structures, indicated by name, in the name-table part of the object file.

Wr_string writes cnt bytes, indicated by stringaddr, in the string table part of the object file.

The next few routines can be used independantly: Wr_arhdr writes the archive member header arhdr to file descriptor fd.

Wr_ranlib writes cnt ranlib structures, indicated by ran, to file descriptor fd.

Wr_int2 writes a 2-byte integer i to file descriptor fd, low order byte first.

Wr_long writes a 4-byte integer l to file descriptor fd, low order word first, low order byte first.

Wr_bytes writes l bytes from buf to file descriptor fd.

Most of the rd_ routines are the opposite of the wr_ routines. However, a few of them deserve special mentioning:

Rd_fdopen initialises for reading an "object file" from file descriptor fd, at its current position. This is useful for reading an object that resides in an archive. It returns 1 if it succeeds, 0 otherwise. When using this entry point for reading, rd_close does not have to be called.

Rd_rew_relo rewinds the relocation part, so that it can be read again. Led(6) sometimes needs this.

Rd_unsigned2 reads two bytes from file descriptor fd and interpretes them as an unsigned integer.

Rd_arhdr returns 1 if a header was read, and 0 on end-of-file.

When using any of the reading routines, a routine named rd_fatal must be defined. It is called when a read fails, and is not supposed to return. Likewise, a routine wr_fatal must be defined when using any of the writing routines.

FILES
~em/h/out.h
~em/h/arch.h
~em/h/ranlib.h
~em/modules/lib/libobject.a: the library in which these routines reside

SEE ALSO
ack.out(5), arch(1), aal(1)

DIAGNOSTICS
The routines wr_open, rd_open, and rd_fdopen return 0 if they fail, and 1 if they succeed.