#include <readwrite.h>
#include <stdio.h>
#include <unistd.h>

BOOL delete_record(FILE *fp)
{
 C long beginning = ftell(fp);
 BOOL ok = beginning!=(-1L), ok2=TRUE;
 long next = -1, nextnext = -1;
 char c1;

 ok = ok && read_long_4(fp, &next);
 ok = ok && next>beginning+1;

 /* If next record is also deleted, collect them together. */
 ok2 = ok && fseek(fp, next, SEEK_SET)==0;
 ok2 = ok2 && read_long_4(fp, &nextnext);
 ok2 = ok2 && read_char_1(fp, &c1) && c1=='\0';

 ok = ok && fseek(fp, beginning, SEEK_SET)==0;
 ok = ok && write_long_4(fp, ok2 ? nextnext : next);
 ok = ok && write_char_1(fp, '\0');
 ok = ok && fseek(fp, beginning, SEEK_SET)==0;

 return ok;
}
