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_int4, 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(const char *filename)

void wr_close(void)

void wr_ohead(const struct outhead *head)

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

void wr_outsect(int sectno)

void wr_emit(const char *emit, long cnt)

void wr_putc(int c)

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

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

void wr_string(const char *addr, long len)

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

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

void wr_int2(FILE* fd, int i)

void wr_long(FILE* fd, long l)

void wr_bytes(FILE* fd, const char* buf, long cnt)

int rd_open(const char *filename)

int rd_fdopen(FILE* fd)

void rd_close(void)

void rd_ohead(struct outhead *head)

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

void rd_outsect(int sectno)

void rd_emit(char *emit, long cnt)

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

void rd_rew_relos(struct outhead *head)

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

void rd_string(char *stringaddr, long cnt)

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

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

int rd_int2(FILE* fd)

unsigned int rd_unsigned2(FILE* fd)

long rd_int4FILE* fd)

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

FILE* rd_fd(void)

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 secno. This routine can be used to switch between sections.

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

wr_putc adds byte 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 addr, 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 cnt 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_relos 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 interprets 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.