Contents

조회 수 8087 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
349 System/OS [ms-sql] 프로시져 예제.. file hooni 2013.04.23 14280
348 Develop [c#] 파일(File) 쓰기 ㅎㅎ hooni 2013.04.23 14294
347 Develop [ios][swift] 초간단 카달로그 앱 (Catalog App) file hooni 2016.06.27 14312
346 System/OS [linux] 간단한 vi편집기 사용 명령 hooni 2003.04.23 14382
345 System/OS [linux] Xwindow/Xmanager 사용 hooni 2003.04.23 14395
344 System/OS [linux] 기존 환경설정 저장하면서 커널 컴파일.. hooni 2003.04.23 14447
343 Develop [html] 캐쉬된 웹페이지 사용하지 않도록 하는 방법 hooni 2003.04.23 14449
342 System/OS [linux] ipchains 옵션 hooni 2003.04.23 14450
341 Develop [js] 자바스크립트를 동적으로 로딩하기 hooni 2013.04.23 14455
340 System/OS [linux] 쉘 스크립트에 대한 설명과 예제.. hooni 2003.04.23 14484
339 System/OS [linux] 셀 스크립트 if, for, case in.. hooni 2003.04.23 14500
338 Develop [c] flooding 알고리즘 미로 찾기(도스용) 소스코드 9 file hooni 2003.04.23 14524
Board Pagination Prev 1 ... 65 66 67 68 69 70 71 72 73 74 ... 99 Next
/ 99