Object module now uses ANSI C I/O
This commit is contained in:
parent
5ec9de401d
commit
8457ec6791
|
@ -3,15 +3,8 @@
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
#include <local.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <out.h>
|
|
||||||
#include <ranlib.h>
|
|
||||||
#include <arch.h>
|
|
||||||
#include "object.h"
|
|
||||||
|
|
||||||
#if ! defined(CHAR_UNSIGNED)
|
#if ! defined(CHAR_UNSIGNED)
|
||||||
#define CHAR_UNSIGNED 0
|
#define CHAR_UNSIGNED 0
|
||||||
|
@ -40,7 +33,7 @@ struct fil {
|
||||||
char *pnow;
|
char *pnow;
|
||||||
char *pbegin;
|
char *pbegin;
|
||||||
long currpos;
|
long currpos;
|
||||||
int fd;
|
FILE* fd;
|
||||||
char pbuf[WBUFSIZ];
|
char pbuf[WBUFSIZ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,147 +16,71 @@ and write ACK-object files and libraries
|
||||||
.br
|
.br
|
||||||
.B #include <object.h>
|
.B #include <object.h>
|
||||||
.PP
|
.PP
|
||||||
.B int wr_open(filename)
|
.B FILE* wr_open(const char *filename)
|
||||||
.br
|
|
||||||
.B char *filename;
|
|
||||||
.PP
|
.PP
|
||||||
.B void wr_close()
|
.B void wr_close()
|
||||||
.PP
|
.PP
|
||||||
.B void wr_ohead(head)
|
.B void wr_ohead(struct outhead *head)
|
||||||
.br
|
|
||||||
.B struct outhead *head;
|
|
||||||
.PP
|
.PP
|
||||||
.B void wr_sect(sect, cnt)
|
.B void wr_sect(struct outsect *sect, unsigned int cnt)
|
||||||
.br
|
|
||||||
.B struct outsect *sect;
|
|
||||||
.br
|
|
||||||
.B unsigned int cnt;
|
|
||||||
.PP
|
.PP
|
||||||
.B void wr_outsect(sectionnr)
|
.B void wr_outsect(int sectionnr)
|
||||||
.br
|
|
||||||
.B int sectionnr;
|
|
||||||
.PP
|
.PP
|
||||||
.B void wr_emit(emit, cnt)
|
.B void wr_emit(const char *emit, long cnt)
|
||||||
.br
|
|
||||||
.B char *emit;
|
|
||||||
.br
|
|
||||||
.B long cnt;
|
|
||||||
.PP
|
.PP
|
||||||
.B void wr_putc(ch)
|
.B void wr_putc(int ch)
|
||||||
.PP
|
.PP
|
||||||
.B void wr_relo(relo, cnt)
|
.B void wr_relo(const struct outrelo *relo, unsigned int cnt)
|
||||||
.br
|
|
||||||
.B struct outrelo *relo;
|
|
||||||
.br
|
|
||||||
.B unsigned int cnt;
|
|
||||||
.PP
|
.PP
|
||||||
.B void wr_name(name, cnt)
|
.B void wr_name(struct outname *name, unsigned int cnt)
|
||||||
.br
|
|
||||||
.B struct outname *name;
|
|
||||||
.br
|
|
||||||
.B unsigned int cnt;
|
|
||||||
.PP
|
.PP
|
||||||
.B void wr_string(stringaddr, cnt)
|
.B void wr_string(const char *stringaddr, long cnt)
|
||||||
.br
|
|
||||||
.B char *stringaddr;
|
|
||||||
.br
|
|
||||||
.B long cnt;
|
|
||||||
.PP
|
.PP
|
||||||
.B void wr_arhdr(fd, arhdr)
|
.B void wr_arhdr(FILE* fd, struct ar_hdr *arhdr)
|
||||||
.br
|
|
||||||
.B struct ar_hdr *arhdr;
|
|
||||||
.PP
|
.PP
|
||||||
.B void wr_ranlib(fd, ran, cnt)
|
.B void wr_ranlib(FILE* fd, struct ranlib *ran, long cnt)
|
||||||
.br
|
|
||||||
.B struct ranlib *ran;
|
|
||||||
.br
|
|
||||||
.B long cnt;
|
|
||||||
.PP
|
.PP
|
||||||
.B void wr_int2(fd, i)
|
.B void wr_int2(FILE* fd, int i)
|
||||||
.PP
|
.PP
|
||||||
.B void wr_long(fd, l)
|
.B void wr_long(FILE* fd, long l)
|
||||||
.br
|
|
||||||
.B long l;
|
|
||||||
.PP
|
.PP
|
||||||
.B void wr_bytes(fd, buf, l)
|
.B void wr_bytes(FILE* fd, const char* buf, long l)
|
||||||
.br
|
|
||||||
.B char *buf;
|
|
||||||
.br
|
|
||||||
.B long l;
|
|
||||||
.PP
|
.PP
|
||||||
.B int rd_open(filename)
|
.B int rd_open(const char *filename)
|
||||||
.br
|
|
||||||
.B char *filename;
|
|
||||||
.PP
|
.PP
|
||||||
.B int rd_fdopen(fd)
|
.B int rd_fdopen(FILE* fd)
|
||||||
.PP
|
.PP
|
||||||
.B void rd_close()
|
.B void rd_close()
|
||||||
.PP
|
.PP
|
||||||
.B void rd_ohead(head)
|
.B void rd_ohead(struct outhead *head)
|
||||||
.br
|
|
||||||
.B struct outhead *head;
|
|
||||||
.PP
|
.PP
|
||||||
.B void rd_sect(sect, cnt)
|
.B void rd_sect(struct outsect *sect, unsigned int cnt)
|
||||||
.br
|
|
||||||
.B struct outsect *sect;
|
|
||||||
.br
|
|
||||||
.B unsigned int cnt;
|
|
||||||
.PP
|
.PP
|
||||||
.B void rd_outsect(sectionnr)
|
.B void rd_outsect(int sectionnr)
|
||||||
.br
|
|
||||||
.B int sectionnr;
|
|
||||||
.PP
|
.PP
|
||||||
.B void rd_emit(emit, cnt)
|
.B void rd_emit(char *emit, long cnt)
|
||||||
.br
|
|
||||||
.B char *emit;
|
|
||||||
.br
|
|
||||||
.B long cnt;
|
|
||||||
.PP
|
.PP
|
||||||
.B void rd_relo(relo, cnt)
|
.B void rd_relo(struct outrelo *relo, unsigned int cnt)
|
||||||
.br
|
|
||||||
.B struct outrelo *relo;
|
|
||||||
.br
|
|
||||||
.B unsigned int cnt;
|
|
||||||
.PP
|
.PP
|
||||||
.B void rd_rew_relo(head)
|
.B void rd_rew_relo(struct outhead *head)
|
||||||
.br
|
|
||||||
.B struct outhead *head;
|
|
||||||
.PP
|
.PP
|
||||||
.B void rd_name(name, cnt)
|
.B void rd_name(struct outname *name, unsigned int cnt)
|
||||||
.br
|
|
||||||
.B struct outname *name;
|
|
||||||
.br
|
|
||||||
.B unsigned int cnt;
|
|
||||||
.PP
|
.PP
|
||||||
.B void rd_string(stringaddr, cnt)
|
.B void rd_string(char *stringaddr, long cnt)
|
||||||
.br
|
|
||||||
.B char *stringaddr;
|
|
||||||
.br
|
|
||||||
.B long cnt;
|
|
||||||
.PP
|
.PP
|
||||||
.B int rd_arhdr(fd, arhdr)
|
.B int rd_arhdr(FILE* fd, struct ar_hdr *arhdr)
|
||||||
.br
|
|
||||||
.B struct ar_hdr *arhdr;
|
|
||||||
.PP
|
.PP
|
||||||
.B void rd_ranlib(fd, ran, cnt)
|
.B void rd_ranlib(FILE* fd, struct ranlib *ran, long cnt)
|
||||||
.br
|
|
||||||
.B struct ranlib *ran;
|
|
||||||
.br
|
|
||||||
.B long cnt;
|
|
||||||
.PP
|
.PP
|
||||||
.B int rd_int2(fd)
|
.B int rd_int2(FILE* fd)
|
||||||
.PP
|
.PP
|
||||||
.B unsigned int rd_unsigned2(fd)
|
.B unsigned int rd_unsigned2(FILE* fd)
|
||||||
.PP
|
.PP
|
||||||
.B long rd_long(fd)
|
.B long rd_long(FILE* fd)
|
||||||
.PP
|
.PP
|
||||||
.B void rd_bytes(fd, buf, l)
|
.B void rd_bytes(FILE* fd, char *buf, long l)
|
||||||
.br
|
|
||||||
.B char *buf;
|
|
||||||
.br
|
|
||||||
.B long l;
|
|
||||||
.PP
|
.PP
|
||||||
.B int rd_fd()
|
.B FILE* rd_fd()
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
These routines come in handy when reading or writing ACK-object files
|
These routines come in handy when reading or writing ACK-object files
|
||||||
or libraries. No checking is performed.
|
or libraries. No checking is performed.
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/*
|
/*
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
#include <fcntl.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "out.h"
|
||||||
|
#include "object.h"
|
||||||
#include "obj.h"
|
#include "obj.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -29,7 +33,7 @@
|
||||||
|
|
||||||
static long offset[MAXSECT];
|
static long offset[MAXSECT];
|
||||||
|
|
||||||
static int outfile;
|
static FILE* outfile;
|
||||||
static long outseek[NPARTS];
|
static long outseek[NPARTS];
|
||||||
static long currpos;
|
static long currpos;
|
||||||
static long rd_base;
|
static long rd_base;
|
||||||
|
@ -46,7 +50,7 @@ OUTREAD(int p, char* b, long n)
|
||||||
register long l = outseek[p];
|
register long l = outseek[p];
|
||||||
|
|
||||||
if (currpos != l) {
|
if (currpos != l) {
|
||||||
lseek(outfile, l, 0);
|
fseek(outfile, l, SEEK_SET);
|
||||||
}
|
}
|
||||||
rd_bytes(outfile, b, n);
|
rd_bytes(outfile, b, n);
|
||||||
l += n;
|
l += n;
|
||||||
|
@ -57,25 +61,23 @@ OUTREAD(int p, char* b, long n)
|
||||||
/*
|
/*
|
||||||
* Open the output file according to the chosen strategy.
|
* Open the output file according to the chosen strategy.
|
||||||
*/
|
*/
|
||||||
int
|
int rd_open(const char* f)
|
||||||
rd_open(const char* f)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((outfile = open(f, 0)) < 0)
|
if ((outfile = fopen(f, "rb")) == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
return rd_fdopen(outfile);
|
return rd_fdopen(outfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int offcnt;
|
static int offcnt;
|
||||||
|
|
||||||
int
|
int rd_fdopen(FILE* fd)
|
||||||
rd_fdopen(int fd)
|
|
||||||
{
|
{
|
||||||
register int i;
|
register int i;
|
||||||
|
|
||||||
for (i = 0; i < NPARTS; i++) outseek[i] = 0;
|
for (i = 0; i < NPARTS; i++) outseek[i] = 0;
|
||||||
offcnt = 0;
|
offcnt = 0;
|
||||||
rd_base = lseek(fd, 0L, 1);
|
rd_base = fseek(fd, 0L, SEEK_CUR);
|
||||||
if (rd_base < 0) {
|
if (rd_base < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -86,16 +88,14 @@ rd_fdopen(int fd)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void rd_close(void)
|
||||||
rd_close(void)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
close(outfile);
|
fclose(outfile);
|
||||||
outfile = -1;
|
outfile = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
FILE* rd_fd(void)
|
||||||
rd_fd(void)
|
|
||||||
{
|
{
|
||||||
return outfile;
|
return outfile;
|
||||||
}
|
}
|
||||||
|
@ -221,6 +221,10 @@ rd_string(char* addr, long len)
|
||||||
OUTREAD(PARTCHAR, addr, len);
|
OUTREAD(PARTCHAR, addr, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef SYMDBUG
|
#ifdef SYMDBUG
|
||||||
void
|
void
|
||||||
rd_dbug(char* buf, long size)
|
rd_dbug(char* buf, long size)
|
||||||
|
|
|
@ -1,25 +1,31 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/*
|
/*
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "out.h"
|
||||||
|
#include "arch.h"
|
||||||
|
#include "object.h"
|
||||||
#include "obj.h"
|
#include "obj.h"
|
||||||
|
|
||||||
int
|
extern void rd_fatal(void);
|
||||||
rd_arhdr(fd, arhdr)
|
|
||||||
register struct ar_hdr *arhdr;
|
int rd_arhdr(FILE* fd, register struct ar_hdr *arhdr)
|
||||||
{
|
{
|
||||||
char buf[AR_TOTAL];
|
char buf[AR_TOTAL];
|
||||||
register char *c = buf;
|
register char *c = buf;
|
||||||
register char *p = arhdr->ar_name;
|
register char *p = arhdr->ar_name;
|
||||||
register int i;
|
register size_t i;
|
||||||
|
|
||||||
i = read(fd, c, AR_TOTAL);
|
i = fread(c, 1, AR_TOTAL, fd);
|
||||||
if (i == 0) return 0;
|
if (i == 0) return 0;
|
||||||
if (i != AR_TOTAL) {
|
if (i != AR_TOTAL) {
|
||||||
rd_fatal();
|
rd_fatal();
|
||||||
}
|
}
|
||||||
i = 14;
|
i = AR_NAME_MAX;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
*p++ = *c++;
|
*p++ = *c++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include "obj.h"
|
#include "obj.h"
|
||||||
|
|
||||||
#define MININT (1 << (sizeof(int) * 8 - 1))
|
#define MININT (1 << (sizeof(int) * 8 - 1))
|
||||||
|
@ -14,20 +16,21 @@
|
||||||
|
|
||||||
static int maxchunk = MAXCHUNK;
|
static int maxchunk = MAXCHUNK;
|
||||||
|
|
||||||
|
extern void rd_fatal(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We don't have to worry about byte order here.
|
* We don't have to worry about byte order here.
|
||||||
* Just read "cnt" bytes from file-descriptor "fd".
|
* Just read "cnt" bytes from file-descriptor "fd".
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
rd_bytes(fd, string, cnt)
|
rd_bytes(FILE* fd, register char *string, register long cnt)
|
||||||
register char *string;
|
|
||||||
register long cnt;
|
|
||||||
{
|
{
|
||||||
|
size_t read_bytes;
|
||||||
while (cnt) {
|
while (cnt) {
|
||||||
register int n = cnt >= maxchunk ? maxchunk : cnt;
|
register size_t n = cnt >= maxchunk ? maxchunk : cnt;
|
||||||
|
|
||||||
if (read(fd, string, n) != n)
|
read_bytes = fread(string, 1, n, fd);
|
||||||
|
if (read_bytes != n)
|
||||||
rd_fatal();
|
rd_fatal();
|
||||||
string += n;
|
string += n;
|
||||||
cnt -= n;
|
cnt -= n;
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/*
|
/*
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "out.h"
|
||||||
|
#include "object.h"
|
||||||
#include "obj.h"
|
#include "obj.h"
|
||||||
|
|
||||||
int
|
int rd_int2(FILE* fd)
|
||||||
rd_int2(fd)
|
|
||||||
{
|
{
|
||||||
char buf[2];
|
char buf[2];
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/*
|
/*
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "out.h"
|
||||||
|
#include "object.h"
|
||||||
#include "obj.h"
|
#include "obj.h"
|
||||||
|
|
||||||
long
|
|
||||||
rd_long(fd)
|
long rd_long(FILE* fd)
|
||||||
{
|
{
|
||||||
char buf[4];
|
char buf[4];
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/*
|
/*
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "out.h"
|
||||||
|
#include "arch.h"
|
||||||
|
#include "ranlib.h"
|
||||||
|
#include "object.h"
|
||||||
#include "obj.h"
|
#include "obj.h"
|
||||||
|
|
||||||
void
|
void rd_ranlib(FILE* fd, register struct ranlib *ran, register long cnt)
|
||||||
rd_ranlib(fd, ran, cnt)
|
|
||||||
register struct ranlib *ran;
|
|
||||||
register long cnt;
|
|
||||||
{
|
{
|
||||||
rd_bytes(fd, (char *) ran, cnt * SZ_RAN);
|
rd_bytes(fd, (char *) ran, cnt * SZ_RAN);
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/*
|
/*
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "out.h"
|
||||||
|
#include "object.h"
|
||||||
#include "obj.h"
|
#include "obj.h"
|
||||||
|
|
||||||
unsigned int
|
unsigned int rd_unsigned2(FILE* fd)
|
||||||
rd_unsigned2(fd)
|
|
||||||
{
|
{
|
||||||
char buf[2];
|
char buf[2];
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,12 @@
|
||||||
* part. In this case #define OUTSEEK.
|
* part. In this case #define OUTSEEK.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "out.h"
|
||||||
|
#include "object.h"
|
||||||
#include "obj.h"
|
#include "obj.h"
|
||||||
|
#include "ranlib.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parts of the output file.
|
* Parts of the output file.
|
||||||
|
@ -21,7 +25,7 @@ static long offset[MAXSECT];
|
||||||
struct fil __parts[NPARTS];
|
struct fil __parts[NPARTS];
|
||||||
|
|
||||||
#ifdef OUTSEEK
|
#ifdef OUTSEEK
|
||||||
static int outfile;
|
static FILE* outfile;
|
||||||
static long currpos;
|
static long currpos;
|
||||||
#endif
|
#endif
|
||||||
int __sectionnr;
|
int __sectionnr;
|
||||||
|
@ -34,7 +38,7 @@ __wr_flush(struct fil *ptr)
|
||||||
#ifdef OUTSEEK
|
#ifdef OUTSEEK
|
||||||
/* seek to correct position even if we aren't going to write now */
|
/* seek to correct position even if we aren't going to write now */
|
||||||
if (currpos != ptr->currpos) {
|
if (currpos != ptr->currpos) {
|
||||||
currpos = lseek(ptr->fd, ptr->currpos, 0);
|
currpos = fseek(ptr->fd, ptr->currpos, SEEK_SET);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (ptr->pnow > ptr->pbegin) {
|
if (ptr->pnow > ptr->pbegin) {
|
||||||
|
@ -116,8 +120,7 @@ OUTWRITE(int p, const char *b, long n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void BEGINSEEK(int p, long o)
|
||||||
BEGINSEEK(int p, long o)
|
|
||||||
/* p = part number, o = offset in file */
|
/* p = part number, o = offset in file */
|
||||||
{
|
{
|
||||||
struct fil *ptr = &__parts[p];
|
struct fil *ptr = &__parts[p];
|
||||||
|
@ -126,7 +129,7 @@ BEGINSEEK(int p, long o)
|
||||||
ptr->fd = outfile;
|
ptr->fd = outfile;
|
||||||
ptr->currpos = o;
|
ptr->currpos = o;
|
||||||
#else
|
#else
|
||||||
ptr->currpos = lseek(ptr->fd, o, 0);
|
ptr->currpos = fseek(ptr->fd, o, SEEK_SET);
|
||||||
#endif
|
#endif
|
||||||
if (p >= PARTRELO) o = 0; /* no attempt to align writes
|
if (p >= PARTRELO) o = 0; /* no attempt to align writes
|
||||||
for the time being */
|
for the time being */
|
||||||
|
@ -139,39 +142,37 @@ BEGINSEEK(int p, long o)
|
||||||
/*
|
/*
|
||||||
* Open the output file according to the chosen strategy.
|
* Open the output file according to the chosen strategy.
|
||||||
*/
|
*/
|
||||||
int
|
int wr_open(const char *f)
|
||||||
wr_open(const char *f)
|
|
||||||
{
|
{
|
||||||
struct fil *fdp;
|
struct fil *fdp;
|
||||||
|
|
||||||
close(creat(f, 0666));
|
fclose(fopen(f,"wb"));
|
||||||
#ifdef OUTSEEK
|
#ifdef OUTSEEK
|
||||||
if ((outfile = open(f, 1)) < 0)
|
if ((outfile = fopen(f, "ab+")) == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
currpos = 0;
|
currpos = 0;
|
||||||
#else /* not OUTSEEK */
|
#else /* not OUTSEEK */
|
||||||
for (fdp = &__parts[PARTEMIT]; fdp < &__parts[NPARTS]; fdp++)
|
for (fdp = &__parts[PARTEMIT]; fdp < &__parts[NPARTS]; fdp++)
|
||||||
if ((fdp->fd = open(f, 1)) < 0)
|
if ((fdp->fd = fopen(f, "wb+")) == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
#endif /* not OUTSEEK */
|
#endif /* not OUTSEEK */
|
||||||
offcnt = 0;
|
offcnt = 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void wr_close(void)
|
||||||
wr_close()
|
|
||||||
{
|
{
|
||||||
struct fil *ptr;
|
struct fil *ptr;
|
||||||
|
|
||||||
for (ptr = &__parts[PARTEMIT]; ptr < &__parts[NPARTS]; ptr++) {
|
for (ptr = &__parts[PARTEMIT]; ptr < &__parts[NPARTS]; ptr++) {
|
||||||
__wr_flush(ptr);
|
__wr_flush(ptr);
|
||||||
#ifndef OUTSEEK
|
#ifndef OUTSEEK
|
||||||
close(ptr->fd);
|
fclose(ptr->fd);
|
||||||
#endif /* not OUTSEEK */
|
#endif /* not OUTSEEK */
|
||||||
ptr->fd = -1;
|
ptr->fd = NULL;
|
||||||
}
|
}
|
||||||
#ifdef OUTSEEK
|
#ifdef OUTSEEK
|
||||||
close(outfile);
|
fclose(outfile);
|
||||||
outfile = -1;
|
outfile = -1;
|
||||||
#endif /* OUTSEEK */
|
#endif /* OUTSEEK */
|
||||||
}
|
}
|
||||||
|
@ -259,7 +260,7 @@ wr_outsect(int s)
|
||||||
if (s != sectionnr && s >= (SECTCNT-1) && sectionnr >= (SECTCNT-1)) {
|
if (s != sectionnr && s >= (SECTCNT-1) && sectionnr >= (SECTCNT-1)) {
|
||||||
#ifdef OUTSEEK
|
#ifdef OUTSEEK
|
||||||
if (currpos != ptr->currpos)
|
if (currpos != ptr->currpos)
|
||||||
currpos = lseek(ptr->fd, ptr->currpos, 0);
|
currpos = fseek(ptr->fd, ptr->currpos, SEEK_SET);
|
||||||
#endif
|
#endif
|
||||||
wr_bytes(ptr->fd, ptr->pbegin, (long)(ptr->pnow - ptr->pbegin));
|
wr_bytes(ptr->fd, ptr->pbegin, (long)(ptr->pnow - ptr->pbegin));
|
||||||
ptr->currpos += ptr->pnow - ptr->pbegin;
|
ptr->currpos += ptr->pnow - ptr->pbegin;
|
||||||
|
@ -268,7 +269,7 @@ wr_outsect(int s)
|
||||||
#endif
|
#endif
|
||||||
offset[sectionnr] = ptr->currpos;
|
offset[sectionnr] = ptr->currpos;
|
||||||
if (offset[s] != ptr->currpos) {
|
if (offset[s] != ptr->currpos) {
|
||||||
ptr->currpos = lseek(ptr->fd, offset[s], 0);
|
ptr->currpos = fseek(ptr->fd, offset[s], SEEK_SET);
|
||||||
#ifdef OUTSEEK
|
#ifdef OUTSEEK
|
||||||
currpos = ptr->currpos;
|
currpos = ptr->currpos;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,18 +1,24 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/*
|
/*
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
|
||||||
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "out.h"
|
||||||
|
#include "arch.h"
|
||||||
|
#include "object.h"
|
||||||
#include "obj.h"
|
#include "obj.h"
|
||||||
|
|
||||||
void
|
|
||||||
wr_arhdr(fd, arhdr)
|
void wr_arhdr(FILE* fd, register struct ar_hdr *arhdr)
|
||||||
register struct ar_hdr *arhdr;
|
|
||||||
{
|
{
|
||||||
char buf[AR_TOTAL];
|
char buf[AR_TOTAL];
|
||||||
register char *c = buf;
|
register char *c = buf;
|
||||||
register char *p = arhdr->ar_name;
|
register char *p = arhdr->ar_name;
|
||||||
register int i = 14;
|
register int i = AR_NAME_MAX;
|
||||||
|
|
||||||
while (i--) {
|
while (i--) {
|
||||||
*c++ = *p++;
|
*c++ = *p++;
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include "obj.h"
|
#include "obj.h"
|
||||||
|
|
||||||
#define MININT (1 << (sizeof(int) * 8 - 1))
|
#define MININT (1 << (sizeof(int) * 8 - 1))
|
||||||
|
@ -14,18 +16,25 @@
|
||||||
|
|
||||||
static const int maxchunk = MAXCHUNK;
|
static const int maxchunk = MAXCHUNK;
|
||||||
|
|
||||||
|
extern void wr_fatal(void);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Just write "cnt" bytes to file-descriptor "fd".
|
* Just write "cnt" bytes to file-descriptor "fd".
|
||||||
*/
|
*/
|
||||||
void
|
void wr_bytes(FILE* fd, const char *string, long cnt)
|
||||||
wr_bytes(int fd, const char *string, long cnt)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
while (cnt) {
|
size_t written_bytes;
|
||||||
|
while (cnt)
|
||||||
|
{
|
||||||
int n = cnt >= maxchunk ? maxchunk : cnt;
|
int n = cnt >= maxchunk ? maxchunk : cnt;
|
||||||
|
|
||||||
if (write(fd, string, n) != n)
|
written_bytes = fwrite(string, 1, n, fd);
|
||||||
|
if (written_bytes != (size_t)n)
|
||||||
|
{
|
||||||
wr_fatal();
|
wr_fatal();
|
||||||
|
}
|
||||||
string += n;
|
string += n;
|
||||||
cnt -= n;
|
cnt -= n;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/*
|
/*
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "out.h"
|
||||||
|
#include "object.h"
|
||||||
#include "obj.h"
|
#include "obj.h"
|
||||||
|
|
||||||
void
|
void wr_int2(FILE* fd, int i)
|
||||||
wr_int2(fd, i)
|
|
||||||
{
|
{
|
||||||
char buf[2];
|
char buf[2];
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/*
|
/*
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "out.h"
|
||||||
|
#include "object.h"
|
||||||
#include "obj.h"
|
#include "obj.h"
|
||||||
|
|
||||||
void
|
void wr_long(FILE* fd, long l)
|
||||||
wr_long(fd, l)
|
|
||||||
long l;
|
|
||||||
{
|
{
|
||||||
char buf[4];
|
char buf[4];
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/*
|
/*
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "out.h"
|
||||||
|
#include "object.h"
|
||||||
#include "obj.h"
|
#include "obj.h"
|
||||||
|
|
||||||
extern int __sectionnr;
|
extern int __sectionnr;
|
||||||
void __wr_flush(struct fil *);
|
void __wr_flush(struct fil *);
|
||||||
|
|
||||||
void
|
void wr_putc(int ch)
|
||||||
wr_putc(int ch)
|
|
||||||
{
|
{
|
||||||
struct fil *ptr = &__parts[PARTEMIT+getsect(__sectionnr)];
|
struct fil *ptr = &__parts[PARTEMIT+getsect(__sectionnr)];
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/*
|
/*
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
#include "obj.h"
|
|
||||||
|
|
||||||
void
|
#include <stdlib.h>
|
||||||
wr_ranlib(fd, ran, cnt1)
|
#include <stdio.h>
|
||||||
struct ranlib *ran;
|
#include "out.h"
|
||||||
long cnt1;
|
#include "object.h"
|
||||||
|
#include "obj.h"
|
||||||
|
#include "ranlib.h"
|
||||||
|
|
||||||
|
void wr_ranlib(FILE* fd, struct ranlib *ran, long cnt1)
|
||||||
{
|
{
|
||||||
struct ranlib *r;
|
struct ranlib *r;
|
||||||
long cnt, val;
|
long cnt, val;
|
||||||
|
|
Loading…
Reference in a new issue