unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* temporary file name, with a twist
@ 2006-09-07 15:31 nobrowser
  2006-09-07 16:20 ` Miles Bader
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: nobrowser @ 2006-09-07 15:31 UTC (permalink / raw)


Hello,

in my lisp code, I need to get a unique temporary file name, but _with
a specific suffix_.  There doesn't seem to be a built-in or an easy
lispy way of doing this.  As for devious ways, on Debian there is the
tempfile program but I don't think this generalizes even to other Linux
distros.  Or I could use the maildir scheme:
${hostname}_${emacs_pid}_${timestamp}.${suffix}, but how to portably
get the hostname?  mail-host-name can't be used because the very point
is to distinguish between distinct host at the same site.

This must have been done before ...

Thanks,
i

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: temporary file name, with a twist
  2006-09-07 15:31 temporary file name, with a twist nobrowser
@ 2006-09-07 16:20 ` Miles Bader
       [not found] ` <mailman.6588.1157646012.9609.help-gnu-emacs@gnu.org>
  2006-09-07 18:16 ` Reiner Steib
  2 siblings, 0 replies; 8+ messages in thread
From: Miles Bader @ 2006-09-07 16:20 UTC (permalink / raw)


nobrowser@gmail.com writes:
> ${hostname}_${emacs_pid}_${timestamp}.${suffix}, but how to portably
> get the hostname?  mail-host-name can't be used because the very point
> is to distinguish between distinct host at the same site.

(system-name)

?

-Miles
-- 
Yo mama's so fat when she gets on an elevator it HAS to go down.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: temporary file name, with a twist
       [not found] ` <mailman.6588.1157646012.9609.help-gnu-emacs@gnu.org>
@ 2006-09-07 16:33   ` nobrowser
  0 siblings, 0 replies; 8+ messages in thread
From: nobrowser @ 2006-09-07 16:33 UTC (permalink / raw)


Miles Bader wrote:
> nobrowser@gmail.com writes:
> > ${hostname}_${emacs_pid}_${timestamp}.${suffix}, but how to portably
> > get the hostname?  mail-host-name can't be used because the very point
> > is to distinguish between distinct host at the same site.
>
> (system-name)
> 

Thanks.  One would think "apropos host" would work, but nooooooo ...

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: temporary file name, with a twist
  2006-09-07 15:31 temporary file name, with a twist nobrowser
  2006-09-07 16:20 ` Miles Bader
       [not found] ` <mailman.6588.1157646012.9609.help-gnu-emacs@gnu.org>
@ 2006-09-07 18:16 ` Reiner Steib
  2006-09-08  5:52   ` nobrowser
  2 siblings, 1 reply; 8+ messages in thread
From: Reiner Steib @ 2006-09-07 18:16 UTC (permalink / raw)


On Thu, Sep 07 2006, nobrowser@gmail.com wrote:

> in my lisp code, I need to get a unique temporary file name, but
> _with a specific suffix_.

`make-temp-file' or `make-temp-name'?

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: temporary file name, with a twist
  2006-09-07 18:16 ` Reiner Steib
@ 2006-09-08  5:52   ` nobrowser
  2006-09-08  6:30     ` David Kastrup
  2006-09-08  7:05     ` Reiner Steib
  0 siblings, 2 replies; 8+ messages in thread
From: nobrowser @ 2006-09-08  5:52 UTC (permalink / raw)


Reiner Steib wrote:
> On Thu, Sep 07 2006, nobrowser@gmail.com wrote:
>
> > in my lisp code, I need to get a unique temporary file name, but
> > _with a specific suffix_.
>
> `make-temp-file' or `make-temp-name'?
>

Nope, that's what I started with.  Doesn't do the suffix part.

