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.
Having learnt directory too is a interpreted as a file , I tried opening it in vi editor and i found its contents(i mean files n sub-dirs) there , maybe , i thought these strings are symbolic links to the actual contents in memory..
Later, when I tried to print same contents using "cat" it gave me an error that the argument is a directory and hence I wrote a simple C code to open the directory argument as a file (it is ofcourse) n list its contents parsing the file character by char. When i compile n run it with some sub-directory as an argument , unfortunately it didn't print anything.
So this time i edited my code such that it prints the no of bytes too in this (directory) file (just seeking the file pointer to the end n printing its offset using ftell()) n when i run it it gives me the fixed integer "4096" for many directories which i have tried (including the / directory), but still no contents(i.e no bytes) being displayed ..
I felt it crazy n something is there in these directory files which i yet donno ,
as the code appears elementary i don't think its necessary posting it here...
just learnt C in UNIX ( all those editing n using cc,gdb,linking libraries , running executables..) , i am a sort of beginner in UNIX ...
hope i am pretty clear with my doubt.. n any solution is greatly appreciated...
vim interprets directories as files for your convenience to assist you in getting to the file that you actually want. They are not "files". There should be "readdir" functions you can use to read directories.
vim interprets directories as files for your convenience to assist you in getting to the file that you actually want. They are not "files". There should be "readdir" functions you can use to read directories.
And, of course, you can get the source for the "readdir" function -- or, perhaps, the "ls" command -- and see how the directory is read.
Note that a directory, like almost everyting in *nix systems, is a file, but some files require "special" handeling. The information need to do so is (I believe) to be found in the POSIX standards for UNIX systems. (That's a guess, since I've never actually looked at the standards.)
Getting the raw bytes of a directory entry wouldn't be so useful, since the contents (and hence what to do with them to achieve some goal) will depend on the underlying filesystem you are using.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.