/tmp/{gibberish}.o: In function 'main':
test.c:(.text+0x23): warning: the use of 'tmpnam' is dangerous, better use 'mkstemp'
Uugggh... what's up with warning for a given name of a function? Jeez.
Does anyone know of a trick to get rid of this warning, without resolving to [tt]2> /dev/null[/tt] or otherwise castrating more... valid... warnings?
Are you very sure it isn't a #warning in the code? If not, please do change to a more sane compiler that doesn't assume "char *tmpnam()" must be evil because you called it tmpnam.
Now that I think of it, there IS an option to turn that on and off. Unfortunately, I couldn't find it mentioned in the funny manual when I quickly tried to check it.
It seems that the unsafe functions aren't hard-coded: for every unsafe function in libc, there's a section .gnu.warning.name-of-function with the text of a warning to be displayed. For example:
$ objdump -s -j.gnu.warning.tmpnam /lib/libc.so.6
/lib/libc.so.6: file format elf32-i386
Contents of section .gnu.warning.tmpnam:
0000 74686520 75736520 6f662060 746d706e the use of `tmpn
0010 616d2720 69732064 616e6765 726f7573 am' is dangerous
0020 2c206265 74746572 20757365 20606d6b , better use `mk
0030 7374656d 702700 stemp'.
which seems at least a *bit* saner than hardcoding a list of functions into the linker (a non-glibc definition of tmpnam won't give the warning, I hope).
I couldn't see a way to stop the warning, though (apart from stripping the .gnu.warning.tmpnam section out of libc).
Should I ask what the logic behind the decision to create this warning was? If a compiler/linker wants to ***** me out on my logic design or anything else that it has to directly deal with then I don't mind, but doing it over the name of a variable/function? ::)
Just in case I'm misunderstanding, is tmpnam a built-in thing?
Kemp wrote:
Just in case I'm misunderstanding, is tmpnam a built-in thing?
The linker doesn't know about tmpnam specially - libc.so contains a section which says to the linker "if you see someone using tmpnam, give a warning". So it's not built in to the linker, but instead the library containing the dangerous function.
Actually, I was asking if the function itself was a builtin thing, but you answered that anyway. I thought it was something that Solar had made himself and the [linker|whatever] (or the creator of said [linker|whatever]) had just arbitrarily decided [it,they] didn't like the name.
Prolog syntax if you're wondering, the tail end ("whatever") will contain all the other possibilities which I have no experience with and thus can't name off-hand I think a simple list can be represented comma-seperated, been a year or two since I used it.