How to fix C error 'mode_t undeclared'
Problem:
You have C code like
mode_t mode;
but when you try to compile it you see an error message like
main.c: In function ‘main’:
main.c:4:2: error: unknown type name ‘mode_t’
mode_t mode;
^~~~~~
Solution
Add
#include <sys/stat.h>
at the top of the source file where the error occured. In case you want further information about what mode_t
represents, I recommend reading this blogpost.