00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef OPENFILE_H
00021 #define OPENFILE_H
00022
00023 #include "copyright.h"
00024 #include "utility.h"
00025 #include "sysdep.h"
00026
00027 #ifdef FILESYS_STUB // Temporarily implement calls to
00028
00029
00030 class OpenFile {
00031 public:
00032 OpenFile(int f) { file = f; currentOffset = 0; }
00033 ~OpenFile() { Close(file); }
00034
00035 int ReadAt(char *into, int numBytes, int position) {
00036 Lseek(file, position, 0);
00037 return ReadPartial(file, into, numBytes);
00038 }
00039 int WriteAt(char *from, int numBytes, int position) {
00040 Lseek(file, position, 0);
00041 WriteFile(file, from, numBytes);
00042 return numBytes;
00043 }
00044 int Read(char *into, int numBytes) {
00045 int numRead = ReadAt(into, numBytes, currentOffset);
00046 currentOffset += numRead;
00047 return numRead;
00048 }
00049 int Write(char *from, int numBytes) {
00050 int numWritten = WriteAt(from, numBytes, currentOffset);
00051 currentOffset += numWritten;
00052 return numWritten;
00053 }
00054
00055 int Length() { Lseek(file, 0, 2); return Tell(file); }
00056
00057 private:
00058 int file;
00059 int currentOffset;
00060 };
00061
00062 #else // FILESYS
00063 class FileHeader;
00064
00065 class OpenFile {
00066 public:
00067 OpenFile(int sector);
00068
00069 ~OpenFile();
00070
00071 void Seek(int position);
00072
00073
00074 int Read(char *into, int numBytes);
00075
00076
00077
00078 int Write(char *from, int numBytes);
00079
00080 int ReadAt(char *into, int numBytes, int position);
00081
00082
00083 int WriteAt(char *from, int numBytes, int position);
00084
00085 int Length();
00086
00087
00088
00089
00090 private:
00091 FileHeader *hdr;
00092 int seekPosition;
00093 };
00094
00095 #endif // FILESYS
00096
00097 #endif // OPENFILE_H