-
Notifications
You must be signed in to change notification settings - Fork 0
/
Backup.c
72 lines (59 loc) · 1.58 KB
/
Backup.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* ---------------------------------------------------------------------- */
/* Plot - 12-8-94 SSi - Backup.c */
/* ---------------------------------------------------------------------- */
#include "Plot.h"
#include <proto/dos.h>
#include <proto/exec.h>
#include <string.h>
#include <dos.h>
#include <math.h>
#include <exec/memory.h>
/* globale Daten ------------------------------------------------------------ */
extern short Options;
char BackupFileName[560];
/* -------------------------------------------------------------------------- */
void BackupFile(char *Filename) /* legt ein Backup des angegebenen Files an */
{
BPTR in,out;
APTR Buf;
LONG BufLen;
LONG bip; /* BytesInBuffer */
static char CommentString[80];
if (!BackupFileName[0]) return;
if (!Filename) return;
if (!*Filename) return;
{ /* Filekommentar vorbereiten */
static char node[FESIZE];
strcpy(CommentString,"Backup of ");
stcgfn(node,Filename);
strncat(CommentString,node,69);
}
if (in=Open(Filename,MODE_OLDFILE))
{
Seek(in,0,OFFSET_END); /* Buffergröße ermitteln */
BufLen=Seek(in,0,OFFSET_BEGINNING);
Forbid();
{
LONG avmem=AvailMem(MEMF_LARGEST)/2;
BufLen=min(BufLen,avmem);
}
if (Buf=AllocMem(BufLen,0))
{
Permit();
if (out=Open(BackupFileName,MODE_NEWFILE))
{
for (;;) /* Kopierschleife */
{
if ((bip=Read(in,Buf,BufLen))<=0) break;
Write(out,Buf,bip);
}
Close(out);
SetComment(BackupFileName,CommentString);
}
FreeMem(Buf,BufLen);
}
else Permit();
Close(in);
}
return;
}