Atari ST series Technical Reference Manual page 129

Hide thumbs Also See for ST series:
Table of Contents

Advertisement

#include <osbind.h>
#define F_ATTR
#define APPEND
#define READ
Idefine WRITE
char fname[ ] = "A:\TEST.FIL";
char test[]= "This is a test file";
char add[)= "nice";
main()
{
int handle;
long status;
handle = Fcreate(fname, F_ATTR);
0
if(handle<
)
Cconws("Could not create file\n\r");
else
{
status = Fwrite(handle, 19L, test);
printf("\n%ld characters written\n\n",status);
Fclose(handle) ;
handle = Fopen(fname, READ); /* read it to be sure it's there */
status = Fread(handle, 19L, test);
t e s t [status]=
Cconws(test);
printf("\n\r%ld characters read\n\n",status);
Fclose(handle);
handle = Fopen(fname, APPE N D );
status = Fseek(10L, handle, 0);
status = Fwrite(handle,4L,add);
status = Fseek(0L, handle, 0); /* and read the change */
status = Fread(handle, 19L, test);
te s t [status]=
Cconws(test);
printf("\n\r%ld characters read\n",status);
Fclose(handle);
)
/* if you're running this from the Desktop, you may want to
add a pause to give the user a chance to read the output
Cconws("\n\n\rPress any key to end");
Cconin();
)
/******** end of GFILEIO.C *****/
Notice how the count values for reads, writes, and seeks
were specified as 32-bit longwords by placing the character L
(as in 19L) next to them? It's very important to pass argu­
ments of the correct size in these functions. If you pass an
integer as the count byte, it will be assumed to be the first
word of the longword, and you'll end up with a file length
in the millions of bytes. What was intended to be only a
short file can soon fill up a floppy disk if you aren't careful.
Disk and Directory Path Functions
Besides simple reading and writing of files, GEMDOS sup­
ports a number of disk and directory path functions. These
GEMDOS File System Functions
/* For GEHDOS macro definitions */
0
/* file attribute for FCreate()
3
o
2
0
;
0
;
/* create the file */
/* if you can't, quit */
/* otherwise, write test string */
/* and print it out */
/* now change it */
/* print it out */
*/
* /
121

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents