Contents

조회 수 8084 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
409 Develop [js]모바일 웹에서 orientationchange hooni 2013.04.23 20852
408 Develop [kotlin] 코틀린 안드로이드 앱 버전/빌드 정보 hooni 2020.12.15 2809
407 Develop [lego] 세그웨이 이것만 볼것.. ㅎㅎ file hooni 2013.04.23 36843
406 Etc [link] iOS(아이폰) 개발 관련 ㅋㅋ hooni 2013.04.23 22633
405 Etc [link] 유용한 사이트 링크. hooni 2013.08.19 130251
404 System/OS [linux] /etc/fstab 설정 방법.. ㅋㅋ hooni 2013.04.23 13136
403 System/OS [linux] apache, php, jsp 환경설정하기.. hooni 2003.04.23 16140
402 System/OS [linux] APM(apache, php, mysql) + gd 설치순서.. hooni 2003.04.23 20066
401 System/OS [linux] awk 명령어 hooni 2014.03.11 5994
400 System/OS [linux] CentOS 6.5 에서 "Bringing up interface eth0: Determining if ip address 121.78.127.197 is already in use for device eth0..." hooni 2014.04.05 7348
399 System/OS [linux] CentOS 6.x Cati 설치 (yum) hooni 2014.01.17 49587
398 System/OS [linux] CentOS Apache Httpd에 https 적용 hooni 2014.03.05 5330
Board Pagination Prev 1 ... 60 61 62 63 64 65 66 67 68 69 ... 99 Next
/ 99