일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- For Beginners
- 브런치
- 균형잡힌 세상
- QA
- file IO
- 입력 버퍼
- IT
- 시스템 프로그래밍
- 전자책
- 1874
- Baekjoon
- Zero That Out
- The Balance of the World
- c
- 바샤
- File 조작
- 2941
- BAKA
- process control
- LJESNJAK
- 시프
- 5622
- system programming
- Parenthesis
- 해바
- 4949
- 백준
- c++
- Process Communication
- 10773
- Today
- Total
목록file IO (4)
해바
커맨드 라인에서 아래와 같은 내용을 입력받는다 : % ./a.out access() 시스템 호출을 이용하여, 만약 파일이 존재하면 파일에서 20-byte의 데이터를 읽어서 std-out에 출력한다. 만약 존재하지 않으면 파일을 새로 만들어, "hello world"라는 내용을 파일에 write 한다. 자기 홈 디렉토리에 lab4 디렉토리를 만든 후 프로그램 파일(access.c)을 보관할 것 #include #include #include #include #include #include #include #define SIZE 20 int main(int argc, char* argv[]) { int fd; if(argc != 2) printf("usage : a.out "); if(access(argv[..
stat() 시스템 호출을 이용하여 파일의 정보를 출력한다 : 주어진 하나의 파일의 inode 번호를 출력한다. 해당 파일의 처음 생성 날짜/시간, 마지막으로 업데이트 된 날짜/시간, 마지막으로 접근한 날짜/시간을 출력한다. 자기 홈 디렉토리에 lab3 디렉토리를 만든 후 프로그램 파일(stat.c)을 보관할 것 #include #include #include #include int main() { int fd; struct stat sb; if(stat("testfile", &sb) == -1) { perror("stat"); return 1; } printf("Inode number : %ld\n", (long)sb.st_ino); printf("처음 생성 날짜/시간 : %s", ctime(&sb.s..
lseek() 시스템 호출을 사용하여, 파일의 원하는 부분을 출력하도록 만든다 : 테스트용 입력파일 "test.txt"에 "abcdefghijklmnop"를 저장한다. lseek 를 사용하여 파일의 시작에서 10개의 character를 건너뛴 후 부터의 내용을 출력한다. lseek 를 사용하여 파일의 끝에서 앞쪽으로 5개의 character를 건너뛴 후 그 내용을 출력한다. 자기 홈 디렉토리에 lab2 디렉토리를 만든 후 프로그램 파일 size.c를 보관할 것 #include #include #include #include #include #include #define BUFSIZE 512 int main() { int fd; char buf1[BUFSIZE] = ""; char buf2[BUFSIZE]..
open(), close(), read(), write() 시스템 호출을 이용하여, 한 파일의 내용을 다른 파일에 복사하는 copy.c 프로그램을 작성하라. #include #include #include #include #define BUFSIZE 512 #define PERMS 0644 int main(int argc, char** argv) { char buffer[BUFSIZE]; int ofd, nfd;// ofd : 원본파일, nfd : 생성할 파일 ssize_t nread; if((ofd = open(argv[1], O_RDONLY)) == -1) { printf("Cannot open %s\n", argv[1]); exit(1); } // 원본파일 열기 if((nfd = open(argv[..