From 48b1433772924a87e70153a60e3e01a362452d33 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 11 Mar 2019 17:45:31 +0800 Subject: [PATCH] vfs: change fcntl argument to int (instead of va_list), add weak fcntl --- components/lwip/port/esp32/vfs_lwip.c | 4 ++-- components/vfs/include/esp_vfs.h | 4 ++-- components/vfs/vfs.c | 14 ++++++++++---- components/vfs/vfs_uart.c | 3 +-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/components/lwip/port/esp32/vfs_lwip.c b/components/lwip/port/esp32/vfs_lwip.c index 54d71912bb..3610d2e175 100644 --- a/components/lwip/port/esp32/vfs_lwip.c +++ b/components/lwip/port/esp32/vfs_lwip.c @@ -40,9 +40,9 @@ static void lwip_stop_socket_select_isr(BaseType_t *woken) } } -static int lwip_fcntl_r_wrapper(int fd, int cmd, va_list args) +static int lwip_fcntl_r_wrapper(int fd, int cmd, int arg) { - return lwip_fcntl_r(fd, cmd, va_arg(args, int)); + return lwip_fcntl_r(fd, cmd, arg); } static int lwip_ioctl_r_wrapper(int fd, int cmd, va_list args) diff --git a/components/vfs/include/esp_vfs.h b/components/vfs/include/esp_vfs.h index e383c43632..49387dc5ff 100644 --- a/components/vfs/include/esp_vfs.h +++ b/components/vfs/include/esp_vfs.h @@ -163,8 +163,8 @@ typedef struct int (*rmdir)(const char* name); }; union { - int (*fcntl_p)(void* ctx, int fd, int cmd, va_list args); - int (*fcntl)(int fd, int cmd, va_list args); + int (*fcntl_p)(void* ctx, int fd, int cmd, int arg); + int (*fcntl)(int fd, int cmd, int arg); }; union { int (*ioctl_p)(void* ctx, int fd, int cmd, va_list args); diff --git a/components/vfs/vfs.c b/components/vfs/vfs.c index 45633cd03a..61a8f70659 100644 --- a/components/vfs/vfs.c +++ b/components/vfs/vfs.c @@ -657,21 +657,27 @@ int rmdir(const char* name) return ret; } -int fcntl(int fd, int cmd, ...) +int _fcntl_r(struct _reent *r, int fd, int cmd, int arg) { const vfs_entry_t* vfs = get_vfs_for_fd(fd); const int local_fd = get_local_fd(vfs, fd); - struct _reent* r = __getreent(); if (vfs == NULL || local_fd < 0) { __errno_r(r) = EBADF; return -1; } int ret; + CHECK_AND_CALL(ret, r, vfs, fcntl, local_fd, cmd, arg); + return ret; +} + +int __attribute__((weak)) fcntl(int fd, int cmd, ...) +{ va_list args; va_start(args, cmd); - CHECK_AND_CALL(ret, r, vfs, fcntl, local_fd, cmd, args); + int arg = va_arg(args, int); va_end(args); - return ret; + struct _reent* r = __getreent(); + return _fcntl_r(r, fd, cmd, arg); } int ioctl(int fd, int cmd, ...) diff --git a/components/vfs/vfs_uart.c b/components/vfs/vfs_uart.c index ebff91a879..62308e424a 100644 --- a/components/vfs/vfs_uart.c +++ b/components/vfs/vfs_uart.c @@ -265,7 +265,7 @@ static int uart_close(int fd) return 0; } -static int uart_fcntl(int fd, int cmd, va_list args) +static int uart_fcntl(int fd, int cmd, int arg) { assert(fd >=0 && fd < 3); int result = 0; @@ -274,7 +274,6 @@ static int uart_fcntl(int fd, int cmd, va_list args) result |= O_NONBLOCK; } } else if (cmd == F_SETFL) { - int arg = va_arg(args, int); s_non_blocking[fd] = (arg & O_NONBLOCK) != 0; } else { // unsupported operation -- 2.40.0