Views 8084 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;
}

?

  1. [php] Laravel 4. twitter bootstrap 적용하기

    Date2018.04.05 CategoryDevelop Byhooni Views4663
    Read More
  2. [ios] SQLite 사용하기(튜토리얼) + 샘플코드

    Date2014.03.28 CategoryDevelop Byhooni Views4623
    Read More
  3. [ios] iOS에서 디바이스 종류 알아오기

    Date2014.05.24 CategoryDevelop Byhooni Views4606
    Read More
  4. [php][laravel] 라라벨 프로젝트 생성 및 구조

    Date2017.12.15 CategoryDevelop Byhooni Views4600
    Read More
  5. [php][laravel] 초간단 MacOS에서 Laravel 개발 환경 구축

    Date2017.12.15 CategoryDevelop Byhooni Views4599
    Read More
  6. [ios] URL 파라미터 파싱~

    Date2014.05.12 CategoryDevelop Byhooni Views4563
    Read More
  7. macOS에 node, npm 설치하기 (homebrew)

    Date2021.11.06 CategoryDevelop Byhooni Views4553
    Read More
  8. [ios] UILabel with two different color text

    Date2024.12.14 CategoryDevelop Byhooni Views4540
    Read More
  9. [js] jQuery 셀 병합

    Date2014.09.23 CategoryDevelop Byhooni Views4510
    Read More
  10. [ios] Sprite Kit & 사운드 재생시 백그라운드 진입시 앱이 비정상적으로 종료됨

    Date2014.04.18 CategoryDevelop Byhooni Views4489
    Read More
  11. [ios] 아이폰에서 진동(Vibrate) 기능 추가하기

    Date2014.04.18 CategoryDevelop Byhooni Views4472
    Read More
  12. [android] 딜레이를 구현하기 위한 꼼수

    Date2016.11.24 CategoryDevelop Byhooni Views4446
    Read More
  13. [ios] UIWebView 캐쉬 삭제

    Date2014.04.08 CategoryDevelop Byhooni Views4432
    Read More
  14. [ios] 유용한 매크로

    Date2014.03.26 CategoryDevelop Byhooni Views4427
    Read More
  15. [iOS] Xcode 불필요한 캐시 삭제하기

    Date2021.10.12 CategoryDevelop Byhooni Views4403
    Read More
  16. [js] Click button copy to clipboard

    Date2018.04.05 CategoryDevelop Byhooni Views4398
    Read More
Board Pagination Prev 1 ... 42 43 44 45 46 ... 53 Next
/ 53