Implementing the ls -l command in C
maxence57590
Posted messages
4
Status
Member
-
maxence57590 Posted messages 4 Status Member -
maxence57590 Posted messages 4 Status Member -
Hello,
As part of a project, I would like to display the different types of files in a directory (executable, text, etc.).
I can display the files using "opendir," but I keep searching and can't find anything on how to display the types of files... If anyone has a suggestion, thank you in advance.
As part of a project, I would like to display the different types of files in a directory (executable, text, etc.).
I can display the files using "opendir," but I keep searching and can't find anything on how to display the types of files... If anyone has a suggestion, thank you in advance.
4 answers
A regular file is quite different from a symbolic link, a named pipe, or a device entry (character, block).
<ital>struct dirent {
ino_t d_ino; /* numéro d'inode */
off_t d_off; /* pas un décalage; voir NOTES */
unsigned short d_reclen; /* longueur de cet enregistrement */
unsigned char d_type; /* type de fichier; non pris en charge
par tous les types de systèmes de fichiers */
char d_name[256]; /* nom de fichier */
}</ital>
L'entrée d_type contient le type d'entrée.
See
To determine file types, look towards libmagic
--
Gates a donné ^W vous a vendu les fenêtres.
GNU nous a donné toute la maison. (Alexandrin)
<ital>struct dirent {
ino_t d_ino; /* numéro d'inode */
off_t d_off; /* pas un décalage; voir NOTES */
unsigned short d_reclen; /* longueur de cet enregistrement */
unsigned char d_type; /* type de fichier; non pris en charge
par tous les types de systèmes de fichiers */
char d_name[256]; /* nom de fichier */
}</ital>
L'entrée d_type contient le type d'entrée.
See
man 3 readdir
To determine file types, look towards libmagic
--
Gates a donné ^W vous a vendu les fenêtres.
GNU nous a donné toute la maison. (Alexandrin)
maxence57590
Posted messages
4
Status
Member
A big THANK YOU, it really helps me, I feel like I'm not far from my desired goal!
Hello,
The "type of a file" does not exist. All files are a series of bytes, there is no difference.
Depending on the operating system, you may have concepts of extensions or execution rights that allow you to add additional information. But nothing can be generalized.
--
Trust does not exclude control.
The "type of a file" does not exist. All files are a series of bytes, there is no difference.
Depending on the operating system, you may have concepts of extensions or execution rights that allow you to add additional information. But nothing can be generalized.
--
Trust does not exclude control.
Extensions only make sense on Windows.
If you're talking about "ls -l", you're probably on GNU/Linux. So forget about this extension story.
ls -l does not provide the file type. It will only show if it is a directory or not... However, it will also display the file permissions (read, write, etc.).
Is it really ls -l that you want to reproduce?
--
Google is your friend
If you're talking about "ls -l", you're probably on GNU/Linux. So forget about this extension story.
ls -l does not provide the file type. It will only show if it is a directory or not... However, it will also display the file permissions (read, write, etc.).
Is it really ls -l that you want to reproduce?
--
Google is your friend