任何禁用`tempnam'的方法都是危险的,更好的使用`mkstemp'gcc警告?

时间:2021-10-11 06:59:19

I'm using tempnam() only to get the directory name, so this security warning does not apply to my case. How can I disable it? I couldn't find any switches to do it.

我只使用tempnam()来获取目录名,所以这个安全警告不适用于我的情况。我该如何禁用它?我找不到任何开关来做它。

3 个解决方案

#1


If you really only want the directory name, use the string constant macro P_tmpdir, defined in <stdio.h>.

如果您真的只想要目录名,请使用 中定义的字符串常量宏P_tmpdir。

#2


"The tempnam() function returns a pointer to a string that is a valid filename, and such that a file with this name did not exist when tempnam() checked."

“tempnam()函数返回一个指向有效文件名的字符串的指针,并且当tempnam()选中时,该名称的文件不存在。”

The warning arises because of the race condition between checking and a later creating of the file.

由于检查和稍后创建文件之间的竞争条件而产生警告。

You want to only get the directory name? What should that be good for?

您想只获取目录名称?这有什么用?

Like stranger already said, you may disable this (and similar warnings) using -Wno-deprecated-declarations.

就像陌生人已经说过的那样,您可以使用-Wno-deprecated-declarations禁用此(以及类似的警告)。

#3


You can use GCC's -Wno-deprecated-declarations option to disable all warnings like this. I suggest you handle the warning properly, though, and take the suggestion of the compiler.

您可以使用GCC的-Wno-deprecated-declarations选项来禁用所有这些警告。我建议您正确处理警告,并采取编译器的建议。

#1


If you really only want the directory name, use the string constant macro P_tmpdir, defined in <stdio.h>.

如果您真的只想要目录名,请使用 中定义的字符串常量宏P_tmpdir。

#2


"The tempnam() function returns a pointer to a string that is a valid filename, and such that a file with this name did not exist when tempnam() checked."

“tempnam()函数返回一个指向有效文件名的字符串的指针,并且当tempnam()选中时,该名称的文件不存在。”

The warning arises because of the race condition between checking and a later creating of the file.

由于检查和稍后创建文件之间的竞争条件而产生警告。

You want to only get the directory name? What should that be good for?

您想只获取目录名称?这有什么用?

Like stranger already said, you may disable this (and similar warnings) using -Wno-deprecated-declarations.

就像陌生人已经说过的那样,您可以使用-Wno-deprecated-declarations禁用此(以及类似的警告)。

#3


You can use GCC's -Wno-deprecated-declarations option to disable all warnings like this. I suggest you handle the warning properly, though, and take the suggestion of the compiler.

您可以使用GCC的-Wno-deprecated-declarations选项来禁用所有这些警告。我建议您正确处理警告,并采取编译器的建议。