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 [ios] NSNotificationCenter 초간단 사용 예~ ㅋㄷ hooni 2015.06.26 654
24 Develop [ios] SBCampanion App 초안 file hooni 2015.09.16 653
23 Develop [ios] VIN Scanner (VIN barcode) 스캐너 file hooni 2017.09.16 644
22 Develop [ppt] iOS 플라랩#04(2015.06.19) 발표 자료 file hooni 2015.06.04 636
21 Develop [sh] html 안에 있는 img 다운 받는 쉘 스크립트 file hooni 2020.05.26 635
20 Develop [ios] NSData to NSString (NSString to NSData) hooni 2015.07.21 632
19 Develop [ios] 앱의 로컬 js 파일에서 해당 프로젝트의 이미지 불러오기 hooni 2015.02.10 623
18 Develop [php] XE에서 도메인 별로 광고 다르게 적용하기 file hooni 2015.01.28 612
17 Develop [ios] 새로 만들고 있는 DateMemo file hooni 2016.07.12 600
16 Develop [php] XE 스킨에서 특정 도메인 리다이렉션 file hooni 2015.01.28 573
15 Develop [js] 주소표시줄 URL 읽어오기 (변경까지) secret hooni 2014.01.21 1
14 Develop [iphone] PerfectlyClear 보정솔루션 최신.. secret hooni 2013.05.28 0
13 Develop [ios] IB 없이 개발하기 (html) secret hooni 2013.05.31 0
12 Develop [ios] 스터디 자료 (from 종길M) secret hooni 2013.06.04 0
11 Develop [ios] 패스(path) 앱 메뉴 스타일 secret hooni 2013.06.11 0
10 Develop 이어서 작업할 내용~ secret hooni 2013.11.21 0
Board Pagination Prev 1 ... 49 50 51 52 53 Next
/ 53