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
#include <unistd.h>    //file call f(x) include
#include <fcntl.h>
#include <assert.h>
 
int main(void)
{
    int fd;     // file descriptor 
    fd = open("data.dat", O_CREAT | O_WRONLY);//file open fail => return -1 
    
    assert(fd >= 0); // file open check
    
    //read(), write()
    write(fd, "hello, world", 12);
    
    
    close(fd);
    
    fd = open("data.dat", O_RDONLY);
    assert(fd >= 0);
    
    char msg[13]={0}; // char *str = "hello, world"; 
    read(fd, msg, 12);
    write(1, msg, 13); //memory 1
    write(1, "\n", 1); //memory 1
    
    return 0;
}


열린파일에 대한 정보를 저장하는 배열을 만든다.


열린파일의 정보를 가진 배열은 포인터배열



0 -> 표준입력장치 stdin

1 -> 표준출력장치 stdout

2 -> 표준에러출력장치 stderr

3 -> data.dat

(나중에 통신프로토콜을 만들때 처음 되는 소켓이 3번부터 저장된다)


리눅스에서는 모든 장치를 파일로 다룬다!





size_t        typedef unsiged int size_t i;


ssize_t     typedef int ssize_t i;  











Posted by 차희빈

차희빈

달력