How to fix C error ‘errno undeclared’

Problem:

You have C code like

errno = EFAULT;

but when you try to compile it you see an error message like

main.c: In function ‘main’:
main.c:4:5: error: ‘errno’ undeclared (first use in this function)
     errno = EFAULT;
     ^~~~~
main.c:4:5: note: each undeclared identifier is reported only once for each function it appears in
main.c:4:13: error: ‘EFAULT’ undeclared (first use in this function)
     errno = EFAULT;

Solution:

Add

#include <errno.h>

at the top of the source file where the error occured. This will include both the errno variable and specific error codes like EFAULT.