1 package com.tapina.robe.swi.clib.stdio;
2
3 import com.tapina.robe.runtime.Environment;
4 import com.tapina.robe.runtime.MemoryMap;
5 import com.tapina.robe.swi.clib.Stub;
6
7 import java.io.IOException;
8
9 /***
10 * This function causes any buffered output data to be written to the file pointed to by a1, but only if the last
11 * operation on the file was not input. If a1 is a null pointer, flushing occurs on all open streams.
12 * Returns: EOF if any data is written out, or zero if not.
13 */
14 public class FFlush extends Stub {
15 public void executeStub(Environment environment) {
16 final int[] R = environment.getCpu().R;
17 final MemoryMap memoryMap = environment.getMemoryMap();
18 if (R[0] == 0) {
19 log.warning("Cannot fflush(NULL) yet... ignoring!");
20 } else {
21 final FilePointer filePointer = FilePointer.find(memoryMap.getWord(R[0]));
22 try {
23 filePointer.flush();
24 R[0] = -1;
25 } catch (IOException e) {
26 log.warning("Error during fflush(): " + e.getMessage());
27 R[0] = 0;
28 }
29 }
30 }
31 }