Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/root/sys/src/cmd/refer/fio.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include "refer.h"

/*
 * read and write 32-bit longs in a machine-independent way
 * (given 8-bit bytes!) -- high byte first
 */
void putl(long ll, FILE *f)
{
	putc(ll>>24, f);
	putc(ll>>16, f);
	putc(ll>>8, f);
	putc(ll, f);
	if (ferror(f))
		err("error writing output index file");
}

long getl(FILE *f)
{
	long	l;

	l = 0;
	l |= getc(f)<<24;
	l |= getc(f)<<16;
	l |= getc(f)<<8;
	l |= getc(f);
	if (ferror(f))
		err("error reading index file");
	else if (feof(f))
		err("unexpected end-of-file on index file -- rerun pubindex?");
	return l;
}

void xseek(FILE *f, Fpos l, int n)
{
	if (fseek(f, l, n) < 0)
		err("error seeking on index file -- rerun pubindex?");
}

#include <sys/types.h>
#include <sys/stat.h>

long gdate(FILE *f)
{
	struct stat sb;
	return fstat(fileno(f), &sb) >= 0? sb.st_mtime: 0;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].