Contents

조회 수 7152 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
369 System/OS [windows] 인터넷 익스플로러(IE) 도구모음 표시줄에 아이콘 추가 file hooni 2013.04.23 18216
368 System/OS [windows] 종료, 재시작, 로그아웃 아이콘 만들기 hooni 2013.04.23 18101
367 System/OS [router] 설정과 기본 명령어들 모음 hooni 2013.04.23 15669
366 System/OS NAT와 DHCP에 대한 간단한 설명 hooni 2013.04.23 18327
365 System/OS [linux] 간단한 find 명령어 설명(업데이트 해야 함) hooni 2013.04.23 9110
364 Etc [flash] 맘에 드는 파이차트 file hooni 2013.04.23 12588
363 Develop [web] 웹 연동 프로그램 모음.. file hooni 2013.04.23 6960
362 System/OS [doc] TCP/IP 강의 자료 (html) file hooni 2013.04.23 11170
361 System/OS [linux] 시스템 데몬 종류와 설명 hooni 2013.04.23 11138
360 System/OS [doc] 레드햇 리눅스 메뉴얼 (html버전) file hooni 2013.04.23 10451
359 Etc [flash] 페이지 이동 (액션스크립트) file hooni 2013.04.23 16261
358 PPT [ppt] 웜 과제 진행사항(프레임워크 검증환경 구축) 보고 file hooni 2013.04.23 15892
Board Pagination Prev 1 ... 63 64 65 66 67 68 69 70 71 72 ... 98 Next
/ 98