NetBSD Problem Report #56250
From www@netbsd.org Tue Jun 15 23:56:01 2021
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id B7EA81A921F
for <gnats-bugs@gnats.NetBSD.org>; Tue, 15 Jun 2021 23:56:00 +0000 (UTC)
Message-Id: <20210615235559.5C01A1A923B@mollari.NetBSD.org>
Date: Tue, 15 Jun 2021 23:55:59 +0000 (UTC)
From: mforney@mforney.org
Reply-To: mforney@mforney.org
To: gnats-bugs@NetBSD.org
Subject: mkstemp/mkdtemp not declared with _POSIX_C_SOURCE=200809L
X-Send-Pr-Version: www-1.0
>Number: 56250
>Category: standards
>Synopsis: mkstemp/mkdtemp not declared with _POSIX_C_SOURCE=200809L
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: standards-manager
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Jun 16 00:00:00 +0000 2021
>Closed-Date: Sat Jul 03 14:10:25 +0000 2021
>Last-Modified: Sat Jul 03 14:10:25 +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:/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
*/
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: lib-bug-people->standards-manager
Responsible-Changed-By: dholland@NetBSD.org
Responsible-Changed-When: Wed, 16 Jun 2021 06:58:54 +0000
Responsible-Changed-Why:
.
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/56250 CVS commit: src/include
Date: Sat, 3 Jul 2021 10:07:13 -0400
Module Name: src
Committed By: christos
Date: Sat Jul 3 14:07:13 UTC 2021
Modified Files:
src/include: stdlib.h
Log Message:
PR/56250: Michael Forney: mkstemp/mkdtemp not declared with
_POSIX_C_SOURCE=200809L
To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/include/stdlib.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->closed
State-Changed-By: christos@NetBSD.org
State-Changed-When: Sat, 03 Jul 2021 10:10:25 -0400
State-Changed-Why:
committed the minimal diff
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.