-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile-pc.cpp
23 lines (18 loc) · 870 Bytes
/
file-pc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "c4a.h"
#ifdef FILE_PC
// Support for files
cell inputFp, outputFp;
extern char *toIn;
FILE *makeIn(cell fh) { return fh ? (FILE*)fh: stdin; }
FILE *makeOut(cell fh) { return fh ? (FILE*)fh: stdout; }
cell fileOpen(const char *name, const char *mode) { return (cell)fopen(name, mode); }
void fileClose(cell fh) { fclose((FILE*)fh); }
cell fileSize(cell fh) { fseek((FILE*)fh, 0, SEEK_END); return filePos(fh); }
void fileDelete(const char *name) { remove(name); }
cell fileRead(char *buf, int sz, cell fh) { return fread(buf, 1, sz, makeIn(fh)); }
cell fileWrite(char *buf, int sz, cell fh) { return fwrite(buf, 1, sz, makeOut(fh)); }
cell fileSeek(cell fh, cell pos) { return fseek((FILE*)fh,pos,SEEK_SET) ? 1 : 0; }
cell filePos(cell fh) { return ftell((FILE*)fh); }
void fileInit() { blockInit(); }
void fileExit() { flushBlocks(0); }
#endif // FILE_PC