shithub: sdbm

ref: 64e312636599ea2c86f21dc1176dca7da77bd74a
dir: /util.c/

View raw version
#include <u.h>
#include <libc.h>
#include <stdio.h>
#include "sdbm.h"

void
oops(char *s1, char *s2)
{
	extern char *progname;
	if (progname)
		fprintf(stderr, "%s:", progname);
	fprintf(stderr, s1, s2);
	fprintf(stderr, "\n");

	exits(s2);
}

int
okpage(char *pag)
{
	register unsigned n;
	register off;
	register short *ino = (short *) pag;

	if ((n = ino[0]) > PBLKSIZ / sizeof(short))
		return 0;

	if (!n)
		return 1;

	off = PBLKSIZ;
	for (ino++; n; ino += 2) {
		if (ino[0] > off || ino[1] > off ||
		    ino[1] > ino[0])
			return 0;
		off = ino[1];
		n -= 2;
	}

	return 1;
}