How portable is mktemp(1)?

2020-02-08 03:52发布

As the title suggests — can I be reasonably sure that mktemp will exist on any unix-y operating system I'm likely to encounter?

4条回答
做自己的国王
2楼-- · 2020-02-08 04:22

A mktemp function (AKA mktemp(3)) first appeared in Unix V7 so it's likely to be everywhere. However, a mktemp command (aka mktemp(1)) first appeared, I believe, on OpenBSD 2.1, so if you have to deal with truly antediluvian Unix systems you might have to worry -- unless you can distribute the very portable mktemp.org version (to fix the potential lack of this utility on some customer's antediluvian system). How likely you are to encounter antediluvian system is nigh impossible for us to guess, of course -- e.g., in HP-UX, mktemp(1) has been around for at least 8 years (even most enterprises probably have updated their Unix OS's within that time frame), in Xenix I believe it appeared in 3.0 (in 1992), etc, etc.

查看更多
男人必须洒脱
3楼-- · 2020-02-08 04:29

On Solaris 9 it's in package SMCmktemp, see http://sunfreeware.com/indexsparc9.html:

uname -s
SunOS
uname -r
5.9
/usr/sbin/pkgchk -l -p /usr/local/bin/mktemp
Pathname: /usr/local/bin/mktemp
Type: regular file
Expected mode: 0555
Expected owner: bin
Expected group: bin
Expected file size (bytes): 8884
Expected sum(1) of contents: 6493
Expected last modification: Nov 05 08:48:17 2002
Referenced by the following packages:
SMCmktemp
Current status: installed

查看更多
4楼-- · 2020-02-08 04:33

FYI, mktemp appears to NOT be included with Solaris 9 (released 2002/2003) - just ran across this today:

$ uname -a
SunOS dcmnapp02 5.9 Generic_122300-47 sun4u sparc SUNW,Sun-Fire-V440
$ mktemp
bash: mktemp: command not found
$ man mktemp
bash-2.05$ man mktemp
Reformatting page.  Please Wait... done

Standard C Library Functions                           mktemp(3C)

NAME
     mktemp - make a unique file name

SYNOPSIS
     #include 

     char *mktemp(char *template);
查看更多
啃猪蹄的小仙女
5楼-- · 2020-02-08 04:44

POSIX does not seem to specify mktemp(1).

It looks like most modern systems have it, but the available functionality and the semantics of the options vary between implementations (so particular invocations may not be portable):

So if you want a portable solution you may need to stick to functionality and options that mean the same thing on all of your platforms of interest.

查看更多
登录 后发表回答