To use, first compile ASyncIO.c using:
sc NMINC STRMERGE NOSTKCHK IGNORE=73 ASyncIO.c
which produces the ASyncIO.o file
, and then compile this example by linking to it:
sc LINK example.c LIB asyncio.o
By default, the code copies the s:user-startup
file to ram:tmp_file
.
/*************************************************************************/ /* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */ /*************************************************************************/ /* */ /* copyasync */ /* */ /* Copies a file to RAM: */ /* */ /* Depends on: ASyncIO.o, ASyncIO.h */ /* Compile using SASC: sc LINK example.c LIB asyncio.o */ /* */ /*************************************************************************/ #include <exec/types.h> #include <exec/exec.h> #include <dos/dos.h> #include <dos/dosextens.h> #include <stdio.h> #include <clib/exec_protos.h> #include <clib/dos_protos.h> #include "ASyncIO.h" #define SOURCE "s:user-startup" #define DESTINATION "ram:tmp_file" int main(void) { struct AsyncFile *i; struct AsyncFile *o; LONG c; /* Open the source file asynchronousely. */ if(!(i = OpenAsync(SOURCE, MODE_READ, 8192))) { printf("error: unable to open file.\n"); return 1; } /* Open the destination file asynchronousely. */ if(!(o = OpenAsync(DESTINATION, MODE_WRITE, 8192))) { printf("error: unable to open destination file.\n"); return 1; } /* While there is a new character in the input * write the character to the output */ while((c = ReadCharAsync(i)) >= 0) { WriteCharAsync(o, c); } /* Close handles. */ CloseAsync(o); CloseAsync(i); return 0; }