/*
 * WatchClock.c
 * Aufruf mit DICE: dcc GuardClock.c -o GuardClock
 */

#include <dos/dos.h>
#include <exec/types.h>
#include <clib/macros.h>

#define FILENAME "S:WatchClock.dat"

main()
{
  LONG tm_now[3],dys_now,dys_last,result=0;
  BPTR *file;

  if (file=(APTR)Open(FILENAME,MODE_READWRITE)) { /* Data-File öffnen */
    DateStamp(&tm_now);               /* aktuelle Zeit holen */
    dys_now=tm_now[0];               /* Tage seit 1.1.1978 */
    if (Read(file,&dys_last,4)) {    /* Data-File auslesen */
      if( ABS(dys_now-dys_last) > 30*3 ) {      /* Uhr verstellt ? */
        puts("Vorsicht, Uhr könnte verstellt sein !");
        result=5;
      } else {  /* wenn nicht, */
        Seek(file,0,OFFSET_BEGINNING);   /* aktuelle Zeit in Data-File */
        Write(file,&dys_now,4);          /* schreiben */
      }
    } else Write(file,&dys_now,4);
    Close(file);
  } else puts("Die Datei S:WatchClock.dat ließ sich nicht anlegen");
  exit(result);
}
