NetBSD Problem Report #56402

From www@netbsd.org  Tue Sep 14 23:34:30 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 9832B1A921F
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 14 Sep 2021 23:34:30 +0000 (UTC)
Message-Id: <20210914233429.1BA7A1A9239@mollari.NetBSD.org>
Date: Tue, 14 Sep 2021 23:34:29 +0000 (UTC)
From: k0ga@shike2.com
Reply-To: k0ga@shike2.com
To: gnats-bugs@NetBSD.org
Subject: Definition of lldiv_t with ANSI_SOURCE and POSIX_SOURCE
X-Send-Pr-Version: www-1.0

>Number:         56402
>Category:       standards
>Synopsis:       Definition of lldiv_t with ANSI_SOURCE and POSIX_SOURCE
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    standards-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Sep 14 23:35:00 +0000 2021
>Originator:     Roberto E. Vargas Caballero
>Release:        NetBSD 9.1
>Organization:
>Environment:
NetBSD odin 9.1 NetBSD 9.1 (GENERIC) #0: Sun Oct 18 19:24:30 UTC 2020  mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64

>Description:
When a source file including stdlib.h is compiled with the flags -_ANSI_SOURCE and _POSIX_SOURCE the compilation fails with the error:

/usr/include/stdlib.h:227:1: error: unknown type name 'lldiv_t'; did you mean 'ldiv_t'?

Looking in the /usr/include/stdlib.h we find:


#if !defined(_ANSI_SOURCE) && \
    (defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
     (__cplusplus - 0) >= 201103L || defined(_NETBSD_SOURCE))
typedef struct {
        /* LONGLONG */
        long long int quot;     /* quotient */
        /* LONGLONG */
        long long int rem;      /* remainder */
} lldiv_t;
#endif


...

#if defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
    defined(_NETBSD_SOURCE) || (__cplusplus - 0) >= 201103L

/* LONGLONG */
long long int   atoll(const char *);
/* LONGLONG */
long long int   llabs(long long int);
/* LONGLONG */
lldiv_t         lldiv(long long int, long long int);
/* LONGLONG */
long long int   strtoll(const char * __restrict, char ** __restrict, int);
/* LONGLONG */
unsigned long long int
                strtoull(const char * __restrict, char ** __restrict, int);
float           strtof(const char * __restrict, char ** __restrict);
long double     strtold(const char * __restrict, char ** __restrict);
#endif


We can see that the definition of lldiv_t is enabled only when !defined(_ANSI_SOURCE) but lldiv() is declared regardless of the value of _ANSI_SOURCE. The same check should be used in both places.

>How-To-Repeat:
$ cat <<EOF > f.c
#define _ANSI_SOURCE
#define _POSIX_SOURCE

#include <stdlib.h>

int
main(void)
{
        return 0;
}
EOF
$ cc f.c
In file included from f.c:4:0:
/usr/include/stdlib.h:227:1: error: unknown type name 'lldiv_t'; did you mean 'ldiv_t'?
>Fix:
--- /usr/include/stdlib.h       2020-10-18 21:24:30.000000000 +0200
+++ /usr/include/stdlib.h.new 2021-09-15 01:02:48.399518921 +0200
/*
 * ISO C99
 */
-#if defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
-    defined(_NETBSD_SOURCE) || (__cplusplus - 0) >= 201103L
+#if !defined(_ANSI_SOURCE) && \
+    (defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
+     (__cplusplus - 0) >= 201103L || defined(_NETBSD_SOURCE))

NetBSD Home
NetBSD PR Database Search

(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.