diff --git a/docs/manual/embedded.md b/docs/manual/embedded.md index e3f4c4c81..d9f0f3ee7 100644 --- a/docs/manual/embedded.md +++ b/docs/manual/embedded.md @@ -1530,6 +1530,7 @@ what it calls: string in flash. A floating-point conversion prints `?`, as avr-libc's does without `-lprintf_flt`; EmbCC has no `printf_flt`; - the `` functions; +- `errno`, with one value for the program (AVR has no threads of its own); - `setjmp` and `longjmp`, with a 24-byte `jmp_buf`: r2-r17, Y, the stack pointer, SREG and the return address. diff --git a/lib/avr/errno.c b/lib/avr/errno.c new file mode 100644 index 000000000..086cb412c --- /dev/null +++ b/lib/avr/errno.c @@ -0,0 +1,6 @@ +/* AVR has no threads of its own, so errno is one value for the program. */ +#include + +static int g_errno; + +int *__errno_location(void) { return &g_errno; } diff --git a/tests/golden/avr-libc-run.sh b/tests/golden/avr-libc-run.sh index f25e4d645..b99bfbee7 100644 --- a/tests/golden/avr-libc-run.sh +++ b/tests/golden/avr-libc-run.sh @@ -30,6 +30,7 @@ done ${CC:-cc} -w -I$D $D/host.c -o "$out/host" || fail "the host program" "$out/host" > "$out/host.txt" || fail "the host program does not run" { cat <<'EOF' +errno 34 byte 22 fe word 1234 beef dword 89abcdef qword 102030405060708 float 5 ptr world diff --git a/tests/golden/avr-libc-run/prog.c b/tests/golden/avr-libc-run/prog.c index f85432195..5d3602060 100644 --- a/tests/golden/avr-libc-run/prog.c +++ b/tests/golden/avr-libc-run/prog.c @@ -2,6 +2,7 @@ * and the _P functions, and the printf family, on QEMU's ATmega328P. */ #include #include +#include #include #include @@ -33,6 +34,9 @@ int main(void) UCSR0B = _BV(TXEN0); UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); + errno = ERANGE; + SHOW("errno %d", errno); + /* pgm_read_* */ SHOW("byte %x %x word %x %x", pgm_read_byte(&bytes[1]), pgm_read_byte(&bytes[3]), pgm_read_word(&words[0]), pgm_read_word(&words[1]));