OBJECT(3ACK)

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, wr_fd, 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>

int wr_open(filename)
char *filename;

wr_close()

wr_ohead(head)
struct outhead *head;

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

wr_outsect(sectionnr)
int sectionnr;

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

wr_putc(ch)

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

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

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

wr_arhdr(fd, arhdr)
struct ar_hdr *arhdr;

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

wr_int2(fd, i)

wr_long(fd, l)
long l;

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

int wr_fd()

int rd_open(filename)
char *filename;

int rd_fdopen(fd)

rd_close()

rd_ohead(head)
struct outhead *head;

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

rd_outsect(sectionnr)
int sectionnr;

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

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

rd_rew_relo(head)
struct outhead *head;

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

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

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

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

int rd_int2(fd)

unsigned int rd_unsigned2(fd)

long rd_long(fd)

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

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.

Wr_fd returns the current output file descriptor.

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. If you use this entry point for reading, you don't have to call rd_close to close the file. You can close the file yourself.

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, you must define a routine named rd_fatal. 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.