mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 18:57:19 +02:00
Merge branch 'bugfix/libc_link_issues_v4.0' into 'release/v4.0'
newlib: fix linking issues (fcntl, system, raise) (backport v4.0) See merge request espressif/esp-idf!7000
This commit is contained in:
@ -134,7 +134,11 @@ static esp_err_t esp_tcp_connect(const char *host, int hostlen, int port, int *s
|
|||||||
}
|
}
|
||||||
if (cfg->non_block) {
|
if (cfg->non_block) {
|
||||||
int flags = fcntl(fd, F_GETFL, 0);
|
int flags = fcntl(fd, F_GETFL, 0);
|
||||||
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
|
ret = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
|
||||||
|
if (ret < 0) {
|
||||||
|
ESP_LOGE(TAG, "Failed to configure the socket as non-blocking (errno %d)", errno);
|
||||||
|
goto err_freesocket;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,18 +15,31 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/reent.h>
|
#include <reent.h>
|
||||||
|
#include <sys/fcntl.h>
|
||||||
|
|
||||||
|
|
||||||
|
int system(const char* str)
|
||||||
|
{
|
||||||
|
errno = ENOSYS;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int _system_r(struct _reent *r, const char *str)
|
int _system_r(struct _reent *r, const char *str)
|
||||||
{
|
{
|
||||||
__errno_r(r) = ENOSYS;
|
__errno_r(r) = ENOSYS;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int raise(int sig)
|
||||||
|
{
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
int _raise_r(struct _reent *r, int sig)
|
int _raise_r(struct _reent *r, int sig)
|
||||||
{
|
{
|
||||||
abort();
|
abort();
|
||||||
@ -54,6 +67,17 @@ void _exit(int __status)
|
|||||||
abort();
|
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,
|
/* No-op function, used to force linking this file,
|
||||||
instead of the syscalls implementation from libgloss.
|
instead of the syscalls implementation from libgloss.
|
||||||
*/
|
*/
|
||||||
|
@ -182,3 +182,8 @@ TEST_CASE("fmod and fmodf work as expected", "[newlib]")
|
|||||||
TEST_ASSERT_EQUAL(0.1, fmod(10.1, 2.0));
|
TEST_ASSERT_EQUAL(0.1, fmod(10.1, 2.0));
|
||||||
TEST_ASSERT_EQUAL(0.1f, fmodf(10.1f, 2.0f));
|
TEST_ASSERT_EQUAL(0.1f, fmodf(10.1f, 2.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("newlib: can link 'system', 'raise'", "[newlib]")
|
||||||
|
{
|
||||||
|
printf("system: %p, raise: %p\n", &system, &raise);
|
||||||
|
}
|
||||||
|
@ -202,6 +202,17 @@ TEST_CASE("can write to UART while another task is reading", "[vfs]")
|
|||||||
vSemaphoreDelete(write_arg.done);
|
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
|
#ifdef CONFIG_VFS_SUPPORT_TERMIOS
|
||||||
TEST_CASE("Can use termios for UART", "[vfs]")
|
TEST_CASE("Can use termios for UART", "[vfs]")
|
||||||
{
|
{
|
||||||
|
@ -725,16 +725,6 @@ int _fcntl_r(struct _reent *r, int fd, int cmd, int arg)
|
|||||||
return ret;
|
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, ...)
|
int ioctl(int fd, int cmd, ...)
|
||||||
{
|
{
|
||||||
const vfs_entry_t* vfs = get_vfs_for_fd(fd);
|
const vfs_entry_t* vfs = get_vfs_for_fd(fd);
|
||||||
|
Reference in New Issue
Block a user