Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <time.h>
- #include <fcntl.h> //Inclus les flags pour open
- char* getType(struct stat f){
- switch (f.st_mode & S_IFMT) {
- case S_IFBLK: return "périphérique bloc"; break;
- case S_IFCHR: return "périphérique caractère"; break;
- case S_IFDIR: return "répertoire"; break;
- case S_IFIFO: return "FIFO/tube"; break;
- case S_IFLNK: return "lien symbolique"; break;
- case S_IFREG: return "fichier ordinaire"; break;
- case S_IFSOCK: return "socket"; break;
- default: return "inconnu ?"; break;
- }
- }
- int main(int argc, char* argv[]){
- if (argc != 2){
- printf("Usage %s [file]\n", argv[0]);
- return -1;
- }
- else{
- int ld = open(argv[1], O_RDONLY);
- struct stat retour;
- if (fstat(ld, &retour) == 0){
- printf(" inode n° %i\n UID du propiétaire: %i \n GID du propriétaire: %i\n Taille (octets): %i\n Date dernier accès: %s Type : %s\n Droits : %c%c%c%c%c%c%c%c%c\n",
- retour.st_ino,
- retour.st_uid,
- retour.st_gid,
- retour.st_size,
- ctime(&retour.st_atime),
- getType(retour),
- (retour.st_mode & S_IRUSR) ? 'r' : '-', (retour.st_mode & S_IWUSR) ? 'w' : '-', (retour.st_mode & S_IXUSR) ? 'x' : '-',
- (retour.st_mode & S_IRGRP) ? 'r' : '-', (retour.st_mode & S_IWGRP) ? 'w' : '-', (retour.st_mode & S_IXGRP) ? 'x' : '-',
- (retour.st_mode & S_IROTH) ? 'r' : '-', (retour.st_mode & S_IWOTH) ? 'w' : '-', (retour.st_mode & S_IXOTH) ? 'x' : '-');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement