zsh-workers
 help / color / mirror / code / Atom feed
From: Clinton Bunch <cdb_zsh@zentaur.org>
To: Daniel Shahaf <d.s@daniel.shahaf.name>, zsh-workers@zsh.org
Subject: Re: [RFC] adding zmktemp command
Date: Thu, 28 Mar 2019 10:00:24 -0500	[thread overview]
Message-ID: <45a86a2c-c277-c29e-2c69-06eec33b627a@zentaur.org> (raw)
In-Reply-To: <38c2ebfc-f238-4f85-af76-b87c9e7f4531@www.fastmail.com>

On 3/28/2019 4:38 AM, Daniel Shahaf wrote:
> Clinton Bunch wrote on Wed, 27 Mar 2019 21:18 +00:00:
>> I'm thinking of adding a zmktemp command either in a new module (e.g.
>> zsh/tempfile) or in the zsh/files module.
> ...
>> Thoughts?
> A few.
>
> - I wonder if implementing mktemp in the shell is easier than expecting
>    people to install a third-party mktemp(1) binary with whatever
>    functionality they desire.  BSD systems often have both BSD make and
>    GNU make, so it's conceivable that HP-UX systems could have both the
>    native mktemp(1) and a third-party one.
>    
>    (To be clear, I do not object to your RFC; I just wonder if there's a
>    better solution to the underlying problem.)

That situation is why I proposed this.  On my HP-UX systems I use gnu 
coreutils mktemp, but either I have to order my path so that it's before 
/usr/bin, which can get me non-standard versions of standard commands 
which might affect the script, or name it something else (which I did, 
gmktemp).  Either way this makes for less portable scripts.  That also 
requires that the script writer have access to install packages or the 
wherewithal to build these packages and install them in their home 
directory themselves.

>
> - There's already a gettempname() function in the shell's C implementation;
>    it relies on mktemp(3) being available.  A module implementation might
>    be able to reuse that.
Actually I was thinking about modifying this as well to use either a 
system mkstemps where available or a hand-rolled one.  The names 
generated on HP-UX by mktemp(3) are extremely predictable (basically it 
zero-pads the pid and starts incrementing the leftmost digit on 
subsequent calls.  This is likely to be a bigger deal in a shell script 
where the tempfile might be repeatedly opened and closed and the name 
handed off as an argument to an external command, than internally where 
all I/O to the file is done with an already opened file descriptor.
>
> - O_EXCL is exposed by zsh/system's 'sysopen' builtin, so a pure zsh
>    implementation should be possible.

I didn't think about a pure zsh implementation, but modifying the 
template character by character in zsh sounds like at least as much work 
as it is in C, but slower.

>
> (I think you're aware of the following, but for the record:)
>
> There is a *limited* workaround: '() { … } =(:)' creates a tempfile (in
> ${TMPPREFIX:h}, if that's set).  The catch is that the file is deleted
> when the anonymous function returns, so it's effectively a lexically
> scoped tempfile.  And, of course, it's not a substitute for «mktemp -d».
> (So, no, that's not a replacement to a proper mktemp(1).)
>
> Cheers,
>
> Daniel

  reply	other threads:[~2019-03-28 15:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20190327211847epcas2p395ce077891a4535f19e1e9605217df7c@epcas2p3.samsung.com>
2019-03-27 21:16 ` Clinton Bunch
2019-03-28  9:38   ` Daniel Shahaf
2019-03-28 15:00     ` Clinton Bunch [this message]
2019-03-28 21:13       ` Daniel Shahaf
2019-03-29 15:20         ` Clinton Bunch
2019-03-28 15:17   ` Peter Stephenson
2019-03-28 15:25     ` Clinton Bunch
2019-03-28 15:36   ` Oliver Kiddle
2019-03-28 15:40     ` Clinton Bunch
2019-03-28 20:26       ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45a86a2c-c277-c29e-2c69-06eec33b627a@zentaur.org \
    --to=cdb_zsh@zentaur.org \
    --cc=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).