Skip to content

posix: Clean up various headers #16626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions include/posix/mqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <kernel.h>
#include <posix/time.h>
#include <fcntl.h>
#include "posix_types.h"
#include "sys/stat.h"

Expand All @@ -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);
Expand Down
54 changes: 0 additions & 54 deletions include/posix/sys/stat.h

This file was deleted.

22 changes: 19 additions & 3 deletions include/posix/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <newlib.h>

#ifdef __NEWLIB__
/* Newever Newlib 3.x+ */
#include <sys/_timespec.h>
#else
/* 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
#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 <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
Expand Down
1 change: 0 additions & 1 deletion include/posix/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ extern "C" {
#include <fs/fs.h>

/* 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);
Expand Down
4 changes: 4 additions & 0 deletions lib/libc/minimal/include/fcntl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
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/types.h>

struct timespec {
time_t tv_sec;
long tv_nsec;
};

#endif /* ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS__TIMESPEC_H_ */
46 changes: 43 additions & 3 deletions lib/libc/minimal/include/sys/stat.h
Original file line number Diff line number Diff line change
@@ -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_ */
5 changes: 1 addition & 4 deletions lib/libc/minimal/include/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sys/_timespec.h>

/*
* Conversion between civil time and UNIX time. The companion
Expand Down
1 change: 1 addition & 0 deletions tests/posix/common/src/mqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <ztest.h>
#include <zephyr.h>
#include <sys/printk.h>
#include <fcntl.h>
#include <mqueue.h>
#include <pthread.h>

Expand Down
1 change: 1 addition & 0 deletions tests/posix/fs/src/test_fs_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <stdio.h>
#include <fcntl.h>
#include <posix/unistd.h>
#include <posix/dirent.h>
#include "test_fs.h"
Expand Down
1 change: 1 addition & 0 deletions tests/posix/fs/src/test_fs_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <string.h>
#include <fcntl.h>
#include <posix/unistd.h>
#include "test_fs.h"

Expand Down