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
번호 분류 제목 글쓴이 날짜 조회 수
345 System/OS [linux] 메타(기호)문자의 의미와 사용 hooni 2003.04.23 16386
344 System/OS [linux] 새 하드디스크 추가하기..(내공쌓기) hooni 2003.04.23 13807
343 System/OS [linux] 센드메일 동적릴레이 설치 hooni 2003.04.23 15228
342 System/OS [linux] 셀 스크립트 if, for, case in.. hooni 2003.04.23 13688
341 System/OS [linux] 쉘 스크립트 (Shell Script) hooni 2003.04.23 12064
340 Develop [linux] 쉘 스크립트를 이용한 BBS hooni 2003.04.23 10047
339 System/OS [linux] 쉘 스크립트에 대한 설명과 예제.. hooni 2003.04.23 13413
338 System/OS [linux] 쉘 환경변수 PS1(프롬프트) hooni 2003.04.23 13492
337 System/OS [linux] 쉘스크립트 expr hooni 2014.03.11 15619
336 System/OS [linux] 스케쥴링 순서(nice) 변경하기 hooni 2003.04.23 12538
335 System/OS [linux] 시스템 데몬 종류와 설명 hooni 2013.04.23 11139
334 System/OS [linux] 아파치 설치/설정(proxy) hooni 2003.04.23 12965
Board Pagination Prev 1 ... 65 66 67 68 69 70 71 72 73 74 ... 98 Next
/ 98