[fpc-pascal] Temporary Filenames in GO32

Tomas Hajny XHajT03 at mbox.vol.cz
Thu Oct 12 19:38:47 CEST 2006

Jason P Sage wrote:
> I read an old thread about how to make temporary filenames (unique
> filenames
> My algorithm is platform independent but I know my technique may be
> frowned
> upon by many but it works.
> I create a file called something intuitive: counterlockfile.lock
> Each call to my unit TRIES to open the file for REWRITE - if it can't
> (because another process has it - then it retries a few times with a
> sleep/yield call and both the repeat attempts and sleep duration are
> configurable.

Actually, I don't think your solution really is platform independent. The
main reason for that is that file locking doesn't work the same way on
different platforms, so in fact you can have 2 processes having the same
file open for writing on some platforms.

In addition to that, your approach doesn't seem to be very efficient from
my point of view, because it implies additional disk accesses.
Furthermore, it only works across programs created with the same unit,
whereas other programs not using your unit (and possibly not created with
FPC at all) could easily create files with the same name, thus uniqueness
is not really guaranteed.

SysUtils.GetTempFileName is supposed to provide you with such filename,
but the appropriate platform specific implementation for GO32v2 is
currently missing (i.e. only general version not necessarily guaranteeing
uniqueness is in place). I guess I could fix that, because the appropriate
API is provided by DOS, but I'd need to check the real implementation to
make sure that it really works properly for multiple emulated DOS virtual
DOS machines/sessions running under a different operating system.


More information about the fpc-pascal mailing list