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
번호 분류 제목 글쓴이 날짜 조회 수
849 System/OS [linux] 이기종간의 파일 공유(Samba) hooni 2003.04.23 14901
848 System/OS [linux] 웹로그분석기(webalizer) 설치 & 팁 hooni 2003.04.23 14884
847 System/OS [linux] 우분투 APM + phpmyadmin 설치 hooni 2013.10.07 49331
846 System/OS [linux] 아파치설치/설정(모니터링) hooni 2003.04.23 14154
845 System/OS [linux] 아파치설치/설정(CGI부분) hooni 2003.04.23 14569
844 System/OS [linux] 아파치설치/설정 - 알리어싱(aliasing) hooni 2003.04.23 51371
843 System/OS [linux] 아파치설치/설정 - 사용인증 hooni 2003.04.23 15088
842 System/OS [linux] 아파치설치/설정 - SSI(Server Side Include) hooni 2003.04.23 13207
841 System/OS [linux] 아파치설치/설정 hooni 2003.04.23 14492
840 System/OS [linux] 아파치 설치/설정(proxy) hooni 2003.04.23 12965
839 System/OS [linux] 시스템 데몬 종류와 설명 hooni 2013.04.23 11139
838 System/OS [linux] 스케쥴링 순서(nice) 변경하기 hooni 2003.04.23 12545
Board Pagination Prev 1 ... 23 24 25 26 27 28 29 30 31 32 ... 98 Next
/ 98