FSF.MkTemp

Far Manager

MkTemp

The FSF.MkTemp function is used to create a temporary file name with the path based on a specified template.
char* WINAPI MkTemp(
  char *Dest,
  const char *Prefix
);

Parameters

Dest
Pointer to buffer to receive the temporary file name. It must be large enough to hold the resulting string (the path to the temporary directory + 12 characters for the name of the temporary file).
Prefix
Points to a null-terminated prefix string. At most four leading characters from that string will be used as the filename prefix. FAR will pad the prefix with zeroes if its length is less than 4 bytes.
If Prefix is NULL or points to an empty string, the standard prefix "FTMP" will be used.

Return value

Pointer to Dest containing the temporary file name, or NULL if function has failed. A possible reason for the failure is that the temporary directory contains too many files and should be cleaned.

Remarks

  1. The temporary file name is obtained by concatenating the temporary directory path (returned by the GetTempPath Windows API function), the prefix passed to the function and several random hexadecimal digits. The name has the following format:

    PrefXXXP.PTT

    where
       Pref - Pref is the 4-character prefix;
       XXX - three random hexadecimal digits;
       PP - two hexagemical digits from process ID (returned by the GetCurrentProcessId Windows API function);
       TT - two hexagemical digits from thread ID (returned by the GetCurrentThreadId Windows API function).

  2. Unlike in FAR 1.70 beta 3, this function does not create the file on the disk; it only generates the name.
  3. In FAR 1.70 beta 3, this function used only the first three characters of the prefix.

Example

char TempName[NM];

FSF.MkTemp(TempName,NULL);        -> "FTMP000D.P50"
FSF.MkTemp(TempName,"");          -> "FTMP000D.P50"
FSF.MkTemp(TempName,"MY");        -> "MY00000D.P50"
FSF.MkTemp(TempName,"BaR");       -> "BAR0000D.P50"
FSF.MkTemp(TempName,"TstPlugin"); -> "TSTP000D.P50"