Skip to content

Commit

Permalink
lib: posix, minlibc: struct itimerspec is defined by sys/timespec.h
Browse files Browse the repository at this point in the history
Newlib has it defined in sys/timespec.h, and thus per the established
conventions, everything else relies on it being there. Specifically,
minimal libc acquires sys/timespec.h with a similar definition, and
POSIX headers rely on that header. Still with a workaround for old
Newlib version as used by Xtensa (but all infrastructure for that is
already there; actually, this patch removes duplicate similar-infra,
which apparently didn't work as expected by now, so now we have a
single workaround, not 2 different once).

To emphasize a point, now there 2 headers:

sys/_timespec.h, defining struct timespec, and
sys/timespec.h, defining struct itimerspec

That's how Newlib has it, and what we faithfully embrace and follow,
because otherwise, there will be header conflicts depending on
various libc and POSIX subsys options.

Signed-off-by: Paul Sokolovsky <[email protected]>
  • Loading branch information
pfalcon authored and galak committed Sep 26, 2019
1 parent ae5a7bb commit 0173d86
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
33 changes: 7 additions & 26 deletions include/posix/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#ifdef __NEWLIB__
/* Newever Newlib 3.x+ */
#include <sys/_timespec.h>
#include <sys/timespec.h>
#else /* __NEWLIB__ */
/* Workaround for older Newlib 2.x, as used by Xtensa. It lacks sys/_timeval.h,
* so mimic it here.
Expand All @@ -29,6 +29,11 @@ struct timespec {
long tv_nsec;
};

struct itimerspec {
struct timespec it_interval; /* Timer interval */
struct timespec it_value; /* Timer expiration */
};

#ifdef __cplusplus
}
#endif
Expand All @@ -38,33 +43,9 @@ struct timespec {

#else /* CONFIG_NEWLIB_LIBC */
/* Not Newlib */
#include <sys/_timespec.h>
#include <sys/timespec.h>
#endif /* CONFIG_NEWLIB_LIBC */

/* Older newlib's like 2.{0-2}.0 don't define any newlib version defines, only
* __NEWLIB_H__ so we use that to decide if itimerspec was defined in
* sys/types.h w/o any protection. It appears sometime in the 2.3.0 version
* of newlib did itimerspec move out of sys/types.h, however version 2.3.0
* seems to report itself as __NEWLIB_MINOR__ == 2, where as 2.2.0 doesn't
* even define __NEWLIB_MINOR__ or __NEWLIB__
*/
#if !defined(__NEWLIB_H__) || (__NEWLIB__ >= 3) || \
(__NEWLIB__ == 2 && __NEWLIB_MINOR__ >= 2)

#ifdef __cplusplus
extern "C" {
#endif

struct itimerspec {
struct timespec it_interval; /* Timer interval */
struct timespec it_value; /* Timer expiration */
};
#ifdef __cplusplus
}
#endif

#endif

#include <kernel.h>
#include <errno.h>
#include "posix_types.h"
Expand Down
17 changes: 17 additions & 0 deletions lib/libc/minimal/include/sys/timespec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2019 Linaro Limited
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS_TIMESPEC_H_
#define ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS_TIMESPEC_H_

#include <sys/_timespec.h>

struct itimerspec {
struct timespec it_interval; /* Timer interval */
struct timespec it_value; /* Timer expiration */
};

#endif /* ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS_TIMESPEC_H_ */

0 comments on commit 0173d86

Please sign in to comment.