Contents

조회 수 7162 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
#define MAXSIZE 65535
#define CRLF "\n"

#include <string.h>
#include <stdio.h>
#include <unistd.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

const char *getline(int sockfd){
        static char buf[MAXSIZE + 1] = "";
        static char *pbuf = buf;

        int i;
        ssize_t len;

        char *retptr;
        char *crlf;

        do{
                /* 개행문자 찾으면 */
                if(crlf = strstr(pbuf, CRLF)){
                        retptr = pbuf;

                        pbuf = crlf + strlen(CRLF);
                        *crlf = '\0';

                        return retptr;
                }
                
                /* 못 찾았으면 */
                len = strlen(pbuf);
                for(i = 0; i < len; i++) buf[i] = pbuf[i];
                pbuf = buf;
        }while(read(sockfd, buf + len, MAXSIZE - len) > 0);
        /* 데이터 읽고 다시 개행문자 있는지 검사하러 올라가자 */

        return NULL; // 에러 또는 EOF
}

int main(){
        const char *line;

        int fd;
        fd = open("test.c", O_RDONLY);

        while(line = getline(fd))
                printf("LINE : '%s'\n", line);

        close(fd);

        return 0;
}


?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
613 Develop [js] get방식, url이후 모두 그대로 읽어오기.. hooni 2013.04.23 6865
612 Develop [js] e.stopPropagation() VS e.preventDefault () file hooni 2015.04.14 911
611 Develop [js] Closure를 이용해 캡슐화.. hooni 2013.12.16 9620
610 Develop [js] Click button copy to clipboard hooni 2018.04.05 1286
609 Develop [js] Array.splice() 설명 hooni 2014.04.24 3059
608 Develop [js] AngularJS를 소개합니다. file hooni 2014.01.06 13050
607 Develop [js] AngularJS 란? file hooni 2015.11.26 1024
606 Develop [js] ajax를 이용해 외부문서 불러오기.. hooni 2013.04.23 6808
605 Develop [js] 2차 잉여.. (Quadratic reciprocity) 계산.. file hooni 2013.04.23 7089
604 Develop [js] 2048 예쁘게 만들고 있는거.. ㅋㄷ secret hooni 2015.01.30 0
603 Develop [jsp][php] 간단한 강좌 자료.. file hooni 2003.04.23 8143
602 Develop [jsp][php] LDAP 프로그래밍.. file hooni 2003.04.23 7413
Board Pagination Prev 1 ... 15 16 17 18 19 20 21 22 23 24 ... 71 Next
/ 71