[PATCH 05/18] Add BSD guard for clock_t
Sebastian Huber
sebastian.huber@embedded-brains.de
Thu Apr 14 19:41:00 GMT 2016
----- Craig Howland <howland@LGSInnovations.com> schrieb:
> On 04/14/2016 07:54 AM, Sebastian Huber wrote:
> > Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
> > ---
> > newlib/libc/include/sys/_types.h | 4 +++-
> > newlib/libc/include/sys/times.h | 7 ++++---
> > newlib/libc/include/sys/types.h | 7 ++++---
> > 3 files changed, 11 insertions(+), 7 deletions(-)
> >
> > diff --git a/newlib/libc/include/sys/_types.h b/newlib/libc/include/sys/_types.h
> > index af32bcb..0f5cb9d 100644
> > --- a/newlib/libc/include/sys/_types.h
> > +++ b/newlib/libc/include/sys/_types.h
> > @@ -145,7 +145,9 @@ typedef _LOCK_RECURSIVE_T _flock_t;
> > typedef void *_iconv_t;
> > #endif
> >
> > -#define _CLOCK_T_ unsigned long /* clock() */
> > +#define _CLOCK_T_ unsigned long /* clock() */
> > +typedef _CLOCK_T_ __clock_t;
> > +
> > #define _TIME_T_ long /* time() */
> > #define _CLOCKID_T_ unsigned long
> > #define _TIMER_T_ unsigned long
> > diff --git a/newlib/libc/include/sys/times.h b/newlib/libc/include/sys/times.h
> > index dc072f4..b1f1dc6 100644
> > --- a/newlib/libc/include/sys/times.h
> > +++ b/newlib/libc/include/sys/times.h
> > @@ -7,9 +7,10 @@ extern "C" {
> > #include <_ansi.h>
> > #include <sys/_types.h>
> >
> > -#ifndef __clock_t_defined
> > -typedef _CLOCK_T_ clock_t;
> > -#define __clock_t_defined
> > +#if !defined(__clock_t_defined) && !defined(_CLOCK_T_DECLARED)
> > +typedef _CLOCK_T_ clock_t;
> > +#define __clock_t_defined
> > +#define _CLOCK_T_DECLARED
> > #endif
> >
> > /* Get Process Times, P1003.1b-1993, p. 92 */
> > diff --git a/newlib/libc/include/sys/types.h b/newlib/libc/include/sys/types.h
> > index e48c2f2..f17821b 100644
> > --- a/newlib/libc/include/sys/types.h
> > +++ b/newlib/libc/include/sys/types.h
> > @@ -96,9 +96,10 @@ typedef unsigned int uint; /* System V compatibility */
> > typedef unsigned long ulong; /* System V compatibility */
> > #endif
> >
> > -#ifndef __clock_t_defined
> > -typedef _CLOCK_T_ clock_t;
> > -#define __clock_t_defined
> > +#if !defined(__clock_t_defined) && !defined(_CLOCK_T_DECLARED)
> > +typedef _CLOCK_T_ clock_t;
> > +#define __clock_t_defined
> > +#define _CLOCK_T_DECLARED
> > #endif
> >
> > #ifndef __time_t_defined
> While this is not something that is being introduced by this patch, as long as
> it is being done and making the fact obvious, it sure would be nice if a comment
> could be added to point out that these definitions are in two places and need to
> be kept identical. Perhaps something along the lines of
> /* Both sys/times.h and sys/types.h contain this clock_t definition. They must
> be kept identical. */
> (Even better would be a single place that gets included. But again, this is not
> an issue created by this patch.)
I added a comment about the type guard define patterns to <sys/_types.h> in the first patch of this series. This stuff is not a Newlib invention and originates from glibc and FreeBSD. Every C library seems to do it slightly different.
--
Sebastian Huber, embedded brains GmbH
Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber at embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
More information about the Newlib
mailing list