Warning: include(remarks.php): failed to open stream: No such file or directory in /mnt/tanenbaum/sd3/thesards/masson/W3/v2/Teachings/PR-IT-4205/tp3/content.php on line 3
Warning: include(): Failed opening 'remarks.php' for inclusion (include_path='.:/usr/share/php5:/usr/share/php') in /mnt/tanenbaum/sd3/thesards/masson/W3/v2/Teachings/PR-IT-4205/tp3/content.php on line 3
Exercise 1 - stat ()Using the system call stat(), write a program that displays the inode number, size, modification date and type (file, directory, or otherwise) of a file passed as an argument. No need to format the date change: simply post it as is (in seconds since January 1, 1970). For the type, just print "d", "f", or "?" to specify a directory, file, or something else. To know the type of a file, use S_ISDIR macros family on the field st_mode of the structure passed to stat().
Exercise 2 - lstat ()Modify the previous program to indicate whether the file is a link (with the letter "l") and give the link destination. For this, use the system call lstat() (note: stat() always follows links, and never says if a file is linked or not! Moreover, if you ask stat() to follow an invalid link, it will return an error), and the system call readlink() for the link destination. Read the manpage of readlink () ...
Exercise 3 - My mini-version of ls
Using the library functions opendir() and readdir() (note: there also exists a system call readdir(), use the one described in section 3 of man pages), write a program that lists the contents of the current directory, displaying just the name of each file. Do not forget the closedir() at the end. Then, display the same information as the prior exercise (code reuse) - by adding the name of each file, of course. Warning: you must append the directory name and file name, we recommend the use of snprintf ().
Modify the previous program so that:
- if there is no argument, it functions as the previous program
- if the first argument is a file, it works as the program of Exercise 2
- if the first argument is a directory, it lists the contents of this directory
- if there are several arguments, he treats them one after the other