File:  [CSRG BSD Unix] / 40BSD / lib / libpc / IOSYNC.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:12:53 2018 UTC (8 years, 1 month ago) by root
Branches: MAIN, BSD
CVS tags: HEAD, BSD40
BSD 4.0

/* Copyright (c) 1979 Regents of the University of California */

static char sccsid[] = "@(#)IOSYNC.c 1.1 10/29/80";

#include "h00vars.h"
#include "h01errs.h"

/*
 * insure that a usable image is in the buffer window
 */
IOSYNC(curfile)

	register struct iorec	*curfile;
{
	register short		unit = curfile->funit;
	char			*limit, *ptr;

	if (unit & FWRITE) {
		ERROR(EREADIT, curfile->pfname);
		return;
	}
	if ((unit & SYNC) == 0) {
		return;
	}
	if (unit & EOFF) {
		ERROR(EPASTEOF, curfile->pfname);
		return;
	}
	unit &= ~SYNC;
	fread(curfile->fileptr, curfile->fsize, 1, curfile->fbuf);
	if (ferror(curfile->fbuf)) {
		ERROR(EPASTEOF, curfile->pfname);
		return;
	}
	if (feof(curfile->fbuf)) {
		curfile->funit = unit | EOFF;
		limit = &curfile->fileptr[curfile->fsize];
		for (ptr = curfile->fileptr; ptr < limit; )
			*ptr++ = 0;
		return;
	}
	if (unit & FTEXT) {
		if (*curfile->fileptr == '\n') {
			unit |= EOLN;
			*curfile->fileptr = ' ';
		} else {
			unit &= ~EOLN;
		}
	}
	curfile->funit = unit;
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.