diff --git a/components/lwip/port/esp32/vfs_lwip.c b/components/lwip/port/esp32/vfs_lwip.c index 54d71912b..3610d2e17 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 e383c4363..49387dc5f 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 45633cd03..61a8f7065 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 ebff91a87..62308e424 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