diff --git a/include/posix/mqueue.h b/include/posix/mqueue.h index 3bb9a0e66407..44c97932905c 100644 --- a/include/posix/mqueue.h +++ b/include/posix/mqueue.h @@ -9,6 +9,7 @@ #include #include +#include #include "posix_types.h" #include "sys/stat.h" @@ -25,21 +26,6 @@ typedef struct mq_attr { long mq_curmsgs; /* Number of messages currently queued. */ } mq_attr; -/* FIXME: below should be defined into fcntl.h file. - * This is temporarily put here. - */ - -#ifndef _SYS_FCNTL_H_ -#define O_CREAT_POS 9 -#define O_CREAT (1 << O_CREAT_POS) - -#define O_EXCL_POS 11 -#define O_EXCL (1 << O_EXCL_POS) - -#define O_NONBLOCK_POS 14 -#define O_NONBLOCK (1 << O_NONBLOCK_POS) -#endif /* _SYS_FCNTL_H_ */ - mqd_t mq_open(const char *name, int oflags, ...); int mq_close(mqd_t mqdes); int mq_unlink(const char *name); diff --git a/include/posix/sys/stat.h b/include/posix/sys/stat.h deleted file mode 100644 index 7b4b2eadab80..000000000000 --- a/include/posix/sys/stat.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2018 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef ZEPHYR_INCLUDE_POSIX_SYS_STAT_H_ -#define ZEPHYR_INCLUDE_POSIX_SYS_STAT_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef CONFIG_POSIX_API -#include - -#define S_IRWXU 00700 -#define S_IRUSR 00400 -#define S_IWUSR 00200 -#define S_IXUSR 00100 - -#define S_IRWXG 00070 -#define S_IRGRP 00040 -#define S_IWGRP 00020 -#define S_IXGRP 00010 - -#define S_IRWXO 00007 -#define S_IROTH 00004 -#define S_IWOTH 00002 -#define S_IXOTH 00001 - -/* File open modes */ -#define O_ACCMODE 0003 -#define O_RDONLY 00 -#define O_WRONLY 01 -#define O_RDWR 02 - -#define SEEK_SET 0 /* Seek from beginning of file. */ -#define SEEK_CUR 1 /* Seek from current position. */ -#define SEEK_END 2 /* Seek from end of file. */ - -struct stat { - unsigned long st_size; - unsigned long st_blksize; - unsigned long st_blocks; -}; - -#endif /* CONFIG_POSIX_API */ - -#ifdef __cplusplus -} -#endif - -#endif /* ZEPHYR_INCLUDE_POSIX_SYS_STAT_H_ */ diff --git a/include/posix/time.h b/include/posix/time.h index 2838399cd648..72b3b8b386b2 100644 --- a/include/posix/time.h +++ b/include/posix/time.h @@ -10,14 +10,30 @@ extern "C" { #endif +#ifdef CONFIG_NEWLIB_LIBC +/* Kludge to support outdated newlib version as used in SDK 0.10 for Xtensa */ +#include +#ifdef __NEWLIB__ +/* Newever Newlib 3.x+ */ +#include +#else +/* Workaround for older Newlib 2.x, as used by Xtensa. It lacks sys/_timeval.h, + * so mimic it here. + */ +#include #ifndef __timespec_defined -#define __timespec_defined struct timespec { - signed int tv_sec; - signed int tv_nsec; + time_t tv_sec; + long tv_nsec; }; #endif +#endif + +#else +/* Not Newlib */ +#include +#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 diff --git a/include/posix/unistd.h b/include/posix/unistd.h index d25006a557da..fb1fe806b5cc 100644 --- a/include/posix/unistd.h +++ b/include/posix/unistd.h @@ -21,7 +21,6 @@ extern "C" { #include /* File related operations */ -extern int open(const char *name, int flags); extern int close(int file); extern ssize_t write(int file, const void *buffer, size_t count); extern ssize_t read(int file, void *buffer, size_t count); diff --git a/lib/libc/minimal/include/fcntl.h b/lib/libc/minimal/include/fcntl.h index 453442d44c99..caa79c91965f 100644 --- a/lib/libc/minimal/include/fcntl.h +++ b/lib/libc/minimal/include/fcntl.h @@ -7,10 +7,14 @@ #ifndef ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_FCNTL_H_ #define ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_FCNTL_H_ +#define O_CREAT 0x0200 +#define O_EXCL 0x0800 #define O_NONBLOCK 0x4000 #define F_DUPFD 0 #define F_GETFL 3 #define F_SETFL 4 +int open(const char *name, int flags); + #endif /* ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS_FCNTL_H_ */ diff --git a/lib/libc/minimal/include/sys/_timespec.h b/lib/libc/minimal/include/sys/_timespec.h new file mode 100644 index 000000000000..5e8364c77265 --- /dev/null +++ b/lib/libc/minimal/include/sys/_timespec.h @@ -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 + +struct timespec { + time_t tv_sec; + long tv_nsec; +}; + +#endif /* ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS__TIMESPEC_H_ */ diff --git a/lib/libc/minimal/include/sys/stat.h b/lib/libc/minimal/include/sys/stat.h index 4636b5400506..54f05bdd64d4 100644 --- a/lib/libc/minimal/include/sys/stat.h +++ b/lib/libc/minimal/include/sys/stat.h @@ -1,9 +1,49 @@ /* - * Copyright (c) 2018 Linaro Limited + * Copyright (c) 2018 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ +#ifndef ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS_STAT_H_ +#define ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS_STAT_H_ -/* Dummy sys/stat.h to fulfill the requirements of certain libraries. - */ +#ifdef __cplusplus +extern "C" { +#endif + +#define S_IRWXU 00700 +#define S_IRUSR 00400 +#define S_IWUSR 00200 +#define S_IXUSR 00100 + +#define S_IRWXG 00070 +#define S_IRGRP 00040 +#define S_IWGRP 00020 +#define S_IXGRP 00010 + +#define S_IRWXO 00007 +#define S_IROTH 00004 +#define S_IWOTH 00002 +#define S_IXOTH 00001 + +/* File open modes */ +#define O_ACCMODE 0003 +#define O_RDONLY 00 +#define O_WRONLY 01 +#define O_RDWR 02 + +#define SEEK_SET 0 /* Seek from beginning of file. */ +#define SEEK_CUR 1 /* Seek from current position. */ +#define SEEK_END 2 /* Seek from end of file. */ + +struct stat { + unsigned long st_size; + unsigned long st_blksize; + unsigned long st_blocks; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS_STAT_H_ */ diff --git a/lib/libc/minimal/include/time.h b/lib/libc/minimal/include/time.h index 84c976f72c8d..918ef864934e 100644 --- a/lib/libc/minimal/include/time.h +++ b/lib/libc/minimal/include/time.h @@ -34,10 +34,7 @@ struct tm { typedef int64_t time_t; typedef int32_t suseconds_t; -struct timespec { - time_t tv_sec; - long tv_nsec; -}; +#include /* * Conversion between civil time and UNIX time. The companion diff --git a/tests/posix/common/src/mqueue.c b/tests/posix/common/src/mqueue.c index d7123ea64e67..c83f3751fbcc 100644 --- a/tests/posix/common/src/mqueue.c +++ b/tests/posix/common/src/mqueue.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include diff --git a/tests/posix/fs/src/test_fs_dir.c b/tests/posix/fs/src/test_fs_dir.c index 46e4f0311f3c..4b3d02ebe7c0 100644 --- a/tests/posix/fs/src/test_fs_dir.c +++ b/tests/posix/fs/src/test_fs_dir.c @@ -5,6 +5,7 @@ */ #include +#include #include #include #include "test_fs.h" diff --git a/tests/posix/fs/src/test_fs_file.c b/tests/posix/fs/src/test_fs_file.c index 5b6036a2cc6c..614f99ac47dd 100644 --- a/tests/posix/fs/src/test_fs_file.c +++ b/tests/posix/fs/src/test_fs_file.c @@ -5,6 +5,7 @@ */ #include +#include #include #include "test_fs.h"