Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit declaration of function 'ftruncate' #3

Closed
imba-tjd opened this issue Jun 29, 2018 · 2 comments
Closed

Implicit declaration of function 'ftruncate' #3

imba-tjd opened this issue Jun 29, 2018 · 2 comments

Comments

@imba-tjd
Copy link
Owner

imba-tjd commented Jun 29, 2018

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.
qq 20180629173139
qq 20180629152812

@imba-tjd imba-tjd added the help wanted Extra attention is needed label Jun 29, 2018
@alrshdn
Copy link

alrshdn commented May 11, 2024

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.

@imba-tjd
Copy link
Owner Author

imba-tjd commented May 26, 2024

@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.

@imba-tjd imba-tjd removed the help wanted Extra attention is needed label May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants