Ejemplo n.º 1
0
Archivo: snm.c Proyecto: 8l/subc
void nm_arc(FILE *f) {
	char	ah[ARH_LEN];
	char	ohd[OHDSZ];
	char	*ip;
	int	i;
	int	pos;

	rewind(f);
	for (;;) {
		i = fread(ah, 1, ARH_LEN, f);
		if (feof(f)) return;
		if (i != ARH_LEN) readerr();
		if (strncmp(&ah[AR_MAGIC], A_MAGIC, strlen(A_MAGIC)))
			error("magic match failed", NULL);
		Aname = &ah[AR_NAME];
		ip = &ah[AR_SIZE];
		i = ip[0] + (ip[1] << 8);
		pos = ftell(f);
		if (fread(ohd, 1, OHDSZ, f) != OHDSZ)
			readerr();
		if (ohd[OMAGIC] == O_MAGIC) {
			ufseek(f, pos, SEEK_SET);
			ufseek(f, ohd[OPUBP] + (ohd[OPUBP+1]<<8), SEEK_CUR);
			nm_sym(f);
		}
		ufseek(f, pos, SEEK_SET);
		ufseek(f, i, SEEK_CUR);
		while (i++%16) fgetc(f);
	}
}
Ejemplo n.º 2
0
int iDBF::prefix() 
{
	int width= Field[pos]->Width;
	read(buf, width);
	buf[width]= '\x0';
	if (fail()) readerr();
	return width;
}
Ejemplo n.º 3
0
Archivo: snm.c Proyecto: 8l/subc
void nm_obj(FILE *f) {
	char	ohd[OHDSZ];
	int	off;

	rewind(f);
	if (fread(ohd, 1, OHDSZ, f) != OHDSZ)
		readerr();
	off = ohd[OPUBP] + (ohd[OPUBP+1]<<8);
	ufseek(f, off, SEEK_SET);
	nm_sym(f);
}
Ejemplo n.º 4
0
char *get_sector(u32_t vsec)
/* Read a sector "vsec" from the image into memory and return its address.
 * Return nil on error.  (This routine tries to read an entire track, so
 * the next request is usually satisfied from the track buffer.)
 */
{
	u32_t sec;
	int r;
#define SECBUFS 16
	static char bufdata[SECBUFS * SECTOR_SIZE + RAW_ALIGN];
	static size_t count;		/* Number of sectors in the buffer. */
	static u32_t bufsec;		/* First Sector now in the buffer. */
	char *buf = bufdata + RAW_ALIGN - (unsigned) &bufdata % RAW_ALIGN;

	if (vsec == 0) count= 0;	/* First sector; initialize. */

	if ((sec= (*vir2sec)(vsec)) == -1) return nil;

	if (sec == 0) {
		/* A hole. */
		count= 0;
		memset(buf, 0, SECTOR_SIZE);
		return buf;
	}

	/* Can we return a sector from the buffer? */
	if ((sec - bufsec) < count) {
		return buf + ((size_t) (sec - bufsec) << SECTOR_SHIFT);
	}

	/* Not in the buffer. */
	count= 0;
	bufsec= sec;

	/* Read a whole track if possible. */
	while (++count < SECBUFS && !dev_boundary(bufsec + count)) {
		vsec++;
		if ((sec= (*vir2sec)(vsec)) == -1) break;

		/* Consecutive? */
		if (sec != bufsec + count) break;
	}

	/* Actually read the sectors. */
	if ((r= readsectors(mon2abs(buf), bufsec, count)) != 0) {
		readerr(bufsec, r);
		count= 0;
		errno= 0;
		return nil;
	}
	return buf;
}