Previous Book Contents Book Index Next

Inside Macintosh: Files /
Chapter 1 - Introduction to File Management / File Management Reference
File Access Routines / Reading, Writing, and Closing Files


You can use the FSRead function to read any number of bytes from an open file.

FUNCTION FSRead (refNum: Integer; VAR count: LongInt; 
                  buffPtr: Ptr): OSErr;
The file reference number of an open file.
On input, the number of bytes to read; on output, the number of bytes actually read.
A pointer to the data buffer into which the bytes are to be read.
The FSRead function attempts to read the requested number of bytes from the specified file into the specified buffer. The buffPtr parameter points to that buffer; this buffer is allocated by your application and must be at least as large as the count parameter.

Because the read operation begins at the current mark, you might want to set the mark first by calling the SetFPos function. If you try to read past the logical end-of-file, FSRead reads in all the data up to the end-of-file, moves the mark to the end-of-file, and returns eofErr as its function result. Otherwise, FSRead moves the file mark to the byte following the last byte read and returns noErr.

noErr0No error
ioErr-36I/O error
fnOpnErr-38File not open
eofErr-39Logical end-of-file reached
posErr-40Attempt to position mark before start of file
fLckdErr-45File is locked
paramErr-50Negative count
rfNumErr-51Bad reference number
afpAccessDenied-5000User does not have the correct access to the file

Previous Book Contents Book Index Next

© Apple Computer, Inc.
2 JUL 1996