Is it possible to use opendir repeatedly in C?

房东的猫 提交于 2019-12-12 19:29:11

问题


I am trying to debug right now in C and am curious if it is alright to call opendir() repeatedly without having to first call closedir() because I am trying to run a loop to open sub-directories when the while-loop that calls readdir() encounters them. And I assume that closing the current directory would cause me to lose the ability to read it.


回答1:


You can use opendir() repeatedly. Just keep your DIR *s and call closedir() when you're done with each.




回答2:


Yes, you can do multiple opendir() calls. Be wary of symbolic link loops which could cause you to get into an infinite loop and consume all available memory.




回答3:


You'll have to be careful not to leak the DIR* that you are collecting, but as long as you don't hit the file-descriptor limit you shouldn't have any problem with having multiple opendir() open at the same time.



来源:https://stackoverflow.com/questions/1742997/is-it-possible-to-use-opendir-repeatedly-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!