forked from davidar/sdbm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.c
51 lines (40 loc) · 735 Bytes
/
util.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sdbm.h"
void
oops(const char *fmt, ...)
{
extern char *progname;
va_list argp;
if (progname)
fprintf(stderr, "%s: ", progname);
va_start(argp, fmt);
vfprintf(stderr, fmt, argp);
va_end(argp);
if (errno > 0)
fprintf(stderr, " (%s)", strerror(errno));
fprintf(stderr, "\n");
exit(EXIT_FAILURE);
}
int
okpage(char *pag)
{
unsigned n;
int off;
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;
}