Contents

조회 수 8088 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
589 Develop [css] 화면 스크롤 제어 ㅋㅋ hooni 2003.04.23 9691
588 Develop [c] CGI Library to C^^ hooni 2003.04.23 9691
587 Develop [c] 소수점 반올림^^ hooni 2003.04.23 9690
586 Develop [linux] 날짜나 파일의 내용으로 검색하는 방법(find 명령 사용) hooni 2013.04.23 9674
585 Develop [c] 파이프(popen)로 다른 프로세스 실행결과 가져오기 file hooni 2013.04.23 9669
584 Develop [c++] 쓰레드(Thread) 객체의 사용 hooni 2013.04.23 9664
583 Develop [c] 쓰레드에 대한 내용 퍼오기..ㅡㅡ; hooni 2013.04.23 9649
582 Develop [js] Text 중 URL 형식을 인식해 단축 URL로 변경 file hooni 2013.04.23 9617
581 Develop [c] 아파치 모듈(Apache Module) 만들기 hooni 2013.04.23 9616
580 Develop [c] 캘린더 양음 변환 함수 hooni 2003.04.23 9609
579 Develop [doc] Equation Solving에 대한 발표자료.. file hooni 2013.04.23 9601
578 Develop [c++] namespace 사용 예 hooni 2003.04.23 9547
Board Pagination Prev 1 ... 45 46 47 48 49 50 51 52 53 54 ... 99 Next
/ 99