Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Files /
Chapter 2 - File Manager / File Manager Reference
High-Level File Access Routines / Reading, Writing, and Closing Files


FSRead

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;
refNum
The file reference number of an open file.
count
On input, the number of bytes to read; on output, the number of bytes actually read.
buffPtr
A pointer to the data buffer into which the bytes are to be read.
DESCRIPTION
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.

Note
The low-level PBRead function lets you set the mark without having to call SetFPos. Also, if you want to read data in newline mode, you must use PBRead instead of FSRead.
RESULT CODES
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