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
번호 분류 제목 글쓴이 날짜 조회 수
363 Develop [php] php+db 연동(odbc, mssql, mysql, sybase) 3 hooni 2013.04.23 9695
362 Develop [js] 초간단 암호화/복호화 소스.. hooni 2003.04.23 9722
361 Develop [c] 숫자(int, Number)를 hex코드로 변환하는 소스 file hooni 2013.04.23 9723
360 Develop [c] UCP/TCP 채팅 소스 - 정리해야 함.. file hooni 2003.04.23 9724
359 Develop [c++] 레지스트리 등록 예제 1 file hooni 2013.04.23 9724
358 Develop [js] 스크롤을 포함한 마우스 위치 찾는 코드 hooni 2003.04.23 9727
357 Develop [c] 레포트용으로 제출했던 여러 소스코드 모음 file hooni 2003.04.23 9728
356 Develop [c] 압축 알고리즘 소스 및 정리 file hooni 2013.04.23 9732
355 Develop [c] fgets() 함수 사용하기.. hooni 2003.04.23 9747
354 Develop [c] 지나가는 패킷 잡기 hooni 2003.04.23 9774
353 Develop [c++] 채팅로봇 소스.. ㅋㄷㅋㄷ file hooni 2013.04.23 9789
352 Develop [c] OpenGL 시어핀스키 가스킷(p.73 - 첫시간) hooni 2003.04.23 9812
Board Pagination Prev 1 ... 36 37 38 39 40 41 42 43 44 45 ... 71 Next
/ 71