As the title suggests — can I be reasonably sure that mktemp
will exist on any unix-y operating system I'm likely to encounter?
views:
103answers:
2A 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.
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):
- mktemp(1) from OpenBSD — mktemp(1) originated in OpenBSD 2.1
- mktemp(1) from FreeBSD
- mktemp(1) from Mac OS X — almost always the same as from FreeBSD
- mktemp(1) from Todd C. Miller of sudo fame
- mktemp(1) from Solaris
- mktemp(1) from GNU coreutils
- mktemp(1) from HP/UX — this one seems particularly divergent from most of the others listed here
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.