Views 7152 Votes 0 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
25 Develop 라이브러리에 대한 설명 (static & dynamic library) hooni 2013.04.23 6946
24 Develop 레고 NXT 마인드스톰 밸런싱 로봇 ㅎㅎ file hooni 2013.04.23 57714
23 Develop 레고 마인드스톰 NXT 수도쿠, 큐브 소스코드.. 20 file hooni 2013.04.23 81421
22 Develop 리팩토링 계획안 file hooni 2017.05.15 751
21 Develop 링크들 보고 지울 내용 secret hooni 2019.11.21 0
20 Develop 모터에 대한 pid 제어.. ㅎㅎ file hooni 2013.04.23 18878
19 Develop 밸런싱 로봇.. 최종.. (관련 논문도 첨부) ㅋㅋ file hooni 2013.04.23 22820
18 Develop 베지어 곡선(Bézier curve) 알고리즘(spline 곡선) 3 file hooni 2013.04.23 33267
17 Develop 사이버보안실무 발표자료 (2017.06.08) file hooni 2017.06.05 1211
16 Develop 사이버보안실무 수업 메모 secret hooni 2017.03.23 0
15 Develop 서기의 PHP 동영상 강의(싱싱해) hooni 2013.05.15 30982
14 Develop 아이 훌레시 작업중 ㅋㅋ secret hooni 2013.08.09 0
13 Develop 알고리즘 성능 분석 기준 hooni 2014.06.24 2786
12 Develop 알고리즘 성능분석 file hooni 2014.06.24 2965
11 Develop 웹페이지 성능 테스트 툴 설명 hooni 2013.04.23 27447
10 Develop 이어서 작업할 내용~ secret hooni 2013.11.21 0
Board Pagination Prev 1 ... 49 50 51 52 53 Next
/ 53