Implicit declaration of function 'ftruncate'
see this code.
I have included unistd.h and sys/types.h, but it doesn't work.
However, my program did't report 'bus error' and crash.

I know this is so old, but there is no issue in answering it now. Since you have enabled all warnings, you will have to compile with:
gcc -D_XOPEN_SOURCE=<version> ...
<version> has to be 500 or more for this specific feature (ftruncate(...)). This is shown in its manual page and in your screenshot.
You can find more explanation in feature_test_macros(7); run the command:
man 7 feature_test_macros
Hope this help! Have a nice day.
@alrshdn Thank you! I have no experence in developing Linux C program.
You are right. I tested it again and the warning disappers. ~~Accroding to the doc, it's because I'm using a newer glibc now.~~
Well, it seems that /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L means I need to use glibc >= 2.12 and define _POSIX_C_SOURCE >= 200809L. Althouth I tested printf("%ld\n", _POSIX_C_SOURCE); and it actually prints 200809 now.
I also tried to ask ChatGPT. After some instructions, it gives the solution of #define _POSIX_C_SOURCE 200809L, which is bigger than 200112L. Students thesedays should have a better learning experience than I did.