1 package com.tapina.robe.swi.clib.stdio;
2
3 import com.tapina.robe.runtime.Environment;
4 import com.tapina.robe.swi.clib.Stub;
5
6 import java.io.IOException;
7
8 /***
9 * This function reads the file position indicator for the file pointed to by stream. For binary files this is the
10 * number of characters from the beginning of the file, but for text files it could be anything. If there is an
11 * error, the reason is stored in errno .
12 * Returns: File pointer for stream, or -1L if there is an error.
13 */
14 public class FTell extends Stub {
15 public void executeStub(Environment environment) {
16 final int[] R = environment.getCpu().R;
17 FilePointer filePointer = FilePointer.find(environment.getMemoryMap().getWord(R[0]));
18 try {
19 R[0] = filePointer.getPosition();
20 } catch (IOException e) {
21 log.warning("Error in ftell(): " + e.getMessage());
22 R[0] = -1;
23 }
24 }
25 }