Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @file main.c
- * @brief Description
- * @date 2015-10-24
- * @author name of author
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <unistd.h>
- #include <signal.h>
- #include <errno.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/sem.h>
- #include <sys/shm.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <assert.h>
- #include "debug.h"
- #include "memory.h"
- char *tipo_file_str(mode_t st_mode);
- int main(int argc, char *argv[]){
- if(argc < 2){
- //fprintf(stderr, "Numero de argumentos invalido!\nRecebi %i em vez de 2!\nSyntax: %s path_fich\n", argc, argv[0]);
- //exit(1);
- ERROR(1, "Numero de argumentos invalido!\nRecebi %i em vez de 2!\nSyntax: %s path_fich\n", argc, argv[0]);
- }
- int ret_stat;
- struct stat stat_buf;
- int i;
- for(i=1;i<argc;i++){
- ret_stat = stat(argv[i],&stat_buf);
- if(ret_stat==-1){
- fprintf(stderr,"Erro: chamada stat para recurso '%s' - %s\n",argv[i],strerror(errno));
- exit(1);
- }
- printf("O ficheiro %s e um %s\n", argv[i], tipo_file_str(stat_buf.st_mode));
- }
- return 0;
- }
- char *tipo_file_str(mode_t st_mode){
- if(S_ISREG(st_mode)){
- return "ficheiro normal";
- }else if(S_ISDIR(st_mode)){
- return "Diretorio";
- }else if(S_ISLNK(st_mode)){
- return "Atalho";
- }
- return "outro";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement