Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2001-11

Temporary file names under GO32

9 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Aitor Santamaria Merino

Has anyone ever written a function to get a temporary unique file name? DOS has a function:
Int $21, AH=$5A
http://www.ctyme.com/intr/rb-3014.htm

but as I am not acquantied with the FILE records, and where the handle is stored, I was wondering if someone has ever done this.

Otherwise, I suppose I can always make a function based on current date/time...

Aitor

Ralf A. Quint
to Nico Aragon
you wrote 8 lines
Hola, >Has anyone ever written a function to get a temporary unique file name? In Windows there're GetTempFileName and GetTempFileName32. For Linux, a hint: I heard that Borland had used somebody else's algorithm to implement GUIDs. Implementation could be in FreeCLX.

Well, Nico, that all doesn't help Aitor at all, as you can see in the subject, he is asking for a solution for the GO32 version of the compiler, so neither your hint for Windows or Linux apply here..... :-(((

Ralf

Unknown author
to Nico Aragon: In Windows there're GetTempFileName and GetTempFileName32. For Linux, a hint: I heard…
Nico Aragon wrote 8 lines
Hola, >Has anyone ever written a function to get a temporary unique file name? In Windows there're GetTempFileName and GetTempFileName32. For Linux, a hint: I heard that Borland had used somebody else's algorithm to implement GUIDs. Implementation could be in FreeCLX.

Simply use the tmpnam function from libc:

Function tmpnam (s : pchar) : pchar;cdecl;external 'c';
s may point to a buffer in which the filename is be copied;

Michael.

Aitor Santamaria Merino
to Ralf A. Quint: Well, Nico, that all doesn't help Aitor at all, as you can see in the subject, he is…

Ok, as I started the thread, here we go with a home-made one. It produces dull names formed by letters (not neccessarily filenames), which are unique UP TO a second of difference... I would have to modify it, as if one needed to produce several TEMP files at once, it would be a problem:

FUNCTION GetTempName: string;
type
      a4 = array[1..4] of byte;
var
    dw,s100: word;
    td   : datetime;
    pack : longint;
    name : string;
    i    : byte;
begin
      getdate (td.year,td.month,td.day,dw);
      gettime (td.hour,td.min,td.sec,s100);
      packtime (td, pack);
      name := '';
      for i:=1 to 8 do
         if (i mod 8)=1
             then name := name + chr (ord('A')+ (a4(pack)[((i-1) div 2)
+1] and 15))
             else name := name + chr (ord('A')+ (a4(pack)[((i-1) div 2)
+1] >> 4));
      GetTempName := name
end;

WAIT, WAIT!! it compiles and seems to work??? ONE QUESTION: if you look carefully, you'll see that a C operator has slipped in (sorry): >> Does it mean that this operator is accepted in FPK as well? Anyway, I will change it to SHR...

Aitor

Ralf A. Quint wrote 23 lines
At 12:34 PM 11/25/2001, you wrote: > Hola, > > >Has anyone ever written a function to get a temporary unique file name? > > In Windows there're GetTempFileName and GetTempFileName32. > > For Linux, a hint: I heard that Borland had used somebody else's > algorithm to implement GUIDs. Implementation could be in FreeCLX. Well, Nico, that all doesn't help Aitor at all, as you can see in the subject, he is asking for a solution for the GO32 version of the compiler, so neither your hint for Windows or Linux apply here..... :-((( Ralf _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Aitor Santamar�a
Show quoted text 16 lines
> Hola, > > >Has anyone ever written a function to get a temporary unique file name? > > In Windows there're GetTempFileName and GetTempFileName32. > > For Linux, a hint: I heard that Borland had used somebody else's > algorithm to implement GUIDs. Implementation could be in FreeCLX. Simply use the tmpnam function from libc: Function tmpnam (s : pchar) : pchar;cdecl;external 'c'; s may point to a buffer in which the filename is be copied;

Well, thanks to all for the contribution, but my priority is it to be GO32V2, does it work under this platform?

Aitor
_____________________________________________________________________ Si no encuentras lo que buscas... �a qu� est�s esperando para entrar en www.wanadoo.es? Con nuestro nuevo motor de b�squeda conseguir�s m�s r�pido resultados de actualidad, personalizados y renovados diariamente.

Michael Van Canneyt
to Aitor Santamar�a
Aitor Santamar�a wrote 18 lines
> > Hola, > > > > >Has anyone ever written a function to get a temporary unique file name? > > > > In Windows there're GetTempFileName and GetTempFileName32. > > > > For Linux, a hint: I heard that Borland had used somebody else's > > algorithm to implement GUIDs. Implementation could be in FreeCLX. > > > Simply use the tmpnam function from libc: > > Function tmpnam (s : pchar) : pchar;cdecl;external 'c'; > > s may point to a buffer in which the filename is be copied; > Well, thanks to all for the contribution, but my priority is it to be GO32V2, does it work under this platform?

It should be as it is part of the C library.

Michael.

Aitor Santamar�a

What can I be doing bad here?

program test;
uses strings;
Function tmpnam (s : pchar) : pchar;cdecl;external 'c';
var
   s: pchar;
begin
        new (s);
        writeln (strpas(tmpnam(s)))
end.
 test.pas(5,55) Error: Creation of Dynamic/Shared Libraries not supported

Aitor

Show quoted text 23 lines
> > > Hola, > > > > > > >Has anyone ever written a function to get a temporary unique file name? > > > > > > In Windows there're GetTempFileName and GetTempFileName32. > > > > > > For Linux, a hint: I heard that Borland had used somebody else's > > > algorithm to implement GUIDs. Implementation could be in FreeCLX. > > > > > > Simply use the tmpnam function from libc: > > > > Function tmpnam (s : pchar) : pchar;cdecl;external 'c'; > > > > s may point to a buffer in which the filename is be copied; > > > > Well, thanks to all for the contribution, but my priority is it to be GO32V2, does it work under this platform? It should be as it is part of the C library. Michael.

_____________________________________________________________________ Si no encuentras lo que buscas... �a qu� est�s esperando para entrar en www.wanadoo.es? Con nuestro nuevo motor de b�squeda conseguir�s m�s r�pido resultados de actualidad, personalizados y renovados diariamente.