Kaynağa Gözat

newlib: define fcntl as strong symbol

Closes https://github.com/espressif/esp-idf/issues/3694
Closes https://github.com/espressif/esp-idf/issues/4407
Ivan Grokhotkov 6 yıl önce
ebeveyn
işleme
85656ca77d

+ 14 - 1
components/newlib/syscalls.c

@@ -15,10 +15,12 @@
 #include <string.h>
 #include <stdbool.h>
 #include <stdlib.h>
+#include <stdarg.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <errno.h>
-#include <sys/reent.h>
+#include <reent.h>
+#include <sys/fcntl.h>
 
 
 int system(const char* str)
@@ -65,6 +67,17 @@ void _exit(int __status)
     abort();
 }
 
+/* Replaces newlib fcntl, which has been compiled without HAVE_FCNTL */
+int fcntl(int fd, int cmd, ...)
+{
+    va_list args;
+    va_start(args, cmd);
+    int arg = va_arg(args, int);
+    va_end(args);
+    struct _reent* r = __getreent();
+    return _fcntl_r(r, fd, cmd, arg);
+}
+
 /* No-op function, used to force linking this file,
    instead of the syscalls implementation from libgloss.
  */

+ 11 - 0
components/vfs/test/test_vfs_uart.c

@@ -202,6 +202,17 @@ TEST_CASE("can write to UART while another task is reading", "[vfs]")
     vSemaphoreDelete(write_arg.done);
 }
 
+TEST_CASE("fcntl supported in UART VFS", "[vfs]")
+{
+    int flags = fcntl(STDIN_FILENO, F_GETFL, 0);
+    TEST_ASSERT_NOT_EQUAL(-1, flags);
+    int res = fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK);
+    TEST_ASSERT_NOT_EQUAL(-1, res);
+    /* revert */
+    res = fcntl(STDIN_FILENO, F_SETFL, flags);
+    TEST_ASSERT_NOT_EQUAL(-1, res);
+}
+
 #ifdef CONFIG_VFS_SUPPORT_TERMIOS
 TEST_CASE("Can use termios for UART", "[vfs]")
 {

+ 0 - 10
components/vfs/vfs.c

@@ -725,16 +725,6 @@ int _fcntl_r(struct _reent *r, int fd, int cmd, int arg)
     return ret;
 }
 
-int __attribute__((weak)) fcntl(int fd, int cmd, ...)
-{
-    va_list args;
-    va_start(args, cmd);
-    int arg = va_arg(args, int);
-    va_end(args);
-    struct _reent* r = __getreent();
-    return _fcntl_r(r, fd, cmd, arg);
-}
-
 int ioctl(int fd, int cmd, ...)
 {
     const vfs_entry_t* vfs = get_vfs_for_fd(fd);