Contents

조회 수 7162 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
613 Develop [js] 한글주소(URL) 인코딩(encode, Encoding), 자바스크립트(JavaScript) hooni 2013.04.23 11345
612 Develop [ios] iOS In App Purchase 코드 부분 샘플 2 hooni 2013.11.20 11328
611 Develop [unix] 유닉스 명령에 메타문자 사용 hooni 2014.02.19 11298
610 Develop [switch] 시스코 스위치(catalyst 2950) telnet 설정 hooni 2013.04.23 11295
609 Develop [c] 파일입출력 간단한 설명 hooni 2003.04.23 11271
608 Develop [c] 최대공약수, 최소공배수, 서로소 구하기 (펌) hooni 2013.04.23 11203
607 Develop [c] 파일입출력, 링크리스트(linked list)를 이용한 주소록(도스용) 소스코드 1 file hooni 2003.04.23 11187
606 Develop [iphone] 파일 업로드 샘플 코드 ㅎㅎ secret hooni 2013.04.23 11120
605 Develop [자료구조] 트리(tree) 용어정리 file hooni 2003.04.23 11104
604 Develop [c++] SetWindowPos함수를 이용한 크기조절 예제 1 file hooni 2013.04.23 11103
603 Develop [c] 네트워크 트래릭 모니터링.. 졸업작품.. 2 file hooni 2013.04.23 11071
602 Develop [c] 소수 구하기 #2 (입력한 숫자가 소수인지 판별하기..) hooni 2013.04.23 11003
Board Pagination Prev 1 ... 15 16 17 18 19 20 21 22 23 24 ... 71 Next
/ 71