NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/56250: mkstemp/mkdtemp not declared with _POSIX_C_SOURCE=200809L



>Number:         56250
>Category:       lib
>Synopsis:       mkstemp/mkdtemp not declared with _POSIX_C_SOURCE=200809L
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jun 16 00:00:00 +0000 2021
>Originator:     Michael Forney
>Release:        9.2
>Organization:
>Environment:
NetBSD build 9.2 NetBSD 9.2 (GENERIC) #0: Wed May 12 13:15:55 UTC 2021  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC
amd64
>Description:
In POSIX issue 7, mkstemp was moved from XSI to Base[0], however NetBSD stdlib.h only declares it when _XOPEN_SOURCE or _NETBSD_SOURCE is declared. Additionally, mkdtemp was added to issue 7 from the 2006 Extended API Set.

Looking at the rest of the functions in this block, it seems that getsubopt has the same problem.

[0] https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdtemp.html#tag_16_326_13
>How-To-Repeat:
Try to compile the following test program:

#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
int main(void) {
	mkstemp("/tmp/XXXXXX");
	return 0;
}

The result is:

t.c: In function 'main':
t.c:4:2: warning: implicit declaration of function 'mkstemp'; did you mean 'system'? [-Wimplicit-function-declaration]
  mkstemp("/tmp/XXXXXX");
  ^~~~~~~
  system

>Fix:
These functions should be declared in their own conditional block that is also triggered by _POSIX_C_SOURCE>=200809L.

As far as I can tell, mkdtemp was never an XSI function, so I'm not sure if it is correct to declare it when _XOPEN_SOURCE=500 or 600. I also don't know if there is a feature test macro for the 2006 Extended API set where it was introduced (https://publications.opengroup.org/c062). However, since mkdtemp was already being declared for _XOPEN_SOURCE>=500, I just left it as-is to avoid potentially breaking anything.

Here is a diff to fix the issue:

diff --git a/include/stdlib.h b/include/stdlib.h
index 51dbb0c70836..f47d0b9467ee 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -186,12 +186,8 @@ void	 srandom(unsigned int) __RENAME(__srandom60);
 #endif
 #ifdef _NETBSD_SOURCE
 #define	RANDOM_MAX	0x7fffffff	/* (((long)1 << 31) - 1) */
-int	 mkostemp(char *, int);
-int	 mkostemps(char *, int, int);
 #endif
 
-char	*mkdtemp(char *);
-int	 mkstemp(char *);
 char	*mktemp(char *)
 #ifdef __MKTEMP_OK__
 	__RENAME(_mktemp)
@@ -206,8 +202,6 @@ int	 ttyslot(void);
 
 void	*valloc(size_t);		/* obsoleted by malloc() */
 
-int	 getsubopt(char **, char * const *, char **);
-
 int	 grantpt(int);
 int	 unlockpt(int);
 char	*ptsname(int);
@@ -255,6 +249,24 @@ int	 posix_openpt(int);
 int	 posix_memalign(void **, size_t, size_t);
 #endif
 
+/*
+ * The Open Group Base Specifications, Issue 7; IEEE Std 1003.1-2008 (POSIX)
+ *   or
+ * X/Open Portability Guide >= Issue 4 Version 2
+ */
+#if (_POSIX_C_SOURCE - 0) >= 200809L || \
+    (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
+    (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
+char	*mkdtemp(char *);
+int	 mkstemp(char *);
+#ifdef _NETBSD_SOURCE
+int	 mkostemp(char *, int);
+int	 mkostemps(char *, int, int);
+#endif
+
+int	 getsubopt(char **, char * const *, char **);
+#endif
+
 /*
  * Implementation-defined extensions
  */



Home | Main Index | Thread Index | Old Index