41 lines
1.2 KiB
C
41 lines
1.2 KiB
C
// SPDX-License-Identifier: GPL-3.0-or-later
|
||
// Compile both ways and link with a third source that uses stdio rewind alone.
|
||
#ifdef LEGACY_FIRST
|
||
#include <disk.h>
|
||
#include <stdio.h>
|
||
#define CHECK_ORDER checkLegacyFirst
|
||
#else
|
||
#include <stdio.h>
|
||
#include <disk.h>
|
||
#define CHECK_ORDER checkStdioFirst
|
||
#endif
|
||
|
||
int CHECK_ORDER(void)
|
||
{
|
||
static byte fat[MAX_NUM_GRANULES];
|
||
static struct FileDesc descriptor;
|
||
void (*resetDescriptor)(struct FileDesc *) = rewind;
|
||
void (*resetStream)(FILE *) = vcc_rewind;
|
||
char bytes[3];
|
||
FILE *stream;
|
||
int ok;
|
||
|
||
// initdisk installs this source file’s FAT buffer without clearing the cache flag.
|
||
fatUpToDate = FALSE;
|
||
if (!initdisk(fat) || !openfile(&descriptor, "SAFE.DAT"))
|
||
return 1;
|
||
ok = read(&descriptor, bytes, 3) == 3 && memcmp(bytes, "pre", 3) == 0;
|
||
resetDescriptor(&descriptor);
|
||
ok = ok && read(&descriptor, bytes, 3) == 3 && memcmp(bytes, "pre", 3) == 0;
|
||
if (close(&descriptor) || !ok)
|
||
return 1;
|
||
|
||
stream = fopen("SAFE.DAT", "rb");
|
||
if (!stream)
|
||
return 1;
|
||
ok = fgetc(stream) == 'p' && fgetc(stream) == 'r';
|
||
resetStream(stream);
|
||
ok = ok && ftell(stream) == 0L && fgetc(stream) == 'p';
|
||
return fclose(stream) || !ok;
|
||
}
|