newlib: set errno in the explicitly provided reent structure

Since these functions receive the pointer to reent structure, they
should set errno in it rather than using thread-local errno.

This didn't cause practical issues because console functions in IDF
are only called from threads, and in that case 'r' is a pointer to
the thread-local structure, so &errno is the same thing as
&__errno_r(r). Still, fixing this for consistency.
This commit is contained in:
Ivan Grokhotkov 2021-09-15 14:56:31 +02:00
parent 5da66d1d39
commit ccda990ce5

View File

@ -24,9 +24,9 @@
#include "sdkconfig.h"
#include "esp_rom_uart.h"
static int syscall_not_implemented(void)
static int syscall_not_implemented(struct _reent *r, ...)
{
errno = ENOSYS;
__errno_r(r) = ENOSYS;
return -1;
}
@ -44,7 +44,7 @@ ssize_t _write_r_console(struct _reent *r, int fd, const void * data, size_t siz
}
return size;
}
errno = EBADF;
__errno_r(r) = EBADF;
return -1;
}
@ -61,7 +61,7 @@ ssize_t _read_r_console(struct _reent *r, int fd, void * data, size_t size)
}
return received;
}
errno = EBADF;
__errno_r(r) = EBADF;
return -1;
}
@ -118,8 +118,6 @@ int _isatty_r(struct _reent *r, int fd)
/* These functions are not expected to be overridden */
int system(const char* str)
__attribute__((alias("syscall_not_implemented")));
int _system_r(struct _reent *r, const char *str)
__attribute__((alias("syscall_not_implemented")));
int raise(int sig)
@ -137,6 +135,13 @@ void _exit(int __status)
#pragma GCC diagnostic pop
/* Similar to syscall_not_implemented, but not taking struct _reent argument */
int system(const char* str)
{
errno = ENOSYS;
return -1;
}
/* Replaces newlib fcntl, which has been compiled without HAVE_FCNTL */
int fcntl(int fd, int cmd, ...)
{