Contents

Views 7161 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
#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
No. Category Subject Author Date Views
325 Develop [c] 압축 알고리즘 소스 및 정리 file hooni 2013.04.23 8787
324 Develop [java] 채팅창 처럼.. swing.. file hooni 2013.04.23 8790
323 Develop [c++] 레지스트리 등록 예제 1 file hooni 2013.04.23 8807
322 Develop [c++] mfc 이용한 트레이아이콘(TrayIcon) 클래스 예제 프로젝트 file hooni 2013.04.23 8819
321 Develop [c] 함수 요약 (검색해서 쓰세요..) hooni 2003.04.23 8828
320 Develop [c++] 윈도우 프로세스뷰어 분석.. ㅋㅋ file hooni 2013.04.23 8856
319 Develop [c] 지나가는 패킷 잡기 hooni 2003.04.23 8861
318 Develop [html] SVG(Scalable Vector Graphics) 간단 정리 hooni 2014.02.13 8862
317 Develop [js] 초간단 암호화/복호화 소스.. hooni 2003.04.23 8864
316 Develop [c] 약수/최대공약수/완전수 알고리즘 hooni 2003.04.23 8892
315 Develop [c++] 채팅로봇 소스.. ㅋㄷㅋㄷ file hooni 2013.04.23 8898
314 Develop [js] jQjuery $ 활용 hooni 2013.12.17 8898
Board Pagination Prev 1 ... 39 40 41 42 43 44 45 46 47 48 ... 71 Next
/ 71