1 package com.tapina.robe.swi.clib.stdio; 2 3 import com.tapina.robe.runtime.*; 4 import com.tapina.robe.swi.clib.Stub; 5 6 import java.io.File; 7 import java.io.IOException; 8 9 /*** 10 * The function generates a original (ie not used for an exisiting file) filename. It will generate up to TMP_MAX 11 * unique names. If a1 points to an array then the name is copied into this array (which should have length of 12 * at least L_tmpnam ). If a1 is a null pointer then tmpnam creates its own array, but subsequent calls may 13 * overwrite the name. 14 * Returns: Pointer to filename. 15 */ 16 public class TmpNam extends Stub { 17 RawDataBlock tmpnamSpace = null; 18 19 public void executeStub(Environment environment) { 20 final int[] R = environment.getCpu().R; 21 try { 22 final File tmpfile = File.createTempFile("robe", ""); 23 final String acornName = FilenameUtils.nativeToAcorn(tmpfile.getCanonicalPath()); 24 final MemoryMap memoryMap = environment.getMemoryMap(); 25 if (R[0] == 0) { 26 if (tmpnamSpace != null) { 27 memoryMap.removeSystemDataBlock(tmpnamSpace); 28 } 29 tmpnamSpace = memoryMap.createSystemDataBlock(acornName); 30 R[0] = tmpnamSpace.getAddress(); 31 } else { 32 memoryMap.storeString0(R[0], acornName); 33 } 34 } catch (IOException e) { 35 log.severe("Unexpected error in tmpname(): " + e.getMessage()); 36 R[0] = 0; 37 } 38 } 39 }