Issue with S_ISDIR() result in C (maybe because stat() isn't setting its struct properly?)

前端 未结 1 939
无人及你
无人及你 2021-01-29 03:01

I want my program to take a directory, then print the contents of that directory and state whether or not each item is a directory or not. If I give it a directory containing fi

相关标签:
1条回答
  • 2021-01-29 03:16

    You're passing stat the name of the file, but it needs a path to the file. If you check the return value for stat, you'll see that it's only succeeding for . and .., because they exist in any directory.

    Canonical answer: Do not ever try to understand the behavior of a program that blows through error conditions. As soon as it's even the tiniest bit mysterious (at the latest), add code to check the return values of all functions.

    0 讨论(0)
提交回复
热议问题