void FileSeekPos(int file, int pos, int mode)
Pass a handle to a file open in either read or write mode, an distance in bytes to move, and a mode to determine the starting position.... Pants... I'll do this later.
#define SEEK_SET 0 #define SEEK_CUR 1 #define SEEK_END 2
int file = FileOpen("readme.txt", FILE_READ); FileSeekPos(file, 25, SEEK_SET); Log(str(FileReadByte(file))); FileClose(file); // Reads the 26th byte from the start of the readme // Remeber newline markers are two characters // Logs '97' which is the ascii value of little a // "Welcome to VERGE 3! " // "(Readme.txt, 2004.09.28 edition of v3)" // ^ int file = FileOpen("dump.txt", FILE_WRITE); FileWrite(file, "Oh fuck!"); FileSeekPos(file, 0-4, SEEK_END); FileWriteByte(file, '*'); FileClose(file); // Going backwards from the end of the file // We impose a little censorship! Yeay!
Talkback #1 written by Zip on 2004-06-23.
This should move the current position in the file (int file) by offset (int pos) in bytes (?). Where you move from is set by (int mode), which takes the following values (from v3vergec.txt): {"SEEK_SET", "0" } {"SEEK_CUR", "1" } {"SEEK_END", "2" } 0 should be move from the start of the file, 1 should be move from the current position, 2 move backwards from the end of the file. This can be used on a file in either read or write mode, and is the only seek that can be used if in write. Also, either my code is funny, or it sometimes plays up. Probably the former. Zip
Doc Nav |
Your docs |