[유닉스 시스템 프로그래밍] 3장 파일과 디렉토리 (1)
- 최초 등록일
- 2022.02.09
- 최종 저작일
- 2021.11
- 9페이지/ MS 워드
- 가격 1,000원
목차
없음
본문내용
연습문제 1~3
1
1. #include <sys/types.h>
2. #include <sys/stat.h>
3. #include <unistd.h>
4. #include <stdio.h>
5. #include <stdlib.h>
6. #include <time.h>
7.
8. void printfFileAuthority(mode_t mode);
9.
10. int main(int argc, char *argv[]) {
11. char *src;
12.
13. // 인자값에 대한 처리
14. switch (argc) {
15. case 1:
16. printf("인자가 없습니다.\n");
17. exit(1);
18. break;
19. case 2:
20. src = argv[1];
21. break;
22. default:
23. printf("인자가 많습니다.\n");
24. exit(1);
25. break;
26. }
27.
28. struct stat buf, lbuf;
29. stat(src, &buf);
30. lstat(src, &lbuf);
31.
32. printf("파일명 : %s\n", src);
33. printf("Inode 번호 : %d\n", (int)buf.st_ino);
34.
35. printf("파일 종류 : ");
36. if (S_ISLNK(lbuf.st_mode)) {
37. printf("심볼릭 링크 파일");
38. }
39. else {
40. if (S_ISFIFO(buf.st_mode)) {
41. printf("FIFO 파일");
42. }
43. else if (S_ISCHR(buf.st_mode)) {
44. printf("문자 장치 특수 파일");
45. }
46. else if (S_ISDIR(buf.st_mode)) {
47. printf("디렉토리");
48. }
49. else if (S_ISBLK(buf.st_mode)) {
50. printf("블록 장치 특수 파일");
51. }
52. else if (S_ISREG(buf.st_mode)) {
53. printf("일반 파일");
54. }
참고 자료
없음