Search code examples
cdirectorydirent.h

How can I list directories without including files including dirent.h?


I have searched this a lot about this thing: How to make C print all directories without dirent.h. I found something called tiny dirent or something but it wasn't so useful for me becasue it had a licence on it. I have found seveal things more that wasn't uselful. Now, I want to do it myself that I found out the only way is to write one by myself. I am using GCC to compile and I use linux to make one. So, how can I make my own dirent.h without including any header files?


Solution

  • This is operating system specific, since not all C implementations (think of some C program for Arduino) have directories.

    How can I list directories without including files including dirent.h?

    By using some other libraries, or directly some syscalls(2).

    Did you consider using ntfw(3), or readdir(3) ?

    So, how can I make my own dirent.h without including any header files?

    You create C source files with a good editor such as GNU emacs. Or you use (or write) a program generating some C code (e.g. GNU bison).

    You should read a good operating system textbook if you want to create your own OS. Then see also OSDEV, and budget several years of full time work. See also LinuxFromScratch, and study for inspiration the source code of the Linux kernel or of FreeBSD.

    I am using GCC to compile

    Be sure to read the documentation of GCC (user and internals). Use it as gcc -Wall -Wextra -g. You might code your GCC plugin, or generate some C code with e.g. GPP