Advertisement
Guest User

Untitled

a guest
May 31st, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. /**
  2. * @file main.c
  3. * @brief Description
  4. * @date 2015-10-24
  5. * @author name of author
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <sys/types.h>
  11. #include <sys/wait.h>
  12. #include <unistd.h>
  13. #include <signal.h>
  14. #include <errno.h>
  15. #include <string.h>
  16. #include <sys/types.h>
  17. #include <sys/ipc.h>
  18. #include <sys/sem.h>
  19. #include <sys/shm.h>
  20. #include <sys/stat.h>
  21. #include <fcntl.h>
  22. #include <assert.h>
  23.  
  24. #include "debug.h"
  25. #include "memory.h"
  26.  
  27. char *tipo_file_str(mode_t st_mode);
  28.  
  29. int main(int argc, char *argv[]){
  30.  
  31. if(argc < 2){
  32. //fprintf(stderr, "Numero de argumentos invalido!\nRecebi %i em vez de 2!\nSyntax: %s path_fich\n", argc, argv[0]);
  33. //exit(1);
  34. ERROR(1, "Numero de argumentos invalido!\nRecebi %i em vez de 2!\nSyntax: %s path_fich\n", argc, argv[0]);
  35. }
  36.  
  37. int ret_stat;
  38. struct stat stat_buf;
  39. int i;
  40.  
  41. for(i=1;i<argc;i++){
  42.  
  43. ret_stat = stat(argv[i],&stat_buf);
  44. if(ret_stat==-1){
  45. fprintf(stderr,"Erro: chamada stat para recurso '%s' - %s\n",argv[i],strerror(errno));
  46. exit(1);
  47. }
  48. printf("O ficheiro %s e um %s\n", argv[i], tipo_file_str(stat_buf.st_mode));
  49.  
  50. }
  51.  
  52.  
  53. return 0;
  54. }
  55.  
  56. char *tipo_file_str(mode_t st_mode){
  57. if(S_ISREG(st_mode)){
  58. return "ficheiro normal";
  59. }else if(S_ISDIR(st_mode)){
  60. return "Diretorio";
  61. }else if(S_ISLNK(st_mode)){
  62. return "Atalho";
  63. }
  64.  
  65. return "outro";
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement