From 7f9127578ba796306b73f04f121c931dc402d706 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 8 Oct 2018 18:48:22 +0300 Subject: [PATCH] include: posix: unistd: Fix prototypes and dependency For read/write/lseek, use size_t and off_t types, as mandated by POSIX: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html Also, prototypes of unistd.h functions should not depend on CONFIG_POSIX_FS, as (many) of them deal with generic I/O, not with files in filesystem per se. Signed-off-by: Paul Sokolovsky --- include/posix/unistd.h | 8 ++++---- lib/posix/fs.c | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/posix/unistd.h b/include/posix/unistd.h index ca93eb4af1a..3195de3048e 100644 --- a/include/posix/unistd.h +++ b/include/posix/unistd.h @@ -13,7 +13,7 @@ extern "C" { #include "sys/types.h" #include "sys/stat.h" -#ifdef CONFIG_POSIX_FS +#ifdef CONFIG_POSIX_API #include typedef unsigned int mode_t; @@ -21,9 +21,9 @@ typedef unsigned int mode_t; /* File related operations */ extern int open(const char *name, int flags); extern int close(int file); -extern ssize_t write(int file, char *buffer, unsigned int count); -extern ssize_t read(int file, char *buffer, unsigned int count); -extern int lseek(int file, int offset, int whence); +extern ssize_t write(int file, const void *buffer, size_t count); +extern ssize_t read(int file, void *buffer, size_t count); +extern off_t lseek(int file, off_t offset, int whence); /* File System related operations */ extern int rename(const char *old, const char *newp); diff --git a/lib/posix/fs.c b/lib/posix/fs.c index 803a34d523f..3d5743e728d 100644 --- a/lib/posix/fs.c +++ b/lib/posix/fs.c @@ -151,7 +151,7 @@ int close(int fd) * * See IEEE 1003.1 */ -ssize_t write(int fd, char *buffer, unsigned int count) +ssize_t write(int fd, const void *buffer, size_t count) { ssize_t rc; struct fs_file_t *ptr = NULL; @@ -175,7 +175,7 @@ ssize_t write(int fd, char *buffer, unsigned int count) * * See IEEE 1003.1 */ -ssize_t read(int fd, char *buffer, unsigned int count) +ssize_t read(int fd, void *buffer, size_t count) { ssize_t rc; struct fs_file_t *ptr = NULL; @@ -199,7 +199,7 @@ ssize_t read(int fd, char *buffer, unsigned int count) * * See IEEE 1003.1 */ -int lseek(int fd, int offset, int whence) +off_t lseek(int fd, off_t offset, int whence) { int rc; struct fs_file_t *ptr = NULL;