Save
Synopsis
len = Save(filename, buffer, len)
D0 A0 A1 D0C Prototype
ULONG Save(STRPTR filename, APTR buffer, ULONG len);Description
Opens an output channel to a device. It operates in the inverse manner of Load().
This command was designed for writing a file to disk, but its output can be redirected to any available peripheral (device).
The file is opened in MODE_READWRITE, so if the filename already exists on the device, it will be overwritten without any warning. The responsibility of checking for the pre-existence of the file is left to the task; CheckFile() can be used for this purpose.
Inputs
- filename — Address of a string containing the name of the file to write. This can be preceded by
RAM:,PRT:,CON:, etc. - buffer — Pointer to the data buffer. This is the data that will be written to the device.
- len — Number of bytes to transfer to the device. This parameter can be NULL when the buffer was acquired via
Load()andLoad()was responsible for allocating the buffer. Only in this case canlenbe NULL; otherwise it must be specified.
Result
- len — Number of bytes written. If NULL, an error occurred.
Example
/* Load and Save example.c */
APTR mybuffer = Load("Work:page.txt", NULL, MEMF_PUBLIC);
/* Your READ or WRITE operation */
ULONG len = Save("Work:page.txt", mybuffer, NULL);See Also
Implementation
The original 68020 assembly implementation:
; (15-Feb-1995) --- Save(filename,buffer,len) (a0/a1/d0)
_LVOSave
movem.l d2-d4/a2/a6,-(sp)
move.l a1,a2 ; Save Pointer to buffer
move.l d0,d3 ; Save byte len...
move.l ab_DosBase(a6),a6
move.l a0,d1
lea MODE_READWRITE.W,a0
move.l a0,d2
jsr _LVOOpen(a6)
tst.l d0
beq.s NSSEXIT
move.l d0,d4 ; Save BCPL handle
tst.l d3
bne.s UseThis
move.l -4(a2),d3 ; byte TOT
subq.l #4,d3 ; byte data to write
UseThis move.l d4,d1 ; handle
move.l a2,d2
jsr _LVOWrite(a6)
move.l d4,d1
jsr _LVOClose(a6)
move.l d3,d0
NSSEXIT movem.l (sp)+,d2-d4/a2/a6
rts