bug-glibc
[Top][All Lists]
Advanced

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

Re: sys/time.h: no more -ansi timercmp ?


From: Andries . Brouwer
Subject: Re: sys/time.h: no more -ansi timercmp ?
Date: Tue, 26 Jun 2001 03:03:15 +0200 (MET DST)

    From: David Morse <address@hidden>

    Andreas Jaeger <address@hidden> wrote:

    > Add the appropriate feature test macros (details are in the libc
    > manual), e.g. _BSD_SOURCE.

    Ok, read the entry in the manual.  Is the cpp symbol _BSD_SOURCE itself a
    gnu extension, or part of some portable standard?  I.e. which of these is
    correct:

    #ifndef _BSD_SOURCE
     #define _BSD_SOURCE
     #include <sys/time.h>
     #undef _BSD_SOURCE
    #else
     #include <sys/time.h>
    #endif

    or

    #ifdef *GLIBC*
     #ifndef _BSD_SOURCE
      #define _BSD_SOURCE
      #include <sys/time.h>
      #undef _BSD_SOURCE
     #else
      #include <sys/time.h>
     #endif
    #else
     #include <sys/time.h>
    #endif

    where *GLIBC* is some CPP symbol that I don't know yet, that that tells if
    using glibc.

Andreas Jaeger will give the right answer. Let me give the
wrong one.

Adding "some CPP symbol that I don't know yet" is a path that
you do not want to enter. I have seen preprocessor symbol clusters
grow beyond my liking and finally threw them out.

There are _LIBC and _LINUX_C_LIB_VERSION_MAJOR and __GNU_LIBRARY__
and __GLIBC__ and __GLIBC_MINOR__ and probably some I forget.
I think all of them are undocumented.

libc4 and libc5 had (since 4.5.10) macros _LINUX_C_LIB_VERSION
and _LINUX_C_LIB_VERSION_{MAJOR,MINOR,SUBMINOR}, e.g.
"5.4.46", 5, 4, 46 for libc-5.4.46.

The macro __GNU_LIBRARY__ was 1 during glibc1 and libc4, libc5,
and is 6 since glibc2.0.

Since glibc2.0 the preferred macros are __GLIBC__ and __GLIBC_MINOR__
(2, 2 for both 2.2.2 and 2.2.3; I do not think there is a subminor
that would distinguish 2.2.2 from 2.2.3).
They are defined in <features.h>, included by all other include files.

But you wanted timercmp or so, a simple convenience macro.
If you are afraid that defining _BSD_SOURCE may do bad things
to your possibly non-glibc <sys/time.h>, then my solution would be:

#include <sys/time.h>
#ifndef timercmp
#  define timercmp(tvp, uvp, cmp)\
        ((tvp)->tv_sec cmp (uvp)->tv_sec ||\
        (tvp)->tv_sec == (uvp)->tv_sec &&\
        (tvp)->tv_usec cmp (uvp)->tv_usec)
#endif

without introducing strange detailed undocumented information
about (g)libc version macros.

Andries



reply via email to

[Prev in Thread] Current Thread [Next in Thread]