ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
ftw function of ftw.h is a recursive implementation for recursively walking down a directory tree. I want to know how deep can the recursion level be.
I am making a program using ftw in which I may have to give the root directory also for traversing. So how can I know that at what level of subdirectories the function will fail?? TIA
I'm not 100% sure about this, but the stack is usually megabytes in size (8Mb size is default, but it can be set with "ulimit -s"). So unless it's set very low, or other parts of the program uses a lot of stack space, you can't reach that limit. MAX_PATH is usually 256 bytes, which means you can't go deeper than about 128 directories, and that doesn't take much stack space.
Edit: I was mistaken, directories can be a lot deeper than I thought. But the stack still has a lot of space and can hold directories thousands of levels deep..
thanks a lot guys.... that answered my question
I need to understand one more thing
PATH_MAX is the maximum path length allowed on the system....can anyone change it on the system and if he does then what will be the maximum limit of the directory level.
On my system also PATH_MAX is 4096
That would probably require modifying the C-code of fundamental parts of the operating system like libc and/or the kernel.
So, pretty unlikely that your program will be run on such a system. I suppose the find program also depends on this max directory tree recursion limit.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.