include/posix: rearrange for standard use of extern "C"

Consistently place C++ use of extern "C" after all include directives,
within the negative branch of _ASMLANGUAGE if used.

Background from issue #17997:

Declarations that use C linkage should be placed within extern "C"
so the language linkage is correct when the header is included by
a C++ compiler.

Similarly #include directives should be outside the extern "C" to
ensure the language-specific default linkage is applied to any
declarations provided by the included header.

See: https://en.cppreference.com/w/cpp/language/language_linkage
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
Peter Bigot 2019-08-12 12:55:06 -05:00 committed by Carles Cufí
commit ca6e3dcdc4
10 changed files with 56 additions and 37 deletions

View file

@ -6,12 +6,12 @@
#ifndef ZEPHYR_INCLUDE_POSIX_ARPA_INET_H_
#define ZEPHYR_INCLUDE_POSIX_ARPA_INET_H_
#include <net/socket.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <net/socket.h>
static inline char *inet_ntop(sa_family_t family, const void *src, char *dst,
size_t size)
{

View file

@ -6,16 +6,16 @@
#ifndef ZEPHYR_INCLUDE_POSIX_DIRENT_H_
#define ZEPHYR_INCLUDE_POSIX_DIRENT_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <limits.h>
#include "posix_types.h"
#ifdef CONFIG_POSIX_FS
#include <fs/fs.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef void DIR;
struct dirent {
@ -28,10 +28,10 @@ extern DIR *opendir(const char *dirname);
extern int closedir(DIR *dirp);
extern struct dirent *readdir(DIR *dirp);
#endif
#ifdef __cplusplus
}
#endif
#endif /* CONFIG_POSIX_FS */
#endif /* ZEPHYR_INCLUDE_POSIX_DIRENT_H_ */

View file

@ -6,12 +6,12 @@
#ifndef ZEPHYR_INCLUDE_POSIX_NETDB_H_
#define ZEPHYR_INCLUDE_POSIX_NETDB_H_
#include <net/socket.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <net/socket.h>
#define addrinfo zsock_addrinfo
static inline int getaddrinfo(const char *host, const char *service,

View file

@ -7,16 +7,16 @@
#ifndef ZEPHYR_INCLUDE_POSIX_SYS_TYPES_H_
#define ZEPHYR_INCLUDE_POSIX_SYS_TYPES_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifndef CONFIG_ARCH_POSIX
#include <sys/types.h>
#endif
#include <kernel.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned long useconds_t;
/* time related attributes */

View file

@ -7,14 +7,14 @@
#ifndef ZEPHYR_INCLUDE_POSIX_PTHREAD_KEY_H_
#define ZEPHYR_INCLUDE_POSIX_PTHREAD_KEY_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifdef CONFIG_PTHREAD_IPC
#include <sys/slist.h>
#include <zephyr/types.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef u32_t pthread_once_t;
/* pthread_key */

View file

@ -6,13 +6,13 @@
#ifndef ZEPHYR_INCLUDE_POSIX_SEMAPHORE_H_
#define ZEPHYR_INCLUDE_POSIX_SEMAPHORE_H_
#include <posix/time.h>
#include "posix_types.h"
#ifdef __cplusplus
extern "C" {
#endif
#include <posix/time.h>
#include "posix_types.h"
int sem_destroy(sem_t *semaphore);
int sem_getvalue(sem_t *restrict semaphore, int *restrict value);
int sem_init(sem_t *semaphore, int pshared, unsigned int value);

View file

@ -6,12 +6,12 @@
#ifndef ZEPHYR_INCLUDE_POSIX_SIGNAL_H_
#define ZEPHYR_INCLUDE_POSIX_SIGNAL_H_
#include "posix_types.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "posix_types.h"
#ifndef SIGEV_NONE
#define SIGEV_NONE 1
#endif

View file

@ -6,13 +6,13 @@
#ifndef ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_
#define ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_
#include <sys/types.h>
#include <net/socket.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
#include <net/socket.h>
static inline int socket(int family, int type, int proto)
{
return zsock_socket(family, type, proto);

View file

@ -6,10 +6,6 @@
#ifndef ZEPHYR_INCLUDE_POSIX_TIME_H_
#define ZEPHYR_INCLUDE_POSIX_TIME_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifdef CONFIG_NEWLIB_LIBC
/* Kludge to support outdated newlib version as used in SDK 0.10 for Xtensa */
#include <newlib.h>
@ -17,20 +13,30 @@ extern "C" {
#ifdef __NEWLIB__
/* Newever Newlib 3.x+ */
#include <sys/_timespec.h>
#else
#else /* __NEWLIB__ */
/* Workaround for older Newlib 2.x, as used by Xtensa. It lacks sys/_timeval.h,
* so mimic it here.
*/
#include <sys/types.h>
#ifndef __timespec_defined
#ifdef __cplusplus
extern "C" {
#endif
struct timespec {
time_t tv_sec;
long tv_nsec;
};
#endif
#ifdef __cplusplus
}
#endif
#else
#endif /* __timespec_defined */
#endif /* __NEWLIB__ */
#else /* CONFIG_NEWLIB_LIBC */
/* Not Newlib */
#include <sys/_timespec.h>
#endif /* CONFIG_NEWLIB_LIBC */
@ -44,10 +50,19 @@ struct timespec {
*/
#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>
@ -55,6 +70,10 @@ struct itimerspec {
#include "posix_types.h"
#include <posix/signal.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0
#endif

View file

@ -6,10 +6,6 @@
#ifndef ZEPHYR_INCLUDE_POSIX_UNISTD_H_
#define ZEPHYR_INCLUDE_POSIX_UNISTD_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "posix_types.h"
#include "sys/stat.h"
#ifdef CONFIG_NETWORKING
@ -20,6 +16,10 @@ extern "C" {
#ifdef CONFIG_POSIX_API
#include <fs/fs.h>
#ifdef __cplusplus
extern "C" {
#endif
/* File related operations */
extern int close(int file);
extern ssize_t write(int file, const void *buffer, size_t count);