I'll do the maildir thing, I suppose.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: temporary file name, with a twist
  2006-09-08  5:52   ` nobrowser
@ 2006-09-08  6:30     ` David Kastrup
  2006-09-08  7:05     ` Reiner Steib
  1 sibling, 0 replies; 8+ messages in thread
From: David Kastrup @ 2006-09-08  6:30 UTC (permalink / raw)


nobrowser@gmail.com writes:

> Reiner Steib wrote:
>> On Thu, Sep 07 2006, nobrowser@gmail.com wrote:
>>
>> > in my lisp code, I need to get a unique temporary file name, but
>> > _with a specific suffix_.
>>
>> `make-temp-file' or `make-temp-name'?
>>
>
> Nope, that's what I started with.  Doesn't do the suffix part.

Emacs CVS has

make-temp-file is a compiled Lisp function in `files.el'.
(make-temp-file PREFIX &optional DIR-FLAG SUFFIX)

Create a temporary file.
The returned file name (created by appending some random characters at the end
of PREFIX, and expanding against `temporary-file-directory' if necessary),
is guaranteed to point to a newly created empty file.
You can then use `write-region' to write new data into the file.

If DIR-FLAG is non-nil, create a new empty directory instead of a file.

If SUFFIX is non-nil, add that at the end of the file name.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: temporary file name, with a twist
  2006-09-08  5:52   ` nobrowser
  2006-09-08  6:30     ` David Kastrup
@ 2006-09-08  7:05     ` Reiner Steib
  2006-09-08 13:24       ` nobrowser
  1 sibling, 1 reply; 8+ messages in thread
From: Reiner Steib @ 2006-09-08  7:05 UTC (permalink / raw)


On Fri, Sep 08 2006, nobrowser@gmail.com wrote:

> Reiner Steib wrote:
>> On Thu, Sep 07 2006, nobrowser@gmail.com wrote:
>>
>> > in my lisp code, I need to get a unique temporary file name, but
>> > _with a specific suffix_.
>>
>> `make-temp-file' or `make-temp-name'?
>>
>
> Nope, that's what I started with.  Doesn't do the suffix part.

In addition to David's comment, I'd say it's not exactly hard to
append a suffix when using `make-temp-name'; at least easier than
creating maildir-like[1] names.

Bye, Reiner.

[1] BTW, maybe `gnus/nnmaildir.el' provides a function or code for
    this?
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: temporary file name, with a twist
  2006-09-08  7:05     ` Reiner Steib
@ 2006-09-08 13:24       ` nobrowser
  0 siblings, 0 replies; 8+ messages in thread
From: nobrowser @ 2006-09-08 13:24 UTC (permalink / raw)


Reiner Steib wrote:
> On Fri, Sep 08 2006, nobrowser@gmail.com wrote:
>
> > Reiner Steib wrote:
> >> On Thu, Sep 07 2006, nobrowser@gmail.com wrote:
> >>
> >> > in my lisp code, I need to get a unique temporary file name, but
> >> > _with a specific suffix_.
> >>
> >> `make-temp-file' or `make-temp-name'?
> >>
> >
> > Nope, that's what I started with.  Doesn't do the suffix part.
>
> In addition to David's comment, I'd say it's not exactly hard to
> append a suffix when using `make-temp-name'; at least easier than
> creating maildir-like[1] names.

At the slight risk of further insulting a deceased equine, let me
explain:

either way, with make-temp-name or with handcrafted names, I have,
theoretically, the classic tmpnam(3) race condition.  The difference is
that with my own, I control the algorithm so I can be confident that
the race won't actually happen in practice.  I don't have that
confidence with the Emacs names, which for all I know are generated
with tmpnam.  The doc says only that "The Emacs process number forms
part of the result".  But how unique are they actually, what's the
length of the cycle?

Thanks,
i

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-09-08 13:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-07 15:31 temporary file name, with a twist nobrowser
2006-09-07 16:20 ` Miles Bader
     [not found] ` <mailman.6588.1157646012.9609.help-gnu-emacs@gnu.org>
2006-09-07 16:33   ` nobrowser
2006-09-07 18:16 ` Reiner Steib
2006-09-08  5:52   ` nobrowser
2006-09-08  6:30     ` David Kastrup
2006-09-08  7:05     ` Reiner Steib
2006-09-08 13:24       ` nobrowser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).