1afc2ba1Toomas Soome#include "ficl.h"
2afc2ba1Toomas Soome
3afc2ba1Toomas Soome#if FICL_WANT_FILE
4afc2ba1Toomas Soome/*
5afc2ba1Toomas Soome * fileaccess.c
6afc2ba1Toomas Soome *
7afc2ba1Toomas Soome * Implements all of the File Access word set that can be implemented in
8afc2ba1Toomas Soome * portable C.
9afc2ba1Toomas Soome */
10afc2ba1Toomas Soome
11afc2ba1Toomas Soomestatic void
12afc2ba1Toomas SoomepushIor(ficlVm *vm, int success)
13afc2ba1Toomas Soome{
14afc2ba1Toomas Soome	int ior;
15afc2ba1Toomas Soome	if (success)
16afc2ba1Toomas Soome		ior = 0;
17afc2ba1Toomas Soome	else
18afc2ba1Toomas Soome		ior = errno;
19afc2ba1Toomas Soome	ficlStackPushInteger(vm->dataStack, ior);
20afc2ba1Toomas Soome}
21afc2ba1Toomas Soome
22afc2ba1Toomas Soome/* ( c-addr u fam -- fileid ior ) */
23afc2ba1Toomas Soomestatic void
24afc2ba1Toomas SoomeficlFileOpen(ficlVm *vm, char *writeMode)
25afc2ba1Toomas Soome{
26afc2ba1Toomas Soome	int fam = ficlStackPopInteger(vm->dataStack);
27afc2ba1Toomas Soome	int length = ficlStackPopInteger(vm->dataStack);
28afc2ba1Toomas Soome	void *address = (void *)ficlStackPopPointer(vm->dataStack);
29afc2ba1Toomas Soome	char mode[4];
30afc2ba1Toomas Soome	FILE *f;
31afc2ba1Toomas Soome	char *filename = (char *)malloc(length + 1);
32afc2ba1Toomas Soome	memcpy(filename, address, length);
33afc2ba1Toomas Soome	filename[length] = 0;
34afc2ba1Toomas Soome
35afc2ba1Toomas Soome	*mode = 0;
36afc2ba1Toomas Soome
37afc2ba1Toomas Soome	switch (FICL_FAM_OPEN_MODE(fam)) {
38afc2ba1Toomas Soome	case 0:
39afc2ba1Toomas Soome		ficlStackPushPointer(vm->dataStack, NULL);
40afc2ba1Toomas Soome		ficlStackPushInteger(vm->dataStack, EINVAL);
41afc2ba1Toomas Soome	goto EXIT;
42afc2ba1Toomas Soome	case FICL_FAM_READ:
43afc2ba1Toomas Soome		strcat(mode, "r");
44afc2ba1Toomas Soome	break;
45afc2ba1Toomas Soome	case FICL_FAM_WRITE:
46afc2ba1Toomas Soome		strcat(mode, writeMode);
47afc2ba1Toomas Soome	break;
48afc2ba1Toomas Soome	case FICL_FAM_READ | FICL_FAM_WRITE:
49afc2ba1Toomas Soome		strcat(mode, writeMode);
50afc2ba1Toomas Soome		strcat(mode, "+");
51afc2ba1Toomas Soome	break;
52afc2ba1Toomas Soome	}
53afc2ba1Toomas Soome
54afc2ba1Toomas Soome	strcat(mode, (fam & FICL_FAM_BINARY) ? "b" : "t");
55afc2ba1Toomas Soome
56afc2ba1Toomas Soome	f = fopen(filename, mode);
57afc2ba1Toomas Soome	if (f == NULL)
58afc2ba1Toomas Soome		ficlStackPushPointer(vm->dataStack, NULL);
59afc2ba1Toomas Soome	else {
60afc2ba1Toomas Soome		ficlFile *ff = (ficlFile *)malloc(sizeof (ficlFile));
61afc2ba1Toomas Soome		strcpy(ff->filename, filename);
62afc2ba1Toomas Soome		ff->f = f;
63afc2ba1Toomas Soome		ficlStackPushPointer(vm->dataStack, ff);
64afc2ba1Toomas Soome
65afc2ba1Toomas Soome		fseek(f, 0, SEEK_SET);
66afc2ba1Toomas Soome	}
67afc2ba1Toomas Soome	pushIor(vm, f != NULL);
68afc2ba1Toomas Soome
69afc2ba1Toomas SoomeEXIT:
70afc2ba1Toomas Soome	free(filename);
71afc2ba1Toomas Soome}
72afc2ba1Toomas Soome
73afc2ba1Toomas Soome/* ( c-addr u fam -- fileid ior ) */
74afc2ba1Toomas Soomestatic void
75afc2ba1Toomas SoomeficlPrimitiveOpenFile(ficlVm *vm)
76afc2ba1Toomas Soome{
77afc2ba1Toomas Soome	ficlFileOpen(vm, "a");
78afc2ba1Toomas Soome}
79afc2ba1Toomas Soome
80afc2ba1Toomas Soome/* ( c-addr u fam -- fileid ior ) */
81afc2ba1Toomas Soomestatic void
82afc2ba1Toomas SoomeficlPrimitiveCreateFile(ficlVm *vm)
83afc2ba1Toomas Soome{
84afc2ba1Toomas Soome	ficlFileOpen(vm, "w");
85afc2ba1Toomas Soome}
86afc2ba1Toomas Soome
87afc2ba1Toomas Soome/* ( fileid -- ior ) */
88afc2ba1Toomas Soomestatic int
89afc2ba1Toomas SoomeficlFileClose(ficlFile *ff)
90afc2ba1Toomas Soome{
91afc2ba1Toomas Soome	FILE *f = ff->f;
92afc2ba1Toomas Soome	free(ff);
93afc2ba1Toomas Soome	return (!fclose(f));
94afc2ba1Toomas Soome}
95afc2ba1Toomas Soome
96afc2ba1Toomas Soome/* ( fileid -- ior ) */
97afc2ba1Toomas Soomestatic void
98afc2ba1Toomas SoomeficlPrimitiveCloseFile(ficlVm *vm)
99afc2ba1Toomas Soome{
100afc2ba1Toomas Soome	ficlFile *ff = (ficlFile *)ficlStackPopPointer(vm->dataStack);
101afc2ba1Toomas Soome	pushIor(vm, ficlFileClose(ff));
102afc2ba1Toomas Soome}
103afc2ba1Toomas Soome
104afc2ba1Toomas Soome/* ( c-addr u -- ior ) */
105afc2ba1Toomas Soomestatic void
106afc2ba1Toomas SoomeficlPrimitiveDeleteFile(ficlVm *vm)
107afc2ba1Toomas Soome{
108afc2ba1Toomas Soome	int length = ficlStackPopInteger(vm->dataStack);
109afc2ba1Toomas Soome	void *address = (void *)ficlStackPopPointer(vm->dataStack);
110afc2ba1Toomas Soome
111afc2ba1Toomas Soome	char *filename = (char *)malloc(length + 1);
112afc2ba1Toomas Soome	memcpy(filename, address, length);
113afc2ba1Toomas Soome	filename[length] = 0;
114afc2ba1Toomas Soome
115afc2ba1Toomas Soome	pushIor(vm, !unlink(filename));
116afc2ba1Toomas Soome	free(filename);
117afc2ba1Toomas Soome}
118afc2ba1Toomas Soome
119afc2ba1Toomas Soome/* ( c-addr1 u1 c-addr2 u2 -- ior ) */
120afc2ba1Toomas Soomestatic void
121afc2ba1Toomas SoomeficlPrimitiveRenameFile(ficlVm *vm)
122afc2ba1Toomas Soome{
123afc2ba1Toomas Soome	int length;
124afc2ba1Toomas Soome	void *address;
125afc2ba1Toomas Soome	char *from;
126afc2ba1Toomas Soome	char *to;
127afc2ba1Toomas Soome
128afc2ba1Toomas Soome	length = ficlStackPopInteger(vm->dataStack);
129afc2ba1Toomas Soome	address = (void *)ficlStackPopPointer(vm->dataStack);
130afc2ba1Toomas Soome	to = (char *)malloc(length + 1);
131afc2ba1Toomas Soome	memcpy(to, address, length);
132afc2ba1Toomas Soome	to[length] = 0;
133afc2ba1Toomas Soome
134afc2ba1Toomas Soome	length = ficlStackPopInteger(vm->dataStack);
135afc2ba1Toomas Soome	address = (void *)ficlStackPopPointer(vm->dataStack);
136afc2ba1Toomas Soome
137afc2ba1Toomas Soome	from = (char *)malloc(length + 1);
138afc2ba1Toomas Soome	memcpy(from, address, length);
139afc2ba1Toomas Soome	from[length] = 0;
140afc2ba1Toomas Soome
141afc2ba1Toomas Soome	pushIor(vm, !rename(from, to));
142afc2ba1Toomas Soome
143afc2ba1Toomas Soome	free(from);
144afc2ba1Toomas Soome	free(to);
145afc2ba1Toomas Soome}
146afc2ba1Toomas Soome
147afc2ba1Toomas Soome/* ( c-addr u -- x ior ) */
148afc2ba1Toomas Soomestatic void
149afc2ba1Toomas SoomeficlPrimitiveFileStatus(ficlVm *vm)
150afc2ba1Toomas Soome{
151afc2ba1Toomas Soome	int status;
152afc2ba1Toomas Soome	int ior;
153afc2ba1Toomas Soome
154afc2ba1Toomas Soome	int length = ficlStackPopInteger(vm->dataStack);
155afc2ba1Toomas Soome	void *address = (void *)ficlStackPopPointer(vm->dataStack);
156afc2ba1Toomas Soome
157afc2ba1Toomas Soome	char *filename = (char *)malloc(length + 1);
158afc2ba1Toomas Soome	memcpy(filename, address, length);
159afc2ba1Toomas Soome	filename[length] = 0;
160afc2ba1Toomas Soome
161afc2ba1Toomas Soome	ior = ficlFileStatus(filename, &status);
162afc2ba1Toomas Soome	free(filename);
163afc2ba1Toomas Soome
164afc2ba1Toomas Soome	ficlStackPushInteger(vm->dataStack, status);
165afc2ba1Toomas Soome	ficlStackPushInteger(vm->dataStack, ior);
166afc2ba1Toomas Soome}
167afc2ba1Toomas Soome
168afc2ba1Toomas Soome/* ( fileid -- ud ior ) */
169afc2ba1Toomas Soomestatic void
170afc2ba1Toomas SoomeficlPrimitiveFilePosition(ficlVm *vm)
171afc2ba1Toomas Soome{
172afc2ba1Toomas Soome	ficlFile *ff = (ficlFile *)ficlStackPopPointer(vm->dataStack);
173afc2ba1Toomas Soome	long ud = ftell(ff->f);
174afc2ba1Toomas Soome	ficlStackPushInteger(vm->dataStack, ud);
175afc2ba1Toomas Soome	pushIor(vm, ud != -1);
176afc2ba1Toomas Soome}
177afc2ba1Toomas Soome
178afc2ba1Toomas Soome/* ( fileid -- ud ior ) */
179afc2ba1Toomas Soomestatic void
180afc2ba1Toomas SoomeficlPrimitiveFileSize(ficlVm *vm)
181afc2ba1Toomas Soome{
182afc2ba1Toomas Soome	ficlFile *ff = (ficlFile *)ficlStackPopPointer(vm->dataStack);
183afc2ba1Toomas Soome	long ud = ficlFileSize(ff);
184afc2ba1Toomas Soome	ficlStackPushInteger(vm->dataStack, ud);
185afc2ba1Toomas Soome	pushIor(vm, ud != -1);
186afc2ba1Toomas Soome}
187afc2ba1Toomas Soome
188afc2ba1Toomas Soome/* ( i*x fileid -- j*x ) */
189afc2ba1Toomas Soome#define	nLINEBUF	256
190afc2ba1Toomas Soomestatic void
191afc2ba1Toomas SoomeficlPrimitiveIncludeFile(ficlVm *vm)
192afc2ba1Toomas Soome{
193afc2ba1Toomas Soome	ficlFile *ff = (ficlFile *)ficlStackPopPointer(vm->dataStack);
194afc2ba1Toomas Soome	ficlCell id = vm->sourceId;
195afc2ba1Toomas Soome	int  except = FICL_VM_STATUS_OUT_OF_TEXT;
196afc2ba1Toomas Soome	long currentPosition, totalSize;
197afc2ba1Toomas Soome	long size;
198afc2ba1Toomas Soome	ficlString s;
199afc2ba1Toomas Soome	vm->sourceId.p = (void *)ff;
200afc2ba1Toomas Soome
201afc2ba1Toomas Soome	currentPosition = ftell(ff->f);
202afc2ba1Toomas Soome	totalSize = ficlFileSize(ff);
203afc2ba1Toomas Soome	size = totalSize - currentPosition;
204afc2ba1Toomas Soome
205afc2ba1Toomas Soome	if ((totalSize != -1) && (currentPosition != -1) && (size > 0)) {
206afc2ba1Toomas Soome		char *buffer = (char *)malloc(size);
207afc2ba1Toomas Soome		long got = fread(buffer, 1, size, ff->f);
208afc2ba1Toomas Soome		if (got == size) {
209afc2ba1Toomas Soome			FICL_STRING_SET_POINTER(s, buffer);
210afc2ba1Toomas Soome			FICL_STRING_SET_LENGTH(s, size);
211afc2ba1Toomas Soome			except = ficlVmExecuteString(vm, s);
212afc2ba1Toomas Soome		}
213afc2ba1Toomas Soome	}
214afc2ba1Toomas Soome
215afc2ba1Toomas Soome	if ((except < 0) && (except != FICL_VM_STATUS_OUT_OF_TEXT))
216afc2ba1Toomas Soome		ficlVmThrow(vm, except);
217afc2ba1Toomas Soome
218afc2ba1Toomas Soome	/*
219afc2ba1Toomas Soome	 * Pass an empty line with SOURCE-ID == -1 to flush
220afc2ba1Toomas Soome	 * any pending REFILLs (as required by FILE wordset)
221afc2ba1Toomas Soome	 */
222afc2ba1Toomas Soome	vm->sourceId.i = -1;
223afc2ba1Toomas Soome	FICL_STRING_SET_FROM_CSTRING(s, "");
224afc2ba1Toomas Soome	ficlVmExecuteString(vm, s);
225afc2ba1Toomas Soome
226afc2ba1Toomas Soome	vm->sourceId = id;
227afc2ba1Toomas Soome	ficlFileClose(ff);
228afc2ba1Toomas Soome}
229afc2ba1Toomas Soome
230afc2ba1Toomas Soome/* ( c-addr u1 fileid -- u2 ior ) */
231afc2ba1Toomas Soomestatic void
232afc2ba1Toomas SoomeficlPrimitiveReadFile(ficlVm *vm)
233afc2ba1Toomas Soome{
234afc2ba1Toomas Soome	ficlFile *ff = (ficlFile *)ficlStackPopPointer(vm->dataStack);
235afc2ba1Toomas Soome	int length = ficlStackPopInteger(vm->dataStack);
236afc2ba1Toomas Soome	void *address = (void *)ficlStackPopPointer(vm->dataStack);
237afc2ba1Toomas Soome	int result;
238afc2ba1Toomas Soome
239afc2ba1Toomas Soome	clearerr(ff->f);
240afc2ba1Toomas Soome	result = fread(address, 1, length, ff->f);
241afc2ba1Toomas Soome
242afc2ba1Toomas Soome	ficlStackPushInteger(vm->dataStack, result);
243afc2ba1Toomas Soome	pushIor(vm, ferror(ff->f) == 0);
244afc2ba1Toomas Soome}
245afc2ba1Toomas Soome
246afc2ba1Toomas Soome/* ( c-addr u1 fileid -- u2 flag ior ) */
247afc2ba1Toomas Soomestatic void
248afc2ba1Toomas SoomeficlPrimitiveReadLine(ficlVm *vm)
249afc2ba1Toomas Soome{
250afc2ba1Toomas Soome	ficlFile *ff = (ficlFile *)ficlStackPopPointer(vm->dataStack);
251afc2ba1Toomas Soome	int length = ficlStackPopInteger(vm->dataStack);
252afc2ba1Toomas Soome	char *address = (char *)ficlStackPopPointer(vm->dataStack);
253afc2ba1Toomas Soome	int error;
254afc2ba1Toomas Soome	int flag;
255afc2ba1Toomas Soome
256afc2ba1Toomas Soome	if (feof(ff->f)) {
257afc2ba1Toomas Soome		ficlStackPushInteger(vm->dataStack, -1);
258afc2ba1Toomas Soome		ficlStackPushInteger(vm->dataStack, 0);
259afc2ba1Toomas Soome		ficlStackPushInteger(vm->dataStack, 0);
260afc2ba1Toomas Soome		return;
261afc2ba1Toomas Soome	}
262afc2ba1Toomas Soome
263afc2ba1Toomas Soome	clearerr(ff->f);
264afc2ba1Toomas Soome	*address = 0;
265afc2ba1Toomas Soome	fgets(address, length, ff->f);
266afc2ba1Toomas Soome
267afc2ba1Toomas Soome	error = ferror(ff->f);
268afc2ba1Toomas Soome	if (error != 0) {
269afc2ba1Toomas Soome		ficlStackPushInteger(vm->dataStack, -1);
270afc2ba1Toomas Soome		ficlStackPushInteger(vm->dataStack, 0);
271afc2ba1Toomas Soome		ficlStackPushInteger(vm->dataStack, error);
272afc2ba1Toomas Soome		return;
273afc2ba1Toomas Soome	}
274afc2ba1Toomas Soome
275afc2ba1Toomas Soome	length = strlen(address);
276afc2ba1Toomas Soome	flag = (length > 0);
277afc2ba1Toomas Soome	if (length && ((address[length - 1] == '\r') ||
278afc2ba1Toomas Soome	    (address[length - 1] == '\n')))
279afc2ba1Toomas Soome		length--;
280afc2ba1Toomas Soome
281afc2ba1Toomas Soome	ficlStackPushInteger(vm->dataStack, length);
282afc2ba1Toomas Soome	ficlStackPushInteger(vm->dataStack, flag);
283afc2ba1Toomas Soome	ficlStackPushInteger(vm->dataStack, 0); /* ior */
284afc2ba1Toomas Soome}
285afc2ba1Toomas Soome
286afc2ba1Toomas Soome/* ( c-addr u1 fileid -- ior ) */
287afc2ba1Toomas Soomestatic void
288afc2ba1Toomas SoomeficlPrimitiveWriteFile(ficlVm *vm)
289afc2ba1Toomas Soome{
290afc2ba1Toomas Soome	ficlFile *ff = (ficlFile *)ficlStackPopPointer(vm->dataStack);
291afc2ba1Toomas Soome	int length = ficlStackPopInteger(vm->dataStack);
292afc2ba1Toomas Soome	void *address = (void *)ficlStackPopPointer(vm->dataStack);
293afc2ba1Toomas Soome
294afc2ba1Toomas Soome	clearerr(ff->f);
295afc2ba1Toomas Soome	fwrite(address, 1, length, ff->f);
296afc2ba1Toomas Soome	pushIor(vm, ferror(ff->f) == 0);
297afc2ba1Toomas Soome}
298afc2ba1Toomas Soome
299afc2ba1Toomas Soome/* ( c-addr u1 fileid -- ior ) */
300afc2ba1Toomas Soomestatic void
301afc2ba1Toomas SoomeficlPrimitiveWriteLine(ficlVm *vm)
302afc2ba1Toomas Soome{
303afc2ba1Toomas Soome	ficlFile *ff = (ficlFile *)ficlStackPopPointer(vm->dataStack);
304afc2ba1Toomas Soome	size_t length = (size_t)ficlStackPopInteger(vm->dataStack);
305afc2ba1Toomas Soome	void *address = (void *)ficlStackPopPointer(vm->dataStack);
306afc2ba1Toomas Soome
307afc2ba1Toomas Soome	clearerr(ff->f);
308afc2ba1Toomas Soome	if (fwrite(address, 1, length, ff->f) == length)
309afc2ba1Toomas Soome		fwrite("\n", 1, 1, ff->f);
310afc2ba1Toomas Soome	pushIor(vm, ferror(ff->f) == 0);
311afc2ba1Toomas Soome}
312afc2ba1Toomas Soome
313afc2ba1Toomas Soome/* ( ud fileid -- ior ) */
314afc2ba1Toomas Soomestatic void
315afc2ba1Toomas SoomeficlPrimitiveRepositionFile(ficlVm *vm)
316afc2ba1Toomas Soome{
317afc2ba1Toomas Soome	ficlFile *ff = (ficlFile *)ficlStackPopPointer(vm->dataStack);
318afc2ba1Toomas Soome	size_t ud = (size_t)ficlStackPopInteger(vm->dataStack);
319afc2ba1Toomas Soome
320afc2ba1Toomas Soome	pushIor(vm, fseek(ff->f, ud, SEEK_SET) == 0);
321afc2ba1Toomas Soome}
322afc2ba1Toomas Soome
323afc2ba1Toomas Soome/* ( fileid -- ior ) */
324afc2ba1Toomas Soomestatic void
325afc2ba1Toomas SoomeficlPrimitiveFlushFile(ficlVm *vm)
326afc2ba1Toomas Soome{
327afc2ba1Toomas Soome	ficlFile *ff = (ficlFile *)ficlStackPopPointer(vm->dataStack);
328afc2ba1Toomas Soome	pushIor(vm, fflush(ff->f) == 0);
329afc2ba1Toomas Soome}
330afc2ba1Toomas Soome
331afc2ba1Toomas Soome#if FICL_PLATFORM_HAS_FTRUNCATE
332afc2ba1Toomas Soome/* ( ud fileid -- ior ) */
333afc2ba1Toomas Soomestatic void
334afc2ba1Toomas SoomeficlPrimitiveResizeFile(ficlVm *vm)
335afc2ba1Toomas Soome{
336afc2ba1Toomas Soome	ficlFile *ff = (ficlFile *)ficlStackPopPointer(vm->dataStack);
337afc2ba1Toomas Soome	size_t ud = (size_t)ficlStackPopInteger(vm->dataStack);
338afc2ba1Toomas Soome
339afc2ba1Toomas Soome	pushIor(vm, ficlFileTruncate(ff, ud) == 0);
340afc2ba1Toomas Soome}
341afc2ba1Toomas Soome#endif /* FICL_PLATFORM_HAS_FTRUNCATE */
342afc2ba1Toomas Soome#endif /* FICL_WANT_FILE */
343afc2ba1Toomas Soome
344afc2ba1Toomas Soomevoid
345afc2ba1Toomas SoomeficlSystemCompileFile(ficlSystem *system)
346afc2ba1Toomas Soome{
347afc2ba1Toomas Soome#if !FICL_WANT_FILE
348afc2ba1Toomas Soome	FICL_IGNORE(system);
349afc2ba1Toomas Soome#else
350afc2ba1Toomas Soome	ficlDictionary *dictionary = ficlSystemGetDictionary(system);
351afc2ba1Toomas Soome	ficlDictionary *environment = ficlSystemGetEnvironment(system);
352afc2ba1Toomas Soome
353afc2ba1Toomas Soome	FICL_SYSTEM_ASSERT(system, dictionary);
354afc2ba1Toomas Soome	FICL_SYSTEM_ASSERT(system, environment);
355afc2ba1Toomas Soome
356afc2ba1Toomas Soome	ficlDictionarySetPrimitive(dictionary, "create-file",
357afc2ba1Toomas Soome	    ficlPrimitiveCreateFile,  FICL_WORD_DEFAULT);
358afc2ba1Toomas Soome	ficlDictionarySetPrimitive(dictionary, "open-file",
359afc2ba1Toomas Soome	    ficlPrimitiveOpenFile,  FICL_WORD_DEFAULT);
360afc2ba1Toomas Soome	ficlDictionarySetPrimitive(dictionary, "close-file",
361afc2ba1Toomas Soome	    ficlPrimitiveCloseFile,  FICL_WORD_DEFAULT);
362afc2ba1Toomas Soome	ficlDictionarySetPrimitive(dictionary, "include-file",
363afc2ba1Toomas Soome	    ficlPrimitiveIncludeFile,  FICL_WORD_DEFAULT);
364afc2ba1Toomas Soome	ficlDictionarySetPrimitive(dictionary, "read-file",
365afc2ba1Toomas Soome	    ficlPrimitiveReadFile,  FICL_WORD_DEFAULT);
366afc2ba1Toomas Soome	ficlDictionarySetPrimitive(dictionary, "read-line",
367afc2ba1Toomas Soome	    ficlPrimitiveReadLine,  FICL_WORD_DEFAULT);
368afc2ba1Toomas Soome	ficlDictionarySetPrimitive(dictionary, "write-file",
369afc2ba1Toomas Soome	    ficlPrimitiveWriteFile,  FICL_WORD_DEFAULT);
370afc2ba1Toomas Soome	ficlDictionarySetPrimitive(dictionary, "write-line",
371afc2ba1Toomas Soome	    ficlPrimitiveWriteLine,  FICL_WORD_DEFAULT);
372afc2ba1Toomas Soome	ficlDictionarySetPrimitive(dictionary, "file-position",
373afc2ba1Toomas Soome	    ficlPrimitiveFilePosition,  FICL_WORD_DEFAULT);
374afc2ba1Toomas Soome	ficlDictionarySetPrimitive(dictionary, "file-size",
375afc2ba1Toomas Soome	    ficlPrimitiveFileSize,  FICL_WORD_DEFAULT);
376afc2ba1Toomas Soome	ficlDictionarySetPrimitive(dictionary, "reposition-file",
377afc2ba1Toomas Soome	    ficlPrimitiveRepositionFile,  FICL_WORD_DEFAULT);
378afc2ba1Toomas Soome	ficlDictionarySetPrimitive(dictionary, "file-status",
379afc2ba1Toomas Soome	    ficlPrimitiveFileStatus,  FICL_WORD_DEFAULT);
380afc2ba1Toomas Soome	ficlDictionarySetPrimitive(dictionary, "flush-file",
381afc2ba1Toomas Soome	    ficlPrimitiveFlushFile,  FICL_WORD_DEFAULT);
382afc2ba1Toomas Soome
383afc2ba1Toomas Soome	ficlDictionarySetPrimitive(dictionary, "delete-file",
384afc2ba1Toomas Soome	    ficlPrimitiveDeleteFile,  FICL_WORD_DEFAULT);
385afc2ba1Toomas Soome	ficlDictionarySetPrimitive(dictionary, "rename-file",
386afc2ba1Toomas Soome	    ficlPrimitiveRenameFile,  FICL_WORD_DEFAULT);
387afc2ba1Toomas Soome
388afc2ba1Toomas Soome#if FICL_PLATFORM_HAS_FTRUNCATE
389afc2ba1Toomas Soome	ficlDictionarySetPrimitive(dictionary, "resize-file",
390afc2ba1Toomas Soome	    ficlPrimitiveResizeFile,  FICL_WORD_DEFAULT);
391afc2ba1Toomas Soome
392afc2ba1Toomas Soome	ficlDictionarySetConstant(environment, "file", FICL_TRUE);
393afc2ba1Toomas Soome	ficlDictionarySetConstant(environment, "file-ext", FICL_TRUE);
394afc2ba1Toomas Soome#else /*  FICL_PLATFORM_HAS_FTRUNCATE */
395afc2ba1Toomas Soome	ficlDictionarySetConstant(environment, "file", FICL_FALSE);
396afc2ba1Toomas Soome	ficlDictionarySetConstant(environment, "file-ext", FICL_FALSE);
397afc2ba1Toomas Soome#endif /* FICL_PLATFORM_HAS_FTRUNCATE */
398afc2ba1Toomas Soome
399afc2ba1Toomas Soome#endif /* !FICL_WANT_FILE */
400afc2ba1Toomas Soome}