Re: mktemp POSIX (and Linux) divergence

2024-01-16 Thread Lloyd Parkes
Kia ora,
In one out of one samples I checked, the result of mktemp was only
checked for != NULL rather than a more robust check. That same sample
(xsrc/external/mit/smproxy/dist/save.c) also preferred to use mkstemp.

mktemp() got removed from POSIX because using it is just wrong. Given
how much work NetBSD and the external source maintainers have clearly
put into removing uses of mktemp() IMHO I don't think fiddling with it
is warranted. 

Ngā mihi,
Lloyd



mktemp POSIX (and Linux) divergence

2024-01-16 Thread Thomas Klausner
Hi!

Our mktemp man page says:

RETURN VALUES
 The mktemp() and mkdtemp() functions return a pointer to the template on
 success and NULL on failure.

But POSIX[1] (and Linux) say:

The mktemp() function shall return the pointer template. If a unique name 
cannot be created, template shall point to a null string.

where 'null string' is[2]

  3.146 Empty String (or Null String)

  A string whose first byte is a null byte

So NetBSD's mktemp returns NULL on error, while Linux returns a
pointer to string of length 0.

I think mktemp has been removed from POSIX in the meantime, but should
we switch to the POSIX behaviour?

 Thomas


[1] https://pubs.opengroup.org/onlinepubs/009695399/functions/mktemp.html
[2] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html