NetBSD-Bugs archive

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

standards/56402: Definition of lldiv_t with ANSI_SOURCE and POSIX_SOURCE



>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@localhost:/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))



Home | Main Index | Thread Index | Old Index