guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mkstemp strange behavior


From: Alan Grover
Subject: Re: mkstemp strange behavior
Date: Wed, 10 Aug 2005 13:54:31 -0400
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050317)

I ran into this too. My reasoning was something like:

The string, "/tmp/XXXXXX" is constructed at reader time. So, there is
exactly one string. The "let" creates a new variable each time you call
"test", but the variable is bound to the same string.

Mkstemp modifies the (one and only) string the first time.

If you force the value to be computed at exec time, the problem should
go away: (string-append "" "/tmp/XXXXXX").

You could test my theory by something like:

(define (test) (let ((filename "/tmp/XXXXXX")) filename))

(display (eq? (test) (test)))

Which yields #t for me. And, (eq? "/tmp/XXXXXX" "/tmp/XXXXXX") yields
#f, for comparison.

José Roberto B. de A. Monteiro wrote:
> Hello all!
> 
> I was trying to use mkstemp! in my program, instead of tmpnam, but I have no
> success... I mkstemp! is getting me confused. It alters original string, so
> we can easely have the name of temporary file.
> 
> But, with following code, I suposed it would work, but it is reusing an old
> string:
> 
> #!/usr/bin/guile \
> -s
> !#
> 
> (define (test)
>   (let ((filename "/tmp/XXXXXX")
>         (tmp #f))
>     (format #t "before: filename=~A\n" filename)
>     (set! tmp (mkstemp! filename))
>     (format #t "after : filename=~A\n" filename)
>     (close tmp)))
>         
> (format #t "First call...\n")
> (test)
> (format #t "Second call...\n")
> (test)
>                         
> And the result of this code is:
> 
> First call...
> before: filename=/tmp/XXXXXX
> after : filename=/tmp/HGLPtZ
> Second call...
> before: filename=/tmp/HGLPtZ
> ERROR: In procedure mkstemp!:
> ERROR: Invalid argument
> 
> I can not figure out why the string is not set to /tmp/XXXXXX in the second
> call...
> 
> Some help!?
> 
> Regards
> Betoes
> 
> 
> _______________________________________________
> Guile-user mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/guile-user
> 

-- 
Alan Grover
address@hidden
+1.734.476.0969

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]