학교 수업 및 과제/유닉스 프로그래밍
[UNIX 시스템 프로그래밍] 연습문제 3.6 풀이
goId
2018. 5. 30. 14:27
[UNIX 시스템 프로그래밍 second Edition - KEITH HAVILAND저] 연습문제 풀이입니다.
(저작권에 저촉 될 우려가 있어 문제 내용은 생략합니다.)
연습문제 3.6 입니다.
주어진 화일에 대해 읽기, 쓰기 또는 수행접근 여부를 확인하기 위해 access 함수를 이용했습니다.
코드를 보면 쉽게 이해할 것이라 생각합니다.
코드는 C++로 작성하였습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <stdio.h> #include <stdlib.h> #include <unistd.h> void whatable(char* filename) { if(access (filename, R_OK) == -1) perror("cannot read "); else printf("%s readable, proceeding\n", filename); if(access (filename, W_OK) == -1) perror("cannot write "); else printf("%s writeable, proceeding\n", filename); if(access (filename, X_OK) == -1) perror("cannot execute "); else printf("%s executable, proceeding\n", filename); } int main(int argc, char* argv[]) { if(argc == 2) whatable(argv[1]); else { printf("error : no filename or many filename\n"); return -1; } return 0; } | cs |