Discussion:
warning: implicit declaration of function ‘mkstemp’
(too old to reply)
Philipp Klaus Krause
2017-08-03 09:51:40 UTC
Permalink
When using mkstemp() in my C source, I get the gcc warning:

warning: implicit declaration of function ‘mkstemp’

Why?
I use gcc 6.4.0 on a debian GNU/Linux system.
<stdlib.h> is included. I use other POSIX functions (such as
ftruncate() and open()) that are not part of ISO C in the same source
file, but get a warning for mkstemp() only.
I tried using -D_POSIX_C_SOURCE=200112L, but still get the warning.

Philipp
Richard Kettlewell
2017-08-03 10:08:10 UTC
Permalink
Post by Philipp Klaus Krause
warning: implicit declaration of function ‘mkstemp’
Why?
I use gcc 6.4.0 on a debian GNU/Linux system.
<stdlib.h> is included. I use other POSIX functions (such as
ftruncate() and open()) that are not part of ISO C in the same source
file, but get a warning for mkstemp() only.
I tried using -D_POSIX_C_SOURCE=200112L, but still get the warning.
WFM on an up-to-date sid install. What’s your test case?
--
http://www.greenend.org.uk/rjk/
Philipp Klaus Krause
2017-08-03 10:30:03 UTC
Permalink
Post by Richard Kettlewell
Post by Philipp Klaus Krause
warning: implicit declaration of function ‘mkstemp’
Why?
I use gcc 6.4.0 on a debian GNU/Linux system.
<stdlib.h> is included. I use other POSIX functions (such as
ftruncate() and open()) that are not part of ISO C in the same source
file, but get a warning for mkstemp() only.
I tried using -D_POSIX_C_SOURCE=200112L, but still get the warning.
WFM on an up-to-date sid install. What’s your test case?
Sorry for the noise. I just checked again, and I mistook the <stdio.h>
include for <stdlib.h> earlier. With the correct include, the warning is
gone.

Philipp
Jens Thoms Toerring
2017-08-05 15:11:56 UTC
Permalink
Post by Philipp Klaus Krause
warning: implicit declaration of function ‘mkstemp’
Why?
I use gcc 6.4.0 on a debian GNU/Linux system.
<stdlib.h> is included. I use other POSIX functions (such as
ftruncate() and open()) that are not part of ISO C in the same source
file, but get a warning for mkstemp() only.
I tried using -D_POSIX_C_SOURCE=200112L, but still get the warning.
Try '-D_POSIX_C_SOURCE=200809' instead. That's what's required
according to the up-to-date version of the man page (see
<http://man7.org/linux/man-pages/man3/mkstemp.3.html>), and it
works for me. The (somewhat out-dated) man page on my system
also claims that '_POSIX_C_SOURCE=200112L' would do the the
trick, but it doesn't.

BTW, if you always want the newest version of the man pages
you can get them easily via git from

git://git.kernel.org/pub/scm/docs/man-pages/man-pages.git

Best regards, Jens
--
\ Jens Thoms Toerring ___ ***@toerring.de
\__________________________ http://toerring.de
Geoff Clare
2017-08-07 12:47:00 UTC
Permalink
Post by Jens Thoms Toerring
Post by Philipp Klaus Krause
warning: implicit declaration of function ‘mkstemp’
Why?
I use gcc 6.4.0 on a debian GNU/Linux system.
<stdlib.h> is included. I use other POSIX functions (such as
ftruncate() and open()) that are not part of ISO C in the same source
file, but get a warning for mkstemp() only.
I tried using -D_POSIX_C_SOURCE=200112L, but still get the warning.
Try '-D_POSIX_C_SOURCE=200809' instead. That's what's required
according to the up-to-date version of the man page (see
<http://man7.org/linux/man-pages/man3/mkstemp.3.html>), and it
works for me. The (somewhat out-dated) man page on my system
also claims that '_POSIX_C_SOURCE=200112L' would do the the
trick, but it doesn't.
In SUSv3/POSIX.1-2001 the mkstemp() function was part of the XSI option.
Some UNIX/POSIX systems make XSI symbols visible with
_POSIX_C_SOURCE=200112 but some don't. To be sure of making it visible
you need _XOPEN_SOURCE=600 (instead of, or as well as, setting
_POSIX_C_SOURCE=200112).

In SUSv4/POSIX.1-2008 mkstemp() was made mandatory, which is why
_POSIX_C_SOURCE=200809 works (on up-to-date systems). Of course,
_XOPEN_SOURCE=700 would also work.
--
Geoff Clare <***@gclare.org.uk>
Loading...